Freeciv-3.4
Loading...
Searching...
No Matches
ruleload.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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#include <stdarg.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23/* utility */
24#include "bitvector.h"
25#include "deprecations.h"
26#include "fcintl.h"
27#include "log.h"
28#include "mem.h"
29#include "registry.h"
30#include "shared.h"
31#include "string_vector.h"
32#include "support.h"
33
34/* common */
35#include "accessarea.h"
36#include "achievements.h"
37#include "actions.h"
38#include "ai.h"
39#include "base.h"
40#include "capability.h"
41#include "city.h"
42#include "counters.h"
43#include "effects.h"
44#include "extras.h"
45#include "fc_types.h"
46#include "featured_text.h"
47#include "game.h"
48#include "government.h"
49#include "map.h"
50#include "movement.h"
51#include "multipliers.h"
52#include "name_translation.h"
53#include "nation.h"
54#include "packets.h"
55#include "player.h"
56#include "requirements.h"
57#include "rgbcolor.h"
58#include "road.h"
59#include "sex.h"
60#include "specialist.h"
61#include "style.h"
62#include "tech.h"
63#include "tiledef.h"
64#include "traderoutes.h"
65#include "unit.h"
66#include "unittype.h"
67
68/* server */
69#include "citytools.h"
70#include "notify.h"
71#include "plrhand.h"
72#include "rscompat.h"
73#include "rssanity.h"
74#include "settings.h"
75#include "srv_main.h"
76
77/* server/advisors */
78#include "advruleset.h"
79
80/* server/scripting */
81#include "script_server.h"
82
83#include "ruleload.h"
84
85/* RULESET_SUFFIX already used, no leading dot here */
86#define RULES_SUFFIX "ruleset"
87#define SCRIPT_SUFFIX "lua"
88
89#define ADVANCE_SECTION_PREFIX "advance_"
90#define TECH_CLASS_SECTION_PREFIX "techclass_"
91#define BUILDING_SECTION_PREFIX "building_"
92#define CITYSTYLE_SECTION_PREFIX "citystyle_"
93#define MUSICSTYLE_SECTION_PREFIX "musicstyle_"
94#define UEFF_SECTION_PREFIX "ueff_"
95#define EFFECT_SECTION_PREFIX "effect_"
96#define GOVERNMENT_SECTION_PREFIX "government_"
97#define NATION_SET_SECTION_PREFIX "nset" /* without underscore? */
98#define NATION_GROUP_SECTION_PREFIX "ngroup" /* without underscore? */
99#define NATION_SECTION_PREFIX "nation" /* without underscore? */
100#define STYLE_SECTION_PREFIX "style_"
101#define CLAUSE_SECTION_PREFIX "clause_"
102#define EXTRA_SECTION_PREFIX "extra_"
103#define BASE_SECTION_PREFIX "base_"
104#define ROAD_SECTION_PREFIX "road_"
105#define RESOURCE_SECTION_PREFIX "resource_"
106#define TILEDEF_SECTION_PREFIX "tiledef_"
107#define GOODS_SECTION_PREFIX "goods_"
108#define SPECIALIST_SECTION_PREFIX "specialist_"
109#define SUPER_SPECIALIST_SECTION_PREFIX "super_specialist_"
110#define TERRAIN_SECTION_PREFIX "terrain_"
111#define UNIT_CLASS_SECTION_PREFIX "unitclass_"
112#define UNIT_SECTION_PREFIX "unit_"
113#define DISASTER_SECTION_PREFIX "disaster_"
114#define ACHIEVEMENT_SECTION_PREFIX "achievement_"
115#define ENABLER_SECTION_PREFIX "enabler_"
116#define ACTION_SECTION_PREFIX "action_"
117#define MULTIPLIER_SECTION_PREFIX "multiplier_"
118#define COUNTER_SECTION_PREFIX "counter_"
119
120#define check_name(name) (check_strlen(name, MAX_LEN_NAME, nullptr))
121#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, nullptr))
122
123/* Avoid re-reading files */
124static const char name_too_long[] = "Name \"%s\" too long; truncating.";
125#define MAX_SECTION_LABEL 64
126#define section_strlcpy(dst, src) \
127 (void) loud_strlcpy(dst, src, MAX_SECTION_LABEL, name_too_long)
128static char *resource_sections = nullptr;
129static char *terrain_sections = nullptr;
130static char *extra_sections = nullptr;
131static char *base_sections = nullptr;
132static char *road_sections = nullptr;
133static char *tiledef_sections = nullptr;
134
136
137static bool load_rulesetdir(const char *rsdir, bool compat_mode,
139 bool act, bool buffer_script, bool load_luadata);
140static struct section_file *openload_ruleset_file(const char *whichset,
141 const char *rsdir);
142
143static bool load_game_names(struct section_file *file,
144 struct rscompat_info *compat);
145static bool load_action_names(struct section_file *file,
146 struct rscompat_info *compat);
147static bool load_tech_names(struct section_file *file,
148 struct rscompat_info *compat);
149static bool load_unit_names(struct section_file *file,
150 struct rscompat_info *compat);
151static bool load_building_names(struct section_file *file,
152 struct rscompat_info *compat);
153static bool load_government_names(struct section_file *file,
154 struct rscompat_info *compat);
155static bool load_terrain_names(struct section_file *file,
156 struct rscompat_info *compat);
157static bool load_style_names(struct section_file *file,
158 struct rscompat_info *compat);
159static bool load_nation_names(struct section_file *file,
160 struct rscompat_info *compat);
161static bool load_city_name_list(struct section_file *file,
162 struct nation_type *pnation,
163 const char *secfile_str1,
164 const char *secfile_str2,
165 const char **allowed_terrains,
166 size_t atcount);
167
168static bool load_ruleset_techs(struct section_file *file,
169 struct rscompat_info *compat);
170static bool load_ruleset_units(struct section_file *file,
171 struct rscompat_info *compat);
172static bool load_ruleset_buildings(struct section_file *file,
173 struct rscompat_info *compat);
174static bool load_ruleset_governments(struct section_file *file,
175 struct rscompat_info *compat);
176static bool load_ruleset_terrain(struct section_file *file,
177 struct rscompat_info *compat);
178static bool load_ruleset_styles(struct section_file *file,
179 struct rscompat_info *compat);
180static bool load_ruleset_cities(struct section_file *file,
181 struct rscompat_info *compat);
182static bool load_ruleset_effects(struct section_file *file,
183 struct rscompat_info *compat);
184static bool load_ruleset_game(struct section_file *file, bool act,
185 struct rscompat_info *compat);
186static bool load_ruleset_actions(struct section_file *file,
187 struct section_file *gamefile,
188 struct rscompat_info *compat);
189
190static void send_ruleset_tech_classes(struct conn_list *dest);
191static void send_ruleset_techs(struct conn_list *dest);
192static void send_ruleset_unit_classes(struct conn_list *dest);
193static void send_ruleset_units(struct conn_list *dest);
194static void send_ruleset_buildings(struct conn_list *dest);
195static void send_ruleset_terrain(struct conn_list *dest);
196static void send_ruleset_resources(struct conn_list *dest);
197static void send_ruleset_extras(struct conn_list *dest);
198static void send_ruleset_bases(struct conn_list *dest);
199static void send_ruleset_roads(struct conn_list *dest);
200static void send_ruleset_tiledefs(struct conn_list *dest);
201static void send_ruleset_goods(struct conn_list *dest);
202static void send_ruleset_governments(struct conn_list *dest);
203static void send_ruleset_styles(struct conn_list *dest);
204static void send_ruleset_clauses(struct conn_list *dest);
205static void send_ruleset_musics(struct conn_list *dest);
206static void send_ruleset_cities(struct conn_list *dest);
207static void send_ruleset_game(struct conn_list *dest);
208static void send_ruleset_team_names(struct conn_list *dest);
209
210static bool load_ruleset_veteran(struct section_file *file,
211 const char *path,
212 struct veteran_system **vsystem, char *err,
213 size_t err_len);
214static bool load_specialist(const struct section *psection,
215 struct specialist *s,
216 struct section_file *file);
218 int def, int min, int max,
219 const char *path, ...)
221
222char *script_buffer = nullptr;
223char *parser_buffer = nullptr;
224
225/**********************************************************************/
230 const char *file, const char *function,
232 const char *format, ...)
233{
234 va_list args;
235 char buf[MAX_LEN_LOG_LINE];
236
237 if (logger == nullptr && !log_do_output_for_level(level)) {
238 return;
239 }
240
241 va_start(args, format);
242 if (logger != nullptr) {
243 fc_vsnprintf(buf, sizeof(buf), format, args);
244 logger(buf);
245 } else {
246 vdo_log(file, function, line, FALSE, level, buf, sizeof(buf), format, args);
247 }
248 va_end(args);
249
250 if (LOG_FATAL >= level) {
252 }
253}
254
255/**********************************************************************/
259{
260 int purged = 0;
261
262 action_iterate(act_id) {
263 struct action *paction = action_by_number(act_id);
264
266 == 0) {
267 /* Not relevant. */
268 continue;
269 }
270
271 /* Impossible hard requirement. */
273 /* Make sure that all action enablers are disabled. */
275 ae) {
276 ae->rulesave.ruledit_disabled = TRUE;
277 purged++;
279
280 log_normal("Purged all action enablers for %s",
282 }
283
284 /* Impossible requirement vector requirement. */
286 ae) {
287 if (!ae->rulesave.ruledit_disabled
289 || req_vec_is_impossible_to_fulfill(&ae->target_reqs))) {
290 ae->rulesave.ruledit_disabled = TRUE;
291 purged++;
292 log_normal("Purged unused action enabler for %s",
294 }
297
298 return purged;
299}
300
301/**********************************************************************/
305{
306 int purged = 0;
307 enum effect_type type;
308
313 eft->rulesave.do_not_save = TRUE;
314 purged++;
315 log_normal("Purged unused effect for %s",
316 effect_type_name(eft->type));
317 }
319 }
320
321 return purged;
322}
323
324/**********************************************************************/
328{
329 int purged = 0;
330
333
334 return purged;
335}
336
337/**********************************************************************/
342 const char *msg)
343{
344 struct req_vec_problem *problem;
345 bool result;
346
348 reqs);
349
350 if (problem == nullptr) {
351 /* No problem. */
352 return FALSE;
353 }
354
355 if (problem->num_suggested_solutions == 0) {
356 /* No solution. */
358 return FALSE;
359 }
360
361 if (problem->num_suggested_solutions == 1
362 && problem->suggested_solutions[0].operation == RVCO_REMOVE) {
363 /* Remove !present req that never is there. */
364 log_normal("%s", msg);
365 result = req_vec_change_apply(&problem->suggested_solutions[0],
368 return result;
369 }
370
371 /* Not handled. Don't know what this is. */
372 fc_assert(problem->num_suggested_solutions == 1);
374 return FALSE;
375}
376
377/**********************************************************************/
382 const char *msg)
383{
384 struct req_vec_problem *problem;
385 bool result;
386
388 reqs);
389
390 if (problem == nullptr) {
391 /* No problem. */
392 return FALSE;
393 }
394
395 if (problem->num_suggested_solutions == 0) {
396 /* No solution. */
398 return FALSE;
399 }
400
401 if (problem->num_suggested_solutions == 2
402 && problem->suggested_solutions[0].operation == RVCO_REMOVE
403 && problem->suggested_solutions[1].operation == RVCO_REMOVE
404 && are_requirements_equal(&problem->suggested_solutions[0].req,
405 &problem->suggested_solutions[1].req)) {
406 /* Simple duplication is handled. */
407 log_normal("%s", msg);
408 result = req_vec_change_apply(&problem->suggested_solutions[1],
411 return result;
412 }
413
414 /* Requirements of different kinds making each other redundant isn't
415 * supported yet. It could be done by always removing the most general
416 * requirement. So unit type is kept when redundant with unit flag, unit
417 * class and unit class flag etc. */
419 return FALSE;
420}
421
422/**********************************************************************/
427 const char *msg)
428{
429 return (purge_unused_req_vec(reqs, msg)
431}
432
433/**********************************************************************/
438{
439 int purged = 0;
440
441 action_iterate(act_id) {
442 struct action *paction = action_by_number(act_id);
443 char actor_reqs[MAX_LEN_NAME * 2];
444 char target_reqs[MAX_LEN_NAME * 2];
445
446 /* Error log text */
447 fc_snprintf(actor_reqs, sizeof(actor_reqs),
448 "Purged redundant requirement in"
449 " %s in action enabler for %s",
450 "actor_reqs", action_rule_name(paction));
451 fc_snprintf(target_reqs, sizeof(target_reqs),
452 "Purged redundant requirement in"
453 " %s in action enabler for %s",
454 "target_reqs", action_rule_name(paction));
455
456 /* Do the purging. */
458 ae) {
459 while (!ae->rulesave.ruledit_disabled
460 && (purge_redundant_req_vec(&ae->actor_reqs, actor_reqs)
461 || purge_redundant_req_vec(&ae->target_reqs,
462 target_reqs))) {
463 purged++;
464 }
467
468 return purged;
469}
470
471/**********************************************************************/
476{
477 int purged = 0;
478 enum effect_type type;
479
482 char msg[MAX_LEN_NAME * 2];
483
484 /* Error log text */
485 fc_snprintf(msg, sizeof(msg),
486 "Purged redundant requirement in effect of type %s",
488
489 /* Do the purging. */
491 while (purge_redundant_req_vec(&eft->reqs, msg)) {
492 purged++;
493 }
495 }
496
497 return purged;
498}
499
500/**********************************************************************/
505{
506 int purged = 0;
507
510
511 if (purged > 0) {
512 /* An unused requirement may be an obligatory hard requirement. */
514 }
515
516 return purged;
517}
518
519/**********************************************************************/
523static const char *valid_ruleset_filename(const char *subdir,
524 const char *name,
525 const char *extension,
526 bool optional)
527{
528 char filename[512];
529 const char *dfilename;
530
531 fc_assert_ret_val(subdir && name && extension, nullptr);
532
533 fc_snprintf(filename, sizeof(filename), "%s" DIR_SEPARATOR "%s.%s",
535 log_verbose("Trying \"%s\".", filename);
536 dfilename = fileinfoname(get_data_dirs(), filename);
537 if (dfilename) {
538 return dfilename;
539 }
540
541 fc_snprintf(filename, sizeof(filename), "default" DIR_SEPARATOR "%s.%s", name, extension);
542 log_verbose("Trying \"%s\": default ruleset directory.", filename);
543 dfilename = fileinfoname(get_data_dirs(), filename);
544 if (dfilename) {
545 return dfilename;
546 }
547
548 fc_snprintf(filename, sizeof(filename), "%s_%s.%s",
550 log_verbose("Trying \"%s\": alternative ruleset filename syntax.",
551 filename);
552 dfilename = fileinfoname(get_data_dirs(), filename);
553 if (dfilename) {
554 return dfilename;
555 } else if (!optional) {
556 ruleset_error(nullptr, LOG_ERROR,
557 /* TRANS: message about an installation error. */
558 _("Could not find a readable \"%s.%s\" ruleset file."),
559 name, extension);
560 }
561
562 return nullptr;
563}
564
565/**********************************************************************/
569{
570 return script_buffer;
571}
572
573/**********************************************************************/
577{
578 return parser_buffer;
579}
580
581/**********************************************************************/
585static struct section_file *openload_ruleset_file(const char *whichset,
586 const char *rsdir)
587{
588 char sfilename[512];
591 struct section_file *secfile;
592
593 if (dfilename == nullptr) {
594 return nullptr;
595 }
596
597 /* Need to save a copy of the filename for following message, since
598 section_file_load() may call datafilename() for includes. */
600 secfile = secfile_load(sfilename, FALSE);
601
602 if (secfile == nullptr) {
603 ruleset_error(nullptr, LOG_ERROR, "Could not load ruleset '%s':\n%s",
605 }
606
607 return secfile;
608}
609
610/**********************************************************************/
613static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir,
614 char **buffer, bool optional)
615{
618
619 if (dfilename == nullptr) {
620 return optional ? TRI_MAYBE : TRI_NO;
621 }
622
623 if (buffer == nullptr) {
624 if (!script_server_do_file(nullptr, dfilename)) {
625 ruleset_error(nullptr, LOG_ERROR,
626 "\"%s\": could not load ruleset script.",
627 dfilename);
628
629 return TRI_NO;
630 }
631 } else {
633 }
634
635 return TRI_YES;
636}
637
638/**********************************************************************/
641static struct section_file *openload_luadata_file(const char *rsdir)
642{
643 struct section_file *secfile;
644 char sfilename[512];
645 const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
646 "txt", TRUE);
647
648 if (dfilename == nullptr) {
649 return nullptr;
650 }
651
652 /* Need to save a copy of the filename for following message, since
653 section_file_load() may call datafilename() for includes. */
655 secfile = secfile_load(sfilename, FALSE);
656
657 if (secfile == nullptr) {
658 ruleset_error(nullptr, LOG_ERROR, "Could not load luadata '%s':\n%s",
660 }
661
662 return secfile;
663}
664
665/**********************************************************************/
670 const char *sec,
671 const char *sub,
672 const char *rfor)
673{
674 const char *type, *name;
675 int j;
676 const char *filename;
677
678 filename = secfile_name(file);
679
681
682 for (j = 0; (type = secfile_lookup_str_default(file, nullptr, "%s.%s%d.type",
683 sec, sub, j)); j++) {
684 char buf[MAX_LEN_NAME];
685 const char *range;
686 bool survives, present, quiet;
687 struct entry *pentry;
688 struct requirement req;
689
690 if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name",
691 sec, sub, j))) {
692 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
693
694 return nullptr;
695 }
696 name = nullptr;
697 switch (entry_type_get(pentry)) {
698 case ENTRY_BOOL:
699 {
700 bool val;
701
702 if (entry_bool_get(pentry, &val)) {
703 fc_snprintf(buf, sizeof(buf), "%d", val);
704 name = buf;
705 }
706 }
707 break;
708 case ENTRY_INT:
709 {
710 int val;
711
712 if (entry_int_get(pentry, &val)) {
713 fc_snprintf(buf, sizeof(buf), "%d", val);
714 name = buf;
715 }
716 }
717 break;
718 case ENTRY_STR:
720 break;
721 case ENTRY_FLOAT:
723 ruleset_error(nullptr, LOG_ERROR,
724 "\"%s\": trying to have an floating point entry as a requirement name in '%s.%s%d'.",
725 filename, sec, sub, j);
726 break;
729 break;
732 break;
733 case ENTRY_ILLEGAL:
735 break;
736 }
737 if (name == nullptr) {
738 ruleset_error(nullptr, LOG_ERROR,
739 "\"%s\": error in handling requirement name for '%s.%s%d'.",
740 filename, sec, sub, j);
741 return nullptr;
742 }
743
744 if (!(range = secfile_lookup_str(file, "%s.%s%d.range", sec, sub, j))) {
745 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
746
747 return nullptr;
748 }
749
750 survives = FALSE;
751 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.survives",
752 sec, sub, j))
754 ruleset_error(nullptr, LOG_ERROR,
755 "\"%s\": invalid boolean value for survives for "
756 "'%s.%s%d'.", filename, sec, sub, j);
757 }
758
759 present = TRUE;
760 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.present",
761 sec, sub, j))
763 ruleset_error(nullptr, LOG_ERROR,
764 "\"%s\": invalid boolean value for present for "
765 "'%s.%s%d'.", filename, sec, sub, j);
766 }
767 quiet = FALSE;
768 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.quiet",
769 sec, sub, j))
770 && !entry_bool_get(pentry, &quiet)) {
771 ruleset_error(nullptr, LOG_ERROR,
772 "\"%s\": invalid boolean value for quiet for "
773 "'%s.%s%d'.", filename, sec, sub, j);
774 }
775
777 if (req.source.kind == universals_n_invalid()) {
778 ruleset_error(nullptr, LOG_ERROR,
779 "\"%s\" [%s] has invalid or unknown req: "
780 "\"%s\" \"%s\".",
781 filename, sec, type, name);
782
783 return nullptr;
784 }
785
787 }
788
789 return &reqs_list;
790}
791
792/**********************************************************************/
796 struct section_file *file,
797 const char *sec,
798 const char *sub)
799{
800 const char *flag;
801 int j;
802 const char *filename;
803 bool success = TRUE;
804
805 filename = secfile_name(file);
806
807 for (j = 0; (flag = secfile_lookup_str_default(file, nullptr, "%s.%s%d.flag",
808 sec, sub, j)); j++) {
809 struct combat_bonus *bonus = fc_malloc(sizeof(*bonus));
810 const char *type;
811
813 if (!unit_type_flag_id_is_valid(bonus->flag)) {
814 log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.",
815 filename, flag, sec, sub);
816 FC_FREE(bonus);
817 success = FALSE;
818 continue;
819 }
820 type = secfile_lookup_str(file, "%s.%s%d.type", sec, sub, j);
822 if (!combat_bonus_type_is_valid(bonus->type)) {
823 log_error("\"%s\": unknown bonus type \"%s\" in '%s.%s'.",
824 filename, type, sec, sub);
825 FC_FREE(bonus);
826 success = FALSE;
827 continue;
828 }
829 if (!secfile_lookup_int(file, &bonus->value, "%s.%s%d.value",
830 sec, sub, j)) {
831 log_error("\"%s\": failed to get value from '%s.%s%d'.",
832 filename, sec, sub, j);
833 FC_FREE(bonus);
834 success = FALSE;
835 continue;
836 }
838 "%s.%s%d.quiet",
839 sec, sub, j);
841 }
842
843 return success;
844}
845
846/**********************************************************************/
854static bool lookup_tech(struct section_file *file,
855 struct advance **result,
856 const char *prefix, const char *entry,
857 const char *filename,
858 const char *description)
859{
860 const char *sval;
861
862 sval = secfile_lookup_str_default(file, nullptr, "%s.%s", prefix, entry);
863 if (!sval || !strcmp(sval, "Never")) {
864 *result = A_NEVER;
865 } else {
866 *result = advance_by_rule_name(sval);
867
868 if (A_NEVER == *result) {
869 ruleset_error(nullptr, LOG_ERROR,
870 "\"%s\" %s %s: couldn't match \"%s\".",
871 filename, (description ? description : prefix), entry, sval);
872 return FALSE;
873 }
874 }
875
876 return TRUE;
877}
878
879/**********************************************************************/
886static bool lookup_unit_list(struct section_file *file, const char *prefix,
887 const char *entry,
888 struct unit_type **output,
889 const char *filename)
890{
891 const char **slist;
892 size_t nval;
893 int i;
894 bool ok = TRUE;
895
896 /* Pre-fill with nullptr: */
897 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
898 output[i] = nullptr;
899 }
900 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
901 if (nval == 0) {
902 /* 'No vector' is considered same as empty vector */
903 if (slist != nullptr) {
904 free(slist);
905 }
906 return TRUE;
907 }
908 if (nval > MAX_NUM_UNIT_LIST) {
909 ruleset_error(nullptr, LOG_ERROR,
910 "\"%s\": string vector %s.%s too long (%d, max %d)",
911 filename, prefix, entry, (int) nval, MAX_NUM_UNIT_LIST);
912 ok = FALSE;
913 } else if (nval == 1 && strcmp(slist[0], "") == 0) {
914 free(slist);
915 return TRUE;
916 }
917 if (ok) {
918 for (i = 0; i < nval; i++) {
919 const char *sval = slist[i];
921
922 if (!punittype) {
923 ruleset_error(nullptr, LOG_ERROR,
924 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
925 filename, prefix, entry, i, sval);
926 ok = FALSE;
927 break;
928 }
929 output[i] = punittype;
930 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
932 }
933 }
934 free(slist);
935
936 return ok;
937}
938
939/**********************************************************************/
946static bool lookup_tech_list(struct section_file *file, const char *prefix,
947 const char *entry, int *output,
948 const char *filename)
949{
950 const char **slist;
951 size_t nval;
952 int i;
953 bool ok = TRUE;
954
955 /* pre-fill with A_LAST: */
956 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
957 output[i] = A_LAST;
958 }
959 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
960 if (slist == nullptr || nval == 0) {
961 return TRUE;
962 } else if (nval > MAX_NUM_TECH_LIST) {
963 ruleset_error(nullptr, LOG_ERROR,
964 "\"%s\": string vector %s.%s too long (%d, max %d)",
965 filename, prefix, entry, (int) nval, MAX_NUM_TECH_LIST);
966 ok = FALSE;
967 }
968
969 if (ok) {
970 if (nval == 1 && strcmp(slist[0], "") == 0) {
971 FC_FREE(slist);
972 return TRUE;
973 }
974 for (i = 0; i < nval && ok; i++) {
975 const char *sval = slist[i];
977
978 if (padvance == nullptr) {
979 ruleset_error(nullptr, LOG_ERROR,
980 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
981 filename, prefix, entry, i, sval);
982 ok = FALSE;
983 }
984 if (!valid_advance(padvance)) {
985 ruleset_error(nullptr, LOG_ERROR,
986 "\"%s\" %s.%s (%d): \"%s\" is removed.",
987 filename, prefix, entry, i, sval);
988 ok = FALSE;
989 }
990
991 if (ok) {
992 output[i] = advance_number(padvance);
993 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
995 }
996 }
997 }
998 FC_FREE(slist);
999
1000 return ok;
1001}
1002
1003/**********************************************************************/
1010static bool lookup_building_list(struct section_file *file,
1011 const char *prefix, const char *entry,
1012 int *output, const char *filename)
1013{
1014 const char **slist;
1015 size_t nval;
1016 int i;
1017 bool ok = TRUE;
1018
1019 /* pre-fill with B_LAST: */
1020 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1021 output[i] = B_LAST;
1022 }
1023 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
1025 ruleset_error(nullptr, LOG_ERROR,
1026 "\"%s\": string vector %s.%s too long (%d, max %d)",
1027 filename, prefix, entry, (int) nval, MAX_NUM_BUILDING_LIST);
1028 ok = FALSE;
1029 } else if (nval == 0 || (nval == 1 && strcmp(slist[0], "") == 0)) {
1030 if (slist != nullptr) {
1031 FC_FREE(slist);
1032 }
1033 return TRUE;
1034 }
1035 if (ok) {
1036 for (i = 0; i < nval; i++) {
1037 const char *sval = slist[i];
1038 struct impr_type *pimprove = improvement_by_rule_name(sval);
1039
1040 if (pimprove == nullptr) {
1041 ruleset_error(nullptr, LOG_ERROR,
1042 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1043 filename, prefix, entry, i, sval);
1044 ok = FALSE;
1045 break;
1046 }
1047 output[i] = improvement_number(pimprove);
1048 log_debug("%s.%s,%d %s %d", prefix, entry, i, sval, output[i]);
1049 }
1050 }
1051 free(slist);
1052
1053 return ok;
1054}
1055
1056/**********************************************************************/
1062static bool lookup_unit_type(struct section_file *file,
1063 const char *prefix,
1064 const char *entry,
1065 const struct unit_type **result,
1066 const char *filename,
1067 const char *description)
1068{
1069 const char *sval;
1070
1071 sval = secfile_lookup_str_default(file, "None", "%s.%s", prefix, entry);
1072
1073 if (strcmp(sval, "None") == 0) {
1074 *result = nullptr;
1075 } else {
1076 *result = unit_type_by_rule_name(sval);
1077 if (*result == nullptr) {
1078 ruleset_error(nullptr, LOG_ERROR,
1079 "\"%s\" %s %s: couldn't match \"%s\".",
1080 filename, (description ? description : prefix), entry, sval);
1081
1082 return FALSE;
1083 }
1084 }
1085
1086 return TRUE;
1087}
1088
1089/**********************************************************************/
1093static struct government *lookup_government(struct section_file *file,
1094 const char *entry,
1095 const char *filename,
1096 struct government *fallback)
1097{
1098 const char *sval;
1099 struct government *gov;
1100
1101 sval = secfile_lookup_str_default(file, nullptr, "%s", entry);
1102 if (!sval) {
1103 gov = fallback;
1104 } else {
1106 }
1107 if (!gov) {
1108 ruleset_error(nullptr, LOG_ERROR,
1109 "\"%s\" %s: couldn't match \"%s\".",
1110 filename, entry, sval);
1111 }
1112 return gov;
1113}
1114
1115/**********************************************************************/
1118static char *lookup_string(struct section_file *file, const char *prefix,
1119 const char *suffix)
1120{
1121 const char *sval = secfile_lookup_str(file, "%s.%s", prefix, suffix);
1122
1123 if (sval != nullptr) {
1124 char copy[strlen(sval) + 1];
1125
1126 strcpy(copy, sval);
1128 if (strlen(copy) > 0) {
1129 return fc_strdup(copy);
1130 }
1131 }
1132
1133 return nullptr;
1134}
1135
1136/**********************************************************************/
1139static struct strvec *lookup_strvec(struct section_file *file,
1140 const char *prefix, const char *suffix)
1141{
1142 size_t dim;
1143 const char **vec = secfile_lookup_str_vec(file, &dim,
1144 "%s.%s", prefix, suffix);
1145
1146 if (vec != nullptr) {
1147 struct strvec *dest = strvec_new();
1148
1149 strvec_store(dest, vec, dim);
1150 free(vec);
1151 return dest;
1152 }
1153
1154 return nullptr;
1155}
1156
1157/**********************************************************************/
1160static struct extra_type *lookup_resource(const char *filename,
1161 const char *name,
1162 const char *jsection)
1163{
1164 struct extra_type *pres;
1165
1167
1168 if (pres == nullptr) {
1169 ruleset_error(nullptr, LOG_ERROR,
1170 "\"%s\" [%s] has unknown \"%s\".",
1171 filename, jsection, name);
1172 }
1173
1174 return pres;
1175}
1176
1177/**********************************************************************/
1181static bool lookup_terrain(struct section_file *file,
1182 const char *entry,
1183 const char *filename,
1184 struct terrain *pthis,
1185 struct terrain **result,
1186 bool null_acceptable)
1187{
1188 const int j = terrain_index(pthis);
1189 const char *jsection = &terrain_sections[j * MAX_SECTION_LABEL];
1190 const char *name = secfile_lookup_str(file, "%s.%s", jsection, entry);
1191 struct terrain *pterr;
1192
1193 if (name == nullptr && !null_acceptable) {
1194 return FALSE;
1195 }
1196
1197 if (name == nullptr
1198 || *name == '\0'
1199 || (0 == strcmp(name, "none"))
1200 || (0 == strcmp(name, "no"))) {
1201 *result = T_NONE;
1202
1203 return TRUE;
1204 }
1205 if (0 == strcmp(name, "yes")) {
1206 *result = pthis;
1207
1208 return TRUE;
1209 }
1210
1212 *result = pterr;
1213
1214 if (pterr == nullptr) {
1215 ruleset_error(nullptr, LOG_ERROR,
1216 "\"%s\" [%s] has unknown \"%s\".",
1217 secfile_name(file), jsection, name);
1218 return FALSE;
1219 }
1220
1221 return TRUE;
1222}
1223
1224/**********************************************************************/
1231static bool lookup_time(const struct section_file *secfile, int *turns,
1232 const char *sec_name, const char *property_name,
1233 const char *filename, const char *item_name,
1234 bool *ok)
1235{
1236 /* Assumes that PACKET_UNIT_INFO.activity_count in packets.def is UINT16 */
1237 const int max_turns = 65535 / ACTIVITY_FACTOR;
1238
1239 if (!secfile_lookup_int(secfile, turns, "%s.%s", sec_name, property_name)) {
1240 return FALSE;
1241 }
1242
1243 if (*turns > max_turns) {
1244 ruleset_error(nullptr, LOG_ERROR,
1245 "\"%s\": \"%s\": \"%s\" value %d too large (max %d)",
1246 filename, item_name ? item_name : sec_name,
1247 property_name, *turns, max_turns);
1248 *ok = FALSE;
1249 }
1250
1251 return TRUE; /* We found _something */
1252}
1253
1254/**********************************************************************/
1258 const char *domain,
1259 struct section_file *file,
1260 const char *sec_name)
1261{
1262 const char *name = secfile_lookup_str(file, "%s.name", sec_name);
1263 const char *rule_name = secfile_lookup_str(file, "%s.rule_name", sec_name);
1264
1265 if (!name) {
1266 ruleset_error(nullptr, LOG_ERROR,
1267 "\"%s\" [%s]: no \"name\" specified.",
1268 secfile_name(file), sec_name);
1269 return FALSE;
1270 }
1271
1272 names_set(pname, domain, name, rule_name);
1273
1274 return TRUE;
1275}
1276
1277/**********************************************************************/
1281 struct section_file *file,
1282 const char *secname, const char *field_prefix)
1283{
1284 enum trait tr;
1285
1286 /* FIXME: Use specenum trait names without duplicating them here.
1287 * Just needs to take care of case.
1288 * This list is also duplicated in rulesave.c:save_traits() */
1289 const char *trait_names[] = {
1290 "expansionist",
1291 "trader",
1292 "aggressive",
1293 "builder",
1294 nullptr
1295 };
1296
1297 for (tr = trait_begin();
1298 tr != trait_end() && trait_names[tr] != nullptr;
1299 tr = trait_next(tr)) {
1300 out[tr].min = secfile_lookup_int_default(file, -1, "%s.%s%s_min",
1301 secname,
1303 trait_names[tr]);
1304 out[tr].max = secfile_lookup_int_default(file, -1, "%s.%s%s_max",
1305 secname,
1307 trait_names[tr]);
1308 out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
1309 secname,
1311 trait_names[tr]);
1312 }
1313
1314 fc_assert(tr == trait_end()); /* number of trait_names correct */
1315}
1316
1317/**********************************************************************/
1321static bool load_game_names(struct section_file *file,
1322 struct rscompat_info *compat)
1323{
1324 struct section_list *sec;
1325 int nval;
1326 const char *filename = secfile_name(file);
1327 bool ok = TRUE;
1328
1329 /* Section: datafile */
1331 if (compat->version <= 0) {
1332 return FALSE;
1333 }
1334
1335 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
1336 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
1337
1339 nval = (sec != nullptr ? section_list_size(sec) : 0);
1341 int num = nval; /* No "size_t" to printf */
1342
1343 ruleset_error(nullptr, LOG_ERROR,
1344 "\"%s\": Too many achievement types (%d, max %d)",
1345 filename, num, MAX_ACHIEVEMENT_TYPES);
1346 ok = FALSE;
1347 } else {
1349 }
1350
1351 if (ok) {
1354
1355 if (!ruleset_load_names(&pach->name, nullptr, file, sec_name)) {
1356 ruleset_error(nullptr, LOG_ERROR,
1357 "\"%s\": Cannot load achievement names",
1358 filename);
1359 ok = FALSE;
1360 break;
1361 }
1363 }
1364
1366
1367 if (ok) {
1369
1370 nval = (sec != nullptr ? section_list_size(sec) : 0);
1371 if (nval > MAX_GOODS_TYPES) {
1372 int num = nval; /* No "size_t" to printf */
1373
1374 ruleset_error(nullptr, LOG_ERROR,
1375 "\"%s\": Too many goods types (%d, max %d)",
1376 filename, num, MAX_GOODS_TYPES);
1378 ok = FALSE;
1379 } else if (nval < 1) {
1380 ruleset_error(nullptr, LOG_ERROR,
1381 "\"%s\": At least one goods type needed",
1382 filename);
1384 ok = FALSE;
1385 } else {
1387 }
1388
1389 if (ok) {
1391 const char *sec_name
1393
1394 if (!ruleset_load_names(&pgood->name, nullptr, file, sec_name)) {
1395 ruleset_error(nullptr, LOG_ERROR,
1396 "\"%s\": Cannot load goods names",
1397 filename);
1398 ok = FALSE;
1399 break;
1400 }
1402 }
1404 }
1405
1406 if (ok) {
1407
1409
1410 nval = (sec != nullptr ? section_list_size(sec) : 0);
1411 if (nval > MAX_COUNTERS) {
1412 size_t num = nval;
1413
1414 ruleset_error(nullptr, LOG_ERROR,
1415 "\"%s\": Too many counters (" SIZE_T_PRINTF ", max %d)",
1416 filename, num, MAX_COUNTERS);
1417 ok = FALSE;
1418 }
1419
1420 if (ok) {
1421 int count_idx;
1422
1424
1425 for (count_idx = 0; count_idx < nval; count_idx++) {
1426
1428 const char *sec_name
1430
1431 if (!ruleset_load_names(&pcount->name, nullptr, file, sec_name)) {
1432 ruleset_error(nullptr, LOG_ERROR,
1433 "\"%s\": Cannot load counters names",
1434 filename);
1435 ok = FALSE;
1436 break;
1437 }
1438 }
1439 }
1440
1442 }
1443
1444 return ok;
1445}
1446
1447/**********************************************************************/
1451static bool load_action_names(struct section_file *file,
1452 struct rscompat_info *compat)
1453{
1454 const char *filename = secfile_name(file);
1455 bool ok = TRUE;
1456
1457 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1458 return FALSE;
1459 }
1460
1461 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
1462 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
1463
1464 return ok;
1465}
1466
1467/**********************************************************************/
1471static bool load_tech_names(struct section_file *file,
1472 struct rscompat_info *compat)
1473{
1474 struct section_list *sec = nullptr;
1475 /* Number of techs in the ruleset (means without A_NONE). */
1476 int num_techs = 0;
1477 int i;
1478 const char *filename = secfile_name(file);
1479 bool ok = TRUE;
1480 const char *flag;
1481
1482 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1483 return FALSE;
1484 }
1485
1486 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
1487 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
1488
1489 /* User tech flag names */
1490 for (i = 0;
1491 (flag = secfile_lookup_str_default(file, nullptr, "control.flags%d.name", i)) ;
1492 i++) {
1493 const char *helptxt
1494 = secfile_lookup_str_default(file, nullptr, "control.flags%d.helptxt",
1495 i);
1497 ruleset_error(nullptr, LOG_ERROR,
1498 "\"%s\": Duplicate tech flag name '%s'",
1499 filename, flag);
1500 ok = FALSE;
1501 break;
1502 }
1503 if (i > MAX_NUM_USER_TECH_FLAGS) {
1504 ruleset_error(nullptr, LOG_ERROR,
1505 "\"%s\": Too many user tech flags!",
1506 filename);
1507 ok = FALSE;
1508 break;
1509 }
1510
1511 set_user_tech_flag_name(TECH_USER_1 + i, flag, helptxt);
1512 }
1513
1514 if (ok) {
1515 size_t nval;
1516
1517 for (; i < MAX_NUM_USER_TECH_FLAGS; i++) {
1518 set_user_tech_flag_name(TECH_USER_1 + i, nullptr, nullptr);
1519 }
1520
1521 /* Tech classes */
1523
1524 nval = (sec != nullptr ? section_list_size(sec) : 0);
1525 if (nval > MAX_NUM_TECH_CLASSES) {
1526 int num = nval; /* No "size_t" to printf */
1527
1528 ruleset_error(nullptr, LOG_ERROR,
1529 "\"%s\": Too many tech classes (%d, max %d)",
1530 filename, num, MAX_NUM_TECH_CLASSES);
1532 ok = FALSE;
1533 } else {
1535 }
1536
1537 if (ok) {
1539 const char *sec_name
1541
1542 if (!ruleset_load_names(&ptclass->name, nullptr, file, sec_name)) {
1543 ruleset_error(nullptr, LOG_ERROR,
1544 "\"%s\": Cannot load tech class names",
1545 filename);
1546 ok = FALSE;
1547 break;
1548 }
1550 }
1551 }
1552
1553 if (ok) {
1554 /* The techs: */
1556 if (sec == nullptr || 0 == (num_techs = section_list_size(sec))) {
1557 ruleset_error(nullptr, LOG_ERROR,
1558 "\"%s\": No Advances?!?", filename);
1559 ok = FALSE;
1560 } else {
1561 log_verbose("%d advances (including possibly unused)", num_techs);
1562 if (num_techs + A_FIRST > A_LAST) {
1563 ruleset_error(nullptr, LOG_ERROR,
1564 "\"%s\": Too many advances (%d, max %d)",
1565 filename, num_techs, A_LAST - A_FIRST);
1566 ok = FALSE;
1567 }
1568 }
1569 }
1570
1571 if (ok) {
1572 game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */
1573
1574 i = 0;
1575 advance_iterate(adv) {
1576 if (!ruleset_load_names(&adv->name, nullptr, file,
1578 ok = FALSE;
1579 break;
1580 }
1581 i++;
1583 }
1585
1586 return ok;
1587}
1588
1589/**********************************************************************/
1592static bool load_ruleset_techs(struct section_file *file,
1593 struct rscompat_info *compat)
1594{
1595 struct section_list *sec;
1596 const char **slist;
1597 int i;
1598 size_t nval;
1600 const char *filename = secfile_name(file);
1601 bool ok = TRUE;
1602
1604
1605 i = 0;
1607 const char *sec_name = section_name(section_list_get(sec, i));
1608
1609 ptclass->cost_pct = secfile_lookup_int_default(file, 100, "%s.%s",
1610 sec_name, "cost_pct");
1611
1612 i++;
1614
1616
1617 i = 0;
1618 advance_iterate(a) {
1619 const char *sec_name = section_name(section_list_get(sec, i));
1620 const char *sval;
1621 int j, ival;
1622 struct requirement_vector *research_reqs;
1623
1624 if (!lookup_tech(file, &a->require[AR_ONE], sec_name, "req1",
1625 filename, rule_name_get(&a->name))
1626 || !lookup_tech(file, &a->require[AR_TWO], sec_name, "req2",
1627 filename, rule_name_get(&a->name))
1628 || !lookup_tech(file, &a->require[AR_ROOT], sec_name, "root_req",
1629 filename, rule_name_get(&a->name))) {
1630 ok = FALSE;
1631 break;
1632 }
1633
1634 if ((A_NEVER == a->require[AR_ONE] && A_NEVER != a->require[AR_TWO])
1635 || (A_NEVER != a->require[AR_ONE] && A_NEVER == a->require[AR_TWO])) {
1636 ruleset_error(nullptr, LOG_ERROR,
1637 "\"%s\" [%s] \"%s\": \"Never\" with non-\"Never\".",
1638 filename, sec_name, rule_name_get(&a->name));
1639 ok = FALSE;
1640 break;
1641 }
1642 if (a_none == a->require[AR_ONE] && a_none != a->require[AR_TWO]) {
1643 ruleset_error(nullptr, LOG_ERROR,
1644 "\"%s\" [%s] \"%s\": should have \"None\" second.",
1645 filename, sec_name, rule_name_get(&a->name));
1646 ok = FALSE;
1647 break;
1648 }
1649
1650 if (game.control.num_tech_classes == 0) {
1651 a->tclass = nullptr;
1652 } else {
1653 const char *classname;
1654
1655 classname = lookup_string(file, sec_name, "class");
1656 if (classname != nullptr) {
1659 if (a->tclass == nullptr) {
1660 ruleset_error(nullptr, LOG_ERROR,
1661 "\"%s\" [%s] \"%s\": Unknown tech class \"%s\".",
1662 filename, sec_name, rule_name_get(&a->name), classname);
1663 ok = FALSE;
1664 break;
1665 }
1666 } else {
1667 a->tclass = nullptr; /* Default */
1668 }
1669 }
1670
1671 research_reqs = lookup_req_list(file, sec_name, "research_reqs",
1672 rule_name_get(&a->name));
1673 if (research_reqs == nullptr) {
1674 ok = FALSE;
1675 break;
1676 }
1677
1678 requirement_vector_copy(&a->research_reqs, research_reqs);
1679
1680 BV_CLR_ALL(a->flags);
1681
1682 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
1683 for (j = 0; j < nval; j++) {
1684 sval = slist[j];
1685 if (strcmp(sval, "") == 0) {
1686 continue;
1687 }
1690 ruleset_error(nullptr, LOG_ERROR,
1691 "\"%s\" [%s] \"%s\": bad flag name \"%s\".",
1692 filename, sec_name, rule_name_get(&a->name), sval);
1693 ok = FALSE;
1694 break;
1695 } else {
1696 BV_SET(a->flags, ival);
1697 }
1698 }
1699 free(slist);
1700
1701 if (!ok) {
1702 break;
1703 }
1704
1705 sz_strlcpy(a->graphic_str,
1706 secfile_lookup_str_default(file, "-", "%s.graphic", sec_name));
1707 sz_strlcpy(a->graphic_alt,
1709 "%s.graphic_alt", sec_name));
1710
1711 a->helptext = lookup_strvec(file, sec_name, "helptext");
1712 a->bonus_message = lookup_string(file, sec_name, "bonus_message");
1713 a->cost = secfile_lookup_int_default(file, -1, "%s.%s",
1714 sec_name, "cost");
1715 a->num_reqs = 0;
1716
1717 i++;
1719
1720 /* Propagate a root tech up into the tech tree. If a technology
1721 * X has Y has a root tech, then any technology requiring X (in the
1722 * normal way or as a root tech) also has Y as a root tech.
1723 * Later techs may gain a whole set of root techs in this way. The one
1724 * we store in AR_ROOT is a more or less arbitrary one of these,
1725 * also signalling that the set is non-empty; after this, you'll still
1726 * have to walk the tech tree to find them all. */
1727restart:
1728
1729 if (ok) {
1730 advance_iterate(a) {
1731 if (valid_advance(a)
1732 && A_NEVER != a->require[AR_ROOT]) {
1733 bool out_of_order = FALSE;
1734
1735 /* Now find any tech depending on this technology and update its
1736 * root_req. */
1737 advance_iterate(b) {
1738 if (valid_advance(b)
1739 && A_NEVER == b->require[AR_ROOT]
1740 && (a == b->require[AR_ONE] || a == b->require[AR_TWO])) {
1741 b->require[AR_ROOT] = a->require[AR_ROOT];
1742 b->inherited_root_req = TRUE;
1743 if (b < a) {
1745 }
1746 }
1748
1749 if (out_of_order) {
1750 /* HACK: If we just changed the root_tech of a lower-numbered
1751 * technology, we need to go back so that we can propagate the
1752 * root_tech up to that technology's parents... */
1753 goto restart;
1754 }
1755 }
1757
1758 /* Now rename A_NEVER to A_NONE for consistency */
1760 if (A_NEVER == a->require[AR_ROOT]) {
1761 a->require[AR_ROOT] = a_none;
1762 }
1764
1765 /* Some more consistency checking:
1766 Non-removed techs depending on removed techs is too
1767 broken to fix by default, so die.
1768 */
1769 advance_iterate(a) {
1770 if (valid_advance(a)) {
1771 /* We check for recursive tech loops later,
1772 * in build_required_techs_helper. */
1773 if (!valid_advance(a->require[AR_ONE])) {
1774 ruleset_error(nullptr, LOG_ERROR,
1775 "\"%s\" tech \"%s\": req1 leads to removed tech.",
1776 filename, advance_rule_name(a));
1777 ok = FALSE;
1778 break;
1779 }
1780 if (!valid_advance(a->require[AR_TWO])) {
1781 ruleset_error(nullptr, LOG_ERROR,
1782 "\"%s\" tech \"%s\": req2 leads to removed tech.",
1783 filename, advance_rule_name(a));
1784 ok = FALSE;
1785 break;
1786 }
1787 }
1789 }
1790
1792 if (ok) {
1794 }
1795
1796 return ok;
1797}
1798
1799/**********************************************************************/
1803static bool load_unit_names(struct section_file *file,
1804 struct rscompat_info *compat)
1805{
1806 struct section_list *sec = nullptr;
1807 int nval = 0;
1808 int i;
1809 const char *filename = secfile_name(file);
1810 const char *flag;
1811 bool ok = TRUE;
1812
1813 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1814 return FALSE;
1815 }
1816
1817 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
1818 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
1819
1820 /* User unit flag names */
1821 for (i = 0;
1822 (flag = secfile_lookup_str_default(file, nullptr, "control.flags%d.name", i)) ;
1823 i++) {
1824 const char *helptxt
1825 = secfile_lookup_str_default(file, nullptr, "control.flags%d.helptxt",
1826 i);
1827
1830 ruleset_error(nullptr, LOG_ERROR,
1831 "\"%s\": Duplicate unit flag name '%s'",
1832 filename, flag);
1833 ok = FALSE;
1834 break;
1835 }
1836 if (i > MAX_NUM_USER_UNIT_FLAGS) {
1837 ruleset_error(nullptr, LOG_ERROR,
1838 "\"%s\": Too many user unit type flags!",
1839 filename);
1840 ok = FALSE;
1841 break;
1842 }
1843
1845 }
1846
1847 if (ok) {
1848 /* Blank the remaining unit type user flags. */
1849 for (; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
1850 set_user_unit_type_flag_name(UTYF_USER_FLAG_1 + i, nullptr, nullptr);
1851 }
1852 }
1853
1854 if (ok) {
1855 /* User unit class flag names */
1856 for (i = 0;
1857 (flag = secfile_lookup_str_default(file, nullptr,
1858 "control.class_flags%d.name",
1859 i));
1860 i++) {
1861 const char *helptxt = secfile_lookup_str_default(file, nullptr,
1862 "control.class_flags%d.helptxt", i);
1863
1866 ruleset_error(nullptr, LOG_ERROR,
1867 "\"%s\": Duplicate unit class flag name '%s'",
1868 filename, flag);
1869 ok = FALSE;
1870 break;
1871 }
1873 ruleset_error(nullptr, LOG_ERROR,
1874 "\"%s\": Too many user unit class flags!",
1875 filename);
1876 ok = FALSE;
1877 break;
1878 }
1879
1881 }
1882 }
1883
1884 if (ok) {
1885 /* Blank the remaining unit class user flags. */
1886 for (; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
1887 set_user_unit_class_flag_name(UCF_USER_FLAG_1 + i, nullptr, nullptr);
1888 }
1889 }
1890
1891 if (ok) {
1892 /* Unit classes */
1894 if (sec == nullptr || 0 == (nval = section_list_size(sec))) {
1895 ruleset_error(nullptr, LOG_ERROR,
1896 "\"%s\": No unit classes?!?", filename);
1897 ok = FALSE;
1898 } else {
1899 log_verbose("%d unit classes", nval);
1900 if (nval > UCL_LAST) {
1901 ruleset_error(nullptr, LOG_ERROR,
1902 "\"%s\": Too many unit classes (%d, max %d)",
1903 filename, nval, UCL_LAST);
1904 ok = FALSE;
1905 }
1906 }
1907 }
1908
1909 if (ok) {
1911
1913 const int pci = uclass_index(punitclass);
1914
1915 if (!ruleset_load_names(&punitclass->name, nullptr, file,
1917 ok = FALSE;
1918 break;
1919 }
1921 }
1923 sec = nullptr;
1924
1925 /* The names: */
1926 if (ok) {
1928 if (sec == nullptr || 0 == (nval = section_list_size(sec))) {
1929 ruleset_error(nullptr, LOG_ERROR,
1930 "\"%s\": No unit types?!?", filename);
1931 ok = FALSE;
1932 } else {
1933 log_verbose("%d unit types (including possibly unused)", nval);
1934 if (nval > U_LAST) {
1935 ruleset_error(nullptr, LOG_ERROR,
1936 "\"%s\": Too many unit types (%d, max %d)",
1937 filename, nval, U_LAST);
1938 ok = FALSE;
1939 }
1940 }
1941 }
1942
1943 if (ok) {
1945
1947 const int utypei = utype_index(punittype);
1948
1949 if (!ruleset_load_names(&punittype->name, nullptr, file,
1951 ok = FALSE;
1952 break;
1953 }
1955 }
1957
1958 return ok;
1959}
1960
1961/**********************************************************************/
1964static bool load_ruleset_veteran(struct section_file *file,
1965 const char *path,
1966 struct veteran_system **vsystem, char *err,
1967 size_t err_len)
1968{
1969 const char **vlist_name;
1972 int i;
1973 bool ret = TRUE;
1974
1975 /* The pointer should be uninitialised. */
1976 if (*vsystem != nullptr) {
1977 fc_snprintf(err, err_len, "Veteran system is defined?!");
1978 return FALSE;
1979 }
1980
1981 /* Load data. */
1983 "%s.veteran_names", path);
1985 "%s.veteran_power_fact", path);
1987 "%s.veteran_base_raise_chance", path);
1989 "%s.veteran_work_raise_chance",
1990 path);
1992 "%s.veteran_move_bonus", path);
1993
1994 if (count_name > MAX_VET_LEVELS) {
1995 ret = FALSE;
1996 fc_snprintf(err, err_len, "\"%s\": Too many veteran levels (section "
1997 "'%s': %lu, max %d)", secfile_name(file), path,
1998 (long unsigned)count_name, MAX_VET_LEVELS);
1999 } else if (count_name != count_power
2002 || count_name != count_move) {
2003 ret = FALSE;
2004 fc_snprintf(err, err_len, "\"%s\": Different lengths for the veteran "
2005 "settings in section '%s'", secfile_name(file),
2006 path);
2007 } else if (count_name == 0) {
2008 /* Nothing defined. */
2009 *vsystem = nullptr;
2010 } else {
2011 /* Generate the veteran system. */
2013
2014#define rs_sanity_veteran(_path, _entry, _i, _condition, _action) \
2015 if (_condition) { \
2016 log_error("Invalid veteran definition '%s.%s[%d]'!", \
2017 _path, _entry, _i); \
2018 log_debug("Failed check: '%s'. Update value: '%s'.", \
2019 #_condition, #_action); \
2020 _action; \
2021 }
2022 for (i = 0; i < count_name; i++) {
2023 /* Some sanity checks. */
2024 rs_sanity_veteran(path, "veteran_power_fact", i,
2025 (vlist_power[i] < 0), vlist_power[i] = 0);
2026 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2027 (vlist_raise[i] < 0), vlist_raise[i] = 0);
2028 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2029 (vlist_wraise[i] < 0), vlist_wraise[i] = 0);
2030 rs_sanity_veteran(path, "veteran_move_bonus", i,
2031 (vlist_move[i] < 0), vlist_move[i] = 0);
2032 if (i == 0) {
2033 /* First element.*/
2034 rs_sanity_veteran(path, "veteran_power_fact", i,
2035 (vlist_power[i] != 100), vlist_power[i] = 100);
2036 } else if (i == count_name - 1) {
2037 /* Last element. */
2038 rs_sanity_veteran(path, "veteran_power_fact", i,
2039 (vlist_power[i] < vlist_power[i - 1]),
2040 vlist_power[i] = vlist_power[i - 1]);
2041 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2042 (vlist_raise[i] != 0), vlist_raise[i] = 0);
2043 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2044 (vlist_wraise[i] != 0), vlist_wraise[i] = 0);
2045 } else {
2046 /* All elements in between. */
2047 rs_sanity_veteran(path, "veteran_power_fact", i,
2048 (vlist_power[i] < vlist_power[i - 1]),
2049 vlist_power[i] = vlist_power[i - 1]);
2050 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2051 (vlist_raise[i] > 100), vlist_raise[i] = 100);
2052 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2053 (vlist_wraise[i] > 100), vlist_wraise[i] = 100);
2054 }
2055
2058 vlist_wraise[i]);
2059 }
2060#undef rs_sanity_veteran
2061 }
2062
2063 if (vlist_name) {
2065 }
2066 if (vlist_power) {
2068 }
2069 if (vlist_raise) {
2071 }
2072 if (vlist_wraise) {
2074 }
2075 if (vlist_move) {
2077 }
2078
2079 return ret;
2080}
2081
2082/**********************************************************************/
2085static bool load_ruleset_units(struct section_file *file,
2086 struct rscompat_info *compat)
2087{
2088 int j, ival;
2089 size_t nval;
2090 struct section_list *sec, *csec;
2091 const char *sval, **slist;
2092 const char *filename = secfile_name(file);
2093 char msg[MAX_LEN_MSG];
2094 bool ok = TRUE;
2095
2096 if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg,
2097 sizeof(msg))
2098 || game.veteran == nullptr) {
2099 ruleset_error(nullptr, LOG_ERROR,
2100 "Error loading the default veteran system: %s",
2101 msg);
2102 ok = FALSE;
2103 }
2104
2106 nval = (sec != nullptr ? section_list_size(sec) : 0);
2107
2109 nval = (csec != nullptr ? section_list_size(csec) : 0);
2110
2111 if (ok) {
2113 int i = uclass_index(uc);
2114 const char *sec_name = section_name(section_list_get(csec, i));
2115
2116 if (secfile_lookup_int(file, &uc->min_speed, "%s.min_speed", sec_name)) {
2117 uc->min_speed *= SINGLE_MOVE;
2118 } else {
2119 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
2120 ok = FALSE;
2121 break;
2122 }
2123 if (!secfile_lookup_int(file, &uc->hp_loss_pct,
2124 "%s.hp_loss_pct", sec_name)) {
2125 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
2126 ok = FALSE;
2127 break;
2128 }
2129
2130 uc->non_native_def_pct = secfile_lookup_int_default(file, 100,
2131 "%s.non_native_def_pct",
2132 sec_name);
2133
2134 BV_CLR_ALL(uc->flags);
2135 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
2136 for (j = 0; j < nval; j++) {
2137 sval = slist[j];
2138 if (strcmp(sval, "") == 0) {
2139 continue;
2140 }
2141
2144 ok = FALSE;
2147 ruleset_error(nullptr, LOG_ERROR,
2148 "\"%s\" unit_class \"%s\": unit_type flag \"%s\"!",
2149 filename, uclass_rule_name(uc), sval);
2150 } else {
2151 ruleset_error(nullptr, LOG_ERROR,
2152 "\"%s\" unit_class \"%s\": bad flag name \"%s\".",
2153 filename, uclass_rule_name(uc), sval);
2154 }
2155 break;
2156 } else {
2157 BV_SET(uc->flags, ival);
2158 }
2159 }
2160 free(slist);
2161
2162 uc->helptext = lookup_strvec(file, sec_name, "helptext");
2163
2164 if (!ok) {
2165 break;
2166 }
2168 }
2169
2170 if (ok) {
2171 /* Tech and Gov requirements; per unit veteran system */
2173 const int i = utype_index(u);
2174 const struct section *psection = section_list_get(sec, i);
2175 const char *sec_name = section_name(psection);
2176 struct requirement_vector *reqs;
2177
2178 reqs = lookup_req_list(file, sec_name, "reqs",
2179 utype_rule_name(u));
2180
2181 if (reqs == nullptr) {
2182 ok = FALSE;
2183 break;
2184 }
2185
2186 requirement_vector_copy(&u->build_reqs, reqs);
2187
2188 if (!load_ruleset_veteran(file, sec_name, &u->veteran,
2189 msg, sizeof(msg))) {
2190 ruleset_error(nullptr, LOG_ERROR,
2191 "Error loading the veteran system: %s",
2192 msg);
2193 ok = FALSE;
2194 break;
2195 }
2196
2197 if (!lookup_unit_type(file, sec_name, "obsolete_by",
2198 &u->obsoleted_by, filename,
2199 rule_name_get(&u->name))
2200 || !lookup_unit_type(file, sec_name, "convert_to",
2201 &u->converted_to, filename,
2202 rule_name_get(&u->name))) {
2203 ok = FALSE;
2204 break;
2205 }
2206 u->convert_time = 1; /* default */
2207 lookup_time(file, &u->convert_time, sec_name, "convert_time",
2208 filename, rule_name_get(&u->name), &ok);
2210 }
2211
2212 if (ok) {
2213 /* main stats: */
2215 const int i = utype_index(u);
2216 struct unit_class *pclass;
2217 const char *sec_name = section_name(section_list_get(sec, i));
2218 const char *str;
2219
2220 sval = secfile_lookup_str(file, "%s.class", sec_name);
2222 if (!pclass) {
2223 ruleset_error(nullptr, LOG_ERROR,
2224 "\"%s\" unit_type \"%s\": bad class \"%s\".",
2225 filename, utype_rule_name(u), sval);
2226 ok = FALSE;
2227 break;
2228 }
2229 u->uclass = pclass;
2230
2231 sz_strlcpy(u->sound_move,
2232 secfile_lookup_str_default(file, "-", "%s.sound_move",
2233 sec_name));
2234 sz_strlcpy(u->sound_move_alt,
2235 secfile_lookup_str_default(file, "-", "%s.sound_move_alt",
2236 sec_name));
2237 sz_strlcpy(u->sound_fight,
2238 secfile_lookup_str_default(file, "-", "%s.sound_fight",
2239 sec_name));
2240 sz_strlcpy(u->sound_fight_alt,
2241 secfile_lookup_str_default(file, "-", "%s.sound_fight_alt",
2242 sec_name));
2243
2244 if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) {
2245 sz_strlcpy(u->graphic_str, str);
2246 } else {
2247 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
2248 ok = FALSE;
2249 break;
2250 }
2251 sz_strlcpy(u->graphic_alt,
2252 secfile_lookup_str_default(file, "-", "%s.graphic_alt",
2253 sec_name));
2254 sz_strlcpy(u->graphic_alt2,
2255 secfile_lookup_str_default(file, "-", "%s.graphic_alt2",
2256 sec_name));
2257
2258 if (!secfile_lookup_int(file, &u->build_cost,
2259 "%s.build_cost", sec_name)
2260 || !secfile_lookup_int(file, &u->pop_cost,
2261 "%s.pop_cost", sec_name)
2262 || !secfile_lookup_int(file, &u->attack_strength,
2263 "%s.attack", sec_name)
2264 || !secfile_lookup_int(file, &u->defense_strength,
2265 "%s.defense", sec_name)
2266 || !secfile_lookup_int(file, &u->move_rate,
2267 "%s.move_rate", sec_name)
2268 || !secfile_lookup_int(file, &u->vision_radius_sq,
2269 "%s.vision_radius_sq", sec_name)
2270 || !secfile_lookup_int(file, &u->transport_capacity,
2271 "%s.transport_cap", sec_name)
2272 || !secfile_lookup_int(file, &u->firepower,
2273 "%s.firepower", sec_name)
2274 || !secfile_lookup_int(file, &u->fuel,
2275 "%s.fuel", sec_name)
2276 || !secfile_lookup_int(file, &u->happy_cost,
2277 "%s.uk_happy", sec_name)) {
2278 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
2279 ok = FALSE;
2280 break;
2281 }
2282 u->hp
2285 RS_MIN_HP,
2286 RS_MAX_HP,
2287 "%s.hitpoints", sec_name);
2288
2289 u->move_rate *= SINGLE_MOVE;
2290
2291 if (u->firepower <= 0) {
2292 ruleset_error(nullptr, LOG_ERROR,
2293 "\"%s\" unit_type \"%s\":"
2294 " firepower is %d,"
2295 " but must be at least 1. "
2296 " If you want no attack ability,"
2297 " set the unit's attack strength to 0.",
2298 filename, utype_rule_name(u), u->firepower);
2299 ok = FALSE;
2300 break;
2301 }
2302
2303 lookup_cbonus_list(u->bonuses, file, sec_name, "bonuses");
2304
2306 u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s",
2307 sec_name,
2310
2311 slist = secfile_lookup_str_vec(file, &nval, "%s.cargo", sec_name);
2312
2313 BV_CLR_ALL(u->cargo);
2314 for (j = 0; j < nval; j++) {
2315 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2316
2317 if (!uclass) {
2318 ruleset_error(nullptr, LOG_ERROR,
2319 "\"%s\" unit_type \"%s\":"
2320 "has unknown unit class %s as cargo.",
2321 filename, utype_rule_name(u), slist[j]);
2322 ok = FALSE;
2323 break;
2324 }
2325
2326 BV_SET(u->cargo, uclass_index(uclass));
2327 }
2328 free(slist);
2329
2330 if (!ok) {
2331 break;
2332 }
2333
2334 slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec_name);
2335 BV_CLR_ALL(u->targets);
2336 for (j = 0; j < nval; j++) {
2337 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2338
2339 if (!uclass) {
2340 ruleset_error(nullptr, LOG_ERROR,
2341 "\"%s\" unit_type \"%s\":"
2342 "has unknown unit class %s as target.",
2343 filename, utype_rule_name(u), slist[j]);
2344 ok = FALSE;
2345 break;
2346 }
2347
2348 BV_SET(u->targets, uclass_index(uclass));
2349 }
2350 free(slist);
2351
2352 if (!ok) {
2353 break;
2354 }
2355
2356 slist = secfile_lookup_str_vec(file, &nval, "%s.embarks", sec_name);
2357 BV_CLR_ALL(u->embarks);
2358 for (j = 0; j < nval; j++) {
2359 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2360
2361 if (!uclass) {
2362 ruleset_error(nullptr, LOG_ERROR,
2363 "\"%s\" unit_type \"%s\":"
2364 "has unknown unit class %s as embarkable.",
2365 filename, utype_rule_name(u), slist[j]);
2366 ok = FALSE;
2367 break;
2368 }
2369
2370 BV_SET(u->embarks, uclass_index(uclass));
2371 }
2372 free(slist);
2373
2374 if (!ok) {
2375 break;
2376 }
2377
2378 slist = secfile_lookup_str_vec(file, &nval, "%s.disembarks", sec_name);
2379 BV_CLR_ALL(u->disembarks);
2380 for (j = 0; j < nval; j++) {
2381 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2382
2383 if (!uclass) {
2384 ruleset_error(nullptr, LOG_ERROR,
2385 "\"%s\" unit_type \"%s\":"
2386 "has unknown unit class %s as disembarkable.",
2387 filename, utype_rule_name(u), slist[j]);
2388 ok = FALSE;
2389 break;
2390 }
2391
2392 BV_SET(u->disembarks, uclass_index(uclass));
2393 }
2394 free(slist);
2395
2396 if (!ok) {
2397 break;
2398 }
2399
2400 /* Set also all classes that are never unreachable as targets,
2401 * embarks, and disembarks. */
2404 BV_SET(u->targets, uclass_index(preachable));
2405 BV_SET(u->embarks, uclass_index(preachable));
2406 BV_SET(u->disembarks, uclass_index(preachable));
2407 }
2409
2410 str = secfile_lookup_str_default(file, "Main", "%s.vision_layer",
2411 sec_name);
2413 if (!vision_layer_is_valid(u->vlayer)) {
2414 ruleset_error(nullptr, LOG_ERROR,
2415 "\"%s\" unit_type \"%s\":"
2416 "has unknown vision layer %s.",
2417 filename, utype_rule_name(u), str);
2418 ok = FALSE;
2419 break;
2420 }
2421
2422 u->helptext = lookup_strvec(file, sec_name, "helptext");
2423
2424 u->paratroopers_range = secfile_lookup_int_default(file,
2425 0, "%s.paratroopers_range", sec_name);
2426
2427 u->bombard_rate = secfile_lookup_int_default(file, 0,
2428 "%s.bombard_rate", sec_name);
2429 u->city_slots = secfile_lookup_int_default(file, 0,
2430 "%s.city_slots", sec_name);
2431 u->city_size = secfile_lookup_int_default(file, 1,
2432 "%s.city_size", sec_name);
2433 if ((sval
2434 = secfile_lookup_str_default(file, nullptr, "%s.specialist", sec_name))) {
2435 if (!(u->spec_type = specialist_by_rule_name(sval))) {
2436 ruleset_error(nullptr, LOG_ERROR,
2437 "\"%s\" unit_type \"%s\":"
2438 " bad specialist \"%s\".",
2439 filename, utype_rule_name(u), sval);
2440 ok = FALSE;
2441 }
2442 } else {
2443 /* Specialists must have been processed before */
2446 ok = FALSE; break);
2448 }
2449
2451 "%s.tp_defense", sec_name);
2452 u->tp_defense = transp_def_type_by_name(sval, fc_strcasecmp);
2453 if (!transp_def_type_is_valid(u->tp_defense)) {
2454 ruleset_error(nullptr, LOG_ERROR,
2455 "\"%s\" unit_type \"%s\":"
2456 " bad tp_defense \"%s\".",
2457 filename, utype_rule_name(u), sval);
2458 ok = FALSE;
2459 break;
2460 }
2462 }
2463
2464 if (ok) {
2465 /* Flags */
2467 const int i = utype_index(u);
2468
2469 BV_CLR_ALL(u->flags);
2471
2472 slist = secfile_lookup_str_vec(file, &nval, "%s.flags",
2474 for (j = 0; j < nval; j++) {
2475 sval = slist[j];
2476 if (0 == strcmp(sval, "")) {
2477 continue;
2478 }
2481 ok = FALSE;
2484 ruleset_error(nullptr, LOG_ERROR,
2485 "\"%s\" unit_type \"%s\": unit_class flag!",
2486 filename, utype_rule_name(u));
2487 } else {
2488 ruleset_error(nullptr, LOG_ERROR,
2489 "\"%s\" unit_type \"%s\": bad flag name \"%s\".",
2490 filename, utype_rule_name(u), sval);
2491 }
2492 break;
2493 } else {
2494 BV_SET(u->flags, ival);
2495 }
2496 }
2497 free(slist);
2498
2499 if (!ok) {
2500 break;
2501 }
2503 }
2504
2505 /* Roles */
2506 if (ok) {
2508 const int i = utype_index(u);
2509
2510 BV_CLR_ALL(u->roles);
2511
2512 slist = secfile_lookup_str_vec(file, &nval, "%s.roles",
2514 for (j = 0; j < nval; j++) {
2515 sval = slist[j];
2516 if (strcmp(sval, "") == 0) {
2517 continue;
2518 }
2521 ruleset_error(nullptr, LOG_ERROR,
2522 "\"%s\" unit_type \"%s\": bad role name \"%s\".",
2523 filename, utype_rule_name(u), sval);
2524 ok = FALSE;
2525 break;
2526 } else {
2527 BV_SET(u->roles, ival - L_FIRST);
2528 }
2530 }
2531 free(slist);
2533 }
2534
2535 if (ok) {
2536 /* Some more consistency checking: */
2539 if (!valid_advance(padv)) {
2540 ruleset_error(nullptr, LOG_ERROR,
2541 "\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
2542 filename, utype_rule_name(u),
2544 ok = FALSE;
2545 break;
2546 }
2548
2549 if (!ok) {
2550 break;
2551 }
2553 }
2554
2557
2558 if (ok) {
2560 }
2561
2562 return ok;
2563}
2564
2565/**********************************************************************/
2569static bool load_building_names(struct section_file *file,
2570 struct rscompat_info *compat)
2571{
2572 struct section_list *sec;
2573 int i, nval = 0;
2574 const char *filename = secfile_name(file);
2575 bool ok = TRUE;
2576 const char *flag;
2577
2578 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2579 return FALSE;
2580 }
2581
2582 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
2583 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
2584
2585 /* The names: */
2587 if (sec == nullptr || 0 == (nval = section_list_size(sec))) {
2588 ruleset_error(nullptr, LOG_ERROR,
2589 "\"%s\": No improvements?!?", filename);
2590 ok = FALSE;
2591 } else {
2592 log_verbose("%d improvement types (including possibly unused)", nval);
2593 if (nval > B_LAST) {
2594 ruleset_error(nullptr, LOG_ERROR,
2595 "\"%s\": Too many improvements (%d, max %d)",
2596 filename, nval, B_LAST);
2597 ok = FALSE;
2598 }
2599 }
2600
2601 if (ok) {
2603
2604 for (i = 0; i < nval; i++) {
2605 struct impr_type *b = improvement_by_number(i);
2606
2607 if (!ruleset_load_names(&b->name, nullptr, file,
2609 ok = FALSE;
2610 break;
2611 }
2612 }
2613 }
2614
2615 /* User building flag names */
2616 for (i = 0;
2617 (flag = secfile_lookup_str_default(file, nullptr,
2618 "control.building_flags%d.name",
2619 i));
2620 i++) {
2621 const char *helptxt
2622 = secfile_lookup_str_default(file, nullptr,
2623 "control.building_flags%d.helptxt", i);
2624
2626 != impr_flag_id_invalid()) {
2627 ruleset_error(nullptr, LOG_ERROR,
2628 "\"%s\": Duplicate building flag name '%s'",
2629 filename, flag);
2630 ok = FALSE;
2631 break;
2632 }
2634 ruleset_error(nullptr, LOG_ERROR,
2635 "\"%s\": Too many user building flags!",
2636 filename);
2637 ok = FALSE;
2638 break;
2639 }
2640
2641 set_user_impr_flag_name(IF_USER_FLAG_1 + i, flag, helptxt);
2642 }
2643
2645
2646 return ok;
2647}
2648
2649/**********************************************************************/
2652static bool load_ruleset_buildings(struct section_file *file,
2653 struct rscompat_info *compat)
2654{
2655 struct section_list *sec;
2656 const char *item;
2657 int i, nval;
2658 const char *filename = secfile_name(file);
2659 bool ok = TRUE;
2660
2662 nval = (sec != nullptr ? section_list_size(sec) : 0);
2663
2664 for (i = 0; i < nval && ok; i++) {
2665 struct impr_type *b = improvement_by_number(i);
2666 const char *sec_name = section_name(section_list_get(sec, i));
2667 struct requirement_vector *reqs
2668 = lookup_req_list(file, sec_name, "reqs",
2670
2671 if (reqs == nullptr) {
2672 ok = FALSE;
2673 break;
2674 } else {
2675 const char *sval, **slist;
2676 int j, ival;
2677 size_t nflags;
2678
2679 item = secfile_lookup_str(file, "%s.genus", sec_name);
2681 if (!impr_genus_id_is_valid(b->genus)) {
2682 ruleset_error(nullptr, LOG_ERROR,
2683 "\"%s\" improvement \"%s\": couldn't match "
2684 "genus \"%s\".", filename,
2686 ok = FALSE;
2687 break;
2688 }
2689
2690 slist = secfile_lookup_str_vec(file, &nflags, "%s.flags", sec_name);
2691 BV_CLR_ALL(b->flags);
2692
2693 for (j = 0; j < nflags; j++) {
2694 sval = slist[j];
2695 if (strcmp(sval, "") == 0) {
2696 continue;
2697 }
2700 ruleset_error(nullptr, LOG_ERROR,
2701 "\"%s\" improvement \"%s\": bad flag name \"%s\".",
2702 filename, improvement_rule_name(b), sval);
2703 ok = FALSE;
2704 break;
2705 } else {
2706 BV_SET(b->flags, ival);
2707 }
2708 }
2709 free(slist);
2710
2711 if (!ok) {
2712 break;
2713 }
2714
2716
2717 {
2718 struct requirement_vector *obs_reqs
2719 = lookup_req_list(file, sec_name, "obsolete_by",
2721
2722 if (obs_reqs == nullptr) {
2723 ok = FALSE;
2724 break;
2725 } else {
2726 requirement_vector_copy(&b->obsolete_by, obs_reqs);
2727 }
2728 }
2729
2730 if (!secfile_lookup_int(file, &b->build_cost,
2731 "%s.build_cost", sec_name)
2732 || !secfile_lookup_int(file, &b->upkeep,
2733 "%s.upkeep", sec_name)
2734 || !secfile_lookup_int(file, &b->sabotage,
2735 "%s.sabotage", sec_name)) {
2736 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
2737 ok = FALSE;
2738 break;
2739 }
2740
2743 "%s.graphic", sec_name));
2746 "%s.graphic_alt", sec_name));
2749 "%s.graphic_alt2", sec_name));
2750
2753 "%s.sound", sec_name));
2756 "%s.sound_alt", sec_name));
2759 "%s.sound_alt2", sec_name));
2760 b->helptext = lookup_strvec(file, sec_name, "helptext");
2761 }
2762 }
2763
2765 if (ok) {
2767 }
2768
2769 return ok;
2770}
2771
2772/**********************************************************************/
2776static bool load_terrain_names(struct section_file *file,
2777 struct rscompat_info *compat)
2778{
2779 int nval = 0;
2780 struct section_list *sec = nullptr;
2781 const char *flag;
2782 int i;
2783 const char *filename = secfile_name(file);
2784 bool ok = TRUE;
2785
2786 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2787 return FALSE;
2788 }
2789
2790 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
2791 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
2792
2793 /* User terrain flag names */
2794 for (i = 0;
2795 (flag = secfile_lookup_str_default(file, nullptr, "control.flags%d.name", i)) ;
2796 i++) {
2797 const char *helptxt
2798 = secfile_lookup_str_default(file, nullptr, "control.flags%d.helptxt",
2799 i);
2800
2803 ruleset_error(nullptr, LOG_ERROR,
2804 "\"%s\": Duplicate terrain flag name '%s'",
2805 filename, flag);
2806 ok = FALSE;
2807 break;
2808 }
2809 if (i > MAX_NUM_USER_TER_FLAGS) {
2810 ruleset_error(nullptr, LOG_ERROR,
2811 "\"%s\": Too many user terrain flags!",
2812 filename);
2813 ok = FALSE;
2814 break;
2815 }
2816
2817 set_user_terrain_flag_name(TER_USER_1 + i, flag, helptxt);
2818 }
2819
2820 if (ok) {
2821 /* Blank the remaining terrain user flag slots. */
2822 for (; i < MAX_NUM_USER_TER_FLAGS; i++) {
2823 set_user_terrain_flag_name(TER_USER_1 + i, nullptr, nullptr);
2824 }
2825 }
2826
2827 /* User extra flag names */
2828 for (i = 0;
2829 (flag = secfile_lookup_str_default(file, nullptr,
2830 "control.extra_flags%d.name",
2831 i));
2832 i++) {
2833 const char *helptxt = secfile_lookup_str_default(file, nullptr,
2834 "control.extra_flags%d.helptxt", i);
2835
2837 != extra_flag_id_invalid()) {
2838 ruleset_error(nullptr, LOG_ERROR,
2839 "\"%s\": Duplicate extra flag name '%s'",
2840 filename, flag);
2841 ok = FALSE;
2842 break;
2843 }
2845 ruleset_error(nullptr, LOG_ERROR,
2846 "\"%s\": Too many user extra flags!",
2847 filename);
2848 ok = FALSE;
2849 break;
2850 }
2851
2852 set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt);
2853 }
2854
2855 if (ok) {
2856 /* Blank the remaining extra user flag slots. */
2857 for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
2858 set_user_extra_flag_name(EF_USER_FLAG_1 + i, nullptr, nullptr);
2859 }
2860
2861 /* Terrain names */
2862
2864 if (sec == nullptr || 0 == (nval = section_list_size(sec))) {
2865 ruleset_error(nullptr, LOG_ERROR,
2866 "\"%s\": ruleset doesn't have any terrains.",
2867 filename);
2868 ok = FALSE;
2869 } else {
2870 if (nval > MAX_NUM_TERRAINS) {
2871 ruleset_error(nullptr, LOG_ERROR,
2872 "\"%s\": Too many terrains (%d, max %d)",
2873 filename, nval, MAX_NUM_TERRAINS);
2874 ok = FALSE;
2875 }
2876 }
2877 }
2878
2879 if (ok) {
2881
2882 /* Avoid re-reading files */
2883 if (terrain_sections) {
2885 }
2887
2888 terrain_type_iterate(pterrain) {
2889 const int terri = terrain_index(pterrain);
2890 const char *sec_name = section_name(section_list_get(sec, terri));
2891
2892 if (!ruleset_load_names(&pterrain->name, nullptr, file, sec_name)) {
2893 ok = FALSE;
2894 break;
2895 }
2896
2899 }
2900
2902 sec = nullptr;
2903
2904 /* Extra names */
2905
2906 if (ok) {
2908 nval = (sec != nullptr ? section_list_size(sec) : 0);
2909 if (nval > MAX_EXTRA_TYPES) {
2910 ruleset_error(nullptr, LOG_ERROR,
2911 "\"%s\": Too many extra types (%d, max %d)",
2912 filename, nval, MAX_EXTRA_TYPES);
2913 ok = FALSE;
2914 }
2915 }
2916
2917 if (ok) {
2918 int idx;
2919
2921
2922 if (extra_sections) {
2924 }
2926
2927 if (ok) {
2928 for (idx = 0; idx < nval; idx++) {
2929 const char *sec_name = section_name(section_list_get(sec, idx));
2930 struct extra_type *pextra = extra_by_number(idx);
2931
2932 if (!ruleset_load_names(&pextra->name, nullptr, file, sec_name)) {
2933 ok = FALSE;
2934 break;
2935 }
2937 }
2938 }
2939 }
2940
2942 sec = nullptr;
2943
2944 /* Base names */
2945
2946 if (ok) {
2948 nval = (sec != nullptr ? section_list_size(sec) : 0);
2949 if (nval > MAX_EXTRA_TYPES) {
2950 ruleset_error(nullptr, LOG_ERROR,
2951 "\"%s\": Too many base types (%d, max %d)",
2952 filename, nval, MAX_EXTRA_TYPES);
2953 ok = FALSE;
2954 }
2955
2957 }
2958
2959 if (ok) {
2960 int idx;
2961
2962 if (base_sections) {
2964 }
2966
2967 /* Cannot use base_type_iterate() before bases are added to
2968 * EC_BASE caused_by list. Have to get them by extra_type_by_rule_name() */
2969 for (idx = 0; idx < nval; idx++) {
2970 const char *sec_name = section_name(section_list_get(sec, idx));
2971 const char *base_name = secfile_lookup_str(file, "%s.extra", sec_name);
2972
2973 if (base_name != nullptr) {
2975
2976 if (pextra != nullptr) {
2977 base_type_init(pextra, idx);
2979 } else {
2980 ruleset_error(nullptr, LOG_ERROR,
2981 "No extra definition matching base definition \"%s\"",
2982 base_name);
2983 ok = FALSE;
2984 }
2985 } else {
2986 ruleset_error(nullptr, LOG_ERROR,
2987 "Base section \"%s\" does not associate base with any extra",
2988 sec_name);
2989 ok = FALSE;
2990 }
2991 }
2992 }
2993
2995 sec = nullptr;
2996
2997 /* Road names */
2998
2999 if (ok) {
3001 nval = (sec != nullptr ? section_list_size(sec) : 0);
3002 if (nval > MAX_EXTRA_TYPES) {
3003 ruleset_error(nullptr, LOG_ERROR,
3004 "\"%s\": Too many road types (%d, max %d)",
3005 filename, nval, MAX_EXTRA_TYPES);
3006 ok = FALSE;
3007 }
3008
3010 }
3011
3012 if (ok) {
3013 int idx;
3014
3015 if (road_sections) {
3017 }
3019
3020 /* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to
3021 * EC_ROAD caused_by list. Have to get them by extra_type_by_rule_name() */
3022 for (idx = 0; idx < nval; idx++) {
3023 const char *sec_name = section_name(section_list_get(sec, idx));
3024 const char *road_name = secfile_lookup_str(file, "%s.extra", sec_name);
3025
3026 if (road_name != nullptr) {
3028
3029 if (pextra != nullptr) {
3030 road_type_init(pextra, idx);
3032 } else {
3033 ruleset_error(nullptr, LOG_ERROR,
3034 "No extra definition matching road definition \"%s\"",
3035 road_name);
3036 ok = FALSE;
3037 }
3038 } else {
3039 ruleset_error(nullptr, LOG_ERROR,
3040 "Road section \"%s\" does not associate road with any extra",
3041 sec_name);
3042 ok = FALSE;
3043 }
3044 }
3045 }
3046
3048 sec = nullptr;
3049
3050 /* Resource names */
3051 if (ok) {
3053 nval = (sec != nullptr ? section_list_size(sec) : 0);
3054 if (nval > MAX_EXTRA_TYPES) {
3055 ruleset_error(nullptr, LOG_ERROR,
3056 "\"%s\": Too many resource types (%d, max %d)",
3057 filename, nval, MAX_EXTRA_TYPES);
3058 ok = FALSE;
3059 }
3060
3062 }
3063
3064 if (ok) {
3065 int idx;
3066
3067 if (resource_sections) {
3069 }
3071
3072 /* Cannot use resource_type_iterate() before resource are added to
3073 * EC_RESOURCE caused_by list. Have to get them by extra_type_by_rule_name() */
3074 for (idx = 0; idx < nval; idx++) {
3075 const char *sec_name = section_name(section_list_get(sec, idx));
3076 const char *resource_name;
3077 struct extra_type *pextra = nullptr;
3078
3080 = secfile_lookup_str_default(file, nullptr, "%s.extra", sec_name);
3081
3082 if (resource_name != nullptr) {
3084
3085 if (pextra != nullptr) {
3086 resource_type_init(pextra);
3088 } else {
3089 ruleset_error(nullptr, LOG_ERROR,
3090 "No extra definition matching resource definition \"%s\"",
3092 ok = FALSE;
3093 }
3094 } else {
3095 ruleset_error(nullptr, LOG_ERROR,
3096 "Resource section %s does not list extra this resource belongs to.",
3097 sec_name);
3098 ok = FALSE;
3099 }
3100 }
3101 }
3102
3104 sec = nullptr;
3105
3106 /* Tiledef names */
3107
3108 if (ok) {
3110 nval = (sec != nullptr ? section_list_size(sec) : 0);
3111 if (nval > MAX_TILEDEFS) {
3112 ruleset_error(nullptr, LOG_ERROR,
3113 "\"%s\": Too many tiledefs (%d, max %d)",
3114 filename, nval, MAX_TILEDEFS);
3115 ok = FALSE;
3116 }
3117 }
3118
3119 if (ok) {
3120 int idx;
3121
3123
3124 if (tiledef_sections) {
3126 }
3128
3129 if (ok) {
3130 for (idx = 0; idx < nval; idx++) {
3131 const char *sec_name = section_name(section_list_get(sec, idx));
3132 struct tiledef *td = tiledef_by_number(idx);
3133
3134 if (!ruleset_load_names(&td->name, nullptr, file, sec_name)) {
3135 ok = FALSE;
3136 break;
3137 }
3139 }
3140 }
3141 }
3142
3144
3145 return ok;
3146}
3147
3148/**********************************************************************/
3151static bool load_ruleset_terrain(struct section_file *file,
3152 struct rscompat_info *compat)
3153{
3154 size_t nval, nval2;
3155 int j;
3156 bool compat_road = FALSE;
3157 bool compat_rail = FALSE;
3158 bool compat_river = FALSE;
3159 const char **res;
3160 const char *filename = secfile_name(file);
3161 const char *text;
3162 int *res_freq;
3163 bool ok = TRUE;
3164
3165 /* Parameters */
3166
3167 terrain_control.ocean_reclaim_requirement_pct
3168 = secfile_lookup_int_default(file, 101,
3169 "parameters.ocean_reclaim_requirement");
3170 terrain_control.land_channel_requirement_pct
3171 = secfile_lookup_int_default(file, 101,
3172 "parameters.land_channel_requirement");
3173 terrain_control.terrain_thaw_requirement_pct
3174 = secfile_lookup_int_default(file, 101,
3175 "parameters.thaw_requirement");
3176 terrain_control.terrain_freeze_requirement_pct
3177 = secfile_lookup_int_default(file, 101,
3178 "parameters.freeze_requirement");
3179 terrain_control.lake_max_size
3181 "parameters.lake_max_size");
3182 terrain_control.min_start_native_area
3184 "parameters.min_start_native_area");
3185 terrain_control.move_fragments
3187 "parameters.move_fragments");
3188 if (terrain_control.move_fragments < 1) {
3189 ruleset_error(nullptr, LOG_ERROR,
3190 "\"%s\": move_fragments must be at least 1",
3191 filename);
3192 ok = FALSE;
3193 }
3195 terrain_control.igter_cost
3197 "parameters.igter_cost");
3198 if (terrain_control.igter_cost < 1) {
3199 ruleset_error(nullptr, LOG_ERROR,
3200 "\"%s\": igter_cost must be at least 1",
3201 filename);
3202 ok = FALSE;
3203 }
3204 terrain_control.infrapoints = FALSE; /* This will be updated if we find
3205 * an placeable extra. */
3206
3207 terrain_control.pythagorean_diagonal
3209 "parameters.pythagorean_diagonal");
3210
3213 "parameters.ocean_resources");
3214
3215 text = secfile_lookup_str_default(file,
3216 N_("?gui_type:Build Type A Base"),
3217 "extraui.ui_name_base_fortress");
3218 sz_strlcpy(terrain_control.gui_type_base0, text);
3219
3220 text = secfile_lookup_str_default(file,
3221 N_("?gui_type:Build Type B Base"),
3222 "extraui.ui_name_base_airbase");
3223 sz_strlcpy(terrain_control.gui_type_base1, text);
3224
3225 if (ok) {
3226 /* Terrain details */
3227
3228 terrain_type_iterate(pterrain) {
3229 const char **slist;
3230 const int i = terrain_index(pterrain);
3231 const char *tsection = &terrain_sections[i * MAX_SECTION_LABEL];
3232 const char *cstr;
3233 const char *ename;
3234
3235 sz_strlcpy(pterrain->graphic_str,
3236 secfile_lookup_str(file, "%s.graphic", tsection));
3237 sz_strlcpy(pterrain->graphic_alt,
3239 "%s.graphic_alt", tsection));
3240 sz_strlcpy(pterrain->graphic_alt2,
3242 "%s.graphic_alt2", tsection));
3243
3244 pterrain->identifier
3245 = secfile_lookup_str(file, "%s.identifier", tsection)[0];
3246 if ('\0' == pterrain->identifier) {
3247 ruleset_error(nullptr, LOG_ERROR,
3248 "\"%s\" [%s] identifier missing value.",
3249 filename, tsection);
3250 ok = FALSE;
3251 break;
3252 }
3253 if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) {
3254 ruleset_error(nullptr, LOG_ERROR,
3255 "\"%s\" [%s] cannot use '%c' as an identifier;"
3256 " it is reserved for unknown terrain.",
3257 filename, tsection, pterrain->identifier);
3258 ok = FALSE;
3259 break;
3260 }
3261 for (j = T_FIRST; j < i; j++) {
3262 if (pterrain->identifier == terrain_by_number(j)->identifier) {
3263 ruleset_error(nullptr, LOG_ERROR,
3264 "\"%s\" [%s] has the same identifier as [%s].",
3265 filename, tsection,
3267 ok = FALSE;
3268 break;
3269 }
3270 }
3271
3272 if (!ok) {
3273 break;
3274 }
3275
3276 cstr = secfile_lookup_str(file, "%s.class", tsection);
3277 pterrain->tclass = terrain_class_by_name(cstr, fc_strcasecmp);
3278 if (!terrain_class_is_valid(pterrain->tclass)) {
3279 ruleset_error(nullptr, LOG_ERROR,
3280 "\"%s\": [%s] unknown class \"%s\"",
3281 filename, tsection, cstr);
3282 ok = FALSE;
3283 break;
3284 }
3285
3286 if (!secfile_lookup_int(file, &pterrain->movement_cost,
3287 "%s.movement_cost", tsection)
3288 || !secfile_lookup_int(file, &pterrain->defense_bonus,
3289 "%s.defense_bonus", tsection)) {
3290 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
3291 ok = FALSE;
3292 break;
3293 }
3294
3296 pterrain->output[o]
3297 = secfile_lookup_int_default(file, 0, "%s.%s", tsection,
3300
3301 res = secfile_lookup_str_vec(file, &nval, "%s.resources", tsection);
3303 "%s.resource_freq", tsection);
3304 if (nval2 > 0 && nval2 != nval) {
3305 ruleset_error(nullptr, LOG_ERROR,
3306 "\"%s\": [%s] Different lengths for resources "
3307 "and resource frequencies",
3308 filename, tsection);
3309 ok = FALSE;
3310 }
3311 pterrain->resources = fc_calloc(nval + 1, sizeof(*pterrain->resources));
3312 pterrain->resource_freq = fc_calloc(nval + 1,
3313 sizeof(*pterrain->resource_freq));
3314 for (j = 0; j < nval; j++) {
3315 pterrain->resources[j] = lookup_resource(filename, res[j], tsection);
3316 if (pterrain->resources[j] == nullptr) {
3317 ok = FALSE;
3318 break;
3319 }
3320 pterrain->resource_freq[j] = j < nval2
3321 ? res_freq[j]
3323 if (pterrain->resource_freq[j] < RESOURCE_FREQUENCY_MINIMUM
3324 || pterrain->resource_freq[j] > RESOURCE_FREQUENCY_MAXIMUM) {
3325 ruleset_error(nullptr, LOG_ERROR,
3326 "\"%s\": [%s] Resource frequency '%d' "
3327 "outside allowed range",
3328 filename, tsection,
3329 pterrain->resource_freq[j]);
3330 ok = FALSE;
3331 break;
3332 }
3333 }
3334 pterrain->resources[nval] = nullptr;
3335 /* Terminating zero technically not necessary */
3336 pterrain->resource_freq[nval] = 0;
3337 free(res);
3338 res = nullptr;
3339 free(res_freq);
3340 res_freq = nullptr;
3341
3342 if (!ok) {
3343 break;
3344 }
3345
3347 pterrain->road_output_incr_pct[o]
3348 = secfile_lookup_int_default(file, 0, "%s.road_%s_incr_pct",
3351
3352 if (!lookup_time(file, &pterrain->base_time, tsection, "base_time",
3353 filename, nullptr, &ok)
3354 || !lookup_time(file, &pterrain->road_time, tsection, "road_time",
3355 filename, nullptr, &ok)) {
3356 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
3357 ok = FALSE;
3358 break;
3359 }
3360
3361 if (!lookup_terrain(file, "cultivate_result", filename, pterrain,
3362 &pterrain->cultivate_result, FALSE)) {
3363 ruleset_error(nullptr, LOG_ERROR, "%s: No cultivate_result", tsection);
3364 ok = FALSE;
3365 break;
3366 }
3367 if (pterrain->cultivate_result == pterrain) {
3368 ruleset_error(nullptr, LOG_ERROR,
3369 "%s: Cultivating result in terrain itself.",
3370 tsection);
3371 ok = FALSE;
3372 break;
3373 }
3374 if (!secfile_lookup_int(file, &pterrain->irrigation_food_incr,
3375 "%s.irrigation_food_incr", tsection)
3376 || !lookup_time(file, &pterrain->irrigation_time,
3377 tsection, "irrigation_time", filename, nullptr, &ok)) {
3378 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
3379 ok = FALSE;
3380 break;
3381 }
3382
3383 if (!lookup_terrain(file, "plant_result", filename, pterrain,
3384 &pterrain->plant_result, FALSE)) {
3385 ruleset_error(nullptr, LOG_ERROR, "%s: No plant_result", tsection);
3386 ok = FALSE;
3387 break;
3388 }
3389 if (pterrain->plant_result == pterrain) {
3390 ruleset_error(nullptr, LOG_ERROR,
3391 "%s: Planting result in terrain itself.",
3392 tsection);
3393 ok = FALSE;
3394 break;
3395 }
3396 if (!secfile_lookup_int(file, &pterrain->mining_shield_incr,
3397 "%s.mining_shield_incr", tsection)
3398 || !lookup_time(file, &pterrain->mining_time,
3399 tsection, "mining_time", filename, nullptr, &ok)) {
3400 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
3401 ok = FALSE;
3402 break;
3403 }
3404
3405 if (!lookup_time(file, &pterrain->cultivate_time,
3406 tsection, "cultivate_time", filename, nullptr, &ok)) {
3407 ruleset_error(nullptr, LOG_ERROR,
3408 "%s: Missing cultivate_time", tsection);
3409 ok = FALSE;
3410 break;
3411 }
3412 if ((pterrain->cultivate_result != nullptr
3413 && pterrain->cultivate_time <= 0)
3414 || (pterrain->cultivate_result == nullptr
3415 && pterrain->cultivate_time > 0)) {
3416 ruleset_error(nullptr, LOG_ERROR,
3417 "%s: cultivate_result and cultivate_time disagree "
3418 "whether cultivating is enabled", tsection);
3419 ok = FALSE;
3420 break;
3421 }
3422
3423 if (!lookup_time(file, &pterrain->plant_time,
3424 tsection, "plant_time", filename, nullptr, &ok)) {
3425 ruleset_error(nullptr, LOG_ERROR,
3426 "%s: Missing plant_time", tsection);
3427 ok = FALSE;
3428 break;
3429 }
3430 if ((pterrain->plant_result != nullptr
3431 && pterrain->plant_time <= 0)
3432 || (pterrain->plant_result == nullptr
3433 && pterrain->plant_time > 0)) {
3434 ruleset_error(nullptr, LOG_ERROR,
3435 "%s: plant_result and plant_time disagree "
3436 "whether planting is enabled", tsection);
3437 ok = FALSE;
3438 break;
3439 }
3440
3441 res = secfile_lookup_str_vec(file, &nval, "%s.animals", tsection);
3442 pterrain->num_animals = nval;
3443 if (pterrain->num_animals == 0) {
3444 pterrain->animals = nullptr;
3445 } else {
3446 pterrain->animals = fc_calloc(pterrain->num_animals,
3447 sizeof(*pterrain->animals));
3448 for (j = 0; j < pterrain->num_animals; j++) {
3449 pterrain->animals[j] = unit_type_by_rule_name(res[j]);
3450 if (pterrain->animals[j] == nullptr) {
3451 ok = FALSE;
3452 break;
3453 }
3454 }
3455 }
3456 free(res);
3457 res = nullptr;
3458 if (!ok) {
3459 break;
3460 }
3461
3462 if (!lookup_terrain(file, "transform_result", filename, pterrain,
3463 &pterrain->transform_result, TRUE)) {
3464 ok = FALSE;
3465 break;
3466 }
3467 if (!lookup_time(file, &pterrain->transform_time,
3468 tsection, "transform_time", filename, nullptr, &ok)) {
3469 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
3470 ok = FALSE;
3471 break;
3472 }
3473 if ((pterrain->transform_result != nullptr
3474 && pterrain->transform_time <= 0)
3475 || (pterrain->transform_result == nullptr
3476 && pterrain->transform_time > 0)) {
3477 ruleset_error(nullptr, LOG_ERROR,
3478 "%s: transform_result and transform_time disagree "
3479 "whether transforming is enabled", tsection);
3480 ok = FALSE;
3481 break;
3482 }
3483
3484 pterrain->placing_time = 1; /* Default */
3485 lookup_time(file, &pterrain->placing_time,
3486 tsection, "placing_time", filename, nullptr, &ok);
3487
3488 pterrain->pillage_time = 1; /* Default */
3489 lookup_time(file, &pterrain->pillage_time,
3490 tsection, "pillage_time", filename, nullptr, &ok);
3491
3492 if (!lookup_terrain(file, "warmer_wetter_result", filename, pterrain,
3493 &pterrain->warmer_wetter_result, TRUE)
3494 || !lookup_terrain(file, "warmer_drier_result", filename, pterrain,
3495 &pterrain->warmer_drier_result, TRUE)
3496 || !lookup_terrain(file, "cooler_wetter_result", filename, pterrain,
3497 &pterrain->cooler_wetter_result, TRUE)
3498 || !lookup_terrain(file, "cooler_drier_result", filename, pterrain,
3499 &pterrain->cooler_drier_result, TRUE)) {
3500 ok = FALSE;
3501 break;
3502 }
3503
3504 /* Set default removal times */
3505 extra_type_iterate(pextra) {
3506 pterrain->extra_removal_times[extra_index(pextra)] = 0;
3508
3509 for (j = 0; (ename = secfile_lookup_str_default(file, nullptr,
3510 "%s.extra_settings%d.extra",
3511 tsection, j)); j++) {
3512 const struct extra_type *pextra = extra_type_by_rule_name(ename);
3513
3514 if (pextra != nullptr) {
3515 char time_sections[512];
3516
3518 "%s.extra_settings%d", tsection, j);
3519
3520 lookup_time(file, &pterrain->extra_removal_times[extra_index(pextra)],
3521 time_sections, "removal_time", filename, nullptr, &ok);
3522 } else {
3523 ruleset_error(nullptr, LOG_ERROR,
3524 "\"%s\" [%s] has settings for unknown extra \"%s\".",
3525 filename, tsection, ename);
3526 ok = FALSE;
3527 break;
3528 }
3529 }
3530
3531 if (ok) {
3532 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", tsection);
3533 BV_CLR_ALL(pterrain->flags);
3534 for (j = 0; j < nval; j++) {
3535 const char *sval = slist[j];
3536 enum terrain_flag_id flag
3538
3539 if (!terrain_flag_id_is_valid(flag)) {
3540 ruleset_error(nullptr, LOG_ERROR,
3541 "\"%s\" [%s] has unknown flag \"%s\".",
3542 filename, tsection, sval);
3543 ok = FALSE;
3544 break;
3545 } else {
3546 BV_SET(pterrain->flags, flag);
3547 }
3548 }
3549
3550 free(slist);
3551 }
3552
3553 if (!ok) {
3554 break;
3555 }
3556
3557 {
3559
3563 pterrain->property[mtp]
3564 = secfile_lookup_int_default(file, 0, "%s.property_%s", tsection,
3566 }
3567 }
3568
3569 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", tsection);
3570 BV_CLR_ALL(pterrain->native_to);
3571 for (j = 0; j < nval; j++) {
3572 struct unit_class *class = unit_class_by_rule_name(slist[j]);
3573
3574 if (!class) {
3575 ruleset_error(nullptr, LOG_ERROR,
3576 "\"%s\" [%s] is native to unknown unit class \"%s\".",
3577 filename, tsection, slist[j]);
3578 ok = FALSE;
3579 break;
3580 } else {
3581 BV_SET(pterrain->native_to, uclass_index(class));
3582 }
3583 }
3584 free(slist);
3585
3586 if (!ok) {
3587 break;
3588 }
3589
3590 /* Get terrain color */
3591 {
3592 fc_assert_ret_val(pterrain->rgb == nullptr, FALSE);
3593
3594 if (!rgbcolor_load(file, &pterrain->rgb, "%s.color", tsection)) {
3595 ruleset_error(nullptr, LOG_ERROR,
3596 "Missing terrain color definition: %s",
3597 secfile_error());
3598 ok = FALSE;
3599 break;
3600 }
3601 }
3602
3603 pterrain->helptext = lookup_strvec(file, tsection, "helptext");
3605 }
3606
3607 if (ok) {
3608 /* Extra details */
3609 extra_type_iterate(pextra) {
3610 BV_CLR_ALL(pextra->conflicts);
3612
3613 extra_type_iterate(pextra) {
3614 int eidx = extra_index(pextra);
3615 const char *section = &extra_sections[eidx * MAX_SECTION_LABEL];
3616 const char **slist;
3617 struct requirement_vector *reqs;
3618 const char *catname;
3619 int cj;
3620 enum extra_cause cause;
3622 const char *eus_name;
3623 const char *vis_req_name;
3624 const struct advance *vis_req;
3625
3626 catname = secfile_lookup_str(file, "%s.category", section);
3627 if (catname == nullptr) {
3628 ruleset_error(nullptr, LOG_ERROR,
3629 "\"%s\" extra \"%s\" has no category.",
3630 filename, extra_rule_name(pextra));
3631 ok = FALSE;
3632 break;
3633 }
3634 pextra->category = extra_category_by_name(catname, fc_strcasecmp);
3635 if (!extra_category_is_valid(pextra->category)) {
3636 ruleset_error(nullptr, LOG_ERROR,
3637 "\"%s\" extra \"%s\" has invalid category \"%s\".",
3638 filename, extra_rule_name(pextra), catname);
3639 ok = FALSE;
3640 break;
3641 }
3642
3643 slist = secfile_lookup_str_vec(file, &nval, "%s.causes", section);
3644 pextra->causes = 0;
3645 for (cj = 0; cj < nval; cj++) {
3646 const char *sval = slist[cj];
3648
3649 if (!extra_cause_is_valid(cause)) {
3650 ruleset_error(nullptr, LOG_ERROR,
3651 "\"%s\" extra \"%s\": unknown cause \"%s\".",
3652 filename, extra_rule_name(pextra), sval);
3653 ok = FALSE;
3654 break;
3655 } else {
3656 pextra->causes |= (1 << cause);
3657 extra_to_caused_by_list(pextra, cause);
3658 }
3659 }
3660
3661 if (pextra->causes == 0) {
3662 /* Extras that do not have any causes added to EC_NONE list */
3664 }
3665
3666 if (!is_extra_caused_by(pextra, EC_BASE)
3667 && !is_extra_caused_by(pextra, EC_ROAD)
3668 && !is_extra_caused_by(pextra, EC_RESOURCE)) {
3669 /* Not a base, road, nor resource, so special */
3670 pextra->data.special_idx = extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL));
3672 }
3673
3674 free(slist);
3675
3676 slist = secfile_lookup_str_vec(file, &nval, "%s.rmcauses", section);
3677 pextra->rmcauses = 0;
3678 for (j = 0; j < nval; j++) {
3679 const char *sval = slist[j];
3680
3682
3684 ruleset_error(nullptr, LOG_ERROR,
3685 "\"%s\" extra \"%s\": unknown rmcause \"%s\".",
3686 filename, extra_rule_name(pextra), sval);
3687 ok = FALSE;
3688 break;
3689 } else {
3690 pextra->rmcauses |= (1 << rmcause);
3692 }
3693 }
3694
3695 free(slist);
3696
3697 sz_strlcpy(pextra->activity_gfx,
3699 "%s.activity_gfx", section));
3700 sz_strlcpy(pextra->act_gfx_alt,
3702 "%s.act_gfx_alt", section));
3703 sz_strlcpy(pextra->act_gfx_alt2,
3705 "%s.act_gfx_alt2", section));
3706 sz_strlcpy(pextra->rmact_gfx,
3708 "%s.rmact_gfx", section));
3709 sz_strlcpy(pextra->rmact_gfx_alt,
3711 "%s.rmact_gfx_alt", section));
3712 sz_strlcpy(pextra->rmact_gfx_alt2,
3714 "%s.rmact_gfx_alt2", section));
3715 sz_strlcpy(pextra->graphic_str,
3716 secfile_lookup_str_default(file, "-", "%s.graphic", section));
3717 sz_strlcpy(pextra->graphic_alt,
3719 "%s.graphic_alt", section));
3720
3721 reqs = lookup_req_list(file, section, "reqs", extra_rule_name(pextra));
3722 if (reqs == nullptr) {
3723 ok = FALSE;
3724 break;
3725 }
3726 requirement_vector_copy(&pextra->reqs, reqs);
3727
3728 reqs = lookup_req_list(file, section, "rmreqs", extra_rule_name(pextra));
3729 if (reqs == nullptr) {
3730 ok = FALSE;
3731 break;
3732 }
3733 requirement_vector_copy(&pextra->rmreqs, reqs);
3734
3735 reqs = lookup_req_list(file, section, "appearance_reqs", extra_rule_name(pextra));
3736 if (reqs == nullptr) {
3737 ok = FALSE;
3738 break;
3739 }
3740 requirement_vector_copy(&pextra->appearance_reqs, reqs);
3741
3742 reqs = lookup_req_list(file, section, "disappearance_reqs", extra_rule_name(pextra));
3743 if (reqs == nullptr) {
3744 ok = FALSE;
3745 break;
3746 }
3747 requirement_vector_copy(&pextra->disappearance_reqs, reqs);
3748
3749 pextra->buildable = secfile_lookup_bool_default(file,
3751 "%s.buildable", section);
3752 pextra->generated = secfile_lookup_bool_default(file, TRUE,
3753 "%s.generated", section);
3754
3755 pextra->build_time = 0; /* default */
3756 lookup_time(file, &pextra->build_time, section, "build_time",
3757 filename, extra_rule_name(pextra), &ok);
3758 pextra->build_time_factor = secfile_lookup_int_default(file, 1,
3759 "%s.build_time_factor", section);
3760 pextra->removal_time = 0; /* default */
3761 lookup_time(file, &pextra->removal_time, section, "removal_time",
3762 filename, extra_rule_name(pextra), &ok);
3763 pextra->removal_time_factor = secfile_lookup_int_default(file, 1,
3764 "%s.removal_time_factor", section);
3765 pextra->infracost = secfile_lookup_int_default(file, 0,
3766 "%s.infracost", section);
3767 if (pextra->infracost > 0) {
3768 terrain_control.infrapoints = TRUE;
3769 }
3770
3771 pextra->defense_bonus = secfile_lookup_int_default(file, 0,
3772 "%s.defense_bonus",
3773 section);
3774 if (pextra->defense_bonus != 0) {
3775 if (extra_has_flag(pextra, EF_NATURAL_DEFENSE)) {
3777 } else {
3779 }
3780 }
3781
3782 eus_name = secfile_lookup_str_default(file, "Normal", "%s.unit_seen", section);
3784 if (!extra_unit_seen_type_is_valid(pextra->eus)) {
3785 ruleset_error(nullptr, LOG_ERROR,
3786 "\"%s\" extra \"%s\" has illegal unit_seen value \"%s\".",
3787 filename, extra_rule_name(pextra), eus_name);
3788 ok = FALSE;
3789 break;
3790 }
3791 if (pextra->eus == EUS_HIDDEN) {
3793 }
3794
3795 pextra->appearance_chance = secfile_lookup_int_default(file, RS_DEFAULT_EXTRA_APPEARANCE,
3796 "%s.appearance_chance",
3797 section);
3798 pextra->disappearance_chance = secfile_lookup_int_default(file,
3800 "%s.disappearance_chance",
3801 section);
3802
3803 pextra->no_aggr_near_city = secfile_lookup_int_default(file, -1,
3804 "%s.no_aggr_near_city",
3805 section);
3806
3807 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", section);
3808 BV_CLR_ALL(pextra->native_to);
3809 for (j = 0; j < nval; j++) {
3810 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
3811
3812 if (uclass == nullptr) {
3813 ruleset_error(nullptr, LOG_ERROR,
3814 "\"%s\" extra \"%s\" is native to unknown unit class \"%s\".",
3815 filename, extra_rule_name(pextra), slist[j]);
3816 ok = FALSE;
3817 break;
3818 } else {
3819 BV_SET(pextra->native_to, uclass_index(uclass));
3820 }
3821 }
3822 free(slist);
3823
3824 if (!ok) {
3825 break;
3826 }
3827
3828 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
3829 BV_CLR_ALL(pextra->flags);
3830 for (j = 0; j < nval; j++) {
3831 const char *sval = slist[j];
3832 enum extra_flag_id flag;
3833
3835
3836 if (!extra_flag_id_is_valid(flag)) {
3837 ruleset_error(nullptr, LOG_ERROR,
3838 "\"%s\" extra \"%s\": unknown flag \"%s\".",
3839 filename, extra_rule_name(pextra), sval);
3840 ok = FALSE;
3841 break;
3842 } else {
3843 BV_SET(pextra->flags, flag);
3844 }
3845 }
3846 free(slist);
3847
3848 if (pextra->no_aggr_near_city >= 0) {
3850 }
3851
3852 if (extra_has_flag(pextra, EF_CAUSE_ZOC)) {
3854 }
3855
3856 if (!ok) {
3857 break;
3858 }
3859
3860 slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
3861 for (j = 0; j < nval; j++) {
3862 const char *sval = slist[j];
3864
3865 if (pextra2 == nullptr) {
3866 ruleset_error(nullptr, LOG_ERROR,
3867 "\"%s\" extra \"%s\": unknown conflict extra \"%s\".",
3868 filename, extra_rule_name(pextra), sval);
3869 ok = FALSE;
3870 break;
3871 } else {
3872 BV_SET(pextra->conflicts, extra_index(pextra2));
3873 BV_SET(pextra2->conflicts, extra_index(pextra));
3874 }
3875 }
3876
3877 free(slist);
3878
3879 if (!ok) {
3880 break;
3881 }
3882
3883 slist = secfile_lookup_str_vec(file, &nval, "%s.hidden_by", section);
3884 BV_CLR_ALL(pextra->hidden_by);
3885 for (j = 0; j < nval; j++) {
3886 const char *sval = slist[j];
3887 const struct extra_type *top = extra_type_by_rule_name(sval);
3888
3889 if (top == nullptr) {
3890 ruleset_error(nullptr, LOG_ERROR,
3891 "\"%s\" extra \"%s\" hidden by unknown extra \"%s\".",
3892 filename, extra_rule_name(pextra), sval);
3893 ok = FALSE;
3894 break;
3895 } else {
3896 BV_SET(pextra->hidden_by, extra_index(top));
3897 }
3898 }
3899 free(slist);
3900
3901 if (!ok) {
3902 break;
3903 }
3904
3905 slist = secfile_lookup_str_vec(file, &nval, "%s.bridged_over", section);
3906 BV_CLR_ALL(pextra->bridged_over);
3907 for (j = 0; j < nval; j++) {
3908 const char *sval = slist[j];
3909 const struct extra_type *top = extra_type_by_rule_name(sval);
3910
3911 if (top == nullptr) {
3912 ruleset_error(nullptr, LOG_ERROR,
3913 "\"%s\" extra \"%s\" bridged over unknown extra \"%s\".",
3914 filename, extra_rule_name(pextra), sval);
3915 ok = FALSE;
3916 break;
3917 } else {
3918 BV_SET(pextra->bridged_over, extra_index(top));
3919 }
3920 }
3921 free(slist);
3922
3923 if (!ok) {
3924 break;
3925 }
3926
3928 "%s.visibility_req", section);
3930
3931 if (vis_req == nullptr) {
3932 ruleset_error(nullptr, LOG_ERROR,
3933 "\"%s\" %s: unknown visibility_req %s.",
3934 filename, section, vis_req_name);
3935 ok = FALSE;
3936 break;
3937 }
3938
3939 pextra->visibility_req = advance_number(vis_req);
3940
3941 pextra->helptext = lookup_strvec(file, section, "helptext");
3943 }
3944
3945 if (ok) {
3946 int i = 0;
3947 /* Resource details */
3948
3950 char identifier[MAX_LEN_NAME];
3951 const char *id;
3953
3954 if (!presource->data.resource) {
3955 ruleset_error(nullptr, LOG_ERROR,
3956 "\"%s\" extra \"%s\" has \"Resource\" cause but no "
3957 "corresponding [resource_*] section",
3958 filename, extra_rule_name(presource));
3959 ok = FALSE;
3960 break;
3961 }
3962
3964 presource->data.resource->output[o]
3965 = secfile_lookup_int_default(file, 0, "%s.%s", rsection,
3968
3969 id = secfile_lookup_str_default(file, nullptr, "%s.identifier", rsection);
3970
3971 if (id == nullptr) {
3972 presource->data.resource->id_old_save = '\0';
3973 } else {
3974 sz_strlcpy(identifier, id);
3975
3976 presource->data.resource->id_old_save = identifier[0];
3977 if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
3978 ruleset_error(nullptr, LOG_ERROR,
3979 "\"%s\" [%s] identifier missing value.",
3980 filename, rsection);
3981 ok = FALSE;
3982 break;
3983 }
3984 if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
3985 ruleset_error(nullptr, LOG_ERROR,
3986 "\"%s\" [%s] cannot use '%c' as an identifier;"
3987 " it is reserved.",
3988 filename, rsection, presource->data.resource->id_old_save);
3989 ok = FALSE;
3990 break;
3991 }
3992 }
3993
3994 if (!ok) {
3995 break;
3996 }
3997
3998 i++;
4000
4001 for (j = 0; ok && j < game.control.num_resource_types; j++) {
4002 const char *section = &resource_sections[j * MAX_SECTION_LABEL];
4003 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4005
4006 if (!is_extra_caused_by(pextra, EC_RESOURCE)) {
4007 ruleset_error(nullptr, LOG_ERROR,
4008 "\"%s\" resource section [%s]: extra \"%s\" does not "
4009 "have \"Resource\" in its causes",
4010 filename, section, extra_name);
4011 ok = FALSE;
4012 }
4013 }
4014 }
4015
4016 if (ok) {
4017 /* This can't be part of previous loop as we don't want random data from previous
4018 * ruleset to play havoc on us when we have only some resource identifiers loaded
4019 * from the new ruleset. */
4021 if (pres->data.resource->id_old_save != '\0') {
4023 if (pres->data.resource->id_old_save == pres2->data.resource->id_old_save
4024 && pres != pres2) {
4025 ruleset_error(nullptr, LOG_ERROR,
4026 "\"%s\" [%s] has the same identifier as [%s].",
4027 filename,
4030 ok = FALSE;
4031 break;
4032 }
4034
4035 if (!ok) {
4036 break;
4037 }
4038 }
4040 }
4041
4042 if (ok) {
4043 /* Base details */
4045 struct base_type *pbase = extra_base_get(pextra);
4046 const char *section;
4047 const char *gui_str;
4048
4049 if (!pbase) {
4050 ruleset_error(nullptr, LOG_ERROR,
4051 "\"%s\" extra \"%s\" has \"Base\" cause but no "
4052 "corresponding [base_*] section",
4053 filename, extra_rule_name(pextra));
4054 ok = FALSE;
4055 break;
4056 }
4058
4059 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4061 if (!base_gui_type_is_valid(pbase->gui_type)) {
4062 ruleset_error(nullptr, LOG_ERROR,
4063 "\"%s\" base \"%s\": unknown gui_type \"%s\".",
4064 filename, extra_rule_name(pextra), gui_str);
4065 ok = FALSE;
4066 break;
4067 }
4068
4069 pbase->border_sq = secfile_lookup_int_default(file, -1, "%s.border_sq",
4070 section);
4071 pbase->vision_main_sq = secfile_lookup_int_default(file, -1,
4072 "%s.vision_main_sq",
4073 section);
4074 pbase->vision_invis_sq = secfile_lookup_int_default(file, -1,
4075 "%s.vision_invis_sq",
4076 section);
4077 pbase->vision_subs_sq = secfile_lookup_int_default(file, -1,
4078 "%s.vision_subs_sq",
4079 section);
4080
4081 if (!ok) {
4082 break;
4083 }
4084
4087
4089 struct base_type *pbase2;
4090
4091 if (pextra == pextra2) {
4092 /* End of the fully initialized bases iteration. */
4093 break;
4094 }
4095
4098 BV_SET(pextra->conflicts, extra_index(pextra2));
4099 BV_SET(pextra2->conflicts, extra_index(pextra));
4100 }
4102 }
4104
4105 for (j = 0; ok && j < game.control.num_base_types; j++) {
4106 const char *section = &base_sections[j * MAX_SECTION_LABEL];
4107 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4109
4110 if (!is_extra_caused_by(pextra, EC_BASE)) {
4111 ruleset_error(nullptr, LOG_ERROR,
4112 "\"%s\" base section [%s]: extra \"%s\" does not have "
4113 "\"Base\" in its causes",
4114 filename, section, extra_name);
4115 ok = FALSE;
4116 }
4117 }
4118 }
4119
4120 if (ok) {
4122 struct road_type *proad = extra_road_get(pextra);
4123 const char *section;
4124 const char **slist;
4125 const char *special;
4126 const char *modestr;
4127 struct requirement_vector *reqs;
4128 const char *gui_str;
4129
4130 if (!proad) {
4131 ruleset_error(nullptr, LOG_ERROR,
4132 "\"%s\" extra \"%s\" has \"Road\" cause but no "
4133 "corresponding [road_*] section",
4134 filename, extra_rule_name(pextra));
4135 ok = FALSE;
4136 break;
4137 }
4139
4140 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4142 if (!road_gui_type_is_valid(proad->gui_type)) {
4143 ruleset_error(nullptr, LOG_ERROR,
4144 "\"%s\" road \"%s\": unknown gui_type \"%s\".",
4145 filename, extra_rule_name(pextra), gui_str);
4146 ok = FALSE;
4147 break;
4148 }
4149
4150 reqs = lookup_req_list(file, section, "first_reqs", extra_rule_name(pextra));
4151 if (reqs == nullptr) {
4152 ok = FALSE;
4153 break;
4154 }
4155 requirement_vector_copy(&proad->first_reqs, reqs);
4156
4157 if (!secfile_lookup_int(file, &proad->move_cost,
4158 "%s.move_cost", section)) {
4159 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4160 ok = FALSE;
4161 break;
4162 }
4163
4164 modestr = secfile_lookup_str_default(file, "FastAlways", "%s.move_mode",
4165 section);
4167 if (!road_move_mode_is_valid(proad->move_mode)) {
4168 ruleset_error(nullptr, LOG_ERROR,
4169 "Illegal move_mode \"%s\" for road \"%s\"",
4170 modestr, extra_rule_name(pextra));
4171 ok = FALSE;
4172 break;
4173 }
4174
4176 proad->tile_incr_const[o] =
4177 secfile_lookup_int_default(file, 0, "%s.%s_incr_const",
4179 proad->tile_incr[o] =
4180 secfile_lookup_int_default(file, 0, "%s.%s_incr",
4182 proad->tile_bonus[o] =
4183 secfile_lookup_int_default(file, 0, "%s.%s_bonus",
4186
4187 special = secfile_lookup_str_default(file, "None", "%s.compat_special", section);
4188 if (!fc_strcasecmp(special, "Road")) {
4189 if (compat_road) {
4190 ruleset_error(nullptr, LOG_ERROR,
4191 "Multiple roads marked as compatibility \"Road\"");
4192 ok = FALSE;
4193 }
4194 compat_road = TRUE;
4195 proad->compat = ROCO_ROAD;
4196 } else if (!fc_strcasecmp(special, "Railroad")) {
4197 if (compat_rail) {
4198 ruleset_error(nullptr, LOG_ERROR,
4199 "Multiple roads marked as compatibility \"Railroad\"");
4200 ok = FALSE;
4201 }
4202 compat_rail = TRUE;
4203 proad->compat = ROCO_RAILROAD;
4204 } else if (!fc_strcasecmp(special, "River")) {
4205 if (compat_river) {
4206 ruleset_error(nullptr, LOG_ERROR,
4207 "Multiple roads marked as compatibility \"River\"");
4208 ok = FALSE;
4209 }
4211 proad->compat = ROCO_RIVER;
4212 } else if (!fc_strcasecmp(special, "None")) {
4213 proad->compat = ROCO_NONE;
4214 } else {
4215 ruleset_error(nullptr, LOG_ERROR,
4216 "Illegal compatibility special \"%s\" for road %s",
4217 special, extra_rule_name(pextra));
4218 ok = FALSE;
4219 }
4220
4221 if (!ok) {
4222 break;
4223 }
4224
4225 slist = secfile_lookup_str_vec(file, &nval, "%s.integrates", section);
4226 BV_CLR_ALL(proad->integrates);
4227 for (j = 0; j < nval; j++) {
4228 const char *sval = slist[j];
4230 struct road_type *top = nullptr;
4231
4232 if (textra != nullptr) {
4233 top = extra_road_get(textra);
4234 }
4235
4236 if (top == nullptr) {
4237 ruleset_error(nullptr, LOG_ERROR,
4238 "\"%s\" road \"%s\" integrates with unknown road \"%s\".",
4239 filename, extra_rule_name(pextra), sval);
4240 ok = FALSE;
4241 break;
4242 } else {
4243 BV_SET(proad->integrates, road_number(top));
4244 }
4245 }
4246 free(slist);
4247
4248 if (!ok) {
4249 break;
4250 }
4251
4252 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4253 BV_CLR_ALL(proad->flags);
4254 for (j = 0; j < nval; j++) {
4255 const char *sval = slist[j];
4257
4258 if (!road_flag_id_is_valid(flag)) {
4259 ruleset_error(nullptr, LOG_ERROR,
4260 "\"%s\" road \"%s\": unknown flag \"%s\".",
4261 filename, extra_rule_name(pextra), sval);
4262 ok = FALSE;
4263 break;
4264 } else {
4265 BV_SET(proad->flags, flag);
4266 }
4267 }
4268 free(slist);
4269
4270 if (!ok) {
4271 break;
4272 }
4274
4275 for (j = 0; ok && j < game.control.num_road_types; j++) {
4276 const char *section = &road_sections[j * MAX_SECTION_LABEL];
4277 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4279
4280 if (!is_extra_caused_by(pextra, EC_ROAD)) {
4281 ruleset_error(nullptr, LOG_ERROR,
4282 "\"%s\" road section [%s]: extra \"%s\" does not have "
4283 "\"Road\" in its causes",
4284 filename, section, extra_name);
4285 ok = FALSE;
4286 }
4287 }
4288 }
4289
4290 if (ok) {
4291 extra_type_iterate(pextra) {
4292 pextra->bridged = extra_type_list_new();
4294 if (BV_ISSET(pextra->bridged_over, pbridged->id)) {
4295 extra_type_list_append(pextra->bridged, pbridged);
4296 }
4299 }
4300
4301 if (ok) {
4302 /* Tiledef details */
4304 int tdidx = tiledef_index(td);
4306 const char **slist;
4307 int ej;
4308 const char *flag_name;
4309
4310 flag_name = secfile_lookup_str_default(file, nullptr,
4311 "%s.terrain_flag", section);
4312
4313 if (flag_name == nullptr) {
4314 td->terr_flag = terrain_flag_id_invalid();
4315 } else {
4317
4318 if (!terrain_flag_id_is_valid(td->terr_flag)) {
4319 ruleset_error(nullptr, LOG_ERROR,
4320 "%s: Invalid terrain flag %s.",
4322 ok = FALSE;
4323 break;
4324 }
4325 }
4326
4327 slist = secfile_lookup_str_vec(file, &nval, "%s.extras", section);
4328 for (ej = 0; ej < nval; ej++) {
4329 const char *sval = slist[ej];
4330 struct extra_type *pextra = extra_type_by_rule_name(sval);
4331
4332 if (pextra != nullptr) {
4334 if (pextra == old_extra) {
4335 ruleset_error(nullptr, LOG_ERROR,
4336 "%s: Duplicate extra %s.",
4337 section, extra_rule_name(pextra));
4338 ok = FALSE;
4339 break;
4340 }
4342
4343 if (ok) {
4344 extra_type_list_append(td->extras, pextra);
4345 }
4346 } else {
4347 ruleset_error(nullptr, LOG_ERROR,
4348 "%s: Unknown extra name \"%s\".",
4349 section, sval);
4350 ok = FALSE;
4351 }
4352
4353 if (ok) {
4354 td->known = secfile_lookup_bool_default(file, FALSE,
4355 "%s.known", section);
4356 }
4357
4358 if (!ok) {
4359 break;
4360 }
4361 }
4363 }
4364
4365 if (ok) {
4367 }
4368
4369 return ok;
4370}
4371
4372/**********************************************************************/
4376static bool load_government_names(struct section_file *file,
4377 struct rscompat_info *compat)
4378{
4379 int nval = 0;
4380 struct section_list *sec;
4381 const char *filename = secfile_name(file);
4382 bool ok = TRUE;
4383 const char *flag;
4384 int i;
4385
4386 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4387 return FALSE;
4388 }
4389
4390 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
4391 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
4392
4394 if (sec == nullptr || 0 == (nval = section_list_size(sec))) {
4395 ruleset_error(nullptr, LOG_ERROR, "\"%s\": No governments?!?", filename);
4396 ok = FALSE;
4397 } else if (nval > G_LAST) {
4398 ruleset_error(nullptr, LOG_ERROR,
4399 "\"%s\": Too many governments (%d, max %d)",
4400 filename, nval, G_LAST);
4401 ok = FALSE;
4402 }
4403
4404 if (ok) {
4406
4407 /* Government names are needed early so that get_government_by_name will
4408 * work. */
4409 governments_iterate(gov) {
4410 const char *sec_name =
4412
4413 if (!ruleset_load_names(&gov->name, nullptr, file, sec_name)) {
4414 ok = FALSE;
4415 break;
4416 }
4418 }
4419
4421
4422 if (ok) {
4424 nval = (sec != nullptr ? section_list_size(sec) : 0);
4425
4426 if (nval > MAX_NUM_MULTIPLIERS) {
4427 ruleset_error(nullptr, LOG_ERROR,
4428 "\"%s\": Too many multipliers (%d, max %d)",
4429 filename, nval, MAX_NUM_MULTIPLIERS);
4430
4431 ok = FALSE;
4432 } else {
4434 }
4435
4436 if (ok) {
4437 multipliers_iterate(pmul) {
4438 const char *sec_name
4440
4441 if (!ruleset_load_names(&pmul->name, nullptr, file, sec_name)) {
4442 ruleset_error(nullptr, LOG_ERROR,
4443 "\"%s\": Cannot load multiplier names",
4444 filename);
4445 ok = FALSE;
4446 break;
4447 }
4449 }
4450 }
4451
4452 /* User government flag names */
4453 for (i = 0;
4454 (flag = secfile_lookup_str_default(file, nullptr,
4455 "control.flags%d.name",
4456 i));
4457 i++) {
4458 const char *helptxt = secfile_lookup_str_default(file, nullptr,
4459 "control.flags%d.helptxt", i);
4460
4462 != gov_flag_id_invalid()) {
4463 ruleset_error(nullptr, LOG_ERROR,
4464 "\"%s\": Duplicate government flag name '%s'",
4465 filename, flag);
4466 ok = FALSE;
4467 break;
4468 }
4470 ruleset_error(nullptr, LOG_ERROR,
4471 "\"%s\": Too many user government flags!",
4472 filename);
4473 ok = FALSE;
4474 break;
4475 }
4476
4477 set_user_gov_flag_name(GOVF_USER_FLAG_1 + i, flag, helptxt);
4478 }
4479
4481
4482 return ok;
4483}
4484
4485/**********************************************************************/
4489 struct rscompat_info *compat)
4490{
4491 struct section_list *sec;
4492 const char *filename = secfile_name(file);
4493 bool ok = TRUE;
4494
4496
4498 = lookup_government(file, "governments.during_revolution", filename, nullptr);
4499 if (game.government_during_revolution == nullptr) {
4500 ok = FALSE;
4501 }
4502
4503 if (ok) {
4506
4507 /* Easy ones: */
4509 const int i = government_index(g);
4510 const char *sec_name = section_name(section_list_get(sec, i));
4511 struct requirement_vector *reqs
4512 = lookup_req_list(file, sec_name, "reqs", government_rule_name(g));
4513 const char **slist;
4514 int j;
4515 const char *sval;
4516 size_t nval;
4517
4518 if (reqs == nullptr) {
4519 ok = FALSE;
4520 break;
4521 }
4522
4523 if (secfile_entry_lookup(file, "%s.ai_better", sec_name) != nullptr) {
4524 char entry[100];
4525
4526 fc_snprintf(entry, sizeof(entry), "%s.ai_better", sec_name);
4527 g->ai.better = lookup_government(file, entry, filename, nullptr);
4528 if (g->ai.better == nullptr) {
4529 ok = FALSE;
4530 break;
4531 }
4532 } else {
4533 g->ai.better = nullptr;
4534 }
4535 requirement_vector_copy(&g->reqs, reqs);
4536
4537 sz_strlcpy(g->graphic_str,
4538 secfile_lookup_str(file, "%s.graphic", sec_name));
4539 sz_strlcpy(g->graphic_alt,
4540 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
4541 sz_strlcpy(g->sound_str,
4542 secfile_lookup_str_default(file, "-", "%s.sound", sec_name));
4543 sz_strlcpy(g->sound_alt,
4544 secfile_lookup_str_default(file, "-", "%s.sound_alt", sec_name));
4545 sz_strlcpy(g->sound_alt2,
4546 secfile_lookup_str_default(file, "-", "%s.sound_alt2", sec_name));
4547
4548 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
4549 BV_CLR_ALL(g->flags);
4550 for (j = 0; j < nval; j++) {
4551 enum gov_flag_id flag;
4552
4553 sval = slist[j];
4555 if (!gov_flag_id_is_valid(flag)) {
4556 ruleset_error(nullptr, LOG_ERROR,
4557 "\"%s\" government \"%s\": unknown flag \"%s\".",
4558 filename, government_rule_name(g), sval);
4559 ok = FALSE;
4560 break;
4561 } else {
4562 BV_SET(g->flags, flag);
4563 }
4564 }
4565 free(slist);
4566
4567 g->helptext = lookup_strvec(file, sec_name, "helptext");
4569 }
4570
4571
4572 if (ok) {
4573 /* Titles */
4575 const char *sec_name
4577 const char *male, *female;
4578
4579 if (!(male = secfile_lookup_str(file, "%s.ruler_male_title", sec_name))
4580 || !(female = secfile_lookup_str(file, "%s.ruler_female_title",
4581 sec_name))) {
4582 ruleset_error(nullptr, LOG_ERROR,
4583 "Lack of default ruler titles for "
4584 "government \"%s\" (nb %d): %s",
4586 secfile_error());
4587 ok = FALSE;
4588 break;
4589 } else if (government_ruler_title_new(g, nullptr, male, female) == nullptr) {
4590 ruleset_error(nullptr, LOG_ERROR,
4591 "Lack of default ruler titles for "
4592 "government \"%s\" (nb %d).",
4594 ok = FALSE;
4595 break;
4596 }
4598 }
4599
4601
4602 if (ok) {
4604 multipliers_iterate(pmul) {
4605 int id = multiplier_index(pmul);
4606 const char *sec_name = section_name(section_list_get(sec, id));
4607 struct requirement_vector *reqs;
4608
4609 if (!secfile_lookup_int(file, &pmul->start, "%s.start", sec_name)) {
4610 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4611 ok = FALSE;
4612 break;
4613 }
4614 if (!secfile_lookup_int(file, &pmul->stop, "%s.stop", sec_name)) {
4615 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4616 ok = FALSE;
4617 break;
4618 }
4619 if (pmul->stop <= pmul->start) {
4620 ruleset_error(nullptr, LOG_ERROR,
4621 "Multiplier \"%s\" stop (%d) must be greater "
4622 "than start (%d)", multiplier_rule_name(pmul),
4623 pmul->stop, pmul->start);
4624 ok = FALSE;
4625 break;
4626 }
4627 if (!secfile_lookup_int(file, &pmul->step, "%s.step", sec_name)) {
4628 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4629 ok = FALSE;
4630 break;
4631 }
4632 if (((pmul->stop - pmul->start) % pmul->step) != 0) {
4633 ruleset_error(nullptr, LOG_ERROR,
4634 "Multiplier \"%s\" step (%d) does not fit "
4635 "exactly into interval start-stop (%d to %d)",
4636 multiplier_rule_name(pmul), pmul->step,
4637 pmul->start, pmul->stop);
4638 ok = FALSE;
4639 break;
4640 }
4641 if (!secfile_lookup_int(file, &pmul->def, "%s.default", sec_name)) {
4642 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4643 ok = FALSE;
4644 break;
4645 }
4646 if (pmul->def < pmul->start || pmul->def > pmul->stop) {
4647 ruleset_error(nullptr, LOG_ERROR,
4648 "Multiplier \"%s\" default (%d) not within "
4649 "legal range (%d to %d)", multiplier_rule_name(pmul),
4650 pmul->def, pmul->start, pmul->stop);
4651 ok = FALSE;
4652 break;
4653 }
4654 if (((pmul->def - pmul->start) % pmul->step) != 0) {
4655 ruleset_error(nullptr, LOG_ERROR,
4656 "Multiplier \"%s\" default (%d) not legal "
4657 "with respect to step size %d",
4658 multiplier_rule_name(pmul), pmul->def, pmul->step);
4659 ok = FALSE;
4660 break;
4661 }
4662 pmul->offset = secfile_lookup_int_default(file, 0,
4663 "%s.offset", sec_name);
4664 pmul->factor = secfile_lookup_int_default(file, 100,
4665 "%s.factor", sec_name);
4666 if (pmul->factor == 0) {
4667 ruleset_error(nullptr, LOG_ERROR,
4668 "Multiplier \"%s\" scaling factor must "
4669 "not be zero", multiplier_rule_name(pmul));
4670 ok = FALSE;
4671 break;
4672 }
4673
4674 pmul->minimum_turns = secfile_lookup_int_default(file, 0,
4675 "%s.minimum_turns",
4676 sec_name);
4677
4678 reqs = lookup_req_list(file, sec_name, "reqs",
4679 multiplier_rule_name(pmul));
4680 if (reqs == nullptr) {
4681 ok = FALSE;
4682 break;
4683 }
4684 requirement_vector_copy(&pmul->reqs, reqs);
4685
4686 pmul->helptext = lookup_strvec(file, sec_name, "helptext");
4689 }
4690
4691 if (ok) {
4693 }
4694
4695 return ok;
4696}
4697
4698/**********************************************************************/
4709static void send_ruleset_control(struct conn_list *dest)
4710{
4712 int idx = 0;
4713
4715
4716 if (game.ruleset_summary != nullptr) {
4717 struct packet_ruleset_summary summary;
4718
4720
4721 lsend_packet_ruleset_summary(dest, &summary);
4722 }
4723
4724 while (desc_left > 0) {
4726 int this_len = desc_left;
4727
4728 if (this_len > MAX_LEN_CONTENT - 21) {
4730 }
4731
4732 part.text[this_len] = '\0';
4733
4735 idx += this_len;
4737
4739 }
4740}
4741
4742/**********************************************************************/
4747static const char *check_leader_names(struct nation_type *pnation)
4748{
4750 const char *name = nation_leader_name(pleader);
4751
4753 if (prev_leader == pleader) {
4754 break;
4755 } else if (0 == fc_strcasecmp(name, nation_leader_name(prev_leader))) {
4756 return name;
4757 }
4760
4761 return nullptr;
4762}
4763
4764/**********************************************************************/
4768static bool load_nation_names(struct section_file *file,
4769 struct rscompat_info *compat)
4770{
4771 struct section_list *sec;
4772 int j;
4773 bool ok = TRUE;
4774 const char *filename = secfile_name(file);
4775
4776 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4777 return FALSE;
4778 }
4779
4780 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
4781 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
4782
4784 if (sec == nullptr) {
4785 ruleset_error(nullptr, LOG_ERROR,
4786 "No available nations in this ruleset!");
4787 ok = FALSE;
4788 } else if (section_list_size(sec) > MAX_NUM_NATIONS) {
4789 ruleset_error(nullptr, LOG_ERROR,
4790 "Too many nations (max %d, we have %d)!",
4792 ok = FALSE;
4793 } else {
4796
4798 const int i = nation_index(pl);
4799 const char *sec_name = section_name(section_list_get(sec, i));
4800 const char *domain = secfile_lookup_str_default(file, nullptr,
4801 "%s.translation_domain", sec_name);
4802 const char *noun_plural = secfile_lookup_str(file,
4803 "%s.plural", sec_name);
4804
4805
4806 if (domain == nullptr) {
4807 domain = "freeciv-nations";
4808 }
4809
4810 if (!strcmp("freeciv-core", domain)) {
4811 pl->translation_domain = nullptr;
4812 } else if (!strcmp("freeciv-nations", domain)) {
4813 pl->translation_domain = fc_strdup(domain);
4814 } else {
4815 ruleset_error(nullptr, LOG_ERROR,
4816 "Unsupported translation domain \"%s\" for %s",
4817 domain, sec_name);
4818 ok = FALSE;
4819 break;
4820 }
4821
4822 if (!ruleset_load_names(&pl->adjective, pl->translation_domain, file, sec_name)) {
4823 ok = FALSE;
4824 break;
4825 }
4826 name_set(&pl->noun_plural, pl->translation_domain, noun_plural);
4827
4828 /* Check if nation name is already defined. */
4829 for (j = 0; j < i && ok; j++) {
4830 struct nation_type *n2 = nation_by_number(j);
4831
4832 /* Compare strings after stripping off qualifiers -- we don't want
4833 * two nations to end up with identical adjectives displayed to users.
4834 * (This check only catches English, not localisations, of course.) */
4835 if (0 == strcmp(Qn_(untranslated_name(&n2->adjective)),
4836 Qn_(untranslated_name(&pl->adjective)))) {
4837 ruleset_error(nullptr, LOG_ERROR,
4838 "Two nations defined with the same adjective \"%s\": "
4839 "in section \'%s\' and section \'%s\'",
4840 Qn_(untranslated_name(&pl->adjective)),
4842 ok = FALSE;
4843 } else if (!strcmp(rule_name_get(&n2->adjective),
4844 rule_name_get(&pl->adjective))) {
4845 /* We cannot have the same rule name, as the game needs them to be
4846 * distinct. */
4847 ruleset_error(nullptr, LOG_ERROR,
4848 "Two nations defined with the same rule_name \"%s\": "
4849 "in section \'%s\' and section \'%s\'",
4850 rule_name_get(&pl->adjective),
4852 ok = FALSE;
4853 } else if (0 == strcmp(Qn_(untranslated_name(&n2->noun_plural)),
4854 Qn_(untranslated_name(&pl->noun_plural)))) {
4855 /* We don't want identical English plural names either. */
4856 ruleset_error(nullptr, LOG_ERROR,
4857 "Two nations defined with the same plural name \"%s\": "
4858 "in section \'%s\' and section \'%s\'",
4859 Qn_(untranslated_name(&pl->noun_plural)),
4861 ok = FALSE;
4862 }
4863 }
4864 if (!ok) {
4865 break;
4866 }
4868 }
4869
4871
4872 if (ok) {
4874 if (sec != nullptr) {
4876
4877 section_list_iterate(sec, psection) {
4878 struct nation_group *pgroup;
4879 const char *name;
4880
4881 name = secfile_lookup_str(file, "%s.name", section_name(psection));
4882 if (name == nullptr) {
4883 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
4884 ok = FALSE;
4885 break;
4886 }
4888 if (pgroup == nullptr) {
4889 ok = FALSE;
4890 break;
4891 }
4894 sec = nullptr;
4895 }
4896 }
4897
4898 return ok;
4899}
4900
4901/**********************************************************************/
4904static bool is_on_allowed_list(const char *name, const char **list, size_t len)
4905{
4906 int i;
4907
4908 for (i = 0; i < len; i++) {
4909 if (!fc_strcasecmp(name, list[i])) {
4910 return TRUE;
4911 }
4912 }
4913 return FALSE;
4914}
4915
4916/**********************************************************************/
4920static bool load_city_name_list(struct section_file *file,
4921 struct nation_type *pnation,
4922 const char *secfile_str1,
4923 const char *secfile_str2,
4924 const char **allowed_terrains,
4925 size_t atcount)
4926{
4927 size_t dim, j;
4928 bool ok = TRUE;
4929 const char **cities = secfile_lookup_str_vec(file, &dim, "%s.%s",
4931
4932 /* Each string will be of the form "<cityname> (<label>, <label>, ...)".
4933 * The cityname is just the name for this city, while each "label" matches
4934 * a terrain type for the city (or "river"), with a preceding ! to negate
4935 * it. The parentheses are optional (but necessary to have the settings,
4936 * of course). Our job is now to parse it. */
4937 for (j = 0; j < dim; j++) {
4938 size_t len = strlen(cities[j]);
4939 char city_name[len + 1], *p, *next, *end;
4940 struct nation_city *pncity;
4941
4943
4944 /* Now we wish to determine values for all of the city labels. A value
4945 * of NCP_NONE means no preference (which is necessary so that the use
4946 * of this is optional); NCP_DISLIKE means the label is negated and
4947 * NCP_LIKE means it's labelled. Mostly the parsing just involves
4948 * a lot of ugly string handling... */
4949 if ((p = strchr(city_name, '('))) {
4950 *p++ = '\0';
4951
4952 if (!(end = strchr(p, ')'))) {
4953 ruleset_error(nullptr, LOG_ERROR,
4954 "\"%s\" [%s] %s: city name \"%s\" "
4955 "unmatched parenthesis.", secfile_name(file),
4957 ok = FALSE;
4958 } else {
4959 for (*end++ = '\0'; '\0' != *end; end++) {
4960 if (!fc_isspace(*end)) {
4961 ruleset_error(nullptr, LOG_ERROR,
4962 "\"%s\" [%s] %s: city name \"%s\" "
4963 "contains characters after last parenthesis.",
4965 cities[j]);
4966 ok = FALSE;
4967 break;
4968 }
4969 }
4970 }
4971 }
4972
4973 /* Build the nation_city. */
4976 /* The ruleset contains a name that is too long. This shouldn't
4977 * happen - if it does, the author should get immediate feedback. */
4978 ruleset_error(nullptr, LOG_ERROR,
4979 "\"%s\" [%s] %s: city name \"%s\" is too long.",
4980 secfile_name(file),
4982 ok = FALSE;
4983 city_name[MAX_LEN_CITYNAME - 1] = '\0';
4984 }
4985 pncity = nation_city_new(pnation, city_name);
4986
4987 if (p != nullptr) {
4988 /* Handle the labels one at a time. */
4989 do {
4990 enum nation_city_preference prefer;
4991
4992 if ((next = strchr(p, ','))) {
4993 *next = '\0';
4994 }
4996
4997 /* The ! is used to mark a negative, which is recorded with
4998 * NCP_DISLIKE. Otherwise we use a NCP_LIKE.
4999 */
5000 if (*p == '!') {
5001 p++;
5002 prefer = NCP_DISLIKE;
5003 } else {
5004 prefer = NCP_LIKE;
5005 }
5006
5007 if (0 == fc_strcasecmp(p, "river")) {
5008 if (game.server.ruledit.allowed_terrains != nullptr
5009 && !is_on_allowed_list(p,
5011 ruleset_error(nullptr, LOG_ERROR,
5012 "\"%s\" [%s] %s: city \"%s\" "
5013 "has terrain hint \"%s\" not in allowed_terrains.",
5015 city_name, p);
5016 ok = FALSE;
5017 } else {
5019 }
5020 } else {
5021 const struct terrain *pterrain = terrain_by_rule_name(p);
5022
5023 if (pterrain == nullptr) {
5024 /* Try with removing frequent trailing 's'. */
5025 size_t l = strlen(p);
5026
5027 if (0 < l && 's' == fc_tolower(p[l - 1])) {
5028 char saved = p[l - 1];
5029
5030 p[l - 1] = '\0';
5031 pterrain = terrain_by_rule_name(p);
5032 if (pterrain == nullptr) {
5033 /* Didn't help, restore for later allowed_terrains check */
5034 p[l - 1] = saved;
5035 }
5036 }
5037 }
5038
5039 /* Nationset may have been devised with a specific set of terrains
5040 * in mind which don't quite match this ruleset, in which case we
5041 * (a) quietly ignore any hints mentioned that don't happen to be in
5042 * the current ruleset, (b) enforce that terrains mentioned by nations
5043 * must be on the list */
5044 if (pterrain != nullptr
5045 && game.server.ruledit.allowed_terrains != nullptr) {
5046 if (!is_on_allowed_list(p,
5048 /* Terrain exists, but not intended for these nations */
5049 ruleset_error(nullptr, LOG_ERROR,
5050 "\"%s\" [%s] %s: city \"%s\" "
5051 "has terrain hint \"%s\" not in allowed_terrains.",
5053 city_name, p);
5054 ok = FALSE;
5055 break;
5056 }
5057 } else if (!pterrain) {
5058 /* Terrain doesn't exist; only complain if it's not on any list */
5059 if (game.server.ruledit.allowed_terrains == nullptr
5060 || !is_on_allowed_list(p,
5062 ruleset_error(nullptr, LOG_ERROR,
5063 "\"%s\" [%s] %s: city \"%s\" "
5064 "has unknown terrain hint \"%s\".",
5066 city_name, p);
5067 ok = FALSE;
5068 break;
5069 }
5070 }
5071 if (pterrain != nullptr) {
5072 nation_city_set_terrain_preference(pncity, pterrain, prefer);
5073 }
5074 }
5075
5076 p = next ? next + 1 : nullptr;
5077 } while (p != nullptr && '\0' != *p);
5078 }
5079 }
5080
5081 if (cities != nullptr) {
5082 free(cities);
5083 }
5084
5085 return ok;
5086}
5087
5088/**********************************************************************/
5091static bool load_ruleset_nations(struct section_file *file,
5092 struct rscompat_info *compat)
5093{
5094 struct government *gov;
5095 int j;
5096 size_t dim;
5097 char temp_name[MAX_LEN_NAME];
5098 const char **vec;
5099 const char *name, *bad_leader;
5100 const char *sval;
5101 int default_set;
5102 const char *filename = secfile_name(file);
5103 struct section_list *sec = nullptr;
5104 enum trait tr;
5105 bool ok = TRUE;
5106
5107 name = secfile_lookup_str_default(file, nullptr, "ruledit.nationlist");
5108 if (name != nullptr) {
5110 }
5112 "ruledit.embedded_nations");
5113
5114 if (vec != nullptr) {
5115 /* Copy to persistent vector */
5118
5119 for (j = 0; j < game.server.ruledit.embedded_nations_count; j++) {
5121 }
5122
5123 free(vec);
5124 }
5125
5126 game.default_government = nullptr;
5127
5128 ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
5129 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5130 if (game.server.default_traits[tr].min < 0) {
5132 }
5133 if (game.server.default_traits[tr].max < 0) {
5135 }
5136 if (game.server.default_traits[tr].fixed < 0) {
5138
5139 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5141 }
5143 ruleset_error(nullptr, LOG_ERROR,
5144 "Default values for trait %s not sane.",
5145 trait_name(tr));
5146 ok = FALSE;
5147 break;
5148 }
5149 }
5150
5151 if (ok) {
5153 "compatibility.allowed_govs");
5154 if (vec != nullptr) {
5155 /* Copy to persistent vector */
5157 = fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
5159 (const char **)game.server.ruledit.nc_agovs;
5160
5161 for (j = 0; j < game.server.ruledit.ag_count; j++) {
5163 }
5164
5165 free(vec);
5166 }
5167
5169 "compatibility.allowed_terrains");
5170 if (vec != nullptr) {
5171 /* Copy to persistent vector */
5173 = fc_malloc(game.server.ruledit.at_count * sizeof(char *));
5175 (const char **)game.server.ruledit.nc_aterrs;
5176
5177 for (j = 0; j < game.server.ruledit.at_count; j++) {
5179 }
5180
5181 free(vec);
5182 }
5183
5185 "compatibility.allowed_styles");
5186 if (vec != nullptr) {
5187 /* Copy to persistent vector */
5189 = fc_malloc(game.server.ruledit.as_count * sizeof(char *));
5191 (const char **)game.server.ruledit.nc_astyles;
5192
5193 for (j = 0; j < game.server.ruledit.as_count; j++) {
5195 }
5196
5197 free(vec);
5198 }
5199
5200 sval = secfile_lookup_str_default(file, nullptr,
5201 "compatibility.default_government");
5202 /* We deliberately don't check this against allowed_govs. It's only
5203 * specified once so not vulnerable to typos, and may usefully be set in
5204 * a specific ruleset to a gov not explicitly known by the nation set. */
5205 if (sval != nullptr) {
5207 if (game.default_government == nullptr) {
5208 ruleset_error(nullptr, LOG_ERROR,
5209 "Tried to set unknown government type \"%s\" as default_government!",
5210 sval);
5211 ok = FALSE;
5212 } else {
5215 }
5216 }
5217 }
5218
5219 if (ok) {
5221 if (sec != nullptr) {
5223
5224 section_list_iterate(sec, psection) {
5225 const char *set_name, *set_rule_name, *set_description;
5226
5227 set_name = secfile_lookup_str(file, "%s.name", section_name(psection));
5229 secfile_lookup_str(file, "%s.rule_name", section_name(psection));
5230 set_description = secfile_lookup_str_default(file, "", "%s.description",
5231 section_name(psection));
5232 if (set_name == nullptr || set_rule_name == nullptr) {
5233 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
5234 ok = FALSE;
5235 break;
5236 }
5238 ok = FALSE;
5239 break;
5240 }
5243 sec = nullptr;
5244 } else {
5245 ruleset_error(nullptr, LOG_ERROR,
5246 "At least one nation set [" NATION_SET_SECTION_PREFIX "_*] "
5247 "must be defined.");
5248 ok = FALSE;
5249 }
5250 }
5251
5252 if (ok) {
5253 /* Default set that every nation is a member of. */
5254 sval = secfile_lookup_str_default(file, nullptr,
5255 "compatibility.default_nationset");
5256 if (sval != nullptr) {
5258
5259 if (pset != nullptr) {
5261 } else {
5262 ruleset_error(nullptr, LOG_ERROR,
5263 "Unknown default_nationset \"%s\".", sval);
5264 ok = FALSE;
5265 }
5266 } else if (nation_set_count() == 1) {
5267 /* If there's only one set defined, every nation is implicitly a
5268 * member of that set. */
5269 default_set = 0;
5270 } else {
5271 /* No default nation set; every nation must explicitly specify at
5272 * least one set to be a member of. */
5273 default_set = -1;
5274 }
5275 }
5276
5277 if (ok) {
5279 if (sec) {
5280 section_list_iterate(sec, psection) {
5281 struct nation_group *pgroup;
5282 bool hidden;
5283
5284 name = secfile_lookup_str(file, "%s.name", section_name(psection));
5286 if (pgroup == nullptr) {
5287 ok = FALSE;
5288 break;
5289 }
5290
5291 hidden = secfile_lookup_bool_default(file, FALSE, "%s.hidden",
5292 section_name(psection));
5294
5295 if (!secfile_lookup_int(file, &j, "%s.match", section_name(psection))) {
5296 ruleset_error(nullptr, LOG_ERROR, "Error: %s", secfile_error());
5297 ok = FALSE;
5298 break;
5299 }
5303 sec = nullptr;
5304 }
5305 }
5306
5307 if (ok) {
5309 nations_iterate(pnation) {
5310 struct nation_type *pconflict;
5311 const int i = nation_index(pnation);
5312 char tmp[200] = "\0";
5313 const char *barb_type;
5314 const char *sec_name = section_name(section_list_get(sec, i));
5315 const char *legend;
5316
5317 /* Nation sets and groups. */
5318 if (default_set >= 0) {
5319 nation_set_list_append(pnation->sets,
5321 }
5322 vec = secfile_lookup_str_vec(file, &dim, "%s.groups", sec_name);
5323 for (j = 0; j < dim; j++) {
5324 struct nation_set *pset = nation_set_by_rule_name(vec[j]);
5326
5327 fc_assert(pset == nullptr || pgroup == nullptr);
5328
5329 if (pset != nullptr) {
5330 nation_set_list_append(pnation->sets, pset);
5331 } else if (pgroup != nullptr) {
5332 nation_group_list_append(pnation->groups, pgroup);
5333 } else {
5334 /* For nation authors, this would probably be considered an error.
5335 * But it can happen normally. The civ1 compatibility ruleset only
5336 * uses the nations that were in civ1, so not all of the links will
5337 * exist. */
5338 log_verbose("Nation %s: Unknown set/group \"%s\".",
5339 nation_rule_name(pnation), vec[j]);
5340 }
5341 }
5342 if (vec != nullptr) {
5343 free(vec);
5344 }
5345 if (nation_set_list_size(pnation->sets) < 1) {
5346 ruleset_error(nullptr, LOG_ERROR,
5347 "Nation %s is not a member of any nation set",
5348 nation_rule_name(pnation));
5349 ok = FALSE;
5350 break;
5351 }
5352
5353 /* Nation conflicts. */
5354 vec = secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec_name);
5355 for (j = 0; j < dim; j++) {
5357
5358 if (pnation == pconflict) {
5359 ruleset_error(nullptr, LOG_ERROR,
5360 "Nation %s conflicts with itself",
5361 nation_rule_name(pnation));
5362 ok = FALSE;
5363 break;
5364 } else if (pconflict != nullptr) {
5365 nation_list_append(pnation->server.conflicts_with, pconflict);
5366 } else {
5367 /* For nation authors, this would probably be considered an error.
5368 * But it can happen normally. The civ1 compatibility ruleset only
5369 * uses the nations that were in civ1, so not all of the links will
5370 * exist. */
5371 log_verbose("Nation %s: conflicts_with nation \"%s\" is unknown.",
5372 nation_rule_name(pnation), vec[j]);
5373 }
5374 }
5375 if (vec != nullptr) {
5376 free(vec);
5377 }
5378 if (!ok) {
5379 break;
5380 }
5381
5382 /* Nation leaders. */
5383 for (j = 0; j < MAX_NUM_LEADERS; j++) {
5384 const char *sexstr;
5385 sex_t sex;
5386 bool is_male = FALSE;
5387
5388 name = secfile_lookup_str(file, "%s.leaders%d.name", sec_name, j);
5389 if (name == nullptr) {
5390 /* No more to read. */
5391 break;
5392 }
5393
5394 if (check_name(name)) {
5395 /* The ruleset contains a name that is too long. This shouldn't
5396 * happen - if it does, the author should get immediate feedback */
5398 ruleset_error(nullptr, LOG_ERROR,
5399 "Nation %s: leader name \"%s\" is too long.",
5400 nation_rule_name(pnation), name);
5401 ok = FALSE;
5402 break;
5403 }
5404
5405 sexstr = secfile_lookup_str(file, "%s.leaders%d.sex", sec_name, j);
5406 if (sexstr == nullptr) {
5407 ruleset_error(nullptr, LOG_ERROR,
5408 "Nation %s: leader \"%s\": %s.",
5409 nation_rule_name(pnation), name, secfile_error());
5410 ok = FALSE;
5411 break;
5412 }
5413
5415
5416 switch (sex) {
5417 case SEX_MALE:
5418 is_male = TRUE;
5419 break;
5420 case SEX_FEMALE:
5421 is_male = FALSE;
5422 break;
5423 case SEX_UNKNOWN:
5424 ruleset_error(nullptr, LOG_ERROR,
5425 "Nation %s: leader \"%s\" has unsupported "
5426 "sex variant \"%s\".",
5427 nation_rule_name(pnation), name, sexstr);
5428 ok = FALSE;
5429 break;
5430 }
5431
5432 if (ok) {
5433 (void) nation_leader_new(pnation, name, is_male);
5434 }
5435 }
5436 if (!ok) {
5437 break;
5438 }
5439
5440 /* Check the number of leaders. */
5441 if (j == MAX_NUM_LEADERS) {
5442 /* Too much leaders, get the real number defined in the ruleset. */
5443 while (secfile_entry_lookup(file, "%s.leaders%d.name",
5444 sec_name, j) != nullptr) {
5445 j++;
5446 }
5447 ruleset_error(nullptr, LOG_ERROR,
5448 "Nation %s: Too many leaders; max is %d",
5450 ok = FALSE;
5451 break;
5452 } else if (j == 0) {
5453 ruleset_error(nullptr, LOG_ERROR,
5454 "Nation %s: no leaders; at least one is required.",
5455 nation_rule_name(pnation));
5456 ok = FALSE;
5457 break;
5458 }
5459
5460 /* Check if leader name is not already defined in this nation. */
5461 if ((bad_leader = check_leader_names(pnation))) {
5462 ruleset_error(nullptr, LOG_ERROR,
5463 "Nation %s: leader \"%s\" defined more than once.",
5464 nation_rule_name(pnation), bad_leader);
5465 ok = FALSE;
5466 break;
5467 }
5468
5469 /* Nation player color preference, if any */
5470 fc_assert_ret_val(pnation->server.rgb == nullptr, FALSE);
5471 (void) rgbcolor_load(file, &pnation->server.rgb, "%s.color", sec_name);
5472
5473 /* Load nation traits */
5474 ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
5475 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5476 bool server_traits_used = TRUE;
5477
5478 if (pnation->server.traits[tr].min < 0) {
5479 pnation->server.traits[tr].min = game.server.default_traits[tr].min;
5480 } else {
5482 }
5483 if (pnation->server.traits[tr].max < 0) {
5484 pnation->server.traits[tr].max = game.server.default_traits[tr].max;
5485 } else {
5487 }
5488 if (pnation->server.traits[tr].fixed < 0) {
5489 if (server_traits_used) {
5490 pnation->server.traits[tr].fixed = game.server.default_traits[tr].fixed;
5491 } else {
5492 int diff = pnation->server.traits[tr].max - pnation->server.traits[tr].min;
5493
5494 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5495 pnation->server.traits[tr].fixed = diff / 2 + pnation->server.traits[tr].min;
5496 }
5497 }
5498 if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
5499 ruleset_error(nullptr, LOG_ERROR,
5500 "%s values for trait %s not sane.",
5501 nation_rule_name(pnation), trait_name(tr));
5502 ok = FALSE;
5503 break;
5504 }
5505 }
5506
5507 if (!ok) {
5508 break;
5509 }
5510
5511 pnation->is_playable =
5512 secfile_lookup_bool_default(file, TRUE, "%s.is_playable", sec_name);
5513
5514 /* Check barbarian type. Default is "None" meaning not a barbarian */
5515 barb_type = secfile_lookup_str_default(file, "None",
5516 "%s.barbarian_type", sec_name);
5517 pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp);
5518 if (!barbarian_type_is_valid(pnation->barb_type)) {
5519 ruleset_error(nullptr, LOG_ERROR,
5520 "Nation %s, barbarian_type is invalid (\"%s\")",
5521 nation_rule_name(pnation), barb_type);
5522 ok = FALSE;
5523 break;
5524 }
5525
5526 if (pnation->barb_type != NOT_A_BARBARIAN
5527 && pnation->is_playable) {
5528 /* We can't allow players to use barbarian nations, barbarians
5529 * may run out of nations */
5530 ruleset_error(nullptr, LOG_ERROR,
5531 "Nation %s marked both barbarian and playable.",
5532 nation_rule_name(pnation));
5533 ok = FALSE;
5534 break;
5535 }
5536
5537 /* Flags */
5538 sz_strlcpy(pnation->flag_graphic_str,
5539 secfile_lookup_str_default(file, "-", "%s.flag", sec_name));
5540 sz_strlcpy(pnation->flag_graphic_alt,
5542 "%s.flag_alt", sec_name));
5543
5544 /* Ruler titles */
5545 for (j = 0;; j++) {
5546 const char *male, *female;
5547
5548 name = secfile_lookup_str_default(file, nullptr,
5549 "%s.ruler_titles%d.government",
5550 sec_name, j);
5551 if (name == nullptr) {
5552 /* End of the list of ruler titles. */
5553 break;
5554 }
5555
5556 /* NB: Even if the government doesn't exist, we load the entries for
5557 * the ruler titles to avoid warnings about unused entries. */
5558 male = secfile_lookup_str(file, "%s.ruler_titles%d.male_title",
5559 sec_name, j);
5560 female = secfile_lookup_str(file, "%s.ruler_titles%d.female_title",
5561 sec_name, j);
5563
5564 /* Nationset may have been devised with a specific set of govs in
5565 * mind which don't quite match this ruleset, in which case we
5566 * (a) quietly ignore any govs mentioned that don't happen to be in
5567 * the current ruleset, (b) enforce that govs mentioned by nations
5568 * must be on the list */
5569 if (gov != nullptr && game.server.ruledit.allowed_govs != nullptr) {
5573 /* Gov exists, but not intended for these nations */
5574 gov = nullptr;
5575 ruleset_error(nullptr, LOG_ERROR,
5576 "Nation %s: government \"%s\" not in allowed_govs.",
5577 nation_rule_name(pnation), name);
5578 ok = FALSE;
5579 break;
5580 }
5581 } else if (!gov) {
5582 /* Gov doesn't exist; only complain if it's not on any list */
5583 if (game.server.ruledit.allowed_govs == nullptr
5587 ruleset_error(nullptr, LOG_ERROR,
5588 "Nation %s: government \"%s\" not found.",
5589 nation_rule_name(pnation), name);
5590 ok = FALSE;
5591 break;
5592 }
5593 }
5594 if (male != nullptr && female != nullptr) {
5595 if (gov) {
5596 (void) government_ruler_title_new(gov, pnation, male, female);
5597 }
5598 } else {
5599 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
5600 ok = FALSE;
5601 break;
5602 }
5603 }
5604 if (!ok) {
5605 break;
5606 }
5607
5608 /* City styles */
5609 name = secfile_lookup_str(file, "%s.style", sec_name);
5610 if (!name) {
5611 ruleset_error(nullptr, LOG_ERROR, "%s", secfile_error());
5612 ok = FALSE;
5613 break;
5614 }
5615 pnation->style = style_by_rule_name(name);
5616 if (pnation->style == nullptr) {
5617 if (game.server.ruledit.allowed_styles == nullptr
5621 ruleset_error(nullptr, LOG_ERROR,
5622 "Nation %s: Illegal style \"%s\"",
5623 nation_rule_name(pnation), name);
5624 ok = FALSE;
5625 break;
5626 } else {
5627 log_verbose("Nation %s: style \"%s\" not supported in this "
5628 "ruleset; using default.",
5629 nation_rule_name(pnation), name);
5630 pnation->style = style_by_number(0);
5631 }
5632 }
5633
5634 /* Civilwar nations */
5635 vec = secfile_lookup_str_vec(file, &dim,
5636 "%s.civilwar_nations", sec_name);
5637 for (j = 0; j < dim; j++) {
5639
5640 /* No test for duplicate nations is performed. If there is a duplicate
5641 * entry it will just cause that nation to have an increased
5642 * probability of being chosen. */
5643 if (pconflict == pnation) {
5644 ruleset_error(nullptr, LOG_ERROR,
5645 "Nation %s is its own civil war nation",
5646 nation_rule_name(pnation));
5647 ok = FALSE;
5648 break;
5649 } else if (pconflict != nullptr) {
5650 nation_list_append(pnation->server.civilwar_nations, pconflict);
5651 nation_list_append(pconflict->server.parent_nations, pnation);
5652 } else {
5653 /* For nation authors, this would probably be considered an error.
5654 * But it can happen normally. The civ1 compatibility ruleset only
5655 * uses the nations that were in civ1, so not all of the links will
5656 * exist. */
5657 log_verbose("Nation %s: civil war nation \"%s\" is unknown.",
5658 nation_rule_name(pnation), vec[j]);
5659 }
5660 }
5661 if (vec != nullptr) {
5662 free(vec);
5663 }
5664 if (!ok) {
5665 break;
5666 }
5667
5668 /* Load nation specific initial items */
5669 if (!lookup_tech_list(file, sec_name, "init_techs",
5670 pnation->init_techs, filename)) {
5671 ok = FALSE;
5672 break;
5673 }
5674 if (!lookup_building_list(file, sec_name, "init_buildings",
5675 pnation->init_buildings, filename)) {
5676 ok = FALSE;
5677 break;
5678 }
5679 if (!lookup_unit_list(file, sec_name, "init_units",
5680 pnation->init_units, filename)) {
5681 ok = FALSE;
5682 break;
5683 }
5684 fc_strlcat(tmp, sec_name, 200);
5685 fc_strlcat(tmp, ".init_government", 200);
5686 if (secfile_entry_by_path(file, tmp)) {
5687 pnation->init_government = lookup_government(file, tmp, filename,
5688 nullptr);
5689 /* If specified, init_government has to be in this specific ruleset,
5690 * not just allowed_govs */
5691 if (pnation->init_government == nullptr) {
5692 ok = FALSE;
5693 break;
5694 }
5695 /* ...but if a list of govs has been specified, enforce that this
5696 * nation's init_government is on the list. */
5697 if (game.server.ruledit.allowed_govs != nullptr
5698 && !is_on_allowed_list(government_rule_name(pnation->init_government),
5701 ruleset_error(nullptr, LOG_ERROR,
5702 "Nation %s: init_government \"%s\" not allowed.",
5703 nation_rule_name(pnation),
5704 government_rule_name(pnation->init_government));
5705 ok = FALSE;
5706 break;
5707 }
5708 }
5709
5710 /* Read default city names. */
5711 if (!load_city_name_list(file, pnation, sec_name, "cities",
5714 ok = FALSE;
5715 break;
5716 }
5717
5718 legend = secfile_lookup_str_default(file, "", "%s.legend", sec_name);
5719 pnation->legend = fc_strdup(legend);
5720 if (check_strlen(pnation->legend, MAX_LEN_MSG, nullptr)) {
5721 ruleset_error(nullptr, LOG_ERROR,
5722 "Nation %s: legend \"%s\" is too long.",
5723 nation_rule_name(pnation),
5724 pnation->legend);
5725 ok = FALSE;
5726 break;
5727 }
5728
5729 pnation->player = nullptr;
5732 sec = nullptr;
5733 }
5734
5735 /* Clean up on aborted load */
5736 if (sec != nullptr) {
5737 fc_assert(!ok);
5739 }
5740
5741 if (ok) {
5743 }
5744
5745 if (ok) {
5746 /* Update cached number of playable nations in the current set */
5748
5749 /* Sanity checks on all sets */
5752
5753 nations_iterate(pnation) {
5754 if (nation_is_in_set(pnation, pset)) {
5755 switch (nation_barbarian_type(pnation)) {
5756 case NOT_A_BARBARIAN:
5757 if (is_nation_playable(pnation)) {
5758 num_playable++;
5759 }
5760 break;
5761 case LAND_BARBARIAN:
5763 break;
5764 case SEA_BARBARIAN:
5766 break;
5767 case ANIMAL_BARBARIAN:
5768 /* Animals are optional */
5769 break;
5772 break;
5773 default:
5775 }
5776 }
5778 if (num_playable < 1) {
5779 ruleset_error(nullptr, LOG_ERROR,
5780 "Nation set \"%s\" has no playable nations. "
5781 "At least one required!", nation_set_rule_name(pset));
5782 ok = FALSE;
5783 break;
5784 }
5785 if (barb_land_count == 0 && barb_both_count == 0) {
5786 ruleset_error(nullptr, LOG_ERROR,
5787 "No land barbarian nation defined in set \"%s\". "
5788 "At least one required!", nation_set_rule_name(pset));
5789 ok = FALSE;
5790 break;
5791 }
5792 if (barb_sea_count == 0 && barb_both_count == 0) {
5793 ruleset_error(nullptr, LOG_ERROR,
5794 "No sea barbarian nation defined in set \"%s\". "
5795 "At least one required!", nation_set_rule_name(pset));
5796 ok = FALSE;
5797 break;
5798 }
5800 }
5801
5802 return ok;
5803}
5804
5805/**********************************************************************/
5809static bool load_style_names(struct section_file *file,
5810 struct rscompat_info *compat)
5811{
5812 bool ok = TRUE;
5813 struct section_list *sec;
5814 const char *filename = secfile_name(file);
5815
5816 if (!rscompat_check_cap_and_version(file, filename, compat)) {
5817 return FALSE;
5818 }
5819
5820 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
5821 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
5822
5824 if (sec == nullptr) {
5825 ruleset_error(nullptr, LOG_ERROR,
5826 "No available nation styles in this ruleset!");
5827 ok = FALSE;
5828 } else {
5830
5832
5834 const int i = style_index(ps);
5835 const char *sec_name = section_name(section_list_get(sec, i));
5836
5837 ruleset_load_names(&ps->name, nullptr, file, sec_name);
5839 }
5840
5842
5843 if (ok) {
5844 /* The citystyle sections: */
5845 int i = 0;
5846
5848 if (sec != nullptr) {
5850 section_list_iterate(sec, style) {
5851 if (!ruleset_load_names(&city_styles[i].name, nullptr, file,
5852 section_name(style))) {
5853 ok = FALSE;
5854 break;
5855 }
5856 i++;
5858
5860 } else {
5862 }
5863 }
5864
5865 return ok;
5866}
5867
5868/**********************************************************************/
5871static bool load_ruleset_styles(struct section_file *file,
5872 struct rscompat_info *compat)
5873{
5874 struct section_list *sec;
5875 int i;
5876 bool ok = TRUE;
5877
5878 /* City Styles ... */
5879
5881
5882 /* Get rest: */
5883 for (i = 0; i < game.control.num_city_styles; i++) {
5884 struct requirement_vector *reqs;
5885 const char *sec_name = section_name(section_list_get(sec, i));
5886
5887 sz_strlcpy(city_styles[i].graphic,
5888 secfile_lookup_str(file, "%s.graphic", sec_name));
5889 sz_strlcpy(city_styles[i].graphic_alt,
5890 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
5891 sz_strlcpy(city_styles[i].citizens_graphic,
5893 "%s.citizens_graphic", sec_name));
5894
5896 if (reqs == nullptr) {
5897 ok = FALSE;
5898 break;
5899 }
5901 }
5902
5904
5905 if (ok) {
5907
5908 if (sec != nullptr) {
5909 int musi;
5910
5913 musi = 0;
5914
5915 section_list_iterate(sec, psection) {
5916 struct requirement_vector *reqs;
5918 const char *sec_name = section_name(psection);
5919
5920 sz_strlcpy(pmus->music_peaceful,
5922 "%s.music_peaceful", sec_name));
5923 sz_strlcpy(pmus->music_combat,
5925 "%s.music_combat", sec_name));
5926
5927 reqs = lookup_req_list(file, sec_name, "reqs", "Music Style");
5928 if (reqs == nullptr) {
5929 ok = FALSE;
5930 break;
5931 }
5933
5934 musi++;
5936 }
5937
5939 }
5940
5941 return ok;
5942}
5943
5944/**********************************************************************/
5951 const char *uflags_path,
5952 const char *filename)
5953{
5954 /* Add each listed protected unit type flag as a !present
5955 * requirement. */
5956 if (secfile_entry_lookup(file, "%s", uflags_path)) {
5958 size_t psize;
5959 int i;
5960
5963 "%s", uflags_path);
5964
5965 if (!protecor_flag) {
5966 /* Entity exists but couldn't read it. */
5967 ruleset_error(nullptr, LOG_ERROR,
5968 "\"%s\": %s: bad unit type flag list.",
5969 filename, uflags_path);
5970
5971 return FALSE;
5972 }
5973
5974 for (i = 0; i < psize; i++) {
5978 FALSE, FALSE, TRUE,
5979 protecor_flag[i]));
5980 }
5981
5983 }
5984
5985 return TRUE;
5986}
5987
5988/**********************************************************************/
5994 const char *actions_path,
5995 const char *filename)
5996{
5997 /* Read the alternative actions. */
5998 if (secfile_entry_lookup(file, "%s", actions_path)) {
5999 enum gen_action *unit_acts;
6000 size_t asize;
6001 int i;
6002
6004 "%s", actions_path);
6005
6006 if (!unit_acts) {
6007 /* Entity exists but couldn't read it. */
6008 ruleset_error(nullptr, LOG_ERROR,
6009 "\"%s\": %s: bad action list",
6010 filename, actions_path);
6011
6012 return FALSE;
6013 }
6014
6015 for (i = 0; i < asize; i++) {
6016 auto_perf->alternatives[i] = unit_acts[i];
6017 }
6018
6019 free(unit_acts);
6020 }
6021
6022 return TRUE;
6023}
6024
6025/**********************************************************************/
6030 const char *item,
6031 const char *filename)
6032{
6033 char uflags_path[100];
6034 char action_path[100];
6035
6037 "missing_unit_upkeep.%s_protected", item);
6039 "missing_unit_upkeep.%s_unit_act", item);
6040
6042 filename)
6044 filename));
6045}
6046
6047/**********************************************************************/
6051static bool load_specialist(const struct section *psection,
6052 struct specialist *s,
6053 struct section_file *file)
6054{
6055 struct requirement_vector *reqs;
6056 const char *sec_name = section_name(psection);
6057 const char *item, *tag;
6058
6059 if (!ruleset_load_names(&s->name, nullptr, file, sec_name)) {
6060 return FALSE;
6061 }
6062
6064 "%s.short_name", sec_name);
6065 name_set(&s->abbreviation, nullptr, item);
6066
6067 tag = secfile_lookup_str(file, "%s.graphic", sec_name);
6068 if (nullptr == tag) {
6069 ruleset_error(nullptr, LOG_ERROR,
6070 "\"%s\": No graphic tag for specialist at %s.",
6071 secfile_name(file), sec_name);
6072 return FALSE;
6073 }
6074 sz_strlcpy(s->graphic_str, tag);
6077 "%s.graphic_alt", sec_name));
6078
6080 if (nullptr == reqs) {
6081 return FALSE;
6082 }
6084
6085 s->helptext = lookup_strvec(file, sec_name, "helptext");
6086
6087 return TRUE;
6088}
6089
6090/**********************************************************************/
6093static bool load_ruleset_cities(struct section_file *file,
6094 struct rscompat_info *compat)
6095{
6096 const char *filename = secfile_name(file);
6097 struct section_list *sec, *ssec = nullptr;
6098 int specs_count;
6099 bool ok = TRUE;
6100 int i = 0;
6101
6102 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6103 return FALSE;
6104 }
6105
6106 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
6107 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
6108
6109 /* Specialist options */
6111
6112 if (!sec) {
6113 ruleset_error(nullptr, LOG_ERROR, "\"%s\": No normal specialists.", filename);
6114
6115 ok = FALSE;
6116 } else {
6119 /* Superspecialists are optional */
6120 if (ssec) {
6122 }
6123 if (specs_count >= SP_MAX) {
6124 ruleset_error(nullptr, LOG_ERROR,
6125 "\"%s\": Too many specialists (%d, max %d).",
6126 filename, specs_count, SP_MAX);
6127 ok = FALSE;
6128 }
6129 }
6130
6131
6132 if (ok) {
6134
6135 section_list_iterate(sec, psection) {
6136 struct specialist *s = specialist_by_number(i);
6137
6138 ok = load_specialist(psection, s, file);
6139
6140 if (!ok) {
6141 break;
6142 }
6143
6144 if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
6146 }
6147 i++;
6149 }
6150
6151 if (ok){
6152 if (DEFAULT_SPECIALIST == -1) {
6153 ruleset_error(nullptr, LOG_ERROR,
6154 "\"%s\": must have zero reqs for at least one "
6155 "specialist type.", filename);
6156 ok = FALSE;
6157 } else {
6159 }
6160 }
6162 sec = nullptr;
6163
6164 if (ssec) {
6165 if (ok) {
6166 section_list_iterate(ssec, psection) {
6167 struct specialist *s = specialist_by_number(i);
6168
6169 ok = load_specialist(psection, s, file);
6170
6171 if (!ok) {
6172 break;
6173 }
6174
6175 i++;
6177 }
6178
6180 ssec = nullptr;
6181 }
6182
6183 if (ok) {
6184 /* City Parameters */
6185
6188 "parameters.celebrate_size_limit");
6190 secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
6193 "parameters.angry_citizens");
6194
6196 secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
6198 secfile_lookup_int_default(file, 0, "parameters.forced_science");
6200 secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
6202 secfile_lookup_int_default(file, 0, "parameters.forced_gold");
6204 + game.info.forced_gold != 100) {
6205 ruleset_error(nullptr, LOG_ERROR,
6206 "\"%s\": Forced taxes do not add up in ruleset!",
6207 filename);
6208 ok = FALSE;
6209 }
6210 }
6211
6212 if (ok) {
6213 /* civ1 & 2 didn't reveal tiles */
6216 "parameters.vision_reveal_tiles");
6217
6219 secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
6220
6221 /* Citizens configuration. */
6224 "citizen.nationality");
6227 "citizen.ubuilder_nationality");
6230 "citizen.convert_speed");
6232 secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
6234 secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
6235 }
6236
6237 if (ok) {
6238 /* Missing unit upkeep. */
6240
6241 /* Can't pay food upkeep! */
6243 auto_perf->cause = AAPC_UNIT_UPKEEP;
6244
6245 /* This is about food upkeep. */
6247 req_from_str("OutputType", "Local",
6248 FALSE, TRUE, TRUE,
6249 "Food"));
6250
6251 /* Internally represented as an action auto performer rule. */
6252 if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
6253 ok = FALSE;
6254 }
6255
6258 "missing_unit_upkeep.food_wipe");
6259
6260 /* Can't pay gold upkeep! */
6262 auto_perf->cause = AAPC_UNIT_UPKEEP;
6263
6264 /* This is about gold upkeep. */
6266 req_from_str("OutputType", "Local",
6267 FALSE, TRUE, TRUE,
6268 "Gold"));
6269
6270 /* Internally represented as an action auto performer rule. */
6271 if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
6272 ok = FALSE;
6273 }
6274
6277 "missing_unit_upkeep.gold_wipe");
6278
6279 /* Can't pay shield upkeep! */
6281 auto_perf->cause = AAPC_UNIT_UPKEEP;
6282
6283 /* This is about shield upkeep. */
6285 req_from_str("OutputType", "Local",
6286 FALSE, TRUE, TRUE,
6287 "Shield"));
6288
6289 /* Internally represented as an action auto performer rule. */
6290 if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
6291 ok = FALSE;
6292 }
6293
6296 "missing_unit_upkeep.shield_wipe");
6297 }
6298
6299 if (ok) {
6301 }
6302
6303 return ok;
6304}
6305
6306/**********************************************************************/
6309static bool load_ruleset_effects(struct section_file *file,
6310 struct rscompat_info *compat)
6311{
6312 struct section_list *sec;
6313 const char *filename;
6314 bool ok = TRUE;
6315
6316 filename = secfile_name(file);
6317
6318 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6319 return FALSE;
6320 }
6321
6322 secfile_entry_ignore_by_path(file, "datafile.description"); /* Unused */
6323 secfile_entry_ignore_by_path(file, "datafile.ruledit"); /* Unused */
6324
6326
6327 if (sec != nullptr) {
6328 section_list_iterate(sec, psection) {
6329 const char *sec_name = section_name(psection);
6330 enum effect_type main_type;
6331 enum effect_type ai_valued_as;
6332 const char *type;
6333
6334 type = secfile_lookup_str(file, "%s.type", sec_name);
6335 if (type == nullptr) {
6336 ruleset_error(nullptr, LOG_ERROR,
6337 "\"%s\" [%s] missing effect type.",
6338 filename, sec_name);
6339 ok = FALSE;
6340 break;
6341 }
6344 ruleset_error(nullptr, LOG_ERROR,
6345 "\"%s\" [%s] lists unknown effect type \"%s\".",
6346 filename, sec_name, type);
6347 ok = FALSE;
6348 break;
6349 }
6350 if (!is_user_effect(main_type)) {
6351 ruleset_error(nullptr, LOG_ERROR,
6352 "\"%s\" [%s] type \"%s\" is not an user effect.",
6353 filename, sec_name, type);
6354 ok = FALSE;
6355 break;
6356 }
6357
6358 type = secfile_lookup_str(file, "%s.ai_valued_as", sec_name);
6359 if (type == nullptr) {
6360 ruleset_error(nullptr, LOG_ERROR,
6361 "\"%s\" [%s] missing ai_valued_as.",
6362 filename, sec_name);
6363 ok = FALSE;
6364 break;
6365 }
6368 ruleset_error(nullptr, LOG_ERROR,
6369 "\"%s\" [%s] lists unknown ai_valued_as \"%s\".",
6370 filename, sec_name, type);
6371 ok = FALSE;
6372 break;
6373 }
6375 ruleset_error(nullptr, LOG_ERROR,
6376 "\"%s\" [%s] ai_valued_as \"%s\" is an user effect.",
6377 filename, sec_name, type);
6378 ok = FALSE;
6379 break;
6380 }
6381
6383 /* It has been set already! */
6384 ruleset_error(nullptr, LOG_ERROR,
6385 "\"%s\" [%s] Duplicate \"%s\" entry.",
6386 filename, sec_name, type);
6387 ok = FALSE;
6388 break;
6389 }
6390
6393
6395 }
6396
6397 /* Parse effects and add them to the effects ruleset cache. */
6399 section_list_iterate(sec, psection) {
6400 enum effect_type eff;
6401 int value;
6402 struct multiplier *pmul;
6403 struct effect *peffect;
6404 const char *sec_name = section_name(psection);
6405 struct requirement_vector *reqs;
6406 const char *type;
6407 const char *comment;
6408
6409 type = secfile_lookup_str(file, "%s.type", sec_name);
6410
6411 if (type == nullptr) {
6412 ruleset_error(nullptr, LOG_ERROR,
6413 "\"%s\" [%s] missing effect type.",
6414 filename, sec_name);
6415 ok = FALSE;
6416 break;
6417 }
6418
6419 if (compat->compat_mode && compat->version < RSFORMAT_3_4) {
6421 }
6422
6424 if (!effect_type_is_valid(eff)) {
6425 ruleset_error(nullptr, LOG_ERROR,
6426 "\"%s\" [%s] lists unknown effect type \"%s\".",
6427 filename, sec_name, type);
6428 ok = FALSE;
6429 break;
6430 }
6431
6432 value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
6433
6434 {
6435 const char *multiplier_name
6436 = secfile_lookup_str(file, "%s.multiplier", sec_name);
6437
6438 if (multiplier_name) {
6440 if (!pmul) {
6441 ruleset_error(nullptr, LOG_ERROR,
6442 "\"%s\" [%s] has unknown multiplier \"%s\".",
6443 filename, sec_name, multiplier_name);
6444 ok = FALSE;
6445 break;
6446 }
6447 } else {
6448 pmul = nullptr;
6449 }
6450 }
6451
6452 peffect = effect_new(eff, value, pmul);
6453
6454 reqs = lookup_req_list(file, sec_name, "reqs", type);
6455 if (reqs == nullptr) {
6456 ok = FALSE;
6457 break;
6458 }
6459
6463
6464 comment = secfile_lookup_str_default(file, nullptr, "%s.comment", sec_name);
6465
6466 if (comment != nullptr) {
6467 peffect->rulesave.comment = fc_strdup(comment);
6468 }
6469
6472
6473 if (ok) {
6475 }
6476
6477 return ok;
6478}
6479
6480/**********************************************************************/
6484 int def, int min, int max,
6485 const char *path, ...)
6486{
6487 char fullpath[256];
6488 int ival;
6489 va_list args;
6490
6491 va_start(args, path);
6492 fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
6493 va_end(args);
6494
6495 if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
6496 ival = def;
6497 }
6498
6499 if (ival < min) {
6500 ruleset_error(nullptr, LOG_ERROR,
6501 "\"%s\" should be in the interval [%d, %d] "
6502 "but is %d; using the minimal value.",
6503 fullpath, min, max, ival);
6504 ival = min;
6505 }
6506
6507 if (ival > max) {
6508 ruleset_error(nullptr, LOG_ERROR,
6509 "\"%s\" should be in the interval [%d, %d] "
6510 "but is %d; using the maximal value.",
6511 fullpath, min, max, ival);
6512 ival = max;
6513 }
6514
6515 return ival;
6516}
6517
6518/**********************************************************************/
6521static bool load_action_range_max(struct section_file *file, action_id act)
6522{
6523 struct action *paction = action_by_number(act);
6524 const char *vname = action_max_range_ruleset_var_name(act);
6525
6526 if (vname != nullptr) {
6527 struct entry *pentry;
6528 int max_range;
6529
6530 pentry = secfile_entry_lookup(file, "actions.%s", vname);
6531
6532 if (pentry == nullptr) {
6534 } else {
6535 const char *custom;
6536
6539 /* max_range already assigned */
6540 } else if (entry_type_get(pentry) == ENTRY_STR
6544 } else {
6545 ruleset_error(nullptr, LOG_ERROR, "Bad actions.%s",
6548
6549 return FALSE;
6550 }
6551 }
6552
6554 }
6555
6556 return TRUE;
6557}
6558
6559/**********************************************************************/
6562static bool load_action_range(struct section_file *file, action_id act)
6563{
6564 struct action *paction = action_by_number(act);
6565 const char *vname;
6566
6567 if (!load_action_range_max(file, act)) {
6568 return FALSE;
6569 }
6570
6572 if (vname != nullptr) {
6573 /* Min range can be loaded from the ruleset. */
6577 "actions.%s",
6578 vname);
6579 }
6580
6581 return TRUE;
6582}
6583
6584/**********************************************************************/
6587static bool load_action_kind(struct section_file *file, action_id act)
6588{
6589 struct action *paction = action_by_number(act);
6591
6592 if (var_name != nullptr) {
6596 paction->result),
6598 "actions.%s", var_name);
6599 } else {
6602 }
6603
6604 return TRUE;
6605}
6606
6607/**********************************************************************/
6611 action_id act)
6612{
6614 /* Actor consumption can be loaded from the ruleset. */
6617 file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
6619 }
6620
6621 return TRUE;
6622}
6623
6624/**********************************************************************/
6628 const char *filename,
6629 struct action *paction,
6630 struct rscompat_info *compat)
6631{
6633
6634 if (var_name != nullptr) {
6635 /* Action blocking can be loaded from the ruleset. */
6636 char fullpath[1024];
6637
6638 fc_snprintf(fullpath, sizeof(fullpath), "actions.%s", var_name);
6639
6640 if (secfile_entry_by_path(file, fullpath)) {
6642 size_t asize;
6643 int j;
6644
6647
6648 if (!blocking_actions) {
6649 /* Entity exists but couldn't read it. */
6650 ruleset_error(nullptr, LOG_ERROR,
6651 "\"%s\": %s: bad action list",
6652 filename, fullpath);
6653
6654 return FALSE;
6655 }
6656
6657 for (j = 0; j < asize; j++) {
6658 BV_SET(paction->blocked_by, blocking_actions[j]);
6659 }
6660
6662 }
6663 }
6664
6665 return TRUE;
6666}
6667
6668/**********************************************************************/
6673 const char *filename,
6674 int performer_slot,
6675 struct action *paction)
6676{
6678 char action_list_path[100];
6679
6681 /* Not relevant. */
6682 return TRUE;
6683 }
6684
6686 auto_perf->cause = AAPC_POST_ACTION;
6687
6688 /* Limit auto performer to this action. */
6691 FALSE, TRUE, TRUE,
6692 paction->id));
6693
6694 /* Load the list of actions. */
6696 "actions.%s",
6699 action_list_path, filename)) {
6700 return FALSE;
6701 }
6702
6703 return TRUE;
6704}
6705
6706/**********************************************************************/
6709static bool lookup_bv_actions(struct section_file *file,
6710 const char *filename,
6711 bv_actions *target,
6712 const char *path)
6713{
6714 if (secfile_entry_by_path(file, path)) {
6716 size_t asize;
6717 int j;
6718
6720 "%s", path);
6721
6722 if (!listed_actions) {
6723 /* Entity exists but couldn't read it. */
6724 ruleset_error(nullptr, LOG_ERROR, "\"%s\": %s: bad action list",
6725 filename, path);
6726
6727 return FALSE;
6728 }
6729
6730 for (j = 0; j < asize; j++) {
6731 BV_SET(*target, listed_actions[j]);
6732 }
6733
6735 }
6736
6737 return TRUE;
6738}
6739
6740/**********************************************************************/
6743static bool load_ruleset_game(struct section_file *file, bool act,
6744 struct rscompat_info *compat)
6745{
6746 const char *sval, **svec;
6747 const char *filename;
6748 int *food_ini;
6749 int i;
6750 size_t teams;
6751 const char *pref_text;
6752 size_t gni_tmp;
6753 struct section_list *sec;
6754 size_t nval;
6755 const char *name;
6756 bool ok = TRUE;
6757
6758 if (file == nullptr) {
6759 return FALSE;
6760 }
6761 filename = secfile_name(file);
6762
6763 name = secfile_lookup_str_default(file, nullptr, "ruledit.description_file");
6764 if (name != nullptr) {
6766 }
6768 = secfile_lookup_bool_default(file, FALSE, "ruledit.std_tileset_compat");
6769
6770 /* Section: tileset */
6771 pref_text = secfile_lookup_str_default(file, "", "tileset.preferred");
6772 if (pref_text[0] != '\0') {
6773 /* There was tileset suggestion */
6775 } else {
6776 /* No tileset suggestions */
6777 game.control.preferred_tileset[0] = '\0';
6778 }
6779
6780 /* Section: soundset */
6781 pref_text = secfile_lookup_str_default(file, "", "soundset.preferred");
6782 if (pref_text[0] != '\0') {
6783 /* There was soundset suggestion */
6785 } else {
6786 /* No soundset suggestions */
6788 }
6789
6790 /* Section: musicset */
6791 pref_text = secfile_lookup_str_default(file, "", "musicset.preferred");
6792 if (pref_text[0] != '\0') {
6793 /* There was musicset suggestion */
6795 } else {
6796 /* No musicset suggestions */
6798 }
6799
6800 /* Section: about */
6801 pref_text = secfile_lookup_str(file, "about.name");
6802 /* Ruleset/modpack name found */
6804
6805 pref_text = secfile_lookup_str_default(file, "", "about.version");
6806 if (pref_text[0] != '\0') {
6807 /* Ruleset/modpack version found */
6809 } else {
6810 /* No version information */
6811 game.control.version[0] = '\0';
6812 }
6813
6814 pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
6815 if (pref_text[0] != '\0') {
6816 /* Alt directory definition found. */
6818 } else {
6819 /* No alt directory information */
6820 game.control.alt_dir[0] = '\0';
6821 }
6822
6823 pref_text = secfile_lookup_str_default(file, "", "about.summary");
6824 if (pref_text[0] != '\0') {
6825 int len;
6826
6827 /* Ruleset/modpack summary found */
6828 len = strlen(pref_text);
6831 } else {
6832 /* No summary */
6833 if (game.ruleset_summary != nullptr) {
6835 game.ruleset_summary = nullptr;
6836 }
6837 }
6838
6839 pref_text = secfile_lookup_str_default(file, "", "about.description");
6840 if (pref_text[0] != '\0') {
6841 int len;
6842
6843 /* Ruleset/modpack description found */
6844 len = strlen(pref_text);
6848 } else {
6849 /* No description */
6850 if (game.ruleset_description != nullptr) {
6852 game.ruleset_description = nullptr;
6853 }
6855 }
6856
6857 pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
6858 if (pref_text[0] != '\0') {
6859 int len = strlen(pref_text);
6860
6863 } else {
6865 game.ruleset_capabilities[0] = '\0';
6866 }
6867
6868 /* Section: options */
6869 if (!lookup_tech_list(file, "options", "global_init_techs",
6870 game.rgame.global_init_techs, filename)) {
6871 ok = FALSE;
6872 }
6873
6874 if (ok) {
6875 if (!lookup_building_list(file, "options", "global_init_buildings",
6876 game.rgame.global_init_buildings, filename)) {
6877 ok = FALSE;
6878 }
6879 }
6880
6881 if (ok) {
6882 const char **slist;
6883 int j;
6884
6886 "options.popup_tech_help");
6887
6888 /* section: civstyle */
6891 "civstyle.base_pollution");
6892
6894
6895 slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
6896 for (j = 0; j < nval; j++) {
6897 enum gameloss_style style;
6898
6899 sval = slist[j];
6900 if (strcmp(sval, "") == 0) {
6901 continue;
6902 }
6904 if (!gameloss_style_is_valid(style)) {
6905 ruleset_error(nullptr, LOG_ERROR,
6906 "\"%s\": bad value \"%s\" for gameloss_style.",
6907 filename, sval);
6908 ok = FALSE;
6909 break;
6910 } else {
6911 game.info.gameloss_style |= style;
6912 }
6913 }
6914 free(slist);
6915 }
6916
6917 if (ok) {
6923 "civstyle.happy_cost");
6929 "civstyle.food_cost");
6935 "civstyle.base_bribe_cost");
6941 "civstyle.ransom_gold");
6944 "civstyle.pillage_select");
6945
6948 "civstyle.tech_steal_allow_holes");
6951 "civstyle.tech_trade_allow_holes");
6954 "civstyle.tech_trade_loss_allow_holes");
6957 "civstyle.tech_parasite_allow_holes");
6960 "civstyle.tech_loss_allow_holes");
6961
6967 "civstyle.upgrade_veteran_loss");
6973 "civstyle.autoupgrade_veteran_loss");
6974
6980 "research.base_tech_cost");
6981
6987 "research.min_tech_cost");
6988
6990 "civstyle.granary_food_ini");
6992
6994 ruleset_error(nullptr, LOG_ERROR,
6995 "Too many granary_food_ini entries (%d, max %d)",
6997 ok = FALSE;
6998 } else if (game.info.granary_num_inis == 0) {
6999 log_error("No values for granary_food_ini. Using default "
7000 "value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
7003 } else {
7004 int gi;
7005
7006 /* check for <= 0 entries */
7007 for (gi = 0; gi < game.info.granary_num_inis; gi++) {
7008 if (food_ini[gi] <= 0) {
7009 if (gi == 0) {
7011 } else {
7012 food_ini[gi] = food_ini[gi - 1];
7013 }
7014 log_error("Bad value for granary_food_ini[%i]. Using %i.",
7015 gi, food_ini[gi]);
7016 }
7018 }
7019 }
7020 free(food_ini);
7021 }
7022
7023 if (ok) {
7029 "civstyle.granary_food_inc");
7030
7037 "civstyle.min_city_center_%s",
7040 }
7041
7042 if (ok) {
7043 const char *tus_text;
7044
7050 "civstyle.init_vis_radius_sq");
7051
7057 "civstyle.init_city_radius_sq");
7058
7060 "civstyle.gold_upkeep_style");
7064 ruleset_error(nullptr, LOG_ERROR,
7065 "Unknown gold upkeep style \"%s\"",
7066 tus_text);
7067 ok = FALSE;
7068 }
7069
7070 if (compat->compat_mode
7071 && compat->version < RSFORMAT_3_4) {
7073 = secfile_lookup_bool_default(file, FALSE, "civstyle.homeless_gold_upkeep");
7074
7077 ruleset_error(nullptr, LOG_ERROR,
7078 "Cannot have homeless_gold_upkeep while gold_upkeep_style \"City\".");
7079 ok = FALSE;
7080 }
7081 } else {
7083 }
7084
7086 "civstyle.output_granularity");
7087
7089 = secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
7090
7092 = secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
7093
7094 /* Section: wonder_visibility */
7095 if (ok) {
7096 const char *text;
7097
7098 text = secfile_lookup_str_default(file,
7100 "wonder_visibility.small_wonders");
7101
7105 ruleset_error(nullptr, LOG_ERROR,
7106 "Unknown wonder visibility type \"%s\"",
7107 text);
7108 ok = FALSE;
7109 }
7110 }
7111
7112 /* section: illness */
7115 "illness.illness_on");
7121 "illness.illness_base_factor");
7127 "illness.illness_min_size");
7133 "illness.illness_trade_infection");
7139 "illness.illness_pollution_factor");
7140
7141 /* section: incite_cost */
7147 "incite_cost.base_incite_cost");
7153 "incite_cost.improvement_factor");
7159 "incite_cost.unit_factor");
7165 "incite_cost.total_factor");
7166 }
7167
7168 if (ok) {
7169 const char *tus_text;
7170
7171 /* Section: combat_rules */
7174 "combat_rules.tired_attack");
7175
7178 "combat_rules.only_killing_makes_veteran");
7179
7182 "combat_rules.only_real_fight_makes_veteran");
7183
7186 "combat_rules.combat_odds_scaled_veterancy");
7187
7190 "combat_rules.damage_reduces_bombard_rate");
7191
7194 "combat_rules.low_firepower_badwallattacker");
7197 "combat_rules.low_firepower_pearl_harbor");
7198
7201 "combat_rules.low_firepower_combat_bonus");
7204 "combat_rules.low_firepower_nonnat_bombard");
7205
7210 "combat_rules.nuke_pop_loss_pct");
7211
7216 "combat_rules.nuke_defender_survival_chance_pct");
7217
7218 /* section: borders */
7224 "borders.radius_sq_city");
7230 "borders.size_effect");
7231
7237 "borders.radius_sq_city_permanent");
7238
7239 /* Section: research */
7241 "research.tech_cost_style");
7245 ruleset_error(nullptr, LOG_ERROR,
7246 "Unknown tech cost style \"%s\"",
7247 tus_text);
7248 ok = FALSE;
7249 }
7250
7252 "research.tech_leakage");
7256 ruleset_error(nullptr, LOG_ERROR,
7257 "Unknown tech leakage \"%s\"",
7258 tus_text);
7259 ok = FALSE;
7260 }
7263 log_error("Only tech_leakage \"%s\" supported with "
7264 "tech_cost_style \"%s\". ",
7267 log_error("Switching to tech_leakage \"%s\".",
7270 }
7276 "research.base_tech_cost");
7277
7279 "research.tech_upkeep_style");
7280
7282
7284 ruleset_error(nullptr, LOG_ERROR,
7285 "Unknown tech upkeep style \"%s\"",
7286 tus_text);
7287 ok = FALSE;
7288 }
7289 }
7290
7291 if (ok) {
7297 "research.tech_upkeep_divider");
7298
7299 sval = secfile_lookup_str_default(file, nullptr, "research.free_tech_method");
7300 if (sval == nullptr) {
7301 ruleset_error(nullptr, LOG_ERROR,
7302 "No free_tech_method given");
7303 ok = FALSE;
7304 } else {
7307 ruleset_error(nullptr, LOG_ERROR,
7308 "Bad value %s for free_tech_method.", sval);
7309 ok = FALSE;
7310 }
7311 }
7312 }
7313
7314 if (ok) {
7315 int cf;
7316
7317 /* section: culture */
7320 "culture.victory_min_points");
7323 "culture.victory_lead_pct");
7326 "culture.migration_pml");
7329 "culture.history_interest_pml");
7330
7331 /* section: world_peace */
7334 "world_peace.victory_turns");
7335
7336 /* section: calendar */
7339 "calendar.skip_year_0");
7342 "calendar.start_year");
7344 = secfile_lookup_int_default(file, 0, "calendar.fragments");
7345
7347 ruleset_error(nullptr, LOG_ERROR,
7348 "Too many calendar fragments. Max is %d",
7350 ok = FALSE;
7352 }
7356 "calendar.positive_label"));
7360 "calendar.negative_label"));
7361
7362 for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
7363 const char *fname;
7364
7365 fname = secfile_lookup_str_default(file, nullptr,
7366 "calendar.fragment_name%d", cf);
7367 if (fname != nullptr) {
7370 }
7371 }
7372 }
7373
7374 if (ok) {
7375 /* Section playercolors */
7376 struct rgbcolor *prgbcolor = nullptr;
7377 bool color_read = TRUE;
7378
7379 /* Check if the player list is defined and empty. */
7380 if (playercolor_count() != 0) {
7381 ok = FALSE;
7382 } else {
7383 i = 0;
7384
7385 while (color_read) {
7386 prgbcolor = nullptr;
7387
7388 color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
7389 if (color_read) {
7391 }
7392
7393 i++;
7394 }
7395
7396 if (playercolor_count() == 0) {
7397 ruleset_error(nullptr, LOG_ERROR, "No player colors defined!");
7398 ok = FALSE;
7399 }
7400
7401 if (ok) {
7402 fc_assert(game.plr_bg_color == nullptr);
7403 if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
7404 ruleset_error(nullptr, LOG_ERROR,
7405 "No background player color defined! (%s)",
7406 secfile_error());
7407 ok = FALSE;
7408 }
7409 }
7410 }
7411 }
7412
7413 if (ok) {
7414 /* section: teams */
7415 svec = secfile_lookup_str_vec(file, &teams, "teams.names");
7416 if (team_slot_count() < teams) {
7418 }
7420 for (i = 0; i < teams; i++) {
7422 }
7423 free(svec);
7424
7426 nval = (sec != nullptr ? section_list_size(sec) : 0);
7427 if (nval > MAX_DISASTER_TYPES) {
7428 int num = nval; /* No "size_t" to printf */
7429
7430 ruleset_error(nullptr, LOG_ERROR,
7431 "\"%s\": Too many disaster types (%d, max %d)",
7432 filename, num, MAX_DISASTER_TYPES);
7434 ok = FALSE;
7435 } else {
7437 }
7438 }
7439
7440 if (ok) {
7442 int id = disaster_index(pdis);
7443 int j;
7444 size_t eff_count;
7445 struct requirement_vector *reqs;
7446 const char *sec_name = section_name(section_list_get(sec, id));
7447
7448 if (!ruleset_load_names(&pdis->name, nullptr, file, sec_name)) {
7449 ruleset_error(nullptr, LOG_ERROR,
7450 "\"%s\": Cannot load disaster names",
7451 filename);
7452 ok = FALSE;
7453 break;
7454 }
7455
7457 if (reqs == nullptr) {
7458 ok = FALSE;
7459 break;
7460 }
7462
7464 "%s.frequency", sec_name);
7465
7466 svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
7467
7468 BV_CLR_ALL(pdis->effects);
7469 for (j = 0; j < eff_count; j++) {
7470 const char *dsval = svec[j];
7472
7474
7476 ruleset_error(nullptr, LOG_ERROR,
7477 "\"%s\" disaster \"%s\": unknown effect \"%s\".",
7478 filename, disaster_rule_name(pdis), dsval);
7479 ok = FALSE;
7480 break;
7481 } else {
7482 BV_SET(pdis->effects, effect);
7483 }
7484 }
7485
7486 free(svec);
7487
7488 if (!ok) {
7489 break;
7490 }
7493 }
7494
7495 if (ok) {
7497
7499 int id = achievement_index(pach);
7500 const char *sec_name = section_name(section_list_get(sec, id));
7501 const char *typename;
7502 const char *msg;
7503
7504 typename = secfile_lookup_str_default(file, nullptr, "%s.type", sec_name);
7505
7506 pach->type = achievement_type_by_name(typename, fc_strcasecmp);
7507 if (!achievement_type_is_valid(pach->type)) {
7508 ruleset_error(nullptr, LOG_ERROR,
7509 "Achievement has unknown type \"%s\".",
7510 typename != nullptr ? typename : "(nullptr)");
7511 ok = FALSE;
7512 }
7513
7514 if (ok) {
7516 "%s.unique", sec_name);
7517
7519 "%s.value", sec_name);
7520 pach->culture = secfile_lookup_int_default(file, 0,
7521 "%s.culture", sec_name);
7522
7523 msg = secfile_lookup_str_default(file, nullptr, "%s.first_msg", sec_name);
7524 if (msg == nullptr) {
7525 ruleset_error(nullptr, LOG_ERROR,
7526 "Achievement %s has no first msg!", sec_name);
7527 ok = FALSE;
7528 } else {
7529 pach->first_msg = fc_strdup(msg);
7530 }
7531 }
7532
7533 if (ok) {
7534 msg = secfile_lookup_str_default(file, nullptr, "%s.cons_msg", sec_name);
7535 if (msg == nullptr) {
7536 if (!pach->unique) {
7537 ruleset_error(nullptr, LOG_ERROR,
7538 "Achievement %s has no msg for consecutive gainers!",
7539 sec_name);
7540 ok = FALSE;
7541 }
7542 } else {
7543 pach->cons_msg = fc_strdup(msg);
7544 }
7545 }
7546
7547 if (!ok) {
7548 break;
7549 }
7552 }
7553
7554 if (ok) {
7555 for (i = 0; (name = secfile_lookup_str_default(file, nullptr,
7556 "trade.settings%d.type",
7557 i)); i++) {
7559
7560 if (type == TRT_LAST) {
7561 ruleset_error(nullptr, LOG_ERROR,
7562 "\"%s\" unknown trade route type \"%s\".",
7563 filename, name);
7564 ok = FALSE;
7565 } else {
7567 const char *cancelling;
7568 const char *bonus;
7569
7570 set->trade_pct = secfile_lookup_int_default(file, 100,
7571 "trade.settings%d.pct", i);
7572 cancelling = secfile_lookup_str_default(file, "Active",
7573 "trade.settings%d.cancelling", i);
7575 if (set->cancelling == TRI_LAST) {
7576 ruleset_error(nullptr, LOG_ERROR,
7577 "\"%s\" unknown trade route cancelling type \"%s\".",
7578 filename, cancelling);
7579 ok = FALSE;
7580 }
7581
7582 bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
7583
7585
7587 ruleset_error(nullptr, LOG_ERROR,
7588 "\"%s\" unknown trade route bonus type \"%s\".",
7589 filename, bonus);
7590 ok = FALSE;
7591 }
7592 }
7593 }
7594 }
7595
7596 if (ok) {
7597 const char *str;
7598
7600 = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
7601
7604 "trade.reveal_trade_partner");
7605
7608 "trade.goods_selection");
7609
7611
7613 ruleset_error(nullptr, LOG_ERROR,
7614 "\"%s\" goods selection method \"%s\" unknown.",
7615 filename, str);
7616 ok = FALSE;
7617 }
7618 }
7619
7620 if (ok) {
7622
7624 int id = goods_index(pgood);
7625 const char *sec_name = section_name(section_list_get(sec, id));
7626 struct requirement_vector *reqs;
7627 const char **slist;
7628 int j;
7629
7631 if (reqs == nullptr) {
7632 ok = FALSE;
7633 break;
7634 }
7636
7637 pgood->from_pct = secfile_lookup_int_default(file, 100,
7638 "%s.from_pct", sec_name);
7639 pgood->to_pct = secfile_lookup_int_default(file, 100,
7640 "%s.to_pct", sec_name);
7641 pgood->onetime_pct = secfile_lookup_int_default(file, 100,
7642 "%s.onetime_pct", sec_name);
7643 pgood->select_priority = secfile_lookup_int_default(file, 1,
7644 "%s.select_priority", sec_name);
7645 pgood->replace_priority = secfile_lookup_int_default(file, 1,
7646 "%s.replace_priority", sec_name);
7647
7648 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
7649 BV_CLR_ALL(pgood->flags);
7650 for (j = 0; j < nval; j++) {
7651 enum goods_flag_id flag;
7652
7653 sval = slist[j];
7655 if (!goods_flag_id_is_valid(flag)) {
7656 ruleset_error(nullptr, LOG_ERROR,
7657 "\"%s\" good \"%s\": unknown flag \"%s\".",
7658 filename, goods_rule_name(pgood), sval);
7659 ok = FALSE;
7660 break;
7661 } else {
7662 BV_SET(pgood->flags, flag);
7663 }
7664 }
7665 free(slist);
7666
7667 pgood->helptext = lookup_strvec(file, sec_name, "helptext");
7670 }
7671
7672 if (ok) {
7673 const char *uname = secfile_lookup_str_default(file, nullptr,
7674 "aarea.access_unit");
7675 const struct unit_type *access_unit = nullptr;
7676
7677 terrain_control.access_unit = -1;
7678
7679 if (uname != nullptr && uname[0] != '\0') {
7680 access_unit = unit_type_by_rule_name(uname);
7681
7682 if (access_unit == nullptr) {
7683 ruleset_error(nullptr, LOG_ERROR, "%s: access unit %s unknown.",
7684 filename, uname);
7685 ok = FALSE;
7686 } else {
7687 terrain_control.access_unit = utype_number(access_unit);
7688 }
7689 }
7690
7691 access_info_init(access_unit);
7692 }
7693
7694 if (ok) {
7696
7697 if (sec != nullptr) {
7698 int num = section_list_size(sec);
7699
7700 for (i = 0; i < num; i++) {
7701 const char *sec_name = section_name(section_list_get(sec, i));
7702 const char *clause_name = secfile_lookup_str_default(file, nullptr,
7703 "%s.type", sec_name);
7705 struct clause_info *info;
7706 struct requirement_vector *reqs;
7707
7708 if (!clause_type_is_valid(type)) {
7709 ruleset_error(nullptr, LOG_ERROR,
7710 "\"%s\" unknown clause type \"%s\".",
7711 filename, clause_name);
7712 ok = FALSE;
7713 break;
7714 }
7715
7716 info = clause_info_get(type);
7717
7718 if (info->enabled) {
7719 ruleset_error(nullptr, LOG_ERROR,
7720 "\"%s\" duplicate clause type \"%s\" definition.",
7721 filename, clause_name);
7722 ok = FALSE;
7723 break;
7724 }
7725
7726 reqs = lookup_req_list(file, sec_name, "giver_reqs", clause_name);
7727 if (reqs == nullptr) {
7728 ok = FALSE;
7729 break;
7730 }
7732
7733 reqs = lookup_req_list(file, sec_name, "receiver_reqs", clause_name);
7734 if (reqs == nullptr) {
7735 ok = FALSE;
7736 break;
7737 }
7739
7740 reqs = lookup_req_list(file, sec_name, "either_reqs", clause_name);
7741 if (reqs == nullptr) {
7742 ok = FALSE;
7743 break;
7744 }
7746
7747 info->enabled = TRUE;
7748 }
7749 }
7751 }
7752
7753 if (ok) {
7755
7756 if (sec != nullptr) {
7757 int num = section_list_size(sec);
7758 int curr;
7759
7760 for (curr = 0; curr < num; curr++) {
7761
7762 struct counter *pcount = counter_by_id(curr);
7763 const char *sec_name = section_name(section_list_get(sec, curr));
7764 const char *counter_type = secfile_lookup_str_default(file, nullptr,
7765 "%s.type",
7766 sec_name);
7767
7770 if (!counter_behavior_is_valid(cb)) {
7771 ruleset_error(nullptr, LOG_ERROR,
7772 "\"%s\" unknown counter type \"%s\".",
7773 filename, counter_type);
7774 ok = FALSE;
7775 break;
7776 }
7777
7778 if (!ruleset_load_names(&pcount->name, nullptr, file, sec_name)) {
7779 ruleset_error(nullptr, LOG_ERROR,
7780 "\"%s\": Cannot load counter names",
7781 filename);
7782 ok = FALSE;
7783 break;
7784 }
7785
7786 pcount->helptext = lookup_strvec(file, sec_name, "helptext");
7787 pcount->type = cb;
7788 if (!secfile_lookup_int(file, &pcount->checkpoint,
7789 "%s.checkpoint", sec_name)) {
7790
7791 ruleset_error(nullptr, LOG_ERROR,
7792 "\"%s\": No checkpoint value",
7793 filename);
7794 ok = FALSE;
7795 break;
7796 }
7797
7798 pcount->target = CTGT_CITY;
7799 pcount->index = curr;
7800 pcount->def = secfile_lookup_int_default(file, 0,
7801 "%s.def",
7802 sec_name);
7804 }
7805 }
7806 }
7807
7808 /* secfile_check_unused() is not here, but only after also settings section
7809 * has been loaded. */
7810
7811 return ok;
7812}
7813
7814/**********************************************************************/
7817static bool load_ruleset_actions(struct section_file *file,
7818 struct section_file *gamefile,
7819 struct rscompat_info *compat)
7820{
7821 bool ok = TRUE;
7822 const char *filename = secfile_name(file);
7823 struct section_list *sec;
7825 struct requirement_vector *reqs;
7826
7827 /* Auto attack. */
7828
7829 /* Action auto performers aren't ready to be exposed in the ruleset
7830 * yet. The behavior when two action auto performers for the same
7831 * cause can fire isn't set in stone yet. How is one of them chosen?
7832 * What if all the actions of the chosen action auto performer turned
7833 * out to be illegal but one of the other action auto performers that
7834 * fired has legal actions? These issues can decide what other action
7835 * rules action auto performers can represent in the future. Deciding
7836 * should therefore wait until a rule needs action auto performers to
7837 * work a certain way. */
7838 /* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
7839 * by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
7840 * requirement vector to the ruleset. */
7841
7842 /* A unit moved next to this unit and the autoattack server setting
7843 * is enabled. */
7846
7847 reqs = lookup_req_list(file,
7848 "auto_attack", "if_attacker",
7849 "auto_attack");
7850 if (reqs == nullptr) {
7851 ok = FALSE;
7852 } else {
7854
7856 "auto_attack.attack_actions",
7857 filename)) {
7858 /* Failed to load auto attack actions */
7859 ruleset_error(nullptr, LOG_ERROR,
7860 "\"%s\": %s: failed load %s.",
7861 filename, "auto_attack", "attack_actions");
7862 ok = FALSE;
7863 }
7864 }
7865
7866 /* Section: actions */
7867 if (ok) {
7868 action_iterate(act_id) {
7869 struct action *paction = action_by_number(act_id);
7870
7871 if (!load_action_blocked_by_list(file, filename, paction, compat)) {
7872 ok = FALSE;
7873 break;
7874 }
7876
7877 if (ok) {
7878 if (!lookup_bv_actions(file, filename,
7880 "actions.diplchance_initial_odds")) {
7881 ok = FALSE;
7882 }
7883 }
7884
7885 if (ok) {
7886 /* If the "Poison City" action or the "Poison City Escape" action
7887 * should empty the granary. */
7888 /* TODO: empty granary and reduce population should become separate
7889 * action effect flags when actions are generalized. */
7893 "actions.poison_empties_food_stock");
7894
7895 /* If the "Steal Maps" action or the "Steal Maps Escape" action always
7896 * will reveal all cities when successful. */
7900 "actions.steal_maps_reveals_all_cities");
7901
7902 /* Allow setting certain properties for some actions before
7903 * generalized actions. */
7904 action_iterate(act_id) {
7905 if (!load_action_range(file, act_id)) {
7906 ok = FALSE;
7907 } else if (!load_action_kind(file, act_id)) {
7908 ok = FALSE;
7909 } else if (!load_action_actor_consuming_always(file, act_id)) {
7910 ok = FALSE;
7911 }
7912
7913 if (!ok) {
7914 break;
7915 }
7917 }
7918
7919 if (ok) {
7920 /* The quiet (don't auto generate help for) property of all actions
7921 * live in a single enum vector. This avoids generic action
7922 * expectations. */
7923 if (secfile_entry_by_path(file, "actions.quiet_actions")) {
7925 size_t asize;
7926 int j;
7927
7930 "actions.quiet_actions");
7931
7932 if (!quiet_actions) {
7933 /* Entity exists but couldn't read it. */
7934 ruleset_error(nullptr, LOG_ERROR,
7935 "\"%s\": actions.quiet_actions: bad action list",
7936 filename);
7937
7938 ok = FALSE;
7939 } else {
7940 for (j = 0; j < asize; j++) {
7941 /* Don't auto generate help text for this action. */
7943 }
7944
7946 }
7947 }
7948 }
7949
7950 if (ok) {
7951 /* Hard code action sub results for now. */
7952
7953 /* Unit Enter Hut */
7955 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
7965
7966 /* Unit Frighten Hut */
7978
7979 /* Unit May Embark */
7980 action_iterate(act_id) {
7981 struct action *paction = action_by_number(act_id);
7982
7984 "civstyle.paradrop_to_transport")
7987 BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
7988 }
7989
7990 /* Embark actions will always embark, not maybe embark. */
7992
7993 /* Non Lethal bombard */
8000 }
8001 }
8002
8003 if (ok) {
8004 /* Forced actions after another action was successfully performed. */
8005
8006 if (!load_action_post_success_force(file, filename,
8010 ok = FALSE;
8011 } else if (!load_action_post_success_force(file, filename,
8015 ok = FALSE;
8016 } else if (!load_action_post_success_force(file, filename,
8019 ACTION_ATTACK))) {
8020 ok = FALSE;
8021 } else if (!load_action_post_success_force(file, filename,
8024 ACTION_ATTACK2))) {
8025 ok = FALSE;
8026 } else if (!load_action_post_success_force(file, filename,
8030 ok = FALSE;
8031 } else if (!load_action_post_success_force(file, filename,
8035 ok = FALSE;
8036 }
8037
8038 /* No "Suicide Attack". Can't act when dead. */
8039 }
8040
8041 if (ok) {
8042 /* The city that made the unit's current tile native is gone.
8043 * Evaluated against an adjacent tile. */
8045 auto_perf->cause = AAPC_CITY_GONE;
8046
8047 /* I have no objections to moving this out of game's actions to
8048 * cities.ruleset, units.ruleset or an other location in game.ruleset
8049 * you find more suitable. -- Sveinung */
8051 "actions.escape_city", filename)) {
8052 ok = FALSE;
8053 }
8054 }
8055
8056 if (ok) {
8057 /* The unit's stack has been defeated and is scheduled for execution
8058 * but the unit has the CanEscape unit type flag.
8059 * Evaluated against an adjacent tile. */
8062
8063 /* I have no objections to moving this out of game's actions to
8064 * cities.ruleset, units.ruleset or an other location in game.ruleset
8065 * you find more suitable. -- Sveinung */
8067 "actions.unit_stack_death", filename)) {
8068 ok = FALSE;
8069 }
8070 }
8071
8072 if (ok) {
8074 if (sec != nullptr) {
8075 section_list_iterate(sec, psection) {
8076 const char *sec_name = section_name(psection);
8077 const char *action_text;
8078 struct action *paction;
8079 const char *ui_name;
8080
8081 action_text = secfile_lookup_str(file, "%s.action", sec_name);
8082
8083 if (action_text == nullptr) {
8084 ruleset_error(nullptr, LOG_ERROR,
8085 "\"%s\" [%s] missing action to configure.",
8086 filename, sec_name);
8087 ok = FALSE;
8088 break;
8089 }
8090
8092 if (paction == nullptr) {
8093 ruleset_error(nullptr, LOG_ERROR,
8094 "\"%s\" [%s] lists unknown action type \"%s\".",
8095 filename, sec_name, action_text);
8096 ok = FALSE;
8097 break;
8098 }
8099
8100 if (paction->configured) {
8101 ruleset_error(nullptr, LOG_ERROR,
8102 "\"%s\" [%s] duplicate configuration for action \"%s\".",
8103 filename, sec_name, action_text);
8104 ok = FALSE;
8105 break;
8106 }
8107
8108 paction->configured = TRUE;
8109
8110 ui_name = secfile_lookup_str_default(file, nullptr,
8111 "%s.ui_name", sec_name);
8112 if (ui_name == nullptr) {
8114 }
8115 sz_strlcpy(paction->ui_name, ui_name);
8117 }
8118 }
8119
8120 if (ok) {
8121 action_iterate(act) {
8122 struct action *paction = action_by_number(act);
8123
8124 if (!paction->configured) {
8126 }
8128 }
8129
8130 if (ok) {
8132
8133 if (sec != nullptr) {
8134 section_list_iterate(sec, psection) {
8135 struct action_enabler *enabler;
8136 const char *sec_name = section_name(psection);
8137 struct action *paction;
8138 struct requirement_vector *actor_reqs;
8139 struct requirement_vector *target_reqs;
8140 const char *action_text;
8141 const char *comment;
8142
8144
8145 action_text = secfile_lookup_str(file, "%s.action", sec_name);
8146
8147 if (action_text == nullptr) {
8148 ruleset_error(nullptr, LOG_ERROR,
8149 "\"%s\" [%s] missing action to enable.",
8150 filename, sec_name);
8151 ok = FALSE;
8152 break;
8153 }
8154
8156 if (paction == nullptr) {
8157 ruleset_error(nullptr, LOG_ERROR,
8158 "\"%s\" [%s] lists unknown action type \"%s\".",
8159 filename, sec_name, action_text);
8160 ok = FALSE;
8161 break;
8162 }
8163
8164 enabler->action = action_id(paction);
8165
8166 actor_reqs = lookup_req_list(file, sec_name, "actor_reqs", action_text);
8167 if (actor_reqs == nullptr) {
8168 ok = FALSE;
8169 break;
8170 }
8171
8172 requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
8173
8174 target_reqs = lookup_req_list(file, sec_name, "target_reqs", action_text);
8175 if (target_reqs == nullptr) {
8176 ok = FALSE;
8177 break;
8178 }
8179
8180 requirement_vector_copy(&enabler->target_reqs, target_reqs);
8181
8182 comment = secfile_lookup_str(file, "%s.comment", sec_name);
8183 if (comment != nullptr) {
8184 enabler->rulesave.comment = fc_strdup(comment);
8185 }
8186
8189
8191 }
8192 }
8193
8194 return ok;
8195}
8196
8197/**********************************************************************/
8201static void send_ruleset_unit_classes(struct conn_list *dest)
8202{
8203 struct packet_ruleset_unit_class packet;
8205 int i;
8206
8207 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
8208 const char *flagname;
8209 const char *helptxt;
8210
8212
8214 if (flagname == nullptr) {
8215 fpacket.name[0] = '\0';
8216 } else {
8218 }
8219
8221 if (helptxt == nullptr) {
8222 fpacket.helptxt[0] = '\0';
8223 } else {
8224 sz_strlcpy(fpacket.helptxt, helptxt);
8225 }
8226
8228 }
8229
8231 packet.id = uclass_number(c);
8232 sz_strlcpy(packet.name, untranslated_name(&c->name));
8233 sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
8234 packet.min_speed = c->min_speed;
8235 packet.hp_loss_pct = c->hp_loss_pct;
8236 packet.non_native_def_pct = c->non_native_def_pct;
8237 packet.flags = c->flags;
8238
8239 PACKET_STRVEC_INSERT(packet.helptext, c->helptext);
8240
8241 lsend_packet_ruleset_unit_class(dest, &packet);
8243}
8244
8245/**********************************************************************/
8249static void send_ruleset_units(struct conn_list *dest)
8250{
8251 struct packet_ruleset_unit packet;
8252#ifdef FREECIV_WEB
8254#endif /* FREECIV_WEB */
8256 int i;
8257
8258 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
8259 const char *flagname;
8260 const char *helptxt;
8261
8263
8265 if (flagname == nullptr) {
8266 fpacket.name[0] = '\0';
8267 } else {
8269 }
8270
8272 if (helptxt == nullptr) {
8273 fpacket.helptxt[0] = '\0';
8274 } else {
8275 sz_strlcpy(fpacket.helptxt, helptxt);
8276 }
8277
8279 }
8280
8282 packet.id = utype_number(u);
8283 sz_strlcpy(packet.name, untranslated_name(&u->name));
8284 sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
8285 sz_strlcpy(packet.sound_move, u->sound_move);
8286 sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
8287 sz_strlcpy(packet.sound_fight, u->sound_fight);
8288 sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
8289 sz_strlcpy(packet.graphic_str, u->graphic_str);
8290 sz_strlcpy(packet.graphic_alt, u->graphic_alt);
8291 sz_strlcpy(packet.graphic_alt2, u->graphic_alt2);
8293 packet.build_cost = u->build_cost;
8294 packet.pop_cost = u->pop_cost;
8295 packet.spectype_id = specialist_index(u->spec_type);
8296 packet.attack_strength = u->attack_strength;
8297 packet.defense_strength = u->defense_strength;
8298 packet.move_rate = u->move_rate;
8299
8300 /* Shallow-copy (borrow) requirement vector */
8301 packet.build_reqs = u->build_reqs;
8302
8303 packet.vision_radius_sq = u->vision_radius_sq;
8304 packet.transport_capacity = u->transport_capacity;
8305 packet.hp = u->hp;
8306 packet.firepower = u->firepower;
8307 packet.obsoleted_by = u->obsoleted_by
8308 ? utype_number(u->obsoleted_by)
8309 : utype_count();
8310 packet.converted_to = u->converted_to
8311 ? utype_number(u->converted_to)
8312 : utype_count();
8313 packet.convert_time = u->convert_time;
8314 packet.fuel = u->fuel;
8315 packet.flags = u->flags;
8316 packet.roles = u->roles;
8317 packet.happy_cost = u->happy_cost;
8319 packet.upkeep[o] = u->upkeep[o];
8321 packet.paratroopers_range = u->paratroopers_range;
8322 packet.bombard_rate = u->bombard_rate;
8323 packet.city_size = u->city_size;
8324 packet.city_slots = u->city_slots;
8325 packet.tp_defense = u->tp_defense;
8326 packet.cargo = u->cargo;
8327 packet.targets = u->targets;
8328 packet.embarks = u->embarks;
8329 packet.disembarks = u->disembarks;
8330 packet.vlayer = u->vlayer;
8331
8332 if (u->veteran == nullptr) {
8333 /* Use the default veteran system. */
8334 packet.veteran_levels = 0;
8335 } else {
8336 /* Per unit veteran system definition. */
8338
8339 for (i = 0; i < packet.veteran_levels; i++) {
8340 const struct veteran_level *vlevel = utype_veteran_level(u, i);
8341
8343 packet.power_fact[i] = vlevel->power_fact;
8344 packet.move_bonus[i] = vlevel->move_bonus;
8345 packet.base_raise_chance[i] = vlevel->base_raise_chance;
8346 packet.work_raise_chance[i] = vlevel->work_raise_chance;
8347 }
8348 }
8349 PACKET_STRVEC_INSERT(packet.helptext, u->helptext);
8350
8351 packet.worker = u->adv.worker;
8352
8353#ifdef FREECIV_WEB
8354 web_packet.id = utype_number(u);
8355
8356 BV_CLR_ALL(web_packet.utype_actions);
8357
8358 action_iterate(act) {
8359 if (utype_can_do_action(u, act)) {
8360 BV_SET(web_packet.utype_actions, act);
8361 }
8363#endif /* FREECIV_WEB */
8364
8365 lsend_packet_ruleset_unit(dest, &packet);
8367
8368 combat_bonus_list_iterate(u->bonuses, pbonus) {
8370
8371 bonuspacket.unit = packet.id;
8372 bonuspacket.flag = pbonus->flag;
8373 bonuspacket.type = pbonus->type;
8374 bonuspacket.value = pbonus->value;
8375 bonuspacket.quiet = pbonus->quiet;
8376
8380}
8381
8382/**********************************************************************/
8386static void send_ruleset_specialists(struct conn_list *dest)
8387{
8388 struct packet_ruleset_specialist packet;
8389
8392
8393 packet.id = spec_id;
8395 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
8399
8400 /* Shallow-copy (borrow) requirement vector */
8401 packet.reqs = s->reqs;
8402
8404
8405 lsend_packet_ruleset_specialist(dest, &packet);
8407}
8408/**********************************************************************/
8411static void send_ruleset_tech_classes(struct conn_list *dest)
8412{
8413 struct packet_ruleset_tech_class packet;
8414
8416 packet.id = ptclass->idx;
8417 sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
8418 sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
8419 packet.cost_pct = ptclass->cost_pct;
8420
8421 lsend_packet_ruleset_tech_class(dest, &packet);
8423}
8424
8425/**********************************************************************/
8429static void send_ruleset_techs(struct conn_list *dest)
8430{
8431 struct packet_ruleset_tech packet;
8433 int i;
8434
8435 for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
8436 const char *flagname;
8437 const char *helptxt;
8438
8439 fpacket.id = i + TECH_USER_1;
8440
8442 if (flagname == nullptr) {
8443 fpacket.name[0] = '\0';
8444 } else {
8446 }
8447
8449 if (helptxt == nullptr) {
8450 fpacket.helptxt[0] = '\0';
8451 } else {
8452 sz_strlcpy(fpacket.helptxt, helptxt);
8453 }
8454
8456 }
8457
8458 /* Since we have to prepend the tech requirements to the requirement
8459 * vector, we need to initialize a separate vector and deep-copy the
8460 * other requirements into it. */
8462
8463 advance_iterate(a) {
8464 packet.id = advance_number(a);
8465 packet.removed = !valid_advance(a);
8466 if (a->tclass == nullptr) {
8467 packet.tclass = 0;
8468 } else {
8469 packet.tclass = a->tclass->idx;
8470 }
8471 sz_strlcpy(packet.name, untranslated_name(&a->name));
8472 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8473 sz_strlcpy(packet.graphic_str, a->graphic_str);
8474 sz_strlcpy(packet.graphic_alt, a->graphic_alt);
8475
8476 /* Reset requirement vector. */
8478
8479 /* The requirements req1 and req2 are needed to research a tech. Send
8480 * them in the research_reqs requirement vector. Range is set to player
8481 * since pooled research is configurable. */
8482
8483 if ((a->require[AR_ONE] != A_NEVER)
8484 && advance_number(a->require[AR_ONE]) > A_NONE) {
8485 struct requirement req
8487 FALSE, TRUE, FALSE,
8488 advance_number(a->require[AR_ONE]));
8490 }
8491
8492 if ((a->require[AR_TWO] != A_NEVER)
8493 && advance_number(a->require[AR_TWO]) > A_NONE) {
8494 struct requirement req
8496 FALSE, TRUE, FALSE,
8497 advance_number(a->require[AR_TWO]));
8499 }
8500
8501 /* The requirements of the tech's research_reqs also goes in the
8502 * packet's research_reqs requirement vector. */
8503 requirement_vector_iterate(&a->research_reqs, req) {
8506
8507 packet.root_req = a->require[AR_ROOT]
8508 ? advance_number(a->require[AR_ROOT])
8509 : advance_count();
8510
8511 packet.flags = a->flags;
8512 packet.cost = a->cost;
8513 packet.num_reqs = a->num_reqs;
8514 PACKET_STRVEC_INSERT(packet.helptext, a->helptext);
8515
8516 lsend_packet_ruleset_tech(dest, &packet);
8518
8520}
8521
8522/**********************************************************************/
8525static void send_ruleset_counters(struct conn_list *dest)
8526{
8528 struct packet_ruleset_counter packet;
8529
8530 sz_strlcpy(packet.name, untranslated_name(&pcount->name));
8531 sz_strlcpy(packet.rule_name, rule_name_get(&pcount->name));
8532 packet.checkpoint = pcount->checkpoint;
8533 packet.behavior = pcount->type;
8534 packet.type = pcount->target;
8535 packet.def = pcount->def;
8536
8537 PACKET_STRVEC_INSERT(packet.helptext, pcount->helptext);
8538 lsend_packet_ruleset_counter(dest, &packet);
8540}
8541
8542/**********************************************************************/
8546static void send_ruleset_buildings(struct conn_list *dest)
8547{
8548 int i;
8549
8550 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
8552 const char *flagname;
8553 const char *helptxt;
8554
8556
8558 if (flagname == nullptr) {
8559 fpacket.name[0] = '\0';
8560 } else {
8562 }
8563
8565 if (helptxt == nullptr) {
8566 fpacket.helptxt[0] = '\0';
8567 } else {
8568 sz_strlcpy(fpacket.helptxt, helptxt);
8569 }
8570
8572 }
8573
8575 struct packet_ruleset_building packet;
8576
8577 packet.id = improvement_number(b);
8578 packet.genus = b->genus;
8579 sz_strlcpy(packet.name, untranslated_name(&b->name));
8580 sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
8581 sz_strlcpy(packet.graphic_str, b->graphic_str);
8582 sz_strlcpy(packet.graphic_alt, b->graphic_alt);
8583 sz_strlcpy(packet.graphic_alt2, b->graphic_alt2);
8584
8585 /* Shallow-copy (borrow) requirement vectors */
8586 packet.reqs = b->reqs;
8587 packet.obs_reqs = b->obsolete_by;
8588
8589 packet.build_cost = b->build_cost;
8590 packet.upkeep = b->upkeep;
8591 packet.sabotage = b->sabotage;
8592 packet.flags = b->flags;
8593 sz_strlcpy(packet.soundtag, b->soundtag);
8594 sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
8595 sz_strlcpy(packet.soundtag_alt2, b->soundtag_alt2);
8596 PACKET_STRVEC_INSERT(packet.helptext, b->helptext);
8597
8598 lsend_packet_ruleset_building(dest, &packet);
8600}
8601
8602/**********************************************************************/
8606static void send_ruleset_terrain(struct conn_list *dest)
8607{
8608 struct packet_ruleset_terrain packet;
8610 int i;
8611
8613
8614 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
8615 const char *flagname;
8616 const char *helptxt;
8617
8618 fpacket.id = i + TER_USER_1;
8619
8621 if (flagname == nullptr) {
8622 fpacket.name[0] = '\0';
8623 } else {
8625 }
8626
8628 if (helptxt == nullptr) {
8629 fpacket.helptxt[0] = '\0';
8630 } else {
8631 sz_strlcpy(fpacket.helptxt, helptxt);
8632 }
8633
8635 }
8636
8637 terrain_type_iterate(pterrain) {
8638 packet.id = terrain_number(pterrain);
8639 packet.tclass = pterrain->tclass;
8640 packet.native_to = pterrain->native_to;
8641
8642 sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
8643 sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
8644 sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
8645 sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
8646 sz_strlcpy(packet.graphic_alt2, pterrain->graphic_alt2);
8647
8648 packet.movement_cost = pterrain->movement_cost;
8649 packet.defense_bonus = pterrain->defense_bonus;
8650
8652 packet.output[o] = pterrain->output[o];
8654
8655 packet.num_resources = 0;
8656 terrain_resources_iterate(pterrain, res, freq) {
8657 packet.resources[packet.num_resources] = extra_number(res);
8658 packet.resource_freq[packet.num_resources] = freq;
8659 packet.num_resources++;
8661
8663 packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
8665
8666 packet.base_time = pterrain->base_time;
8667 packet.road_time = pterrain->road_time;
8668
8669 packet.cultivate_result = (pterrain->cultivate_result
8670 ? terrain_number(pterrain->cultivate_result)
8671 : terrain_count());
8672 packet.cultivate_time = pterrain->cultivate_time;
8673
8674 packet.plant_result = (pterrain->plant_result
8675 ? terrain_number(pterrain->plant_result)
8676 : terrain_count());
8677 packet.plant_time = pterrain->plant_time;
8678
8679 packet.irrigation_food_incr = pterrain->irrigation_food_incr;
8680 packet.irrigation_time = pterrain->irrigation_time;
8681
8682 packet.mining_shield_incr = pterrain->mining_shield_incr;
8683 packet.mining_time = pterrain->mining_time;
8684
8685 packet.num_animals = 0;
8686 terrain_animals_iterate(pterrain, panimal) {
8687 packet.animals[packet.num_animals] = utype_number(panimal);
8688 packet.num_animals++;
8690
8691 packet.transform_result = (pterrain->transform_result
8692 ? terrain_number(pterrain->transform_result)
8693 : terrain_count());
8694 packet.placing_time = pterrain->placing_time;
8695 packet.pillage_time = pterrain->pillage_time;
8696 packet.transform_time = pterrain->transform_time;
8697
8699 for (i = 0; i < game.control.num_extra_types; i++) {
8700 packet.extra_removal_times[i] = pterrain->extra_removal_times[i];
8701 }
8702
8703 packet.flags = pterrain->flags;
8704
8705 packet.color_red = pterrain->rgb->r;
8706 packet.color_green = pterrain->rgb->g;
8707 packet.color_blue = pterrain->rgb->b;
8708
8709 PACKET_STRVEC_INSERT(packet.helptext, pterrain->helptext);
8710
8711 lsend_packet_ruleset_terrain(dest, &packet);
8713}
8714
8715/**********************************************************************/
8718static void send_ruleset_resources(struct conn_list *dest)
8719{
8720 struct packet_ruleset_resource packet;
8721
8723 packet.id = extra_index(presource);
8724
8726 packet.output[o] = presource->data.resource->output[o];
8728
8729 lsend_packet_ruleset_resource(dest, &packet);
8731}
8732
8733/**********************************************************************/
8737static void send_ruleset_extras(struct conn_list *dest)
8738{
8739 int i;
8740
8741 for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
8743 const char *flagname;
8744 const char *helptxt;
8745
8747
8749 if (flagname == nullptr) {
8750 fpacket.name[0] = '\0';
8751 } else {
8753 }
8754
8756 if (helptxt == nullptr) {
8757 fpacket.helptxt[0] = '\0';
8758 } else {
8759 sz_strlcpy(fpacket.helptxt, helptxt);
8760 }
8761
8763 }
8764
8766 struct packet_ruleset_extra packet;
8767 int j;
8768
8769 packet.id = extra_number(e);
8770 sz_strlcpy(packet.name, untranslated_name(&e->name));
8771 sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
8772
8773 packet.category = e->category;
8774
8775 BV_CLR_ALL(packet.causes);
8776 for (j = 0; j < EC_COUNT; j++) {
8777 if (is_extra_caused_by(e, j)) {
8778 BV_SET(packet.causes, j);
8779 }
8780 }
8781
8782 BV_CLR_ALL(packet.rmcauses);
8783 for (j = 0; j < ERM_COUNT; j++) {
8784 if (is_extra_removed_by(e, j)) {
8785 BV_SET(packet.rmcauses, j);
8786 }
8787 }
8788
8789 sz_strlcpy(packet.activity_gfx, e->activity_gfx);
8790 sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
8791 sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
8792 sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
8793 sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
8794 sz_strlcpy(packet.rmact_gfx_alt2, e->rmact_gfx_alt2);
8795 sz_strlcpy(packet.graphic_str, e->graphic_str);
8796 sz_strlcpy(packet.graphic_alt, e->graphic_alt);
8797
8798 /* Shallow-copy (borrow) requirement vectors */
8799 packet.reqs = e->reqs;
8800 packet.rmreqs = e->rmreqs;
8801
8802 packet.appearance_chance = e->appearance_chance;
8803 /* Shallow-copy (borrow) requirement vector */
8804 packet.appearance_reqs = e->appearance_reqs;
8805
8806 packet.disappearance_chance = e->disappearance_chance;
8807 /* Shallow-copy (borrow) requirement vector */
8808 packet.disappearance_reqs = e->disappearance_reqs;
8809
8810 packet.visibility_req = e->visibility_req;
8811 packet.buildable = e->buildable;
8812 packet.generated = e->generated;
8813 packet.build_time = e->build_time;
8814 packet.build_time_factor = e->build_time_factor;
8815 packet.removal_time = e->removal_time;
8816 packet.removal_time_factor = e->removal_time_factor;
8817 packet.infracost = e->infracost;
8818 packet.defense_bonus = e->defense_bonus;
8819 packet.eus = e->eus;
8820 packet.no_aggr_near_city = e->no_aggr_near_city;
8821
8822 packet.native_to = e->native_to;
8823
8824 packet.flags = e->flags;
8825 packet.hidden_by = e->hidden_by;
8826 packet.bridged_over = e->bridged_over;
8827 packet.conflicts = e->conflicts;
8828
8829 PACKET_STRVEC_INSERT(packet.helptext, e->helptext);
8830
8831 lsend_packet_ruleset_extra(dest, &packet);
8833}
8834
8835/**********************************************************************/
8839static void send_ruleset_bases(struct conn_list *dest)
8840{
8842 struct base_type *b = extra_base_get(pextra);
8843 struct packet_ruleset_base packet;
8844
8845 packet.id = base_number(b);
8846
8847 packet.gui_type = b->gui_type;
8848 packet.border_sq = b->border_sq;
8849 packet.vision_main_sq = b->vision_main_sq;
8850 packet.vision_invis_sq = b->vision_invis_sq;
8851 packet.vision_subs_sq = b->vision_subs_sq;
8852
8853 lsend_packet_ruleset_base(dest, &packet);
8855}
8856
8857/**********************************************************************/
8861static void send_ruleset_roads(struct conn_list *dest)
8862{
8863 struct packet_ruleset_road packet;
8864
8866 struct road_type *r = extra_road_get(pextra);
8867
8868 packet.id = road_number(r);
8869
8870 packet.gui_type = r->gui_type;
8871
8872 /* Shallow-copy (borrow) requirement vector */
8873 packet.first_reqs = r->first_reqs;
8874
8875 packet.move_cost = r->move_cost;
8876 packet.move_mode = r->move_mode;
8877
8879 packet.tile_incr_const[o] = r->tile_incr_const[o];
8880 packet.tile_incr[o] = r->tile_incr[o];
8881 packet.tile_bonus[o] = r->tile_bonus[o];
8883
8884 packet.compat = r->compat;
8885
8886 packet.integrates = r->integrates;
8887 packet.flags = r->flags;
8888
8889 lsend_packet_ruleset_road(dest, &packet);
8891}
8892
8893/**********************************************************************/
8897static void send_ruleset_tiledefs(struct conn_list *dest)
8898{
8899 struct packet_ruleset_tiledef packet;
8900
8903
8904 packet.id = tiledef_number(td);
8905 sz_strlcpy(packet.name, untranslated_name(&td->name));
8906 sz_strlcpy(packet.rule_name, rule_name_get(&td->name));
8907
8909 extra_type_list_iterate(td->extras, pextra) {
8910 BV_SET(extras, extra_index(pextra));
8912
8913 packet.extras = extras;
8914
8915 packet.known = td->known;
8916
8917 lsend_packet_ruleset_tiledef(dest, &packet);
8919}
8920
8921/**********************************************************************/
8925static void send_ruleset_goods(struct conn_list *dest)
8926{
8927 struct packet_ruleset_goods packet;
8928
8930 packet.id = goods_number(g);
8931 sz_strlcpy(packet.name, untranslated_name(&g->name));
8932 sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
8933
8934 /* Shallow-copy (borrow) requirement vector */
8935 packet.reqs = g->reqs;
8936
8937 packet.from_pct = g->from_pct;
8938 packet.to_pct = g->to_pct;
8939 packet.onetime_pct = g->onetime_pct;
8940 packet.select_priority = g->select_priority;
8941 packet.replace_priority = g->replace_priority;
8942 packet.flags = g->flags;
8943
8944 PACKET_STRVEC_INSERT(packet.helptext, g->helptext);
8945
8946 lsend_packet_ruleset_goods(dest, &packet);
8948}
8949
8950/**********************************************************************/
8954static void send_ruleset_disasters(struct conn_list *dest)
8955{
8956 struct packet_ruleset_disaster packet;
8957
8959 packet.id = disaster_number(d);
8960
8961 sz_strlcpy(packet.name, untranslated_name(&d->name));
8962 sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
8963
8964 /* Shallow-copy (borrow) requirement vector */
8965 packet.reqs = d->reqs;
8966
8967 packet.frequency = d->frequency;
8968
8969 packet.effects = d->effects;
8970
8971 lsend_packet_ruleset_disaster(dest, &packet);
8973}
8974
8975/**********************************************************************/
8979static void send_ruleset_achievements(struct conn_list *dest)
8980{
8981 struct packet_ruleset_achievement packet;
8982
8984 packet.id = achievement_number(a);
8985
8986 sz_strlcpy(packet.name, untranslated_name(&a->name));
8987 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8988
8989 packet.type = a->type;
8990 packet.unique = a->unique;
8991 packet.value = a->value;
8992
8993 lsend_packet_ruleset_achievement(dest, &packet);
8995}
8996
8997/**********************************************************************/
9000static void send_ruleset_actions(struct conn_list *dest)
9001{
9002 struct packet_ruleset_action packet;
9003
9004 action_iterate(act) {
9005 struct action *paction = action_by_number(act);
9006
9007 packet.id = act;
9009 packet.quiet = action_by_number(act)->quiet;
9010
9011 packet.result = paction->result;
9012 packet.sub_results = paction->sub_results;
9013 packet.actor_consuming_always = paction->actor_consuming_always;
9014
9015 packet.act_kind = action_by_number(act)->actor_kind;
9016 packet.tgt_kind = action_by_number(act)->target_kind;
9018
9021 packet.blocked_by = action_by_number(act)->blocked_by;
9022
9023 lsend_packet_ruleset_action(dest, &packet);
9025}
9026
9027/**********************************************************************/
9031{
9032 struct packet_ruleset_action_enabler packet;
9033
9036
9037 /* Shallow-copy (borrow) requirement vectors */
9038 packet.actor_reqs = enabler->actor_reqs;
9039 packet.target_reqs = enabler->target_reqs;
9040
9043}
9044
9045/**********************************************************************/
9050{
9051 int counter;
9052 int id;
9053 struct packet_ruleset_action_auto packet;
9054
9055 id = 0;
9057 packet.id = id++;
9058
9059 packet.cause = aperf->cause;
9060
9061 /* Shallow-copy (borrow) requirement vector */
9062 packet.reqs = aperf->reqs;
9063
9064 for (counter = 0;
9065 /* Can't list more actions than all actions. */
9067 /* ACTION_NONE terminates the list. */
9068 && aperf->alternatives[counter] != ACTION_NONE;
9069 counter++) {
9070 packet.alternatives[counter] = aperf->alternatives[counter];
9071 }
9072 packet.alternatives_count = counter;
9073
9074 lsend_packet_ruleset_action_auto(dest, &packet);
9076}
9077
9078/**********************************************************************/
9082static void send_ruleset_trade_routes(struct conn_list *dest)
9083{
9084 struct packet_ruleset_trade packet;
9086
9087 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
9089
9090 packet.id = type;
9091 packet.trade_pct = set->trade_pct;
9092 packet.cancelling = set->cancelling;
9093 packet.bonus_type = set->bonus_type;
9094
9095 lsend_packet_ruleset_trade(dest, &packet);
9096 }
9097}
9098
9099/**********************************************************************/
9103static void send_ruleset_governments(struct conn_list *dest)
9104{
9105 struct packet_ruleset_government gov;
9107 int i;
9108
9109 for (i = 0; i < MAX_NUM_USER_GOVERNMENT_FLAGS; i++) {
9111 const char *flagname;
9112 const char *helptxt;
9113
9115
9117 if (flagname == nullptr) {
9118 fpacket.name[0] = '\0';
9119 } else {
9121 }
9122
9124 if (helptxt == nullptr) {
9125 fpacket.helptxt[0] = '\0';
9126 } else {
9127 sz_strlcpy(fpacket.helptxt, helptxt);
9128 }
9129
9131 }
9132
9134 /* Send one packet_government */
9135 gov.id = government_number(g);
9136
9137 /* Shallow-copy (borrow) requirement vector */
9138 gov.reqs = g->reqs;
9139
9140 gov.flags = g->flags;
9141
9142 sz_strlcpy(gov.name, untranslated_name(&g->name));
9143 sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
9144 sz_strlcpy(gov.graphic_str, g->graphic_str);
9145 sz_strlcpy(gov.graphic_alt, g->graphic_alt);
9146 sz_strlcpy(gov.sound_str, g->sound_str);
9147 sz_strlcpy(gov.sound_alt, g->sound_alt);
9148 sz_strlcpy(gov.sound_alt2, g->sound_alt2);
9149 PACKET_STRVEC_INSERT(gov.helptext, g->helptext);
9150
9152
9153 /* Send one packet_government_ruler_title per ruler title. */
9155 const struct nation_type *pnation = ruler_title_nation(pruler_title);
9156
9157 title.gov = government_number(g);
9158 title.nation = pnation ? nation_number(pnation) : nation_count();
9159 sz_strlcpy(title.male_title,
9161 sz_strlcpy(title.female_title,
9166}
9167
9168/**********************************************************************/
9172static void send_ruleset_nations(struct conn_list *dest)
9173{
9176 struct packet_ruleset_nation packet;
9177 int i;
9178
9180 i = 0;
9185 i++;
9188
9190 i = 0;
9192 sz_strlcpy(groups_packet.groups[i],
9194 groups_packet.hidden[i] = pgroup->hidden;
9195 i++;
9198
9200 packet.id = nation_number(n);
9201 if (n->translation_domain == nullptr) {
9202 packet.translation_domain[0] = '\0';
9203 } else {
9204 sz_strlcpy(packet.translation_domain, n->translation_domain);
9205 }
9206 sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
9207 sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
9208 sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
9209 sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
9210 sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
9211
9212 i = 0;
9216 i++;
9218 packet.leader_count = i;
9219
9220 packet.style = style_number(n->style);
9221 packet.is_playable = n->is_playable;
9222 packet.barbarian_type = n->barb_type;
9223
9224 sz_strlcpy(packet.legend, n->legend);
9225
9226 i = 0;
9228 packet.sets[i++] = nation_set_number(pset);
9230 packet.nsets = i;
9231
9232 i = 0;
9234 packet.groups[i++] = nation_group_number(pgroup);
9236 packet.ngroups = i;
9237
9238 packet.init_government_id = n->init_government
9239 ? government_number(n->init_government) : government_count();
9240 fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
9241 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9242 if (n->init_techs[i] != A_LAST) {
9243 packet.init_techs[i] = n->init_techs[i];
9244 } else {
9245 break;
9246 }
9247 }
9248 packet.init_techs_count = i;
9249 fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
9250 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
9251 const struct unit_type *t = n->init_units[i];
9252 if (t) {
9253 packet.init_units[i] = utype_number(t);
9254 } else {
9255 break;
9256 }
9257 }
9258 packet.init_units_count = i;
9260 == ARRAY_SIZE(n->init_buildings));
9261 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9262 if (n->init_buildings[i] != B_LAST) {
9263 /* Impr_type_id to int */
9264 packet.init_buildings[i] = n->init_buildings[i];
9265 } else {
9266 break;
9267 }
9268 }
9269 packet.init_buildings_count = i;
9270
9271 lsend_packet_ruleset_nation(dest, &packet);
9273
9274 /* Send initial values of is_pickable */
9276}
9277
9278/**********************************************************************/
9282static void send_ruleset_styles(struct conn_list *dest)
9283{
9284 struct packet_ruleset_style packet;
9285
9286 styles_iterate(s) {
9287 packet.id = style_index(s);
9288 sz_strlcpy(packet.name, untranslated_name(&s->name));
9289 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
9290
9291 lsend_packet_ruleset_style(dest, &packet);
9293}
9294
9295/**********************************************************************/
9298static void send_ruleset_clauses(struct conn_list *dest)
9299{
9300 struct packet_ruleset_clause packet;
9301 int i;
9302
9303 for (i = 0; i < CLAUSE_COUNT; i++) {
9304 struct clause_info *info = clause_info_get(i);
9305
9306 packet.type = i;
9307 packet.enabled = info->enabled;
9308
9309 /* Shallow-copy (borrow) requirement vectors */
9310 packet.giver_reqs = info->giver_reqs;
9311 packet.receiver_reqs = info->receiver_reqs;
9312 packet.either_reqs = info->either_reqs;
9313
9314 lsend_packet_ruleset_clause(dest, &packet);
9315 }
9316}
9317
9318/**********************************************************************/
9322static void send_ruleset_multipliers(struct conn_list *dest)
9323{
9324 multipliers_iterate(pmul) {
9325 struct packet_ruleset_multiplier packet;
9326
9327 packet.id = multiplier_number(pmul);
9328 packet.start = pmul->start;
9329 packet.stop = pmul->stop;
9330 packet.step = pmul->step;
9331 packet.def = pmul->def;
9332 packet.offset = pmul->offset;
9333 packet.factor = pmul->factor;
9334 packet.minimum_turns = pmul->minimum_turns;
9335
9336 sz_strlcpy(packet.name, untranslated_name(&pmul->name));
9337 sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
9338
9339 /* Shallow-copy (borrow) requirement vector */
9340 packet.reqs = pmul->reqs;
9341
9342 PACKET_STRVEC_INSERT(packet.helptext, pmul->helptext);
9343
9344 lsend_packet_ruleset_multiplier(dest, &packet);
9346}
9347
9348/**********************************************************************/
9352static void send_ruleset_cities(struct conn_list *dest)
9353{
9355 int k;
9356
9357 for (k = 0; k < game.control.num_city_styles; k++) {
9358 city_p.style_id = k;
9359
9360 /* Shallow-copy (borrow) requirement vector */
9361 city_p.reqs = city_styles[k].reqs;
9362
9365 sz_strlcpy(city_p.graphic, city_styles[k].graphic);
9366 sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
9367 sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic);
9368
9370 }
9371}
9372
9373/**********************************************************************/
9377static void send_ruleset_musics(struct conn_list *dest)
9378{
9379 struct packet_ruleset_music packet;
9380
9382 packet.id = pmus->id;
9383
9384 sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
9385 sz_strlcpy(packet.music_combat, pmus->music_combat);
9386
9387 /* Shallow-copy (borrow) requirement vector */
9388 packet.reqs = pmus->reqs;
9389
9390 lsend_packet_ruleset_music(dest, &packet);
9392}
9393
9394/**********************************************************************/
9398static void send_ruleset_game(struct conn_list *dest)
9399{
9401 int i;
9402
9403 fc_assert_ret(game.veteran != nullptr);
9404
9405 /* Per unit veteran system definition. */
9406 misc_p.veteran_levels = game.veteran->levels;
9407
9408 for (i = 0; i < misc_p.veteran_levels; i++) {
9409 const struct veteran_level *vlevel = game.veteran->definitions + i;
9410
9411 sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
9412 misc_p.power_fact[i] = vlevel->power_fact;
9413 misc_p.move_bonus[i] = vlevel->move_bonus;
9414 misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
9415 misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
9416 }
9417
9418 fc_assert(sizeof(misc_p.global_init_techs)
9419 == sizeof(game.rgame.global_init_techs));
9420 fc_assert(ARRAY_SIZE(misc_p.global_init_techs)
9422 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9424 misc_p.global_init_techs[i] = game.rgame.global_init_techs[i];
9425 } else {
9426 break;
9427 }
9428 }
9429 misc_p.global_init_techs_count = i;
9430
9431 fc_assert(ARRAY_SIZE(misc_p.global_init_buildings)
9433 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9435 /* Impr_type_id to int */
9436 misc_p.global_init_buildings[i] =
9438 } else {
9439 break;
9440 }
9441 }
9442 misc_p.global_init_buildings_count = i;
9443
9444 misc_p.default_specialist = DEFAULT_SPECIALIST;
9445
9446 fc_assert_ret(game.plr_bg_color != nullptr);
9447
9448 misc_p.background_red = game.plr_bg_color->r;
9449 misc_p.background_green = game.plr_bg_color->g;
9450 misc_p.background_blue = game.plr_bg_color->b;
9451
9453}
9454
9455/**********************************************************************/
9459static void send_ruleset_team_names(struct conn_list *dest)
9460{
9462
9464 const char *name = team_slot_defined_name(tslot);
9465
9466 if (name == nullptr) {
9467 /* End of defined names. */
9468 break;
9469 }
9470
9472 sz_strlcpy(team_name_info_p.team_name, name);
9473
9476}
9477
9478/**********************************************************************/
9481static void notify_ruleset_fallback(const char *msg)
9482{
9483 notify_conn(nullptr, nullptr, E_LOG_FATAL, ftc_warning, "%s", msg);
9484}
9485
9486/**********************************************************************/
9489bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
9490 rs_conversion_logger logger,
9491 bool act, bool buffer_script, bool load_luadata)
9492{
9493 set_ruleset_compat_mode(compat_mode);
9494
9495 if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
9496 act, buffer_script, load_luadata)) {
9498 return TRUE;
9499 }
9500
9501 if (alt != nullptr) {
9502 if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
9503 load_luadata)) {
9505
9507 return TRUE;
9508 }
9509 }
9510
9511 /* Fallback to previous one. */
9512 if (restore != nullptr) {
9513 if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
9515
9516 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
9517
9519
9520 /* We're in sane state as restoring previous ruleset succeeded,
9521 * but return failure to indicate that this is not what caller
9522 * wanted. */
9523 return FALSE;
9524 }
9525 }
9526
9528
9529 /* Fallback to default one, but not if that's what we tried already */
9531 && (restore == nullptr || strcmp(GAME_DEFAULT_RULESETDIR, restore))) {
9533 buffer_script, TRUE)) {
9534 /* We're in sane state as fallback ruleset loading succeeded,
9535 * but return failure to indicate that this is not what caller
9536 * wanted. */
9538
9539 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
9540
9541 return FALSE;
9542 }
9543 }
9544
9545#ifdef FREECIV_WEB
9546 log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
9547 "https://github.com/freeciv/freeciv-web"));
9548#endif /* FREECIV_WEB */
9549
9550 /* Cannot load even default ruleset, we're in completely unusable state */
9552
9554}
9555
9556/**********************************************************************/
9560{
9561 if (file != nullptr) {
9562 secfile_destroy(file);
9563 }
9564}
9565
9566/**********************************************************************/
9576
9577/**********************************************************************/
9581static bool load_rulesetdir(const char *rsdir, bool compat_mode,
9582 rs_conversion_logger logger,
9583 bool act, bool buffer_script, bool load_luadata)
9584{
9587 struct section_file *actionfile;
9588 bool ok = TRUE;
9590
9591 log_normal(_("Loading rulesets."));
9592
9594 compat_info.compat_mode = compat_mode;
9595 compat_info.log_cb = logger;
9596
9599 /* Reset the list of available player colors. */
9603
9604 if (script_buffer != nullptr) {
9606 script_buffer = nullptr;
9607 }
9608 if (parser_buffer != nullptr) {
9610 parser_buffer = nullptr;
9611 }
9612
9613 server.playable_nations = 0;
9614
9618 buildfile = openload_ruleset_file("buildings", rsdir);
9619 govfile = openload_ruleset_file("governments", rsdir);
9621 terrfile = openload_ruleset_file("terrain", rsdir);
9626
9627 if (load_luadata) {
9629 } else {
9630 game.server.luadata = nullptr;
9631 }
9632
9633 if (techfile == nullptr
9634 || buildfile == nullptr
9635 || govfile == nullptr
9636 || unitfile == nullptr
9637 || terrfile == nullptr
9638 || stylefile == nullptr
9639 || cityfile == nullptr
9640 || nationfile == nullptr
9641 || effectfile == nullptr
9642 || actionfile == nullptr
9643 || gamefile == nullptr) {
9644 ok = FALSE;
9645 }
9646
9647 if (ok) {
9648 /* Note: Keep load_game_names() first so that compat_info.version is
9649 * correctly initialized. */
9659 }
9660
9661 if (ok) {
9663 }
9664
9665 if (ok) {
9667 }
9668 if (ok) {
9670 }
9671 if (ok) {
9673 }
9674 if (ok) {
9676 }
9677 if (ok) {
9678 /* Terrain must precede nations and units */
9680 }
9681 if (ok) {
9683 }
9684 if (ok) {
9686 }
9687 if (ok) {
9689 }
9690 if (ok) {
9692 }
9693 if (ok) {
9695 }
9696 if (ok) {
9698 }
9699
9700 if (ok) {
9701 /* Init nations we just loaded. */
9703
9704 /* Needed by role_unit_precalcs(). */
9706
9707 /* Prepare caches we want to sanity check. */
9711
9714 }
9715
9716 if (ok) {
9717 /* Only load settings for a sane ruleset */
9718 ok = settings_ruleset(gamefile, "settings", act,
9719 compat_info.compat_mode
9720 && compat_info.version < RSFORMAT_CURRENT);
9721
9722 if (ok) {
9724 }
9725 }
9726
9738
9739 if (extra_sections) {
9741 extra_sections = nullptr;
9742 }
9743 if (base_sections) {
9745 base_sections = nullptr;
9746 }
9747 if (road_sections) {
9749 road_sections = nullptr;
9750 }
9751 if (resource_sections) {
9753 resource_sections = nullptr;
9754 }
9755 if (terrain_sections) {
9757 terrain_sections = nullptr;
9758 }
9759
9760 if (ok) {
9762 }
9763
9764 if (ok) {
9765 char **buffer = buffer_script ? &script_buffer : nullptr;
9766
9768
9770
9771 ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
9772 }
9773
9774 if (ok) {
9775 enum fc_tristate pret;
9776 char **buffer = buffer_script ? &parser_buffer : nullptr;
9777
9778 pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
9779
9780 if (pret == TRI_MAYBE && buffer_script) {
9782 "-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
9783 }
9784
9785 ok = (pret != TRI_NO);
9786 }
9787
9788 if (ok && !buffer_script) {
9789 ok = (openload_script_file("default", rsdir, nullptr, FALSE) == TRI_YES);
9790 }
9791
9792 if (ok && act) {
9793 /* Populate remaining caches. */
9800 ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
9804
9805 /* Build advisors unit class cache corresponding to loaded rulesets */
9807 CALL_FUNC_EACH_AI(units_ruleset_init);
9808
9809 /* We may need to adjust the number of AI players
9810 * if the number of available nations changed. */
9812 }
9813
9814 return ok;
9815}
9816
9817/**********************************************************************/
9821{
9822 struct section_file *file;
9823 bool ok = TRUE;
9824
9826 if (file == nullptr) {
9827 ruleset_error(nullptr, LOG_ERROR,
9828 "Could not load game.ruleset:\n%s",
9829 secfile_error());
9830 ok = FALSE;
9831 }
9832 if (ok) {
9833 settings_ruleset(file, "settings", TRUE, FALSE);
9834 secfile_destroy(file);
9835 }
9836
9837 return ok;
9838}
9839
9840/**********************************************************************/
9843void send_rulesets(struct conn_list *dest)
9844{
9846
9847 /* ruleset_control also indicates to client that ruleset sending starts. */
9849
9850 /* Currently containing control-kind of data of nation sets and groups,
9851 * this too must be sent before any requirement vector may depend on
9852 * that data. */
9854
9855 send_ruleset_game(dest);
9865 send_ruleset_techs(dest);
9868 send_ruleset_units(dest);
9870 send_ruleset_extras(dest);
9871 send_ruleset_bases(dest);
9872 send_ruleset_roads(dest);
9876 send_ruleset_goods(dest);
9878 send_ruleset_styles(dest);
9880 send_ruleset_cities(dest);
9882 send_ruleset_musics(dest);
9883 send_ruleset_cache(dest);
9884
9885 /* Indicate client that all rulesets have now been sent. */
9887
9888 /* Changed game settings will be send in
9889 * connecthand.c:establish_new_connection() */
9890
9892}
void access_info_init(const struct unit_type *aunit)
Definition accessarea.c:39
void access_info_close(void)
Definition accessarea.c:55
int achievement_index(const struct achievement *pach)
int achievement_number(const struct achievement *pach)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:5961
void actions_rs_pre_san_gen(void)
Definition actions.c:899
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6412
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7130
bool action_is_in_use(struct action *paction)
Definition actions.c:5915
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7326
struct action * action_by_rule_name(const char *name)
Definition actions.c:1100
const char * action_rule_name(const struct action *action)
Definition actions.c:1237
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6955
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6592
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6781
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:1547
const char * action_ui_name_default(int act)
Definition actions.c:6044
struct action_enabler * action_enabler_new(void)
Definition actions.c:1496
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5850
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1580
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:245
#define action_auto_perf_iterate_end
Definition actions.h:350
#define action_enablers_iterate_end
Definition actions.h:283
#define ACTION_AUTO_MOVED_ADJ
Definition actions.h:375
#define ACTION_AUTO_POST_BRIBE_UNIT
Definition actions.h:376
#define action_id_get_sub_target_kind(act_id)
Definition actions.h:421
#define ACTION_AUTO_UPKEEP_GOLD
Definition actions.h:373
#define enabler_get_action_id(_enabler_)
Definition actions.h:187
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define NUM_ACTIONS
Definition actions.h:63
#define ACTION_AUTO_ESCAPE_STACK
Definition actions.h:382
#define action_has_result(_act_, _res_)
Definition actions.h:184
#define ACTION_AUTO_ESCAPE_CITY
Definition actions.h:381
#define action_enabler_list_iterate_end
Definition actions.h:194
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:105
#define action_by_result_iterate_end
Definition actions.h:249
#define ACTION_AUTO_POST_WIPE_UNITS
Definition actions.h:383
#define ACTION_AUTO_UPKEEP_SHIELD
Definition actions.h:374
#define action_iterate_end
Definition actions.h:218
#define ACTION_AUTO_POST_BRIBE_STACK
Definition actions.h:377
#define action_enablers_iterate(_enabler_)
Definition actions.h:277
#define ACTION_AUTO_POST_ATTACK2
Definition actions.h:379
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:192
#define action_id(_act_)
Definition actions.h:426
#define action_iterate(_act_)
Definition actions.h:214
#define action_auto_perf_iterate(_act_perf_)
Definition actions.h:338
#define ACTION_AUTO_UPKEEP_FOOD
Definition actions.h:372
#define ACTION_AUTO_POST_ATTACK
Definition actions.h:378
#define ACTION_AUTO_POST_COLLECT_RANSOM
Definition actions.h:380
#define ACTION_NONE
Definition actions.h:59
int actres_min_range_default(enum action_result result)
Definition actres.c:380
int actres_max_range_default(enum action_result result)
Definition actres.c:471
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:778
void adv_units_ruleset_init(void)
Definition advruleset.c:33
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:390
#define str
Definition astring.c:76
#define n
Definition astring.c:77
Base_type_id base_number(const struct base_type *pbase)
Definition base.c:96
void base_type_init(struct extra_type *pextra, int idx)
Definition base.c:122
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:163
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
void city_styles_alloc(int num)
Definition city.c:3504
void city_production_caravan_shields_init(void)
Definition city.c:1831
const char * city_style_rule_name(const int style)
Definition city.c:1818
const char * get_output_identifier(Output_type_id output)
Definition city.c:619
static const struct city struct citystyle * city_styles
Definition city.c:84
#define output_type_iterate(output)
Definition city.h:853
#define output_type_iterate_end
Definition city.h:859
static struct fc_sockaddr_list * list
Definition clinet.c:102
char * incite_cost
Definition comments.c:77
#define MAX_LEN_CONTENT
Definition conn_types.h:32
#define MAX_LEN_MSG
Definition conn_types.h:37
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:734
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:722
struct counter * counter_by_id(int id)
Definition counters.c:82
void attach_city_counter(struct counter *counter)
Definition counters.c:94
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:292
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
Disaster_type_id disaster_number(const struct disaster_type *pdis)
Definition disaster.c:56
Disaster_type_id disaster_index(const struct disaster_type *pdis)
Definition disaster.c:69
#define disaster_type_iterate(_p)
Definition disaster.h:82
#define disaster_type_iterate_end
Definition disaster.h:88
int int id
Definition editgui_g.h:28
struct @22::@23 reqs
void send_ruleset_cache(struct conn_list *dest)
Definition effects.c:609
struct effect * effect_new(enum effect_type type, int value, struct multiplier *pmul)
Definition effects.c:186
void user_effect_ai_valued_set(enum effect_type tgt, enum effect_type valued_as)
Definition effects.c:1354
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
enum effect_type user_effect_ai_valued_as(enum effect_type real)
Definition effects.c:1365
void effect_req_append(struct effect *peffect, struct requirement req)
Definition effects.c:266
bool is_user_effect(enum effect_type eff)
Definition effects.c:1345
#define effect_list_iterate_end
Definition effects.h:81
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:212
const char * extra_flag_helptxt(enum extra_flag_id id)
Definition extras.c:988
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Definition extras.c:947
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Definition extras.c:1046
struct extra_type_list * extra_type_list_of_zoccers(void)
Definition extras.c:267
int extra_number(const struct extra_type *pextra)
Definition extras.c:161
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:875
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:249
void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause)
Definition extras.c:312
struct extra_type * extra_by_number(int id)
Definition extras.c:183
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:353
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:259
#define extra_type_iterate(_p)
Definition extras.h:315
static void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.h:214
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_iterate_end
Definition extras.h:321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_index(_e_)
Definition extras.h:183
#define extra_type_list_iterate_end
Definition extras.h:167
#define extra_base_get(_e_)
Definition extras.h:190
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define MAX_NUM_USER_EXTRA_FLAGS
Definition extras.h:83
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
#define MAX_NUM_USER_BUILDING_FLAGS
Definition fc_types.h:493
#define MAX_DISASTER_TYPES
Definition fc_types.h:52
#define MAX_VET_LEVELS
Definition fc_types.h:49
@ ROCO_RAILROAD
Definition fc_types.h:948
@ ROCO_NONE
Definition fc_types.h:948
@ ROCO_RIVER
Definition fc_types.h:948
@ ROCO_ROAD
Definition fc_types.h:948
#define MAX_GRANARY_INIS
Definition fc_types.h:74
#define MAX_NUM_NATIONS
Definition fc_types.h:61
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
#define MAX_GOODS_TYPES
Definition fc_types.h:51
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:811
#define EC_SPECIAL
Definition fc_types.h:809
int action_id
Definition fc_types.h:250
#define SP_MAX
Definition fc_types.h:269
#define EC_NONE
Definition fc_types.h:808
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:812
#define EC_DEFENSIVE
Definition fc_types.h:810
#define MAX_CALENDAR_FRAGMENTS
Definition fc_types.h:63
#define MAX_TILEDEFS
Definition fc_types.h:56
#define MAX_NUM_TECH_CLASSES
Definition fc_types.h:64
#define MAX_NUM_LEADERS
Definition fc_types.h:57
#define MAX_NUM_MULTIPLIERS
Definition fc_types.h:55
#define MAX_NUM_UNIT_LIST
Definition fc_types.h:45
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
@ CTGT_CITY
Definition fc_types.h:128
#define MAX_ACHIEVEMENT_TYPES
Definition fc_types.h:53
#define MAX_LEN_NAME
Definition fc_types.h:68
#define MAX_NUM_TECH_LIST
Definition fc_types.h:44
#define MAX_LEN_CITYNAME
Definition fc_types.h:69
#define MAX_COUNTERS
Definition fc_types.h:108
#define UCL_LAST
Definition fc_types.h:276
#define Q_(String)
Definition fcintl.h:70
#define _(String)
Definition fcintl.h:67
#define Qn_(String)
Definition fcintl.h:89
#define N_(String)
Definition fcintl.h:69
const struct ft_color ftc_warning
struct civ_game game
Definition game.c:62
void game_ruleset_init(void)
Definition game.c:517
void game_ruleset_free(void)
Definition game.c:568
struct world wld
Definition game.c:63
#define RS_DEFAULT_RANSOM_GOLD
Definition game.h:874
#define RS_DEFAULT_GRANARY_FOOD_INI
Definition game.h:826
#define RS_DEFAULT_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:866
#define RS_MIN_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:807
#define RS_MAX_TECH_UPKEEP_DIVIDER
Definition game.h:886
#define RS_MIN_ILLNESS_POLLUTION_PCT
Definition game.h:793
#define RS_DEFAULT_NUKE_POP_LOSS_PCT
Definition game.h:863
#define RS_MAX_BORDER_RADIUS_SQ_CITY
Definition game.h:800
#define RS_DEFAULT_BASE_POLLUTION
Definition game.h:849
#define RS_MIN_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:789
#define RS_MAX_ILLNESS_BASE_FACTOR
Definition game.h:782
#define RS_DEFAULT_INCITE_TOTAL_FCT
Definition game.h:822
#define RS_DEFAULT_ILLNESS_BASE_FACTOR
Definition game.h:780
#define RS_DEFAULT_NEG_YEAR_LABEL
Definition game.h:776
#define RS_MIN_NUKE_POP_LOSS_PCT
Definition game.h:864
#define RS_MIN_INCITE_IMPROVEMENT_FCT
Definition game.h:815
#define RS_MIN_FOOD_COST
Definition game.h:859
#define RS_MIN_BASE_BRIBE_COST
Definition game.h:871
#define RS_MAX_NUKE_POP_LOSS_PCT
Definition game.h:865
#define RS_DEFAULT_INCITE_IMPROVEMENT_FCT
Definition game.h:814
#define RS_MAX_INCITE_IMPROVEMENT_FCT
Definition game.h:816
#define RS_MIN_RANSOM_GOLD
Definition game.h:875
#define RS_ACTION_NO_MAX_DISTANCE
Definition game.h:902
#define RS_DEFAULT_BASE_BRIBE_COST
Definition game.h:870
#define RS_MAX_INCITE_BASE_COST
Definition game.h:812
#define RS_DEFAULT_TECH_UPKEEP_DIVIDER
Definition game.h:884
#define RS_DEFAULT_HAPPY_COST
Definition game.h:854
#define RS_MIN_UPGRADE_VETERAN_LOSS
Definition game.h:881
#define RS_MIN_ILLNESS_MIN_SIZE
Definition game.h:785
#define RS_DEFAULT_POISON_EMPTIES_FOOD_STOCK
Definition game.h:892
#define RS_DEFAULT_GRANARY_FOOD_INC
Definition game.h:828
#define RS_DEFAULT_ILLNESS_ON
Definition game.h:778
#define RS_MAX_FOOD_COST
Definition game.h:860
#define RS_MAX_HAPPY_COST
Definition game.h:856
#define GAME_DEFAULT_CELEBRATESIZE
Definition game.h:507
#define RS_MIN_ILLNESS_BASE_FACTOR
Definition game.h:781
#define RS_DEFAULT_STEAL_MAP_REVEALS_CITIES
Definition game.h:893
#define RS_MIN_TECH_UPKEEP_DIVIDER
Definition game.h:885
#define RS_MAX_RANSOM_GOLD
Definition game.h:876
#define RS_MIN_HAPPY_COST
Definition game.h:855
#define RS_MIN_BORDER_RADIUS_SQ_CITY
Definition game.h:799
#define GAME_DEFAULT_RULESETDIR
Definition game.h:681
#define RS_MIN_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:867
#define RS_MAX_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:808
#define RS_DEFAULT_UPGRADE_VETERAN_LOSS
Definition game.h:880
#define RS_MAX_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:868
#define RS_MAX_INCITE_UNIT_FCT
Definition game.h:820
#define RS_MIN_VIS_RADIUS_SQ
Definition game.h:846
#define RS_DEFAULT_CALENDAR_SKIP_0
Definition game.h:796
#define RS_MAX_ILLNESS_MIN_SIZE
Definition game.h:786
#define RS_DEFAULT_CITY_RADIUS_SQ
Definition game.h:841
#define RS_DEFAULT_HP
Definition game.h:888
#define GAME_DEFAULT_START_YEAR
Definition game.h:748
#define RS_MAX_BORDER_SIZE_EFFECT
Definition game.h:804
#define RS_DEFAULT_BORDER_SIZE_EFFECT
Definition game.h:802
#define RS_MAX_BASE_BRIBE_COST
Definition game.h:872
#define RS_MIN_INCITE_BASE_COST
Definition game.h:811
#define RS_DEFAULT_PILLAGE_SELECT
Definition game.h:878
#define RS_MIN_CITY_RADIUS_SQ
Definition game.h:842
#define RS_MIN_CITY_CENTER_OUTPUT
Definition game.h:833
#define RS_MAX_GRANARY_FOOD_INC
Definition game.h:830
#define RS_MAX_CITY_CENTER_OUTPUT
Definition game.h:834
#define RS_MAX_CITY_RADIUS_SQ
Definition game.h:843
#define RS_DEFAULT_POS_YEAR_LABEL
Definition game.h:774
#define RS_MIN_INCITE_UNIT_FCT
Definition game.h:819
#define RS_MIN_BORDER_SIZE_EFFECT
Definition game.h:803
#define RS_DEFAULT_VIS_RADIUS_SQ
Definition game.h:845
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:806
#define RS_DEFAULT_TIRED_ATTACK
Definition game.h:862
#define RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS
Definition game.h:894
#define RS_MAX_ILLNESS_POLLUTION_PCT
Definition game.h:794
#define RS_DEFAULT_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:788
#define RS_DEFAULT_FOOD_COST
Definition game.h:858
#define RS_DEFAULT_INCITE_UNIT_FCT
Definition game.h:818
#define RS_MAX_INCITE_TOTAL_FCT
Definition game.h:824
#define RS_DEFAULT_INCITE_BASE_COST
Definition game.h:810
#define GAME_DEFAULT_ANGRYCITIZEN
Definition game.h:398
#define RS_DEFAULT_CITY_CENTER_OUTPUT
Definition game.h:832
#define RS_MIN_HP
Definition game.h:889
#define RS_MIN_INCITE_TOTAL_FCT
Definition game.h:823
#define RS_DEFAULT_ILLNESS_POLLUTION_PCT
Definition game.h:792
#define RS_MAX_UPGRADE_VETERAN_LOSS
Definition game.h:882
static void set_ruleset_compat_mode(bool active)
Definition game.h:362
#define RS_MAX_VIS_RADIUS_SQ
Definition game.h:847
#define RS_MIN_GRANARY_FOOD_INC
Definition game.h:829
#define RS_MAX_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:790
#define RS_MAX_HP
Definition game.h:890
#define RS_DEFAULT_ILLNESS_MIN_SIZE
Definition game.h:784
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY
Definition game.h:798
const struct nation_type * ruler_title_nation(const struct ruler_title *pruler_title)
Definition government.c:362
struct ruler_title * government_ruler_title_new(struct government *pgovern, const struct nation_type *pnation, const char *ruler_male_title, const char *ruler_female_title)
Definition government.c:322
const char * ruler_title_female_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:380
Government_type_id government_count(void)
Definition government.c:73
const char * ruler_title_male_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:371
const char * gov_flag_helptxt(enum gov_flag_id id)
Definition government.c:651
void governments_alloc(int num)
Definition government.c:525
Government_type_id government_number(const struct government *pgovern)
Definition government.c:92
const struct ruler_title_hash * government_ruler_titles(const struct government *pgovern)
Definition government.c:312
Government_type_id government_index(const struct government *pgovern)
Definition government.c:84
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
struct government * government_by_rule_name(const char *name)
Definition government.c:57
void set_user_gov_flag_name(enum gov_flag_id id, const char *name, const char *helptxt)
Definition government.c:614
#define governments_iterate(NAME_pgov)
Definition government.h:136
#define G_LAST
Definition government.h:50
#define ruler_titles_iterate(ARG_hash, NAME_rule_title)
Definition government.h:40
#define ruler_titles_iterate_end
Definition government.h:43
#define governments_iterate_end
Definition government.h:139
#define MAX_NUM_USER_GOVERNMENT_FLAGS
Definition government.h:29
const char * title
Definition repodlgs.c:1314
GType type
Definition repodlgs.c:1313
struct impr_type * improvement_by_number(const Impr_type_id id)
Impr_type_id improvement_number(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
void improvement_feature_cache_init(void)
Definition improvement.c:92
struct impr_type * improvement_by_rule_name(const char *name)
void set_user_impr_flag_name(enum impr_flag_id id, const char *name, const char *helptxt)
const char * impr_flag_helptxt(enum impr_flag_id id)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
void vdo_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, char *buf, int buflen, const char *message, va_list args)
Definition log.c:411
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define MAX_LEN_LOG_LINE
Definition log.h:27
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_do_output_for_level(level)
Definition log.h:90
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
log_level
Definition log.h:29
@ LOG_ERROR
Definition log.h:31
@ LOG_FATAL
Definition log.h:30
#define log_error(message,...)
Definition log.h:104
void lsend_packet_ruleset_summary(struct conn_list *dest, const struct packet_ruleset_summary *packet)
void lsend_packet_ruleset_building(struct conn_list *dest, const struct packet_ruleset_building *packet)
void lsend_packet_ruleset_unit_class_flag(struct conn_list *dest, const struct packet_ruleset_unit_class_flag *packet)
void lsend_packet_ruleset_achievement(struct conn_list *dest, const struct packet_ruleset_achievement *packet)
void lsend_packet_ruleset_nation_sets(struct conn_list *dest, const struct packet_ruleset_nation_sets *packet)
void lsend_packet_ruleset_multiplier(struct conn_list *dest, const struct packet_ruleset_multiplier *packet)
void lsend_packet_ruleset_city(struct conn_list *dest, const struct packet_ruleset_city *packet)
void lsend_packet_ruleset_unit(struct conn_list *dest, const struct packet_ruleset_unit *packet)
void lsend_packet_ruleset_clause(struct conn_list *dest, const struct packet_ruleset_clause *packet)
void lsend_packet_ruleset_unit_flag(struct conn_list *dest, const struct packet_ruleset_unit_flag *packet)
void lsend_packet_ruleset_action(struct conn_list *dest, const struct packet_ruleset_action *packet)
void lsend_packet_ruleset_extra(struct conn_list *dest, const struct packet_ruleset_extra *packet)
void lsend_packet_ruleset_nation_groups(struct conn_list *dest, const struct packet_ruleset_nation_groups *packet)
void lsend_packet_ruleset_terrain_control(struct conn_list *dest, const struct packet_ruleset_terrain_control *packet)
void lsend_packet_ruleset_government_ruler_title(struct conn_list *dest, const struct packet_ruleset_government_ruler_title *packet)
void lsend_packet_ruleset_music(struct conn_list *dest, const struct packet_ruleset_music *packet)
void lsend_packet_ruleset_control(struct conn_list *dest, const struct packet_ruleset_control *packet)
void lsend_packet_team_name_info(struct conn_list *dest, const struct packet_team_name_info *packet)
void lsend_packet_ruleset_terrain_flag(struct conn_list *dest, const struct packet_ruleset_terrain_flag *packet)
void lsend_packet_ruleset_unit_class(struct conn_list *dest, const struct packet_ruleset_unit_class *packet)
void lsend_packet_ruleset_disaster(struct conn_list *dest, const struct packet_ruleset_disaster *packet)
void lsend_packet_ruleset_tiledef(struct conn_list *dest, const struct packet_ruleset_tiledef *packet)
void lsend_packet_ruleset_description_part(struct conn_list *dest, const struct packet_ruleset_description_part *packet)
void lsend_packet_ruleset_government(struct conn_list *dest, const struct packet_ruleset_government *packet)
void lsend_packet_ruleset_unit_bonus(struct conn_list *dest, const struct packet_ruleset_unit_bonus *packet)
void lsend_packet_ruleset_base(struct conn_list *dest, const struct packet_ruleset_base *packet)
void lsend_packet_ruleset_resource(struct conn_list *dest, const struct packet_ruleset_resource *packet)
void lsend_packet_ruleset_specialist(struct conn_list *dest, const struct packet_ruleset_specialist *packet)
void lsend_packet_ruleset_tech(struct conn_list *dest, const struct packet_ruleset_tech *packet)
void lsend_packet_ruleset_trade(struct conn_list *dest, const struct packet_ruleset_trade *packet)
void lsend_packet_ruleset_action_enabler(struct conn_list *dest, const struct packet_ruleset_action_enabler *packet)
void lsend_packet_ruleset_gov_flag(struct conn_list *dest, const struct packet_ruleset_gov_flag *packet)
void lsend_packet_ruleset_style(struct conn_list *dest, const struct packet_ruleset_style *packet)
void lsend_packet_ruleset_tech_flag(struct conn_list *dest, const struct packet_ruleset_tech_flag *packet)
void lsend_packet_ruleset_tech_class(struct conn_list *dest, const struct packet_ruleset_tech_class *packet)
void lsend_packet_ruleset_goods(struct conn_list *dest, const struct packet_ruleset_goods *packet)
void lsend_packet_ruleset_game(struct conn_list *dest, const struct packet_ruleset_game *packet)
void lsend_packet_ruleset_nation(struct conn_list *dest, const struct packet_ruleset_nation *packet)
void lsend_packet_ruleset_counter(struct conn_list *dest, const struct packet_ruleset_counter *packet)
void lsend_packet_rulesets_ready(struct conn_list *dest)
void lsend_packet_ruleset_impr_flag(struct conn_list *dest, const struct packet_ruleset_impr_flag *packet)
void lsend_packet_ruleset_extra_flag(struct conn_list *dest, const struct packet_ruleset_extra_flag *packet)
void lsend_packet_ruleset_road(struct conn_list *dest, const struct packet_ruleset_road *packet)
void lsend_packet_ruleset_terrain(struct conn_list *dest, const struct packet_ruleset_terrain *packet)
void lsend_packet_ruleset_action_auto(struct conn_list *dest, const struct packet_ruleset_action_auto *packet)
struct terrain_misc terrain_control
Definition map.c:68
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
int utype_unknown_move_cost(const struct unit_type *utype)
Definition movement.c:104
void init_move_fragments(void)
Definition movement.c:978
#define SINGLE_MOVE
Definition movement.h:26
const char * multiplier_rule_name(const struct multiplier *pmul)
Multiplier_type_id multiplier_number(const struct multiplier *pmul)
Definition multipliers.c:67
struct multiplier * multiplier_by_rule_name(const char *name)
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * untranslated_name(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
void nation_group_set_match(struct nation_group *pgroup, int match)
Definition nation.c:1041
const char * nation_group_untranslated_name(const struct nation_group *pgroup)
Definition nation.c:1062
struct nation_group * nation_group_by_rule_name(const char *name)
Definition nation.c:1016
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
Nation_type_id nation_count(void)
Definition nation.c:503
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:484
struct nation_group * nation_group_new(const char *name)
Definition nation.c:953
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:295
struct nation_set * nation_set_new(const char *set_name, const char *set_rule_name, const char *set_description)
Definition nation.c:714
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:472
struct nation_city * nation_city_new(struct nation_type *pnation, const char *name)
Definition nation.c:347
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:231
const char * nation_set_untranslated_name(const struct nation_set *pset)
Definition nation.c:797
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:201
int nation_set_number(const struct nation_set *pset)
Definition nation.c:706
void nation_city_set_terrain_preference(struct nation_city *pncity, const struct terrain *pterrain, enum nation_city_preference prefer)
Definition nation.c:397
void nation_city_set_river_preference(struct nation_city *pncity, enum nation_city_preference prefer)
Definition nation.c:407
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:832
const char * nation_set_description(const struct nation_set *pset)
Definition nation.c:824
int nation_set_count(void)
Definition nation.c:690
struct nation_set * nation_set_by_number(int id)
Definition nation.c:762
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:121
struct nation_set * nation_set_by_rule_name(const char *name)
Definition nation.c:779
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:495
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:287
int nation_group_count(void)
Definition nation.c:929
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:806
struct nation_leader * nation_leader_new(struct nation_type *pnation, const char *name, bool is_male)
Definition nation.c:241
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
Definition nation.c:1032
void nations_alloc(int num)
Definition nation.c:620
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:212
int nation_group_number(const struct nation_group *pgroup)
Definition nation.c:945
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:57
#define nation_sets_iterate_end
Definition nation.h:333
#define nation_set_list_iterate_end
Definition nation.h:68
#define nation_group_list_iterate(grouplist, pgroup)
Definition nation.h:75
#define nation_sets_iterate(NAME_pset)
Definition nation.h:329
#define nations_iterate_end
Definition nation.h:364
nation_city_preference
Definition nation.h:39
@ NCP_DISLIKE
Definition nation.h:40
@ NCP_LIKE
Definition nation.h:42
#define nations_iterate(NAME_pnation)
Definition nation.h:361
#define nation_leader_list_iterate_end
Definition nation.h:59
#define nation_group_list_iterate_end
Definition nation.h:77
#define nation_set_list_iterate(setlist, pset)
Definition nation.h:66
#define nation_groups_iterate(NAME_pgroup)
Definition nation.h:339
#define nation_groups_iterate_end
Definition nation.h:343
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
#define web_lsend_packet(packetname,...)
Definition packets.h:57
#define PACKET_STRVEC_INSERT(dest, src)
Definition packets.h:191
struct city_list * cities
Definition packhand.c:121
int len
Definition packhand.c:129
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2655
void playercolor_free(void)
Definition plrhand.c:3356
void playercolor_init(void)
Definition plrhand.c:3346
int playercolor_count(void)
Definition plrhand.c:3395
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3375
void count_playable_nations(void)
Definition plrhand.c:2612
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:51
const char * secfile_error(void)
const char * section_name(const struct section *psection)
void secfile_destroy(struct section_file *secfile)
bool entry_bool_get(const struct entry *pentry, bool *value)
void secfile_check_unused(const struct section_file *secfile)
bool secfile_lookup_int(const struct section_file *secfile, int *ival, const char *path,...)
struct section_list * secfile_sections_by_name_prefix(const struct section_file *secfile, const char *prefix)
const char ** secfile_lookup_str_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
struct entry * secfile_entry_lookup(const struct section_file *secfile, const char *path,...)
bool entry_str_get(const struct entry *pentry, const char **value)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
int * secfile_lookup_int_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
bool entry_int_get(const struct entry *pentry, int *value)
const char * secfile_name(const struct section_file *secfile)
struct entry * secfile_entry_by_path(const struct section_file *secfile, const char *path)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
int secfile_lookup_int_def_min_max(const struct section_file *secfile, int defval, int minval, int maxval, const char *path,...)
enum entry_type entry_type_get(const struct entry *pentry)
@ ENTRY_FILEREFERENCE
@ ENTRY_LONG_COMMENT
@ ENTRY_INT
@ ENTRY_FLOAT
@ ENTRY_STR
@ ENTRY_ILLEGAL
@ ENTRY_BOOL
#define secfile_lookup_enum_vec(secfile, dim, specenum_type, path,...)
#define secfile_lookup_enum_default(secfile, defval, specenum_type, path,...)
#define section_list_iterate(seclist, psection)
#define section_list_iterate_end
#define secfile_entry_ignore_by_path(_sfile_, _path_)
req_vec_num_in_item req_vec_vector_number(const void *parent_item, const struct requirement_vector *vec)
struct requirement_vector * req_vec_by_number(const void *parent_item, req_vec_num_in_item number)
bool req_vec_change_apply(const struct req_vec_change *modification, requirement_vector_by_number getter, const void *parent_item)
bool are_requirements_equal(const struct requirement *req1, const struct requirement *req2)
struct requirement req_from_str(const char *type, const char *range, bool survives, bool present, bool quiet, const char *value)
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
void req_vec_problem_free(struct req_vec_problem *issue)
struct req_vec_problem * req_vec_get_first_missing_univ(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
struct req_vec_problem * req_vec_get_first_redundant_req(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
bool req_vec_is_impossible_to_fulfill(const struct requirement_vector *reqs)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
bool rgbcolor_load(struct section_file *file, struct rgbcolor **prgbcolor, char *path,...)
Definition rgbcolor.c:86
Road_type_id road_number(const struct road_type *proad)
Definition road.c:32
void road_integrators_cache_init(void)
Definition road.c:111
void road_type_init(struct extra_type *pextra, int idx)
Definition road.c:93
bool rscompat_names(struct rscompat_info *info)
Definition rscompat.c:335
void rscompat_postprocess(struct rscompat_info *info)
Definition rscompat.c:496
const char * rscompat_effect_name_3_4(const char *old_name)
Definition rscompat.c:572
int rscompat_check_capabilities(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:70
void rscompat_enablers_add_obligatory_hard_reqs(void)
Definition rscompat.c:290
void rscompat_init_info(struct rscompat_info *info)
Definition rscompat.c:61
bool rscompat_check_cap_and_version(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:135
bool sanity_check_ruleset_data(struct rscompat_info *compat)
Definition rssanity.c:910
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1625
#define ENABLER_SECTION_PREFIX
Definition ruleload.c:115
#define check_cityname(name)
Definition ruleload.c:121
static int ruleset_purge_redundant_reqs_enablers(void)
Definition ruleload.c:437
static void ruleset_load_traits(struct trait_limits *out, struct section_file *file, const char *secname, const char *field_prefix)
Definition ruleload.c:1280
static bool load_rulesetdir(const char *rsdir, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9581
#define STYLE_SECTION_PREFIX
Definition ruleload.c:100
static bool lookup_terrain(struct section_file *file, const char *entry, const char *filename, struct terrain *pthis, struct terrain **result, bool null_acceptable)
Definition ruleload.c:1181
static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, size_t err_len)
Definition ruleload.c:1964
static bool load_terrain_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2776
static bool load_style_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5809
int ruleset_purge_unused_entities(void)
Definition ruleload.c:327
#define MUSICSTYLE_SECTION_PREFIX
Definition ruleload.c:93
static char * road_sections
Definition ruleload.c:132
static bool load_ruleset_governments(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:4488
#define MULTIPLIER_SECTION_PREFIX
Definition ruleload.c:117
static struct requirement_vector reqs_list
Definition ruleload.c:135
static void send_ruleset_techs(struct conn_list *dest)
Definition ruleload.c:8429
#define section_strlcpy(dst, src)
Definition ruleload.c:126
static bool load_action_range(struct section_file *file, action_id act)
Definition ruleload.c:6562
#define check_name(name)
Definition ruleload.c:120
static bool load_specialist(const struct section *psection, struct specialist *s, struct section_file *file)
Definition ruleload.c:6051
static void send_ruleset_units(struct conn_list *dest)
Definition ruleload.c:8249
static void send_ruleset_governments(struct conn_list *dest)
Definition ruleload.c:9103
static bool load_action_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1451
static struct extra_type * lookup_resource(const char *filename, const char *name, const char *jsection)
Definition ruleload.c:1160
static struct section_file * openload_luadata_file(const char *rsdir)
Definition ruleload.c:641
#define TILEDEF_SECTION_PREFIX
Definition ruleload.c:106
static bool load_ruleset_techs(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1592
static bool purge_unused_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleload.c:341
void rulesets_deinit(void)
Definition ruleload.c:9570
static void send_ruleset_resources(struct conn_list *dest)
Definition ruleload.c:8718
static bool load_ruleset_buildings(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2652
static char * terrain_sections
Definition ruleload.c:129
static bool lookup_building_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleload.c:1010
static void nullcheck_secfile_destroy(struct section_file *file)
Definition ruleload.c:9559
static int secfile_lookup_int_default_min_max(struct section_file *file, int def, int min, int max, const char *path,...) fc__attribute((__format__(__printf__
Definition ruleload.c:6483
static void send_ruleset_clauses(struct conn_list *dest)
Definition ruleload.c:9298
static void send_ruleset_game(struct conn_list *dest)
Definition ruleload.c:9398
char * parser_buffer
Definition ruleload.c:223
#define NATION_SECTION_PREFIX
Definition ruleload.c:99
static bool load_ruleset_effects(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:6309
static bool lookup_cbonus_list(struct combat_bonus_list *list, struct section_file *file, const char *sec, const char *sub)
Definition ruleload.c:795
static void send_ruleset_nations(struct conn_list *dest)
Definition ruleload.c:9172
static void send_ruleset_roads(struct conn_list *dest)
Definition ruleload.c:8861
static int ruleset_purge_unused_enablers(void)
Definition ruleload.c:258
#define UEFF_SECTION_PREFIX
Definition ruleload.c:94
static char * tiledef_sections
Definition ruleload.c:133
static bool is_on_allowed_list(const char *name, const char **list, size_t len)
Definition ruleload.c:4904
static void send_ruleset_tech_classes(struct conn_list *dest)
Definition ruleload.c:8411
static void send_ruleset_action_enablers(struct conn_list *dest)
Definition ruleload.c:9030
static void send_ruleset_control(struct conn_list *dest)
Definition ruleload.c:4709
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9489
static void send_ruleset_tiledefs(struct conn_list *dest)
Definition ruleload.c:8897
#define GOODS_SECTION_PREFIX
Definition ruleload.c:107
void ruleset_error_real(rs_conversion_logger logger, const char *file, const char *function, int line, enum log_level level, const char *format,...)
Definition ruleload.c:229
#define TERRAIN_SECTION_PREFIX
Definition ruleload.c:110
static struct section_file * openload_ruleset_file(const char *whichset, const char *rsdir)
Definition ruleload.c:585
struct requirement_vector * lookup_req_list(struct section_file *file, const char *sec, const char *sub, const char *rfor)
Definition ruleload.c:669
static void send_ruleset_musics(struct conn_list *dest)
Definition ruleload.c:9377
int ruleset_purge_redundant_reqs(void)
Definition ruleload.c:504
static char * base_sections
Definition ruleload.c:131
#define DISASTER_SECTION_PREFIX
Definition ruleload.c:113
static void send_ruleset_goods(struct conn_list *dest)
Definition ruleload.c:8925
static const char name_too_long[]
Definition ruleload.c:124
bool reload_rulesets_settings(void)
Definition ruleload.c:9820
static struct strvec * lookup_strvec(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleload.c:1139
#define CITYSTYLE_SECTION_PREFIX
Definition ruleload.c:92
static bool lookup_tech(struct section_file *file, struct advance **result, const char *prefix, const char *entry, const char *filename, const char *description)
Definition ruleload.c:854
static bool load_game_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1321
static void send_ruleset_counters(struct conn_list *dest)
Definition ruleload.c:8525
static void send_ruleset_specialists(struct conn_list *dest)
Definition ruleload.c:8386
#define ADVANCE_SECTION_PREFIX
Definition ruleload.c:89
#define EFFECT_SECTION_PREFIX
Definition ruleload.c:95
static void send_ruleset_action_auto_performers(struct conn_list *dest)
Definition ruleload.c:9049
static bool load_government_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:4376
static int char * script_buffer
Definition ruleload.c:222
static bool load_action_blocked_by_list(struct section_file *file, const char *filename, struct action *paction, struct rscompat_info *compat)
Definition ruleload.c:6627
static void send_ruleset_team_names(struct conn_list *dest)
Definition ruleload.c:9459
static void send_ruleset_cities(struct conn_list *dest)
Definition ruleload.c:9352
static bool purge_redundant_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleload.c:426
static char * lookup_string(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleload.c:1118
static const char * check_leader_names(struct nation_type *pnation)
Definition ruleload.c:4747
#define BASE_SECTION_PREFIX
Definition ruleload.c:103
static int ruleset_purge_redundant_reqs_effects(void)
Definition ruleload.c:475
static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir, char **buffer, bool optional)
Definition ruleload.c:613
char * get_parser_buffer(void)
Definition ruleload.c:576
#define ACTION_SECTION_PREFIX
Definition ruleload.c:116
static bool load_building_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2569
#define EXTRA_SECTION_PREFIX
Definition ruleload.c:102
void send_rulesets(struct conn_list *dest)
Definition ruleload.c:9843
#define CLAUSE_SECTION_PREFIX
Definition ruleload.c:101
static bool lookup_unit_list(struct section_file *file, const char *prefix, const char *entry, struct unit_type **output, const char *filename)
Definition ruleload.c:886
static char * resource_sections
Definition ruleload.c:128
#define UNIT_SECTION_PREFIX
Definition ruleload.c:112
#define ACHIEVEMENT_SECTION_PREFIX
Definition ruleload.c:114
static bool load_ruleset_cities(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:6093
static bool load_ruleset_styles(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5871
static struct government * lookup_government(struct section_file *file, const char *entry, const char *filename, struct government *fallback)
Definition ruleload.c:1093
#define SUPER_SPECIALIST_SECTION_PREFIX
Definition ruleload.c:109
static bool load_ruleset_units(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2085
static bool lookup_time(const struct section_file *secfile, int *turns, const char *sec_name, const char *property_name, const char *filename, const char *item_name, bool *ok)
Definition ruleload.c:1231
static void send_ruleset_styles(struct conn_list *dest)
Definition ruleload.c:9282
#define NATION_GROUP_SECTION_PREFIX
Definition ruleload.c:98
static char * extra_sections
Definition ruleload.c:130
#define RULES_SUFFIX
Definition ruleload.c:86
static void send_ruleset_disasters(struct conn_list *dest)
Definition ruleload.c:8954
static bool purge_duplicate_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleload.c:381
static bool lookup_tech_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleload.c:946
#define MAX_SECTION_LABEL
Definition ruleload.c:125
#define BUILDING_SECTION_PREFIX
Definition ruleload.c:91
static bool load_ruleset_game(struct section_file *file, bool act, struct rscompat_info *compat)
Definition ruleload.c:6743
static bool load_nation_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:4768
static void send_ruleset_achievements(struct conn_list *dest)
Definition ruleload.c:8979
#define SCRIPT_SUFFIX
Definition ruleload.c:87
static void send_ruleset_bases(struct conn_list *dest)
Definition ruleload.c:8839
static bool load_ruleset_terrain(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:3151
static int ruleset_purge_unused_effects(void)
Definition ruleload.c:304
static bool load_action_actor_consuming_always(struct section_file *file, action_id act)
Definition ruleload.c:6610
static bool load_action_post_success_force(struct section_file *file, const char *filename, int performer_slot, struct action *paction)
Definition ruleload.c:6672
static bool load_tech_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1471
#define SPECIALIST_SECTION_PREFIX
Definition ruleload.c:108
#define COUNTER_SECTION_PREFIX
Definition ruleload.c:118
static bool load_action_kind(struct section_file *file, action_id act)
Definition ruleload.c:6587
static void send_ruleset_multipliers(struct conn_list *dest)
Definition ruleload.c:9322
char * get_script_buffer(void)
Definition ruleload.c:568
static void send_ruleset_actions(struct conn_list *dest)
Definition ruleload.c:9000
static bool load_city_name_list(struct section_file *file, struct nation_type *pnation, const char *secfile_str1, const char *secfile_str2, const char **allowed_terrains, size_t atcount)
Definition ruleload.c:4920
static bool load_action_auto_uflag_block(struct section_file *file, struct action_auto_perf *auto_perf, const char *uflags_path, const char *filename)
Definition ruleload.c:5949
static bool load_ruleset_nations(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5091
static bool load_action_auto_actions(struct section_file *file, struct action_auto_perf *auto_perf, const char *actions_path, const char *filename)
Definition ruleload.c:5992
static void send_ruleset_unit_classes(struct conn_list *dest)
Definition ruleload.c:8201
#define TECH_CLASS_SECTION_PREFIX
Definition ruleload.c:90
#define RESOURCE_SECTION_PREFIX
Definition ruleload.c:105
static bool lookup_unit_type(struct section_file *file, const char *prefix, const char *entry, const struct unit_type **result, const char *filename, const char *description)
Definition ruleload.c:1062
static void send_ruleset_extras(struct conn_list *dest)
Definition ruleload.c:8737
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action)
static void send_ruleset_terrain(struct conn_list *dest)
Definition ruleload.c:8606
#define GOVERNMENT_SECTION_PREFIX
Definition ruleload.c:96
static bool load_unit_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1803
static void send_ruleset_trade_routes(struct conn_list *dest)
Definition ruleload.c:9082
static bool load_ruleset_actions(struct section_file *file, struct section_file *gamefile, struct rscompat_info *compat)
Definition ruleload.c:7817
static void notify_ruleset_fallback(const char *msg)
Definition ruleload.c:9481
static bool lookup_bv_actions(struct section_file *file, const char *filename, bv_actions *target, const char *path)
Definition ruleload.c:6709
static void send_ruleset_buildings(struct conn_list *dest)
Definition ruleload.c:8546
#define UNIT_CLASS_SECTION_PREFIX
Definition ruleload.c:111
static bool ruleset_load_names(struct name_translation *pname, const char *domain, struct section_file *file, const char *sec_name)
Definition ruleload.c:1257
#define ROAD_SECTION_PREFIX
Definition ruleload.c:104
static const char * valid_ruleset_filename(const char *subdir, const char *name, const char *extension, bool optional)
Definition ruleload.c:523
static bool load_action_range_max(struct section_file *file, action_id act)
Definition ruleload.c:6521
static bool load_muuk_as_action_auto(struct section_file *file, struct action_auto_perf *auto_perf, const char *item, const char *filename)
Definition ruleload.c:6028
#define NATION_SET_SECTION_PREFIX
Definition ruleload.c:97
#define RS_DEFAULT_CONVERT_SPEED
Definition ruleload.h:122
#define RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE
Definition ruleload.h:108
#define RS_DEFAULT_WORLD_PEACE_TURNS
Definition ruleload.h:98
#define RS_DEFAULT_TECH_TRADE_LOSS_HOLES
Definition ruleload.h:83
#define RS_DEFAULT_TECH_COST_STYLE
Definition ruleload.h:89
#define RS_DEFAULT_EXTRA_APPEARANCE
Definition ruleload.h:102
#define RS_DEFAULT_TECH_PARASITE_HOLES
Definition ruleload.h:84
#define GAME_DEFAULT_ACH_VALUE
Definition ruleload.h:77
#define RS_DEFAULT_TECH_TRADE_HOLES
Definition ruleload.h:82
#define RS_DEFAULT_CULTURE_VIC_POINTS
Definition ruleload.h:93
#define RS_DEFAULT_CULTURE_MIGRATION_PML
Definition ruleload.h:95
void(* rs_conversion_logger)(const char *msg)
Definition ruleload.h:41
#define RS_DEFAULT_SMALL_WONDER_VISIBILITY
Definition ruleload.h:110
#define ruleset_error(logger, level, format,...)
Definition ruleload.h:58
#define RS_DEFAULT_ONLY_KILLING_VETERAN
Definition ruleload.h:105
#define RS_DEFAULT_TECH_LOSS_HOLES
Definition ruleload.h:85
#define RS_DEFAULT_HISTORY_INTEREST_PML
Definition ruleload.h:96
#define RS_DEFAULT_TECH_UPKEEP_STYLE
Definition ruleload.h:91
#define RS_DEFAULT_GOODS_SELECTION
Definition ruleload.h:100
#define RS_DEFAULT_PYTHAGOREAN_DIAGONAL
Definition ruleload.h:86
#define RS_DEFAULT_TECH_STEAL_HOLES
Definition ruleload.h:81
#define RS_MIN_MIN_TECH_COST
Definition ruleload.h:117
#define GAME_DEFAULT_ACH_UNIQUE
Definition ruleload.h:76
#define RS_MAX_BASE_TECH_COST
Definition ruleload.h:114
#define RS_DEFAULT_COMBAT_ODDS_SCALED_VETERANCY
Definition ruleload.h:107
#define RS_DEFAULT_MUUK_FOOD_WIPE
Definition ruleload.h:78
#define RS_DEFAULT_MUUK_GOLD_WIPE
Definition ruleload.h:79
#define RS_DEFAULT_BASE_TECH_COST
Definition ruleload.h:112
#define RS_DEFAULT_NATIONALITY
Definition ruleload.h:120
#define GAME_DEFAULT_CHANGABLE_TAX
Definition ruleload.h:73
#define RS_DEFAULT_MUUK_SHIELD_WIPE
Definition ruleload.h:80
#define RSFORMAT_CURRENT
Definition ruleload.h:37
#define RS_DEFAULT_GOLD_UPKEEP_STYLE
Definition ruleload.h:88
#define GAME_DEFAULT_ADDTOSIZE
Definition ruleload.h:72
#define RS_DEFAULT_ONLY_REAL_FIGHT_VETERAN
Definition ruleload.h:106
#define RS_DEFAULT_EXTRA_DISAPPEARANCE
Definition ruleload.h:103
#define RS_MAX_MIN_TECH_COST
Definition ruleload.h:118
#define RS_DEFAULT_MIN_TECH_COST
Definition ruleload.h:116
#define GAME_DEFAULT_VISION_REVEAL_TILES
Definition ruleload.h:74
#define RS_DEFAULT_CULTURE_VIC_LEAD
Definition ruleload.h:94
#define RS_DEFAULT_TECH_LEAKAGE
Definition ruleload.h:90
#define GAME_DEFAULT_DISASTER_FREQ
Definition ruleload.h:75
#define RSFORMAT_3_4
Definition ruleload.h:36
#define RS_MIN_BASE_TECH_COST
Definition ruleload.h:113
static struct compatibility compat[]
Definition savecompat.c:117
bool script_server_init(void)
bool script_server_load_file(const char *filename, char **buf)
void script_server_free(void)
bool script_server_do_file(struct connection *caller, const char *filename)
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
bool settings_ruleset(struct section_file *file, const char *section, bool act, bool compat)
Definition settings.c:4423
sex_t sex_by_name(const char *name)
Definition sex.c:27
sex_t
Definition sex.h:20
@ SEX_UNKNOWN
Definition sex.h:21
@ SEX_FEMALE
Definition sex.h:22
@ SEX_MALE
Definition sex.h:23
bool check_strlen(const char *str, size_t len, const char *errmsg)
Definition shared.c:493
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
const struct strvec * get_data_dirs(void)
Definition shared.c:886
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define DIR_SEPARATOR
Definition shared.h:127
#define ARRAY_SIZE(x)
Definition shared.h:85
struct specialist * specialist_by_rule_name(const char *name)
Definition specialist.c:123
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:110
Specialist_type_id specialist_index(const struct specialist *sp)
Definition specialist.c:90
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:157
#define specialist_type_iterate_end
Definition specialist.h:85
#define specialist_type_iterate(sp)
Definition specialist.h:79
#define DEFAULT_SPECIALIST
Definition specialist.h:43
const char * aifill(int amount)
Definition srv_main.c:2556
void update_nations_with_startpos(void)
Definition srv_main.c:2361
void strvec_store(struct strvec *psv, const char *const *vec, size_t size)
struct strvec * strvec_new(void)
bool actor_consuming_always
Definition actions.h:144
int max_distance
Definition actions.h:127
bool quiet
Definition actions.h:134
char ui_name[MAX_LEN_NAME]
Definition actions.h:130
bv_action_sub_results sub_results
Definition actions.h:115
enum action_actor_kind actor_kind
Definition actions.h:117
bv_actions blocked_by
Definition actions.h:138
enum action_target_kind target_kind
Definition actions.h:118
int min_distance
Definition actions.h:127
struct advance * require[AR_SIZE]
Definition tech.h:129
int border_sq
Definition base.h:44
int vision_main_sq
Definition base.h:45
enum base_gui_type gui_type
Definition base.h:43
int vision_invis_sq
Definition base.h:46
int vision_subs_sq
Definition base.h:47
char * nationlist
Definition game.h:289
int named_teams
Definition game.h:301
size_t as_count
Definition game.h:300
struct civ_game::@32::@36::@42 ruledit
const char ** allowed_govs
Definition game.h:292
int upgrade_veteran_loss
Definition game.h:206
struct rgbcolor * plr_bg_color
Definition game.h:103
int incite_total_factor
Definition game.h:157
int init_vis_radius_sq
Definition game.h:159
bool vision_reveal_tiles
Definition game.h:207
char * description_file
Definition game.h:288
struct packet_ruleset_control control
Definition game.h:83
char * ruleset_summary
Definition game.h:84
char ** nc_agovs
Definition game.h:293
int base_incite_cost
Definition game.h:141
int global_init_techs[MAX_NUM_TECH_LIST]
Definition game.h:110
struct packet_game_info info
Definition game.h:89
int autoupgrade_veteran_loss
Definition game.h:139
char rulesetdir[MAX_LEN_NAME]
Definition game.h:246
int start_year
Definition game.h:198
int incite_improvement_factor
Definition game.h:156
struct section_file * luadata
Definition game.h:254
char ** embedded_nations
Definition game.h:290
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:111
struct trait_limits default_traits[TRAIT_COUNT]
Definition game.h:281
char ** nc_astyles
Definition game.h:299
const char ** allowed_terrains
Definition game.h:295
char * ruleset_description
Definition game.h:85
size_t ag_count
Definition game.h:294
const char ** allowed_styles
Definition game.h:298
bool std_tileset_compat
Definition game.h:302
struct civ_game::@31 rgame
char ** nc_aterrs
Definition game.h:296
size_t embedded_nations_count
Definition game.h:291
int incite_unit_factor
Definition game.h:158
char * ruleset_capabilities
Definition game.h:86
int ransom_gold
Definition game.h:182
struct civ_game::@32::@36 server
size_t at_count
Definition game.h:297
struct veteran_system * veteran
Definition game.h:101
bool homeless_gold_upkeep
Definition game.h:131
struct packet_calendar_info calendar
Definition game.h:90
struct government * default_government
Definition game.h:93
struct civ_game::@32::@36::@37 deprecated
struct government * government_during_revolution
Definition game.h:94
struct civ_map::@44::@46 server
bool ocean_resources
Definition map_types.h:119
struct requirement_vector receiver_reqs
Definition diptreaty.h:61
struct requirement_vector giver_reqs
Definition diptreaty.h:60
struct requirement_vector either_reqs
Definition diptreaty.h:62
bool enabled
Definition diptreaty.h:59
enum unit_type_flag_id flag
Definition unittype.h:472
enum combat_bonus_type type
Definition unittype.h:473
struct name_translation name
Definition extras.h:90
int build_cost
Definition improvement.h:60
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
enum impr_genus_id genus
Definition improvement.h:63
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
struct requirement_vector obsolete_by
Definition improvement.h:59
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:67
char soundtag_alt2[MAX_LEN_NAME]
Definition improvement.h:68
struct requirement_vector reqs
Definition improvement.h:58
struct strvec * helptext
Definition improvement.h:65
struct name_translation name
Definition improvement.h:52
bv_impr_flags flags
Definition improvement.h:64
char soundtag[MAX_LEN_NAME]
Definition improvement.h:66
Definition climisc.h:82
bool hidden
Definition nation.h:171
char * legend
Definition nation.h:107
enum barbarian_type barb_type
Definition nation.h:110
char calendar_fragment_name[MAX_CALENDAR_FRAGMENTS][MAX_LEN_NAME]
char negative_year_label[MAX_LEN_NAME]
char positive_year_label[MAX_LEN_NAME]
bool tech_steal_allow_holes
enum gameloss_style gameloss_style
int granary_food_ini[MAX_GRANARY_INIS]
enum goods_selection_method goods_selection
Government_type_id government_during_revolution_id
enum gold_upkeep_style gold_upkeep_style
int low_firepower_pearl_harbor
bool damage_reduces_bombard_rate
int nuke_defender_survival_chance_pct
enum tech_upkeep_style tech_upkeep_style
bool tech_trade_loss_allow_holes
enum free_tech_method free_tech_method
bool steal_maps_reveals_all_cities
bool only_real_fight_makes_veteran
enum tech_leakage_style tech_leakage
int min_city_center_output[O_LAST]
bool airlift_from_always_enabled
bool only_killing_makes_veteran
bool poison_empties_food_stock
bv_actions diplchance_initial_odds
bool tech_trade_allow_holes
int low_firepower_nonnat_bombard
bool tech_parasite_allow_holes
int low_firepower_combat_bonus
int border_city_permanent_radius_sq
int low_firepower_badwallattacker
bool airlift_to_always_enabled
enum wonder_visib_type small_wonder_visibility
enum tech_cost_style tech_cost_style
bool combat_odds_scaled_veterancy
bool unit_builders_nationality
Government_type_id default_government_id
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
enum achievement_type type
action_id alternatives[MAX_NUM_ACTIONS]
struct requirement_vector reqs
enum action_auto_perf_cause cause
struct requirement_vector actor_reqs
struct requirement_vector target_reqs
char ui_name[MAX_LEN_NAME]
enum action_sub_target_kind sub_tgt_kind
enum action_actor_kind act_kind
bv_action_sub_results sub_results
enum action_target_kind tgt_kind
enum action_result result
enum base_gui_type gui_type
char graphic_alt2[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
struct requirement_vector reqs
struct requirement_vector obs_reqs
char soundtag_alt2[MAX_LEN_NAME]
enum impr_genus_id genus
char soundtag[MAX_LEN_NAME]
char soundtag_alt[MAX_LEN_NAME]
struct strvec * helptext
struct requirement_vector giver_reqs
enum clause_type type
struct requirement_vector receiver_reqs
struct requirement_vector either_reqs
char alt_dir[MAX_LEN_NAME]
char version[MAX_LEN_NAME]
char preferred_musicset[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char preferred_tileset[MAX_LEN_NAME]
char preferred_soundset[MAX_LEN_NAME]
enum counter_target type
char name[MAX_LEN_NAME]
struct strvec * helptext
char rule_name[MAX_LEN_NAME]
enum counter_behavior behavior
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
struct requirement_vector reqs
bv_disaster_effects effects
char helptxt[MAX_LEN_PACKET]
char graphic_str[MAX_LEN_NAME]
struct strvec * helptext
bv_unit_classes native_to
char graphic_alt[MAX_LEN_NAME]
char rmact_gfx[MAX_LEN_NAME]
struct requirement_vector appearance_reqs
char act_gfx_alt[MAX_LEN_NAME]
char act_gfx_alt2[MAX_LEN_NAME]
struct requirement_vector disappearance_reqs
bv_extra_flags flags
char rmact_gfx_alt[MAX_LEN_NAME]
struct requirement_vector rmreqs
enum extra_unit_seen_type eus
char activity_gfx[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
struct requirement_vector reqs
char rmact_gfx_alt2[MAX_LEN_NAME]
struct requirement_vector reqs
bv_goods_flags flags
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
struct strvec * helptext
char helptxt[MAX_LEN_PACKET]
char sound_alt2[MAX_LEN_NAME]
char sound_str[MAX_LEN_NAME]
struct requirement_vector reqs
char graphic_alt[MAX_LEN_NAME]
Government_type_id id
char graphic_str[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char sound_alt[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
struct requirement_vector reqs
char name[MAX_LEN_NAME]
Multiplier_type_id id
char rule_name[MAX_LEN_NAME]
struct requirement_vector reqs
char music_peaceful[MAX_LEN_NAME]
char music_combat[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
bool leader_is_male[MAX_NUM_LEADERS]
int sets[MAX_NUM_NATION_SETS]
Impr_type_id init_buildings[MAX_NUM_BUILDING_LIST]
char adjective[MAX_LEN_NAME]
char translation_domain[MAX_LEN_NAME]
char leader_name[MAX_NUM_LEADERS][MAX_LEN_NAME]
int init_techs[MAX_NUM_TECH_LIST]
Unit_type_id init_units[MAX_NUM_UNIT_LIST]
char legend[MAX_LEN_MSG]
int groups[MAX_NUM_NATION_GROUPS]
Government_type_id init_government_id
enum barbarian_type barbarian_type
char noun_plural[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
bv_road_flags flags
enum road_gui_type gui_type
bv_max_extras integrates
int tile_incr_const[O_LAST]
enum road_compat compat
int tile_incr[O_LAST]
enum road_move_mode move_mode
int tile_bonus[O_LAST]
struct requirement_vector first_reqs
char plural_name[MAX_LEN_NAME]
struct requirement_vector reqs
Specialist_type_id id
char rule_name[MAX_LEN_NAME]
char short_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char text[MAX_LEN_CONTENT]
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
struct strvec * helptext
char name[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
bv_tech_flags flags
struct requirement_vector research_reqs
char helptxt[MAX_LEN_PACKET]
Terrain_type_id transform_result
char name[MAX_LEN_NAME]
int animals[MAX_NUM_ANIMALS]
int resource_freq[MAX_EXTRA_TYPES]
bv_terrain_flags flags
Resource_type_id resources[MAX_EXTRA_TYPES]
char graphic_alt[MAX_LEN_NAME]
bv_unit_classes native_to
int road_output_incr_pct[O_LAST]
char graphic_alt2[MAX_LEN_NAME]
Terrain_type_id cultivate_result
int extra_removal_times[MAX_EXTRA_TYPES]
Terrain_type_id plant_result
char rule_name[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
struct strvec * helptext
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
enum trade_route_illegal_cancelling cancelling
enum trade_route_bonus_type bonus_type
char helptxt[MAX_LEN_PACKET]
bv_unit_class_flags flags
char rule_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
enum vision_layer vlayer
enum transp_def_type tp_defense
char rule_name[MAX_LEN_NAME]
int base_raise_chance[MAX_VET_LEVELS]
int move_bonus[MAX_VET_LEVELS]
int work_raise_chance[MAX_VET_LEVELS]
char sound_move[MAX_LEN_NAME]
bv_unit_classes disembarks
bv_unit_classes cargo
bv_unit_type_flags flags
char sound_fight_alt[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
bv_unit_classes targets
struct requirement_vector build_reqs
int power_fact[MAX_VET_LEVELS]
char veteran_name[MAX_VET_LEVELS][MAX_LEN_NAME]
bv_unit_classes embarks
char sound_fight[MAX_LEN_NAME]
char sound_move_alt[MAX_LEN_NAME]
struct strvec * helptext
char graphic_alt2[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
bv_unit_type_roles roles
Definition goto.c:52
struct universal source
int g
Definition rgbcolor.h:34
int b
Definition rgbcolor.h:34
int r
Definition rgbcolor.h:34
enum road_gui_type gui_type
Definition road.h:80
struct requirement_vector first_reqs
Definition road.h:82
enum road_move_mode move_mode
Definition road.h:75
int tile_bonus[O_LAST]
Definition road.h:78
int tile_incr_const[O_LAST]
Definition road.h:76
int tile_incr[O_LAST]
Definition road.h:77
bv_road_flags flags
Definition road.h:85
int move_cost
Definition road.h:74
enum road_compat compat
Definition road.h:79
bv_max_extras integrates
Definition road.h:84
bool compat_mode
Definition rscompat.h:31
struct requirement_vector reqs
Definition specialist.h:38
char graphic_alt[MAX_LEN_NAME]
Definition specialist.h:36
struct strvec * helptext
Definition specialist.h:40
char graphic_str[MAX_LEN_NAME]
Definition specialist.h:35
struct name_translation name
Definition specialist.h:31
struct name_translation abbreviation
Definition specialist.h:32
char ** vec
enum trade_route_bonus_type bonus_type
Definition traderoutes.h:78
enum trade_route_illegal_cancelling cancelling
Definition traderoutes.h:77
int fixed
Definition traits.h:46
enum universals_n kind
Definition fc_types.h:595
struct veteran_level * definitions
Definition unittype.h:502
struct civ_map map
struct nation_style * style_by_rule_name(const char *name)
Definition style.c:113
struct nation_style * style_by_number(int id)
Definition style.c:84
void styles_alloc(int count)
Definition style.c:36
struct music_style * music_style_by_number(int id)
Definition style.c:165
int style_number(const struct nation_style *pstyle)
Definition style.c:68
void music_styles_alloc(int count)
Definition style.c:129
int style_index(const struct nation_style *pstyle)
Definition style.c:76
#define music_styles_iterate(_p)
Definition style.h:75
#define music_styles_iterate_end
Definition style.h:82
#define styles_iterate(_p)
Definition style.h:48
#define styles_iterate_end
Definition style.h:54
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:925
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:742
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
bool fc_isspace(char c)
Definition support.c:1205
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:787
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:851
char fc_tolower(char c)
Definition support.c:1238
#define sz_strlcpy(dest, src)
Definition support.h:195
#define RETURN_VALUE_AFTER_EXIT(_val_)
Definition support.h:146
#define fc__attribute(x)
Definition support.h:99
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct team_slot * team_slot_by_number(int team_id)
Definition team.c:173
const char * team_slot_defined_name(const struct team_slot *tslot)
Definition team.c:272
int team_slot_index(const struct team_slot *tslot)
Definition team.c:138
int team_slot_count(void)
Definition team.c:112
void team_slot_set_defined_name(struct team_slot *tslot, const char *team_name)
Definition team.c:282
#define team_slots_iterate_end
Definition team.h:89
#define team_slots_iterate(_tslot)
Definition team.h:84
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:110
const char * tech_flag_id_name_cb(enum tech_flag_id flag)
Definition tech.c:438
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:409
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:157
void techs_precalc_data(void)
Definition tech.c:230
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:314
const char * tech_flag_helptxt(enum tech_flag_id id)
Definition tech.c:450
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:205
struct tech_class * tech_class_by_rule_name(const char *name)
Definition tech.c:366
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:100
#define tech_class_index(_ptclass_)
Definition tech.h:190
#define A_NEVER
Definition tech.h:51
#define tech_class_iterate_end
Definition tech.h:201
#define MAX_NUM_USER_TECH_FLAGS
Definition tech.h:105
#define advance_iterate_all_end
Definition tech.h:277
@ AR_TWO
Definition tech.h:109
@ AR_ROOT
Definition tech.h:110
@ AR_ONE
Definition tech.h:108
#define advance_iterate_all(_p)
Definition tech.h:276
static Tech_type_id advance_count(void)
Definition tech.h:167
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_iterate(_p)
Definition tech.h:273
#define tech_class_iterate(_p)
Definition tech.h:195
#define advance_iterate_end
Definition tech.h:274
#define A_LAST
Definition tech.h:45
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:188
Terrain_type_id terrain_count(void)
Definition terrain.c:119
const char * terrain_flag_id_name_cb(enum terrain_flag_id flag)
Definition terrain.c:820
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:139
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:157
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:832
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:275
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:791
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:148
#define RESOURCE_FREQUENCY_MAXIMUM
Definition terrain.h:102
#define terrain_type_iterate(_p)
Definition terrain.h:267
#define terrain_animals_iterate(pterrain, _animal)
Definition terrain.h:299
#define T_NONE
Definition terrain.h:61
#define TERRAIN_UNKNOWN_IDENTIFIER
Definition terrain.h:88
#define terrain_type_iterate_end
Definition terrain.h:273
#define RESOURCE_NONE_IDENTIFIER
Definition terrain.h:52
#define RESOURCE_NULL_IDENTIFIER
Definition terrain.h:51
#define RESOURCE_FREQUENCY_MINIMUM
Definition terrain.h:100
#define MAX_NUM_TERRAINS
Definition terrain.h:69
#define T_FIRST
Definition terrain.h:65
#define MAX_NUM_USER_TER_FLAGS
Definition terrain.h:32
#define terrain_resources_iterate_end
Definition terrain.h:295
#define terrain_resources_iterate(pterrain, _res, _freq)
Definition terrain.h:286
#define terrain_animals_iterate_end
Definition terrain.h:307
#define RESOURCE_FREQUENCY_DEFAULT
Definition terrain.h:101
#define ACTIVITY_FACTOR
Definition tile.h:170
int tiledef_number(const struct tiledef *td)
Definition tiledef.c:62
struct tiledef * tiledef_by_number(int id)
Definition tiledef.c:84
#define tiledef_index(_td_)
Definition tiledef.h:44
#define tiledef_iterate_end
Definition tiledef.h:57
#define tiledef_iterate(_p)
Definition tiledef.h:51
Goods_type_id goods_number(const struct goods_type *pgood)
enum trade_route_illegal_cancelling trade_route_cancelling_type_by_name(const char *name)
struct trade_route_settings * trade_route_settings_by_type(enum trade_route_type type)
const char * goods_rule_name(struct goods_type *pgood)
Goods_type_id goods_index(const struct goods_type *pgood)
enum trade_route_type trade_route_type_by_name(const char *name)
#define goods_type_iterate_end
@ TRI_LAST
Definition traderoutes.h:33
#define goods_type_iterate(_p)
trade_route_type
Definition traderoutes.h:37
@ TRT_NATIONAL
Definition traderoutes.h:38
@ TRT_LAST
Definition traderoutes.h:48
#define TRAIT_DEFAULT_VALUE
Definition traits.h:32
void set_unit_class_caches(struct unit_class *pclass)
Definition unittype.c:2793
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Definition unittype.c:1881
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1794
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:224
void unit_type_action_cache_init(void)
Definition unittype.c:956
void set_unit_type_caches(struct unit_type *ptype)
Definition unittype.c:2852
void role_unit_precalcs(void)
Definition unittype.c:2206
void veteran_system_definition(struct veteran_system *vsystem, int level, const char *vlist_name, int vlist_power, int vlist_move, int vlist_raise, int vlist_wraise)
Definition unittype.c:2722
Unit_type_id utype_count(void)
Definition unittype.c:82
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2662
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2634
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1667
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:102
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1811
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Definition unittype.c:1944
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
void set_user_unit_class_flag_name(enum unit_class_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1839
struct veteran_system * veteran_system_new(int count)
Definition unittype.c:2691
Unit_Class_id uclass_number(const struct unit_class *pclass)
Definition unittype.c:2502
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:396
void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1903
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
#define combat_bonus_list_iterate_end
Definition unittype.h:487
#define L_FIRST
Definition unittype.h:354
#define combat_bonus_list_iterate(bonuslist, pbonus)
Definition unittype.h:485
#define unit_tech_reqs_iterate_end
Definition unittype.h:891
#define unit_class_iterate(_p)
Definition unittype.h:918
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:885
#define MAX_NUM_USER_UNIT_FLAGS
Definition unittype.h:336
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
#define UTYF_LAST_USER_FLAG
Definition unittype.h:335
#define unit_type_iterate(_p)
Definition unittype.h:865
#define U_LAST
Definition unittype.h:40
#define uclass_index(_c_)
Definition unittype.h:749
#define unit_class_iterate_end
Definition unittype.h:925
#define unit_type_iterate_end
Definition unittype.h:872
#define MAX_NUM_USER_UCLASS_FLAGS
Definition unittype.h:128