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, NULL))
121#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, NULL))
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 = NULL;
129static char *terrain_sections = NULL;
130static char *extra_sections = NULL;
131static char *base_sections = NULL;
132static char *road_sections = NULL;
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
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 == NULL && !log_do_output_for_level(level)) {
238 return;
239 }
240
241 va_start(args, format);
242 if (logger != NULL) {
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 == NULL) {
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 == NULL) {
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
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) {
557 /* TRANS: message about an installation error. */
558 _("Could not find a readable \"%s.%s\" ruleset file."),
559 name, extension);
560 }
561
562 return NULL;
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 == NULL) {
594 return NULL;
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 == NULL) {
603 ruleset_error(NULL, 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 == NULL) {
620 return optional ? TRI_MAYBE : TRI_NO;
621 }
622
623 if (buffer == NULL) {
625 ruleset_error(NULL, LOG_ERROR, "\"%s\": could not load ruleset script.",
626 dfilename);
627
628 return TRI_NO;
629 }
630 } else {
632 }
633
634 return TRI_YES;
635}
636
637/**********************************************************************/
640static struct section_file *openload_luadata_file(const char *rsdir)
641{
642 struct section_file *secfile;
643 char sfilename[512];
644 const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
645 "txt", TRUE);
646
647 if (dfilename == NULL) {
648 return NULL;
649 }
650
651 /* Need to save a copy of the filename for following message, since
652 section_file_load() may call datafilename() for includes. */
654 secfile = secfile_load(sfilename, FALSE);
655
656 if (secfile == NULL) {
657 ruleset_error(NULL, LOG_ERROR, "Could not load luadata '%s':\n%s",
659 }
660
661 return secfile;
662}
663
664/**********************************************************************/
669 const char *sec,
670 const char *sub,
671 const char *rfor)
672{
673 const char *type, *name;
674 int j;
675 const char *filename;
676
677 filename = secfile_name(file);
678
680
681 for (j = 0; (type = secfile_lookup_str_default(file, NULL, "%s.%s%d.type",
682 sec, sub, j)); j++) {
683 char buf[MAX_LEN_NAME];
684 const char *range;
685 bool survives, present, quiet;
686 struct entry *pentry;
687 struct requirement req;
688
689 if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name",
690 sec, sub, j))) {
692
693 return NULL;
694 }
695 name = NULL;
696 switch (entry_type_get(pentry)) {
697 case ENTRY_BOOL:
698 {
699 bool val;
700
701 if (entry_bool_get(pentry, &val)) {
702 fc_snprintf(buf, sizeof(buf), "%d", val);
703 name = buf;
704 }
705 }
706 break;
707 case ENTRY_INT:
708 {
709 int val;
710
711 if (entry_int_get(pentry, &val)) {
712 fc_snprintf(buf, sizeof(buf), "%d", val);
713 name = buf;
714 }
715 }
716 break;
717 case ENTRY_STR:
719 break;
720 case ENTRY_FLOAT:
723 "\"%s\": trying to have an floating point entry as a requirement name in '%s.%s%d'.",
724 filename, sec, sub, j);
725 break;
728 break;
731 break;
732 case ENTRY_ILLEGAL:
734 break;
735 }
736 if (NULL == name) {
738 "\"%s\": error in handling requirement name for '%s.%s%d'.",
739 filename, sec, sub, j);
740 return NULL;
741 }
742
743 if (!(range = secfile_lookup_str(file, "%s.%s%d.range", sec, sub, j))) {
745
746 return NULL;
747 }
748
749 survives = FALSE;
750 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.survives",
751 sec, sub, j))
754 "\"%s\": invalid boolean value for survives for "
755 "'%s.%s%d'.", filename, sec, sub, j);
756 }
757
758 present = TRUE;
759 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.present",
760 sec, sub, j))
763 "\"%s\": invalid boolean value for present for "
764 "'%s.%s%d'.", filename, sec, sub, j);
765 }
766 quiet = FALSE;
767 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.quiet",
768 sec, sub, j))
769 && !entry_bool_get(pentry, &quiet)) {
771 "\"%s\": invalid boolean value for quiet for "
772 "'%s.%s%d'.", filename, sec, sub, j);
773 }
774
776 if (req.source.kind == universals_n_invalid()) {
778 "\"%s\" [%s] has invalid or unknown req: "
779 "\"%s\" \"%s\".",
780 filename, sec, type, name);
781
782 return NULL;
783 }
784
786 }
787
788 return &reqs_list;
789}
790
791/**********************************************************************/
795 struct section_file *file,
796 const char *sec,
797 const char *sub)
798{
799 const char *flag;
800 int j;
801 const char *filename;
802 bool success = TRUE;
803
804 filename = secfile_name(file);
805
806 for (j = 0; (flag = secfile_lookup_str_default(file, NULL, "%s.%s%d.flag",
807 sec, sub, j)); j++) {
808 struct combat_bonus *bonus = fc_malloc(sizeof(*bonus));
809 const char *type;
810
812 if (!unit_type_flag_id_is_valid(bonus->flag)) {
813 log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.",
814 filename, flag, sec, sub);
815 FC_FREE(bonus);
816 success = FALSE;
817 continue;
818 }
819 type = secfile_lookup_str(file, "%s.%s%d.type", sec, sub, j);
821 if (!combat_bonus_type_is_valid(bonus->type)) {
822 log_error("\"%s\": unknown bonus type \"%s\" in '%s.%s'.",
823 filename, type, sec, sub);
824 FC_FREE(bonus);
825 success = FALSE;
826 continue;
827 }
828 if (!secfile_lookup_int(file, &bonus->value, "%s.%s%d.value",
829 sec, sub, j)) {
830 log_error("\"%s\": failed to get value from '%s.%s%d'.",
831 filename, sec, sub, j);
832 FC_FREE(bonus);
833 success = FALSE;
834 continue;
835 }
837 "%s.%s%d.quiet",
838 sec, sub, j);
840 }
841
842 return success;
843}
844
845/**********************************************************************/
853static bool lookup_tech(struct section_file *file,
854 struct advance **result,
855 const char *prefix, const char *entry,
856 const char *filename,
857 const char *description)
858{
859 const char *sval;
860
861 sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
862 if (!sval || !strcmp(sval, "Never")) {
863 *result = A_NEVER;
864 } else {
865 *result = advance_by_rule_name(sval);
866
867 if (A_NEVER == *result) {
869 "\"%s\" %s %s: couldn't match \"%s\".",
870 filename, (description ? description : prefix), entry, sval);
871 return FALSE;
872 }
873 }
874
875 return TRUE;
876}
877
878/**********************************************************************/
885static bool lookup_unit_list(struct section_file *file, const char *prefix,
886 const char *entry,
887 struct unit_type **output,
888 const char *filename)
889{
890 const char **slist;
891 size_t nval;
892 int i;
893 bool ok = TRUE;
894
895 /* pre-fill with NULL: */
896 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
897 output[i] = NULL;
898 }
899 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
900 if (nval == 0) {
901 /* 'No vector' is considered same as empty vector */
902 if (slist != NULL) {
903 free(slist);
904 }
905 return TRUE;
906 }
907 if (nval > MAX_NUM_UNIT_LIST) {
909 "\"%s\": string vector %s.%s too long (%d, max %d)",
910 filename, prefix, entry, (int) nval, MAX_NUM_UNIT_LIST);
911 ok = FALSE;
912 } else if (nval == 1 && strcmp(slist[0], "") == 0) {
913 free(slist);
914 return TRUE;
915 }
916 if (ok) {
917 for (i = 0; i < nval; i++) {
918 const char *sval = slist[i];
920
921 if (!punittype) {
923 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
924 filename, prefix, entry, i, sval);
925 ok = FALSE;
926 break;
927 }
928 output[i] = punittype;
929 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
931 }
932 }
933 free(slist);
934
935 return ok;
936}
937
938/**********************************************************************/
945static bool lookup_tech_list(struct section_file *file, const char *prefix,
946 const char *entry, int *output,
947 const char *filename)
948{
949 const char **slist;
950 size_t nval;
951 int i;
952 bool ok = TRUE;
953
954 /* pre-fill with A_LAST: */
955 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
956 output[i] = A_LAST;
957 }
958 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
959 if (slist == NULL || nval == 0) {
960 return TRUE;
961 } else if (nval > MAX_NUM_TECH_LIST) {
963 "\"%s\": string vector %s.%s too long (%d, max %d)",
964 filename, prefix, entry, (int) nval, MAX_NUM_TECH_LIST);
965 ok = FALSE;
966 }
967
968 if (ok) {
969 if (nval == 1 && strcmp(slist[0], "") == 0) {
970 FC_FREE(slist);
971 return TRUE;
972 }
973 for (i = 0; i < nval && ok; i++) {
974 const char *sval = slist[i];
976
977 if (NULL == padvance) {
979 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
980 filename, prefix, entry, i, sval);
981 ok = FALSE;
982 }
983 if (!valid_advance(padvance)) {
985 "\"%s\" %s.%s (%d): \"%s\" is removed.",
986 filename, prefix, entry, i, sval);
987 ok = FALSE;
988 }
989
990 if (ok) {
991 output[i] = advance_number(padvance);
992 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
994 }
995 }
996 }
997 FC_FREE(slist);
998
999 return ok;
1000}
1001
1002/**********************************************************************/
1009static bool lookup_building_list(struct section_file *file,
1010 const char *prefix, const char *entry,
1011 int *output, const char *filename)
1012{
1013 const char **slist;
1014 size_t nval;
1015 int i;
1016 bool ok = TRUE;
1017
1018 /* pre-fill with B_LAST: */
1019 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1020 output[i] = B_LAST;
1021 }
1022 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
1025 "\"%s\": string vector %s.%s too long (%d, max %d)",
1026 filename, prefix, entry, (int) nval, MAX_NUM_BUILDING_LIST);
1027 ok = FALSE;
1028 } else if (nval == 0 || (nval == 1 && strcmp(slist[0], "") == 0)) {
1029 if (slist != NULL) {
1030 FC_FREE(slist);
1031 }
1032 return TRUE;
1033 }
1034 if (ok) {
1035 for (i = 0; i < nval; i++) {
1036 const char *sval = slist[i];
1037 struct impr_type *pimprove = improvement_by_rule_name(sval);
1038
1039 if (NULL == pimprove) {
1041 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1042 filename, prefix, entry, i, sval);
1043 ok = FALSE;
1044 break;
1045 }
1046 output[i] = improvement_number(pimprove);
1047 log_debug("%s.%s,%d %s %d", prefix, entry, i, sval, output[i]);
1048 }
1049 }
1050 free(slist);
1051
1052 return ok;
1053}
1054
1055/**********************************************************************/
1061static bool lookup_unit_type(struct section_file *file,
1062 const char *prefix,
1063 const char *entry,
1064 const struct unit_type **result,
1065 const char *filename,
1066 const char *description)
1067{
1068 const char *sval;
1069
1070 sval = secfile_lookup_str_default(file, "None", "%s.%s", prefix, entry);
1071
1072 if (strcmp(sval, "None") == 0) {
1073 *result = NULL;
1074 } else {
1075 *result = unit_type_by_rule_name(sval);
1076 if (*result == NULL) {
1078 "\"%s\" %s %s: couldn't match \"%s\".",
1079 filename, (description ? description : prefix), entry, sval);
1080
1081 return FALSE;
1082 }
1083 }
1084
1085 return TRUE;
1086}
1087
1088/**********************************************************************/
1092static struct government *lookup_government(struct section_file *file,
1093 const char *entry,
1094 const char *filename,
1095 struct government *fallback)
1096{
1097 const char *sval;
1098 struct government *gov;
1099
1100 sval = secfile_lookup_str_default(file, NULL, "%s", entry);
1101 if (!sval) {
1102 gov = fallback;
1103 } else {
1105 }
1106 if (!gov) {
1108 "\"%s\" %s: couldn't match \"%s\".",
1109 filename, entry, sval);
1110 }
1111 return gov;
1112}
1113
1114/**********************************************************************/
1117static char *lookup_string(struct section_file *file, const char *prefix,
1118 const char *suffix)
1119{
1120 const char *sval = secfile_lookup_str(file, "%s.%s", prefix, suffix);
1121
1122 if (NULL != sval) {
1123 char copy[strlen(sval) + 1];
1124
1125 strcpy(copy, sval);
1127 if (strlen(copy) > 0) {
1128 return fc_strdup(copy);
1129 }
1130 }
1131 return NULL;
1132}
1133
1134/**********************************************************************/
1137static struct strvec *lookup_strvec(struct section_file *file,
1138 const char *prefix, const char *suffix)
1139{
1140 size_t dim;
1141 const char **vec = secfile_lookup_str_vec(file, &dim,
1142 "%s.%s", prefix, suffix);
1143
1144 if (NULL != vec) {
1145 struct strvec *dest = strvec_new();
1146
1147 strvec_store(dest, vec, dim);
1148 free(vec);
1149 return dest;
1150 }
1151 return NULL;
1152}
1153
1154/**********************************************************************/
1157static struct extra_type *lookup_resource(const char *filename,
1158 const char *name,
1159 const char *jsection)
1160{
1161 struct extra_type *pres;
1162
1164
1165 if (pres == NULL) {
1167 "\"%s\" [%s] has unknown \"%s\".",
1168 filename, jsection, name);
1169 }
1170
1171 return pres;
1172}
1173
1174/**********************************************************************/
1178static bool lookup_terrain(struct section_file *file,
1179 const char *entry,
1180 const char *filename,
1181 struct terrain *pthis,
1182 struct terrain **result,
1183 bool null_acceptable)
1184{
1185 const int j = terrain_index(pthis);
1186 const char *jsection = &terrain_sections[j * MAX_SECTION_LABEL];
1187 const char *name = secfile_lookup_str(file, "%s.%s", jsection, entry);
1188 struct terrain *pterr;
1189
1190 if (NULL == name && !null_acceptable) {
1191 return FALSE;
1192 }
1193
1194 if (NULL == name
1195 || *name == '\0'
1196 || (0 == strcmp(name, "none"))
1197 || (0 == strcmp(name, "no"))) {
1198 *result = T_NONE;
1199
1200 return TRUE;
1201 }
1202 if (0 == strcmp(name, "yes")) {
1203 *result = pthis;
1204
1205 return TRUE;
1206 }
1207
1209 *result = pterr;
1210
1211 if (pterr == NULL) {
1213 "\"%s\" [%s] has unknown \"%s\".",
1214 secfile_name(file), jsection, name);
1215 return FALSE;
1216 }
1217
1218 return TRUE;
1219}
1220
1221/**********************************************************************/
1228static bool lookup_time(const struct section_file *secfile, int *turns,
1229 const char *sec_name, const char *property_name,
1230 const char *filename, const char *item_name,
1231 bool *ok)
1232{
1233 /* Assumes that PACKET_UNIT_INFO.activity_count in packets.def is UINT16 */
1234 const int max_turns = 65535 / ACTIVITY_FACTOR;
1235
1236 if (!secfile_lookup_int(secfile, turns, "%s.%s", sec_name, property_name)) {
1237 return FALSE;
1238 }
1239
1240 if (*turns > max_turns) {
1242 "\"%s\": \"%s\": \"%s\" value %d too large (max %d)",
1243 filename, item_name ? item_name : sec_name,
1244 property_name, *turns, max_turns);
1245 *ok = FALSE;
1246 }
1247
1248 return TRUE; /* we found _something */
1249}
1250
1251/**********************************************************************/
1255 const char *domain,
1256 struct section_file *file,
1257 const char *sec_name)
1258{
1259 const char *name = secfile_lookup_str(file, "%s.name", sec_name);
1260 const char *rule_name = secfile_lookup_str(file, "%s.rule_name", sec_name);
1261
1262 if (!name) {
1264 "\"%s\" [%s]: no \"name\" specified.",
1265 secfile_name(file), sec_name);
1266 return FALSE;
1267 }
1268
1269 names_set(pname, domain, name, rule_name);
1270
1271 return TRUE;
1272}
1273
1274/**********************************************************************/
1278 struct section_file *file,
1279 const char *secname, const char *field_prefix)
1280{
1281 enum trait tr;
1282
1283 /* FIXME: Use specenum trait names without duplicating them here.
1284 * Just needs to take care of case.
1285 * This list is also duplicated in rulesave.c:save_traits() */
1286 const char *trait_names[] = {
1287 "expansionist",
1288 "trader",
1289 "aggressive",
1290 "builder",
1291 NULL
1292 };
1293
1294 for (tr = trait_begin(); tr != trait_end() && trait_names[tr] != NULL; tr = trait_next(tr)) {
1295 out[tr].min = secfile_lookup_int_default(file, -1, "%s.%s%s_min",
1296 secname,
1298 trait_names[tr]);
1299 out[tr].max = secfile_lookup_int_default(file, -1, "%s.%s%s_max",
1300 secname,
1302 trait_names[tr]);
1303 out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
1304 secname,
1306 trait_names[tr]);
1307 }
1308
1309 fc_assert(tr == trait_end()); /* number of trait_names correct */
1310}
1311
1312/**********************************************************************/
1316static bool load_game_names(struct section_file *file,
1317 struct rscompat_info *compat)
1318{
1319 struct section_list *sec;
1320 int nval;
1321 const char *filename = secfile_name(file);
1322 bool ok = TRUE;
1323
1324 /* section: datafile */
1326 if (compat->version <= 0) {
1327 return FALSE;
1328 }
1329
1330 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1331 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1332
1334 nval = (NULL != sec ? section_list_size(sec) : 0);
1336 int num = nval; /* No "size_t" to printf */
1337
1339 "\"%s\": Too many achievement types (%d, max %d)",
1340 filename, num, MAX_ACHIEVEMENT_TYPES);
1341 ok = FALSE;
1342 } else {
1344 }
1345
1346 if (ok) {
1349
1350 if (!ruleset_load_names(&pach->name, NULL, file, sec_name)) {
1352 "\"%s\": Cannot load achievement names",
1353 filename);
1354 ok = FALSE;
1355 break;
1356 }
1358 }
1359
1361
1362 if (ok) {
1364
1365 nval = (NULL != sec ? section_list_size(sec) : 0);
1366 if (nval > MAX_GOODS_TYPES) {
1367 int num = nval; /* No "size_t" to printf */
1368
1370 "\"%s\": Too many goods types (%d, max %d)",
1371 filename, num, MAX_GOODS_TYPES);
1373 ok = FALSE;
1374 } else if (nval < 1) {
1376 "\"%s\": At least one goods type needed",
1377 filename);
1379 ok = FALSE;
1380 } else {
1382 }
1383
1384 if (ok) {
1386 const char *sec_name
1388
1389 if (!ruleset_load_names(&pgood->name, NULL, file, sec_name)) {
1391 "\"%s\": Cannot load goods names",
1392 filename);
1393 ok = FALSE;
1394 break;
1395 }
1397 }
1399 }
1400
1401 if (ok) {
1402
1404
1405 nval = (NULL != sec ? section_list_size(sec) : 0);
1406 if (nval > MAX_COUNTERS) {
1407 size_t num = nval;
1408
1410 "\"%s\": Too many counters (" SIZE_T_PRINTF ", max %d)",
1411 filename, num, MAX_COUNTERS);
1412 ok = FALSE;
1413 }
1414
1415 if (ok) {
1416 int count_idx;
1417
1419
1420 for (count_idx = 0; count_idx < nval; count_idx++) {
1421
1423 const char *sec_name
1425
1426 if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
1428 "\"%s\": Cannot load counters names",
1429 filename);
1430 ok = FALSE;
1431 break;
1432 }
1433 }
1434 }
1435
1437 }
1438
1439 return ok;
1440}
1441
1442/**********************************************************************/
1446static bool load_action_names(struct section_file *file,
1447 struct rscompat_info *compat)
1448{
1449 const char *filename = secfile_name(file);
1450 bool ok = TRUE;
1451
1452 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1453 return FALSE;
1454 }
1455
1456 (void) secfile_entry_by_path(file, "datafile.description"); /* Unused */
1457 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* Unused */
1458
1459 return ok;
1460}
1461
1462/**********************************************************************/
1466static bool load_tech_names(struct section_file *file,
1467 struct rscompat_info *compat)
1468{
1469 struct section_list *sec = NULL;
1470 /* Number of techs in the ruleset (means without A_NONE). */
1471 int num_techs = 0;
1472 int i;
1473 const char *filename = secfile_name(file);
1474 bool ok = TRUE;
1475 const char *flag;
1476
1477 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1478 return FALSE;
1479 }
1480
1481 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1482 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1483
1484 /* User tech flag names */
1485 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1486 i++) {
1487 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1488 i);
1491 "\"%s\": Duplicate tech flag name '%s'",
1492 filename, flag);
1493 ok = FALSE;
1494 break;
1495 }
1496 if (i > MAX_NUM_USER_TECH_FLAGS) {
1498 "\"%s\": Too many user tech flags!",
1499 filename);
1500 ok = FALSE;
1501 break;
1502 }
1503
1504 set_user_tech_flag_name(TECH_USER_1 + i, flag, helptxt);
1505 }
1506
1507 if (ok) {
1508 size_t nval;
1509
1510 for (; i < MAX_NUM_USER_TECH_FLAGS; i++) {
1512 }
1513
1514 /* Tech classes */
1516
1517 nval = (NULL != sec ? section_list_size(sec) : 0);
1518 if (nval > MAX_NUM_TECH_CLASSES) {
1519 int num = nval; /* No "size_t" to printf */
1520
1522 "\"%s\": Too many tech classes (%d, max %d)",
1523 filename, num, MAX_NUM_TECH_CLASSES);
1525 ok = FALSE;
1526 } else {
1528 }
1529
1530 if (ok) {
1532 const char *sec_name
1534
1535 if (!ruleset_load_names(&ptclass->name, NULL, file, sec_name)) {
1536 ruleset_error(NULL, LOG_ERROR, "\"%s\": Cannot load tech class names",
1537 filename);
1538 ok = FALSE;
1539 break;
1540 }
1542 }
1543 }
1544
1545 if (ok) {
1546 /* The techs: */
1548 if (NULL == sec || 0 == (num_techs = section_list_size(sec))) {
1550 "\"%s\": No Advances?!?", filename);
1551 ok = FALSE;
1552 } else {
1553 log_verbose("%d advances (including possibly unused)", num_techs);
1554 if (num_techs + A_FIRST > A_LAST) {
1556 "\"%s\": Too many advances (%d, max %d)",
1557 filename, num_techs, A_LAST - A_FIRST);
1558 ok = FALSE;
1559 }
1560 }
1561 }
1562
1563 if (ok) {
1564 game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */
1565
1566 i = 0;
1567 advance_iterate(adv) {
1568 if (!ruleset_load_names(&adv->name, NULL, file,
1570 ok = FALSE;
1571 break;
1572 }
1573 i++;
1575 }
1577
1578 return ok;
1579}
1580
1581/**********************************************************************/
1584static bool load_ruleset_techs(struct section_file *file,
1585 struct rscompat_info *compat)
1586{
1587 struct section_list *sec;
1588 const char **slist;
1589 int i;
1590 size_t nval;
1592 const char *filename = secfile_name(file);
1593 bool ok = TRUE;
1594
1596
1597 i = 0;
1599 const char *sec_name = section_name(section_list_get(sec, i));
1600
1601 ptclass->cost_pct = secfile_lookup_int_default(file, 100, "%s.%s",
1602 sec_name, "cost_pct");
1603
1604 i++;
1606
1608
1609 i = 0;
1610 advance_iterate(a) {
1611 const char *sec_name = section_name(section_list_get(sec, i));
1612 const char *sval;
1613 int j, ival;
1614 struct requirement_vector *research_reqs;
1615
1616 if (!lookup_tech(file, &a->require[AR_ONE], sec_name, "req1",
1617 filename, rule_name_get(&a->name))
1618 || !lookup_tech(file, &a->require[AR_TWO], sec_name, "req2",
1619 filename, rule_name_get(&a->name))
1620 || !lookup_tech(file, &a->require[AR_ROOT], sec_name, "root_req",
1621 filename, rule_name_get(&a->name))) {
1622 ok = FALSE;
1623 break;
1624 }
1625
1626 if ((A_NEVER == a->require[AR_ONE] && A_NEVER != a->require[AR_TWO])
1627 || (A_NEVER != a->require[AR_ONE] && A_NEVER == a->require[AR_TWO])) {
1629 "\"%s\" [%s] \"%s\": \"Never\" with non-\"Never\".",
1630 filename, sec_name, rule_name_get(&a->name));
1631 ok = FALSE;
1632 break;
1633 }
1634 if (a_none == a->require[AR_ONE] && a_none != a->require[AR_TWO]) {
1636 "\"%s\" [%s] \"%s\": should have \"None\" second.",
1637 filename, sec_name, rule_name_get(&a->name));
1638 ok = FALSE;
1639 break;
1640 }
1641
1642 if (game.control.num_tech_classes == 0) {
1643 a->tclass = NULL;
1644 } else {
1645 const char *classname;
1646
1647 classname = lookup_string(file, sec_name, "class");
1648 if (classname != NULL) {
1651 if (a->tclass == NULL) {
1653 "\"%s\" [%s] \"%s\": Unknown tech class \"%s\".",
1654 filename, sec_name, rule_name_get(&a->name), classname);
1655 ok = FALSE;
1656 break;
1657 }
1658 } else {
1659 a->tclass = NULL; /* Default */
1660 }
1661 }
1662
1663 research_reqs = lookup_req_list(file, sec_name, "research_reqs",
1664 rule_name_get(&a->name));
1665 if (research_reqs == NULL) {
1666 ok = FALSE;
1667 break;
1668 }
1669
1670 requirement_vector_copy(&a->research_reqs, research_reqs);
1671
1672 BV_CLR_ALL(a->flags);
1673
1674 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
1675 for (j = 0; j < nval; j++) {
1676 sval = slist[j];
1677 if (strcmp(sval, "") == 0) {
1678 continue;
1679 }
1683 "\"%s\" [%s] \"%s\": bad flag name \"%s\".",
1684 filename, sec_name, rule_name_get(&a->name), sval);
1685 ok = FALSE;
1686 break;
1687 } else {
1688 BV_SET(a->flags, ival);
1689 }
1690 }
1691 free(slist);
1692
1693 if (!ok) {
1694 break;
1695 }
1696
1697 sz_strlcpy(a->graphic_str,
1698 secfile_lookup_str_default(file, "-", "%s.graphic", sec_name));
1699 sz_strlcpy(a->graphic_alt,
1701 "%s.graphic_alt", sec_name));
1702
1703 a->helptext = lookup_strvec(file, sec_name, "helptext");
1704 a->bonus_message = lookup_string(file, sec_name, "bonus_message");
1705 a->cost = secfile_lookup_int_default(file, -1, "%s.%s",
1706 sec_name, "cost");
1707 a->num_reqs = 0;
1708
1709 i++;
1711
1712 /* Propagate a root tech up into the tech tree. If a technology
1713 * X has Y has a root tech, then any technology requiring X (in the
1714 * normal way or as a root tech) also has Y as a root tech.
1715 * Later techs may gain a whole set of root techs in this way. The one
1716 * we store in AR_ROOT is a more or less arbitrary one of these,
1717 * also signalling that the set is non-empty; after this, you'll still
1718 * have to walk the tech tree to find them all. */
1719restart:
1720
1721 if (ok) {
1722 advance_iterate(a) {
1723 if (valid_advance(a)
1724 && A_NEVER != a->require[AR_ROOT]) {
1725 bool out_of_order = FALSE;
1726
1727 /* Now find any tech depending on this technology and update its
1728 * root_req. */
1729 advance_iterate(b) {
1730 if (valid_advance(b)
1731 && A_NEVER == b->require[AR_ROOT]
1732 && (a == b->require[AR_ONE] || a == b->require[AR_TWO])) {
1733 b->require[AR_ROOT] = a->require[AR_ROOT];
1734 b->inherited_root_req = TRUE;
1735 if (b < a) {
1737 }
1738 }
1740
1741 if (out_of_order) {
1742 /* HACK: If we just changed the root_tech of a lower-numbered
1743 * technology, we need to go back so that we can propagate the
1744 * root_tech up to that technology's parents... */
1745 goto restart;
1746 }
1747 }
1749
1750 /* Now rename A_NEVER to A_NONE for consistency */
1752 if (A_NEVER == a->require[AR_ROOT]) {
1753 a->require[AR_ROOT] = a_none;
1754 }
1756
1757 /* Some more consistency checking:
1758 Non-removed techs depending on removed techs is too
1759 broken to fix by default, so die.
1760 */
1761 advance_iterate(a) {
1762 if (valid_advance(a)) {
1763 /* We check for recursive tech loops later,
1764 * in build_required_techs_helper. */
1765 if (!valid_advance(a->require[AR_ONE])) {
1767 "\"%s\" tech \"%s\": req1 leads to removed tech.",
1768 filename, advance_rule_name(a));
1769 ok = FALSE;
1770 break;
1771 }
1772 if (!valid_advance(a->require[AR_TWO])) {
1774 "\"%s\" tech \"%s\": req2 leads to removed tech.",
1775 filename, advance_rule_name(a));
1776 ok = FALSE;
1777 break;
1778 }
1779 }
1781 }
1782
1784 if (ok) {
1786 }
1787
1788 return ok;
1789}
1790
1791/**********************************************************************/
1795static bool load_unit_names(struct section_file *file,
1796 struct rscompat_info *compat)
1797{
1798 struct section_list *sec = NULL;
1799 int nval = 0;
1800 int i;
1801 const char *filename = secfile_name(file);
1802 const char *flag;
1803 bool ok = TRUE;
1804
1805 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1806 return FALSE;
1807 }
1808
1809 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1810 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1811
1812 /* User unit flag names */
1813 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1814 i++) {
1815 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1816 i);
1817
1821 "\"%s\": Duplicate unit flag name '%s'",
1822 filename, flag);
1823 ok = FALSE;
1824 break;
1825 }
1826 if (i > MAX_NUM_USER_UNIT_FLAGS) {
1828 "\"%s\": Too many user unit type flags!",
1829 filename);
1830 ok = FALSE;
1831 break;
1832 }
1833
1835 }
1836
1837 if (ok) {
1838 /* Blank the remaining unit type user flags. */
1839 for (; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
1841 }
1842 }
1843
1844 if (ok) {
1845 /* User unit class flag names */
1846 for (i = 0;
1847 (flag = secfile_lookup_str_default(file, NULL,
1848 "control.class_flags%d.name",
1849 i));
1850 i++) {
1851 const char *helptxt = secfile_lookup_str_default(file, NULL,
1852 "control.class_flags%d.helptxt", i);
1853
1857 "\"%s\": Duplicate unit class flag name '%s'",
1858 filename, flag);
1859 ok = FALSE;
1860 break;
1861 }
1864 "\"%s\": Too many user unit class flags!",
1865 filename);
1866 ok = FALSE;
1867 break;
1868 }
1869
1871 }
1872 }
1873
1874 if (ok) {
1875 /* Blank the remaining unit class user flags. */
1876 for (; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
1878 }
1879 }
1880
1881 if (ok) {
1882 /* Unit classes */
1884 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1886 "\"%s\": No unit classes?!?", filename);
1887 ok = FALSE;
1888 } else {
1889 log_verbose("%d unit classes", nval);
1890 if (nval > UCL_LAST) {
1892 "\"%s\": Too many unit classes (%d, max %d)",
1893 filename, nval, UCL_LAST);
1894 ok = FALSE;
1895 }
1896 }
1897 }
1898
1899 if (ok) {
1901
1903 const int pci = uclass_index(punitclass);
1904
1905 if (!ruleset_load_names(&punitclass->name, NULL, file,
1907 ok = FALSE;
1908 break;
1909 }
1911 }
1913 sec = NULL;
1914
1915 /* The names: */
1916 if (ok) {
1918 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1920 "\"%s\": No unit types?!?", filename);
1921 ok = FALSE;
1922 } else {
1923 log_verbose("%d unit types (including possibly unused)", nval);
1924 if (nval > U_LAST) {
1926 "\"%s\": Too many unit types (%d, max %d)",
1927 filename, nval, U_LAST);
1928 ok = FALSE;
1929 }
1930 }
1931 }
1932
1933 if (ok) {
1935
1937 const int utypei = utype_index(punittype);
1938 if (!ruleset_load_names(&punittype->name, NULL, file,
1940 ok = FALSE;
1941 break;
1942 }
1944 }
1946
1947 return ok;
1948}
1949
1950/**********************************************************************/
1953static bool load_ruleset_veteran(struct section_file *file,
1954 const char *path,
1955 struct veteran_system **vsystem, char *err,
1956 size_t err_len)
1957{
1958 const char **vlist_name;
1961 int i;
1962 bool ret = TRUE;
1963
1964 /* The pointer should be uninitialised. */
1965 if (*vsystem != NULL) {
1966 fc_snprintf(err, err_len, "Veteran system is defined?!");
1967 return FALSE;
1968 }
1969
1970 /* Load data. */
1972 "%s.veteran_names", path);
1974 "%s.veteran_power_fact", path);
1976 "%s.veteran_base_raise_chance", path);
1978 "%s.veteran_work_raise_chance",
1979 path);
1981 "%s.veteran_move_bonus", path);
1982
1983 if (count_name > MAX_VET_LEVELS) {
1984 ret = FALSE;
1985 fc_snprintf(err, err_len, "\"%s\": Too many veteran levels (section "
1986 "'%s': %lu, max %d)", secfile_name(file), path,
1987 (long unsigned)count_name, MAX_VET_LEVELS);
1988 } else if (count_name != count_power
1991 || count_name != count_move) {
1992 ret = FALSE;
1993 fc_snprintf(err, err_len, "\"%s\": Different lengths for the veteran "
1994 "settings in section '%s'", secfile_name(file),
1995 path);
1996 } else if (count_name == 0) {
1997 /* Nothing defined. */
1998 *vsystem = NULL;
1999 } else {
2000 /* Generate the veteran system. */
2002
2003#define rs_sanity_veteran(_path, _entry, _i, _condition, _action) \
2004 if (_condition) { \
2005 log_error("Invalid veteran definition '%s.%s[%d]'!", \
2006 _path, _entry, _i); \
2007 log_debug("Failed check: '%s'. Update value: '%s'.", \
2008 #_condition, #_action); \
2009 _action; \
2010 }
2011 for (i = 0; i < count_name; i++) {
2012 /* Some sanity checks. */
2013 rs_sanity_veteran(path, "veteran_power_fact", i,
2014 (vlist_power[i] < 0), vlist_power[i] = 0);
2015 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2016 (vlist_raise[i] < 0), vlist_raise[i] = 0);
2017 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2018 (vlist_wraise[i] < 0), vlist_wraise[i] = 0);
2019 rs_sanity_veteran(path, "veteran_move_bonus", i,
2020 (vlist_move[i] < 0), vlist_move[i] = 0);
2021 if (i == 0) {
2022 /* First element.*/
2023 rs_sanity_veteran(path, "veteran_power_fact", i,
2024 (vlist_power[i] != 100), vlist_power[i] = 100);
2025 } else if (i == count_name - 1) {
2026 /* Last element. */
2027 rs_sanity_veteran(path, "veteran_power_fact", i,
2028 (vlist_power[i] < vlist_power[i - 1]),
2029 vlist_power[i] = vlist_power[i - 1]);
2030 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2031 (vlist_raise[i] != 0), vlist_raise[i] = 0);
2032 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2033 (vlist_wraise[i] != 0), vlist_wraise[i] = 0);
2034 } else {
2035 /* All elements in between. */
2036 rs_sanity_veteran(path, "veteran_power_fact", i,
2037 (vlist_power[i] < vlist_power[i - 1]),
2038 vlist_power[i] = vlist_power[i - 1]);
2039 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2040 (vlist_raise[i] > 100), vlist_raise[i] = 100);
2041 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2042 (vlist_wraise[i] > 100), vlist_wraise[i] = 100);
2043 }
2044
2047 vlist_wraise[i]);
2048 }
2049#undef rs_sanity_veteran
2050 }
2051
2052 if (vlist_name) {
2054 }
2055 if (vlist_power) {
2057 }
2058 if (vlist_raise) {
2060 }
2061 if (vlist_wraise) {
2063 }
2064 if (vlist_move) {
2066 }
2067
2068 return ret;
2069}
2070
2071/**********************************************************************/
2074static bool load_ruleset_units(struct section_file *file,
2075 struct rscompat_info *compat)
2076{
2077 int j, ival;
2078 size_t nval;
2079 struct section_list *sec, *csec;
2080 const char *sval, **slist;
2081 const char *filename = secfile_name(file);
2082 char msg[MAX_LEN_MSG];
2083 bool ok = TRUE;
2084
2085 if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg,
2086 sizeof(msg))
2087 || game.veteran == NULL) {
2089 "Error loading the default veteran system: %s",
2090 msg);
2091 ok = FALSE;
2092 }
2093
2095 nval = (NULL != sec ? section_list_size(sec) : 0);
2096
2098 nval = (NULL != csec ? section_list_size(csec) : 0);
2099
2100 if (ok) {
2102 int i = uclass_index(uc);
2103 const char *sec_name = section_name(section_list_get(csec, i));
2104
2105 if (secfile_lookup_int(file, &uc->min_speed, "%s.min_speed", sec_name)) {
2106 uc->min_speed *= SINGLE_MOVE;
2107 } else {
2109 ok = FALSE;
2110 break;
2111 }
2112 if (!secfile_lookup_int(file, &uc->hp_loss_pct,
2113 "%s.hp_loss_pct", sec_name)) {
2115 ok = FALSE;
2116 break;
2117 }
2118
2119 uc->non_native_def_pct = secfile_lookup_int_default(file, 100,
2120 "%s.non_native_def_pct",
2121 sec_name);
2122
2123 BV_CLR_ALL(uc->flags);
2124 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
2125 for (j = 0; j < nval; j++) {
2126 sval = slist[j];
2127 if (strcmp(sval, "") == 0) {
2128 continue;
2129 }
2130
2133 ok = FALSE;
2137 "\"%s\" unit_class \"%s\": unit_type flag \"%s\"!",
2138 filename, uclass_rule_name(uc), sval);
2139 } else {
2141 "\"%s\" unit_class \"%s\": bad flag name \"%s\".",
2142 filename, uclass_rule_name(uc), sval);
2143 }
2144 break;
2145 } else {
2146 BV_SET(uc->flags, ival);
2147 }
2148 }
2149 free(slist);
2150
2151 uc->helptext = lookup_strvec(file, sec_name, "helptext");
2152
2153 if (!ok) {
2154 break;
2155 }
2157 }
2158
2159 if (ok) {
2160 /* Tech and Gov requirements; per unit veteran system */
2162 const int i = utype_index(u);
2163 const struct section *psection = section_list_get(sec, i);
2164 const char *sec_name = section_name(psection);
2165 struct requirement_vector *reqs;
2166
2167 reqs = lookup_req_list(file, sec_name, "reqs",
2168 utype_rule_name(u));
2169
2170 if (reqs == NULL) {
2171 ok = FALSE;
2172 break;
2173 }
2174
2175 requirement_vector_copy(&u->build_reqs, reqs);
2176
2177 if (!load_ruleset_veteran(file, sec_name, &u->veteran,
2178 msg, sizeof(msg))) {
2180 "Error loading the veteran system: %s",
2181 msg);
2182 ok = FALSE;
2183 break;
2184 }
2185
2186 if (!lookup_unit_type(file, sec_name, "obsolete_by",
2187 &u->obsoleted_by, filename,
2188 rule_name_get(&u->name))
2189 || !lookup_unit_type(file, sec_name, "convert_to",
2190 &u->converted_to, filename,
2191 rule_name_get(&u->name))) {
2192 ok = FALSE;
2193 break;
2194 }
2195 u->convert_time = 1; /* default */
2196 lookup_time(file, &u->convert_time, sec_name, "convert_time",
2197 filename, rule_name_get(&u->name), &ok);
2199 }
2200
2201 if (ok) {
2202 /* main stats: */
2204 const int i = utype_index(u);
2205 struct unit_class *pclass;
2206 const char *sec_name = section_name(section_list_get(sec, i));
2207 const char *str;
2208
2209 sval = secfile_lookup_str(file, "%s.class", sec_name);
2211 if (!pclass) {
2213 "\"%s\" unit_type \"%s\": bad class \"%s\".",
2214 filename, utype_rule_name(u), sval);
2215 ok = FALSE;
2216 break;
2217 }
2218 u->uclass = pclass;
2219
2220 sz_strlcpy(u->sound_move,
2221 secfile_lookup_str_default(file, "-", "%s.sound_move",
2222 sec_name));
2223 sz_strlcpy(u->sound_move_alt,
2224 secfile_lookup_str_default(file, "-", "%s.sound_move_alt",
2225 sec_name));
2226 sz_strlcpy(u->sound_fight,
2227 secfile_lookup_str_default(file, "-", "%s.sound_fight",
2228 sec_name));
2229 sz_strlcpy(u->sound_fight_alt,
2230 secfile_lookup_str_default(file, "-", "%s.sound_fight_alt",
2231 sec_name));
2232
2233 if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) {
2234 sz_strlcpy(u->graphic_str, str);
2235 } else {
2237 ok = FALSE;
2238 break;
2239 }
2240 sz_strlcpy(u->graphic_alt,
2241 secfile_lookup_str_default(file, "-", "%s.graphic_alt",
2242 sec_name));
2243 sz_strlcpy(u->graphic_alt2,
2244 secfile_lookup_str_default(file, "-", "%s.graphic_alt2",
2245 sec_name));
2246
2247 if (!secfile_lookup_int(file, &u->build_cost,
2248 "%s.build_cost", sec_name)
2249 || !secfile_lookup_int(file, &u->pop_cost,
2250 "%s.pop_cost", sec_name)
2251 || !secfile_lookup_int(file, &u->attack_strength,
2252 "%s.attack", sec_name)
2253 || !secfile_lookup_int(file, &u->defense_strength,
2254 "%s.defense", sec_name)
2255 || !secfile_lookup_int(file, &u->move_rate,
2256 "%s.move_rate", sec_name)
2257 || !secfile_lookup_int(file, &u->vision_radius_sq,
2258 "%s.vision_radius_sq", sec_name)
2259 || !secfile_lookup_int(file, &u->transport_capacity,
2260 "%s.transport_cap", sec_name)
2261 || !secfile_lookup_int(file, &u->firepower,
2262 "%s.firepower", sec_name)
2263 || !secfile_lookup_int(file, &u->fuel,
2264 "%s.fuel", sec_name)
2265 || !secfile_lookup_int(file, &u->happy_cost,
2266 "%s.uk_happy", sec_name)) {
2268 ok = FALSE;
2269 break;
2270 }
2271 u->hp
2274 RS_MIN_HP,
2275 RS_MAX_HP,
2276 "%s.hitpoints", sec_name);
2277
2278 u->move_rate *= SINGLE_MOVE;
2279
2280 if (u->firepower <= 0) {
2282 "\"%s\" unit_type \"%s\":"
2283 " firepower is %d,"
2284 " but must be at least 1. "
2285 " If you want no attack ability,"
2286 " set the unit's attack strength to 0.",
2287 filename, utype_rule_name(u), u->firepower);
2288 ok = FALSE;
2289 break;
2290 }
2291
2292 lookup_cbonus_list(u->bonuses, file, sec_name, "bonuses");
2293
2295 u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s",
2296 sec_name,
2299
2300 slist = secfile_lookup_str_vec(file, &nval, "%s.cargo", sec_name);
2301
2302 BV_CLR_ALL(u->cargo);
2303 for (j = 0; j < nval; j++) {
2304 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2305
2306 if (!uclass) {
2308 "\"%s\" unit_type \"%s\":"
2309 "has unknown unit class %s as cargo.",
2310 filename, utype_rule_name(u), slist[j]);
2311 ok = FALSE;
2312 break;
2313 }
2314
2315 BV_SET(u->cargo, uclass_index(uclass));
2316 }
2317 free(slist);
2318
2319 if (!ok) {
2320 break;
2321 }
2322
2323 slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec_name);
2324 BV_CLR_ALL(u->targets);
2325 for (j = 0; j < nval; j++) {
2326 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2327
2328 if (!uclass) {
2330 "\"%s\" unit_type \"%s\":"
2331 "has unknown unit class %s as target.",
2332 filename, utype_rule_name(u), slist[j]);
2333 ok = FALSE;
2334 break;
2335 }
2336
2337 BV_SET(u->targets, uclass_index(uclass));
2338 }
2339 free(slist);
2340
2341 if (!ok) {
2342 break;
2343 }
2344
2345 slist = secfile_lookup_str_vec(file, &nval, "%s.embarks", sec_name);
2346 BV_CLR_ALL(u->embarks);
2347 for (j = 0; j < nval; j++) {
2348 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2349
2350 if (!uclass) {
2352 "\"%s\" unit_type \"%s\":"
2353 "has unknown unit class %s as embarkable.",
2354 filename, utype_rule_name(u), slist[j]);
2355 ok = FALSE;
2356 break;
2357 }
2358
2359 BV_SET(u->embarks, uclass_index(uclass));
2360 }
2361 free(slist);
2362
2363 if (!ok) {
2364 break;
2365 }
2366
2367 slist = secfile_lookup_str_vec(file, &nval, "%s.disembarks", sec_name);
2368 BV_CLR_ALL(u->disembarks);
2369 for (j = 0; j < nval; j++) {
2370 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2371
2372 if (!uclass) {
2374 "\"%s\" unit_type \"%s\":"
2375 "has unknown unit class %s as disembarkable.",
2376 filename, utype_rule_name(u), slist[j]);
2377 ok = FALSE;
2378 break;
2379 }
2380
2381 BV_SET(u->disembarks, uclass_index(uclass));
2382 }
2383 free(slist);
2384
2385 if (!ok) {
2386 break;
2387 }
2388
2389 /* Set also all classes that are never unreachable as targets,
2390 * embarks, and disembarks. */
2393 BV_SET(u->targets, uclass_index(preachable));
2394 BV_SET(u->embarks, uclass_index(preachable));
2395 BV_SET(u->disembarks, uclass_index(preachable));
2396 }
2398
2399 str = secfile_lookup_str_default(file, "Main", "%s.vision_layer",
2400 sec_name);
2402 if (!vision_layer_is_valid(u->vlayer)) {
2404 "\"%s\" unit_type \"%s\":"
2405 "has unknown vision layer %s.",
2406 filename, utype_rule_name(u), str);
2407 ok = FALSE;
2408 break;
2409 }
2410
2411 u->helptext = lookup_strvec(file, sec_name, "helptext");
2412
2413 u->paratroopers_range = secfile_lookup_int_default(file,
2414 0, "%s.paratroopers_range", sec_name);
2415
2416 u->bombard_rate = secfile_lookup_int_default(file, 0,
2417 "%s.bombard_rate", sec_name);
2418 u->city_slots = secfile_lookup_int_default(file, 0,
2419 "%s.city_slots", sec_name);
2420 u->city_size = secfile_lookup_int_default(file, 1,
2421 "%s.city_size", sec_name);
2422 if ((sval
2423 = secfile_lookup_str_default(file, nullptr, "%s.specialist", sec_name))) {
2424 if (!(u->spec_type = specialist_by_rule_name(sval))) {
2425 ruleset_error(nullptr, LOG_ERROR,
2426 "\"%s\" unit_type \"%s\":"
2427 " bad specialist \"%s\".",
2428 filename, utype_rule_name(u), sval);
2429 ok = FALSE;
2430 }
2431 } else {
2432 /* Specialists must have been processed before */
2435 ok = FALSE; break);
2437 }
2438
2440 "%s.tp_defense", sec_name);
2441 u->tp_defense = transp_def_type_by_name(sval, fc_strcasecmp);
2442 if (!transp_def_type_is_valid(u->tp_defense)) {
2444 "\"%s\" unit_type \"%s\":"
2445 " bad tp_defense \"%s\".",
2446 filename, utype_rule_name(u), sval);
2447 ok = FALSE;
2448 break;
2449 }
2451 }
2452
2453 if (ok) {
2454 /* Flags */
2456 const int i = utype_index(u);
2457
2458 BV_CLR_ALL(u->flags);
2460
2461 slist = secfile_lookup_str_vec(file, &nval, "%s.flags",
2463 for (j = 0; j < nval; j++) {
2464 sval = slist[j];
2465 if (0 == strcmp(sval, "")) {
2466 continue;
2467 }
2470 ok = FALSE;
2474 "\"%s\" unit_type \"%s\": unit_class flag!",
2475 filename, utype_rule_name(u));
2476 } else {
2478 "\"%s\" unit_type \"%s\": bad flag name \"%s\".",
2479 filename, utype_rule_name(u), sval);
2480 }
2481 break;
2482 } else {
2483 BV_SET(u->flags, ival);
2484 }
2485 }
2486 free(slist);
2487
2488 if (!ok) {
2489 break;
2490 }
2492 }
2493
2494 /* Roles */
2495 if (ok) {
2497 const int i = utype_index(u);
2498
2499 BV_CLR_ALL(u->roles);
2500
2501 slist = secfile_lookup_str_vec(file, &nval, "%s.roles",
2503 for (j = 0; j < nval; j++) {
2504 sval = slist[j];
2505 if (strcmp(sval, "") == 0) {
2506 continue;
2507 }
2511 "\"%s\" unit_type \"%s\": bad role name \"%s\".",
2512 filename, utype_rule_name(u), sval);
2513 ok = FALSE;
2514 break;
2515 } else {
2516 BV_SET(u->roles, ival - L_FIRST);
2517 }
2519 }
2520 free(slist);
2522 }
2523
2524 if (ok) {
2525 /* Some more consistency checking: */
2528 if (!valid_advance(padv)) {
2530 "\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
2531 filename, utype_rule_name(u),
2533 ok = FALSE;
2534 break;
2535 }
2537
2538 if (!ok) {
2539 break;
2540 }
2542 }
2543
2546
2547 if (ok) {
2549 }
2550
2551 return ok;
2552}
2553
2554/**********************************************************************/
2558static bool load_building_names(struct section_file *file,
2559 struct rscompat_info *compat)
2560{
2561 struct section_list *sec;
2562 int i, nval = 0;
2563 const char *filename = secfile_name(file);
2564 bool ok = TRUE;
2565 const char *flag;
2566
2567 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2568 return FALSE;
2569 }
2570
2571 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2572 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2573
2574 /* The names: */
2576 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2578 "\"%s\": No improvements?!?", filename);
2579 ok = FALSE;
2580 } else {
2581 log_verbose("%d improvement types (including possibly unused)", nval);
2582 if (nval > B_LAST) {
2584 "\"%s\": Too many improvements (%d, max %d)",
2585 filename, nval, B_LAST);
2586 ok = FALSE;
2587 }
2588 }
2589
2590 if (ok) {
2592
2593 for (i = 0; i < nval; i++) {
2594 struct impr_type *b = improvement_by_number(i);
2595
2596 if (!ruleset_load_names(&b->name, NULL, file, section_name(section_list_get(sec, i)))) {
2597 ok = FALSE;
2598 break;
2599 }
2600 }
2601 }
2602
2603 /* User building flag names */
2604 for (i = 0;
2605 (flag = secfile_lookup_str_default(file, NULL,
2606 "control.building_flags%d.name",
2607 i));
2608 i++) {
2609 const char *helptxt = secfile_lookup_str_default(file, NULL,
2610 "control.building_flags%d.helptxt", i);
2611
2613 != impr_flag_id_invalid()) {
2615 "\"%s\": Duplicate building flag name '%s'",
2616 filename, flag);
2617 ok = FALSE;
2618 break;
2619 }
2622 "\"%s\": Too many user building flags!",
2623 filename);
2624 ok = FALSE;
2625 break;
2626 }
2627
2628 set_user_impr_flag_name(IF_USER_FLAG_1 + i, flag, helptxt);
2629 }
2630
2632
2633 return ok;
2634}
2635
2636/**********************************************************************/
2639static bool load_ruleset_buildings(struct section_file *file,
2640 struct rscompat_info *compat)
2641{
2642 struct section_list *sec;
2643 const char *item;
2644 int i, nval;
2645 const char *filename = secfile_name(file);
2646 bool ok = TRUE;
2647
2649 nval = (NULL != sec ? section_list_size(sec) : 0);
2650
2651 for (i = 0; i < nval && ok; i++) {
2652 struct impr_type *b = improvement_by_number(i);
2653 const char *sec_name = section_name(section_list_get(sec, i));
2654 struct requirement_vector *reqs
2655 = lookup_req_list(file, sec_name, "reqs",
2657
2658 if (reqs == NULL) {
2659 ok = FALSE;
2660 break;
2661 } else {
2662 const char *sval, **slist;
2663 int j, ival;
2664 size_t nflags;
2665
2666 item = secfile_lookup_str(file, "%s.genus", sec_name);
2668 if (!impr_genus_id_is_valid(b->genus)) {
2670 "\"%s\" improvement \"%s\": couldn't match "
2671 "genus \"%s\".", filename,
2673 ok = FALSE;
2674 break;
2675 }
2676
2677 slist = secfile_lookup_str_vec(file, &nflags, "%s.flags", sec_name);
2678 BV_CLR_ALL(b->flags);
2679
2680 for (j = 0; j < nflags; j++) {
2681 sval = slist[j];
2682 if (strcmp(sval, "") == 0) {
2683 continue;
2684 }
2688 "\"%s\" improvement \"%s\": bad flag name \"%s\".",
2689 filename, improvement_rule_name(b), sval);
2690 ok = FALSE;
2691 break;
2692 } else {
2693 BV_SET(b->flags, ival);
2694 }
2695 }
2696 free(slist);
2697
2698 if (!ok) {
2699 break;
2700 }
2701
2703
2704 {
2705 struct requirement_vector *obs_reqs
2706 = lookup_req_list(file, sec_name, "obsolete_by",
2708
2709 if (obs_reqs == NULL) {
2710 ok = FALSE;
2711 break;
2712 } else {
2713 requirement_vector_copy(&b->obsolete_by, obs_reqs);
2714 }
2715 }
2716
2717 if (!secfile_lookup_int(file, &b->build_cost,
2718 "%s.build_cost", sec_name)
2719 || !secfile_lookup_int(file, &b->upkeep,
2720 "%s.upkeep", sec_name)
2721 || !secfile_lookup_int(file, &b->sabotage,
2722 "%s.sabotage", sec_name)) {
2724 ok = FALSE;
2725 break;
2726 }
2727
2730 "%s.graphic", sec_name));
2733 "%s.graphic_alt", sec_name));
2736 "%s.graphic_alt2", sec_name));
2737
2740 "%s.sound", sec_name));
2743 "%s.sound_alt", sec_name));
2746 "%s.sound_alt2", sec_name));
2747 b->helptext = lookup_strvec(file, sec_name, "helptext");
2748 }
2749 }
2750
2752 if (ok) {
2754 }
2755
2756 return ok;
2757}
2758
2759/**********************************************************************/
2763static bool load_terrain_names(struct section_file *file,
2764 struct rscompat_info *compat)
2765{
2766 int nval = 0;
2767 struct section_list *sec = NULL;
2768 const char *flag;
2769 int i;
2770 const char *filename = secfile_name(file);
2771 bool ok = TRUE;
2772
2773 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2774 return FALSE;
2775 }
2776
2777 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2778 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2779
2780 /* User terrain flag names */
2781 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
2782 i++) {
2783 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
2784 i);
2785
2789 "\"%s\": Duplicate terrain flag name '%s'",
2790 filename, flag);
2791 ok = FALSE;
2792 break;
2793 }
2794 if (i > MAX_NUM_USER_TER_FLAGS) {
2796 "\"%s\": Too many user terrain flags!",
2797 filename);
2798 ok = FALSE;
2799 break;
2800 }
2801
2802 set_user_terrain_flag_name(TER_USER_1 + i, flag, helptxt);
2803 }
2804
2805 if (ok) {
2806 /* Blank the remaining terrain user flag slots. */
2807 for (; i < MAX_NUM_USER_TER_FLAGS; i++) {
2809 }
2810 }
2811
2812 /* User extra flag names */
2813 for (i = 0;
2814 (flag = secfile_lookup_str_default(file, NULL,
2815 "control.extra_flags%d.name",
2816 i));
2817 i++) {
2818 const char *helptxt = secfile_lookup_str_default(file, NULL,
2819 "control.extra_flags%d.helptxt", i);
2820
2822 != extra_flag_id_invalid()) {
2824 "\"%s\": Duplicate extra flag name '%s'",
2825 filename, flag);
2826 ok = FALSE;
2827 break;
2828 }
2831 "\"%s\": Too many user extra flags!",
2832 filename);
2833 ok = FALSE;
2834 break;
2835 }
2836
2837 set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt);
2838 }
2839
2840 if (ok) {
2841 /* Blank the remaining extra user flag slots. */
2842 for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
2844 }
2845
2846 /* Terrain names */
2847
2849 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2851 "\"%s\": ruleset doesn't have any terrains.",
2852 filename);
2853 ok = FALSE;
2854 } else {
2855 if (nval > MAX_NUM_TERRAINS) {
2857 "\"%s\": Too many terrains (%d, max %d)",
2858 filename, nval, MAX_NUM_TERRAINS);
2859 ok = FALSE;
2860 }
2861 }
2862 }
2863
2864 if (ok) {
2866
2867 /* Avoid re-reading files */
2868 if (terrain_sections) {
2870 }
2872
2873 terrain_type_iterate(pterrain) {
2874 const int terri = terrain_index(pterrain);
2875 const char *sec_name = section_name(section_list_get(sec, terri));
2876
2877 if (!ruleset_load_names(&pterrain->name, NULL, file, sec_name)) {
2878 ok = FALSE;
2879 break;
2880 }
2881
2884 }
2885
2887 sec = NULL;
2888
2889 /* Extra names */
2890
2891 if (ok) {
2893 nval = (NULL != sec ? section_list_size(sec) : 0);
2894 if (nval > MAX_EXTRA_TYPES) {
2896 "\"%s\": Too many extra types (%d, max %d)",
2897 filename, nval, MAX_EXTRA_TYPES);
2898 ok = FALSE;
2899 }
2900 }
2901
2902 if (ok) {
2903 int idx;
2904
2906
2907 if (extra_sections) {
2909 }
2911
2912 if (ok) {
2913 for (idx = 0; idx < nval; idx++) {
2914 const char *sec_name = section_name(section_list_get(sec, idx));
2915 struct extra_type *pextra = extra_by_number(idx);
2916
2917 if (!ruleset_load_names(&pextra->name, NULL, file, sec_name)) {
2918 ok = FALSE;
2919 break;
2920 }
2922 }
2923 }
2924 }
2925
2927 sec = NULL;
2928
2929 /* Base names */
2930
2931 if (ok) {
2933 nval = (NULL != sec ? section_list_size(sec) : 0);
2934 if (nval > MAX_EXTRA_TYPES) {
2936 "\"%s\": Too many base types (%d, max %d)",
2937 filename, nval, MAX_EXTRA_TYPES);
2938 ok = FALSE;
2939 }
2940
2942 }
2943
2944 if (ok) {
2945 int idx;
2946
2947 if (base_sections) {
2949 }
2951
2952 /* Cannot use base_type_iterate() before bases are added to
2953 * EC_BASE caused_by list. Have to get them by extra_type_by_rule_name() */
2954 for (idx = 0; idx < nval; idx++) {
2955 const char *sec_name = section_name(section_list_get(sec, idx));
2956 const char *base_name = secfile_lookup_str(file, "%s.extra", sec_name);
2957
2958 if (base_name != NULL) {
2960
2961 if (pextra != NULL) {
2962 base_type_init(pextra, idx);
2964 } else {
2966 "No extra definition matching base definition \"%s\"",
2967 base_name);
2968 ok = FALSE;
2969 }
2970 } else {
2972 "Base section \"%s\" does not associate base with any extra",
2973 sec_name);
2974 ok = FALSE;
2975 }
2976 }
2977 }
2978
2980 sec = NULL;
2981
2982 /* Road names */
2983
2984 if (ok) {
2986 nval = (NULL != sec ? section_list_size(sec) : 0);
2987 if (nval > MAX_EXTRA_TYPES) {
2989 "\"%s\": Too many road types (%d, max %d)",
2990 filename, nval, MAX_EXTRA_TYPES);
2991 ok = FALSE;
2992 }
2993
2995 }
2996
2997 if (ok) {
2998 int idx;
2999
3000 if (road_sections) {
3002 }
3004
3005 /* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to
3006 * EC_ROAD caused_by list. Have to get them by extra_type_by_rule_name() */
3007 for (idx = 0; idx < nval; idx++) {
3008 const char *sec_name = section_name(section_list_get(sec, idx));
3009 const char *road_name = secfile_lookup_str(file, "%s.extra", sec_name);
3010
3011 if (road_name != NULL) {
3013
3014 if (pextra != NULL) {
3015 road_type_init(pextra, idx);
3017 } else {
3019 "No extra definition matching road definition \"%s\"",
3020 road_name);
3021 ok = FALSE;
3022 }
3023 } else {
3025 "Road section \"%s\" does not associate road with any extra",
3026 sec_name);
3027 ok = FALSE;
3028 }
3029 }
3030 }
3031
3033 sec = NULL;
3034
3035 /* Resource names */
3036 if (ok) {
3038 nval = (NULL != sec ? section_list_size(sec) : 0);
3039 if (nval > MAX_EXTRA_TYPES) {
3041 "\"%s\": Too many resource types (%d, max %d)",
3042 filename, nval, MAX_EXTRA_TYPES);
3043 ok = FALSE;
3044 }
3045
3047 }
3048
3049 if (ok) {
3050 int idx;
3051
3052 if (resource_sections) {
3054 }
3056
3057 /* Cannot use resource_type_iterate() before resource are added to
3058 * EC_RESOURCE caused_by list. Have to get them by extra_type_by_rule_name() */
3059 for (idx = 0; idx < nval; idx++) {
3060 const char *sec_name = section_name(section_list_get(sec, idx));
3061 const char *resource_name;
3062 struct extra_type *pextra = NULL;
3063
3065
3066 if (resource_name != NULL) {
3068
3069 if (pextra != NULL) {
3070 resource_type_init(pextra);
3072 } else {
3074 "No extra definition matching resource definition \"%s\"",
3076 ok = FALSE;
3077 }
3078 } else {
3080 "Resource section %s does not list extra this resource belongs to.",
3081 sec_name);
3082 ok = FALSE;
3083 }
3084 }
3085 }
3086
3088 sec = nullptr;
3089
3090 /* Tiledef names */
3091
3092 if (ok) {
3094 nval = (NULL != sec ? section_list_size(sec) : 0);
3095 if (nval > MAX_TILEDEFS) {
3097 "\"%s\": Too many tiledefs (%d, max %d)",
3098 filename, nval, MAX_TILEDEFS);
3099 ok = FALSE;
3100 }
3101 }
3102
3103 if (ok) {
3104 int idx;
3105
3107
3108 if (tiledef_sections) {
3110 }
3112
3113 if (ok) {
3114 for (idx = 0; idx < nval; idx++) {
3115 const char *sec_name = section_name(section_list_get(sec, idx));
3116 struct tiledef *td = tiledef_by_number(idx);
3117
3118 if (!ruleset_load_names(&td->name, NULL, file, sec_name)) {
3119 ok = FALSE;
3120 break;
3121 }
3123 }
3124 }
3125 }
3126
3128
3129 return ok;
3130}
3131
3132/**********************************************************************/
3135static bool load_ruleset_terrain(struct section_file *file,
3136 struct rscompat_info *compat)
3137{
3138 size_t nval, nval2;
3139 int j;
3140 bool compat_road = FALSE;
3141 bool compat_rail = FALSE;
3142 bool compat_river = FALSE;
3143 const char **res;
3144 const char *filename = secfile_name(file);
3145 const char *text;
3146 int *res_freq;
3147 bool ok = TRUE;
3148
3149 /* parameters */
3150
3151 terrain_control.ocean_reclaim_requirement_pct
3152 = secfile_lookup_int_default(file, 101,
3153 "parameters.ocean_reclaim_requirement");
3154 terrain_control.land_channel_requirement_pct
3155 = secfile_lookup_int_default(file, 101,
3156 "parameters.land_channel_requirement");
3157 terrain_control.terrain_thaw_requirement_pct
3158 = secfile_lookup_int_default(file, 101,
3159 "parameters.thaw_requirement");
3160 terrain_control.terrain_freeze_requirement_pct
3161 = secfile_lookup_int_default(file, 101,
3162 "parameters.freeze_requirement");
3163 terrain_control.lake_max_size
3165 "parameters.lake_max_size");
3166 terrain_control.min_start_native_area
3168 "parameters.min_start_native_area");
3169 terrain_control.move_fragments
3171 "parameters.move_fragments");
3172 if (terrain_control.move_fragments < 1) {
3174 "\"%s\": move_fragments must be at least 1",
3175 filename);
3176 ok = FALSE;
3177 }
3179 terrain_control.igter_cost
3181 "parameters.igter_cost");
3182 if (terrain_control.igter_cost < 1) {
3184 "\"%s\": igter_cost must be at least 1",
3185 filename);
3186 ok = FALSE;
3187 }
3188 terrain_control.infrapoints = FALSE; /* This will be updated if we find
3189 * an placeable extra. */
3190
3191 terrain_control.pythagorean_diagonal
3193 "parameters.pythagorean_diagonal");
3194
3197 "parameters.ocean_resources");
3198
3199 text = secfile_lookup_str_default(file,
3200 N_("?gui_type:Build Type A Base"),
3201 "extraui.ui_name_base_fortress");
3202 sz_strlcpy(terrain_control.gui_type_base0, text);
3203
3204 text = secfile_lookup_str_default(file,
3205 N_("?gui_type:Build Type B Base"),
3206 "extraui.ui_name_base_airbase");
3207 sz_strlcpy(terrain_control.gui_type_base1, text);
3208
3209 if (ok) {
3210 /* Terrain details */
3211
3212 terrain_type_iterate(pterrain) {
3213 const char **slist;
3214 const int i = terrain_index(pterrain);
3215 const char *tsection = &terrain_sections[i * MAX_SECTION_LABEL];
3216 const char *cstr;
3217 const char *ename;
3218
3219 sz_strlcpy(pterrain->graphic_str,
3220 secfile_lookup_str(file, "%s.graphic", tsection));
3221 sz_strlcpy(pterrain->graphic_alt,
3223 "%s.graphic_alt", tsection));
3224 sz_strlcpy(pterrain->graphic_alt2,
3226 "%s.graphic_alt2", tsection));
3227
3228 pterrain->identifier
3229 = secfile_lookup_str(file, "%s.identifier", tsection)[0];
3230 if ('\0' == pterrain->identifier) {
3232 "\"%s\" [%s] identifier missing value.",
3233 filename, tsection);
3234 ok = FALSE;
3235 break;
3236 }
3237 if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) {
3239 "\"%s\" [%s] cannot use '%c' as an identifier;"
3240 " it is reserved for unknown terrain.",
3241 filename, tsection, pterrain->identifier);
3242 ok = FALSE;
3243 break;
3244 }
3245 for (j = T_FIRST; j < i; j++) {
3246 if (pterrain->identifier == terrain_by_number(j)->identifier) {
3248 "\"%s\" [%s] has the same identifier as [%s].",
3249 filename, tsection,
3251 ok = FALSE;
3252 break;
3253 }
3254 }
3255
3256 if (!ok) {
3257 break;
3258 }
3259
3260 cstr = secfile_lookup_str(file, "%s.class", tsection);
3261 pterrain->tclass = terrain_class_by_name(cstr, fc_strcasecmp);
3262 if (!terrain_class_is_valid(pterrain->tclass)) {
3264 "\"%s\": [%s] unknown class \"%s\"",
3265 filename, tsection, cstr);
3266 ok = FALSE;
3267 break;
3268 }
3269
3270 if (!secfile_lookup_int(file, &pterrain->movement_cost,
3271 "%s.movement_cost", tsection)
3272 || !secfile_lookup_int(file, &pterrain->defense_bonus,
3273 "%s.defense_bonus", tsection)) {
3275 ok = FALSE;
3276 break;
3277 }
3278
3280 pterrain->output[o]
3281 = secfile_lookup_int_default(file, 0, "%s.%s", tsection,
3284
3285 res = secfile_lookup_str_vec(file, &nval, "%s.resources", tsection);
3287 "%s.resource_freq", tsection);
3288 if (nval2 > 0 && nval2 != nval) {
3290 "\"%s\": [%s] Different lengths for resources "
3291 "and resource frequencies",
3292 filename, tsection);
3293 ok = FALSE;
3294 }
3295 pterrain->resources = fc_calloc(nval + 1, sizeof(*pterrain->resources));
3296 pterrain->resource_freq = fc_calloc(nval + 1,
3297 sizeof(*pterrain->resource_freq));
3298 for (j = 0; j < nval; j++) {
3299 pterrain->resources[j] = lookup_resource(filename, res[j], tsection);
3300 if (pterrain->resources[j] == NULL) {
3301 ok = FALSE;
3302 break;
3303 }
3304 pterrain->resource_freq[j] = j < nval2
3305 ? res_freq[j]
3307 if (pterrain->resource_freq[j] < RESOURCE_FREQUENCY_MINIMUM
3308 || pterrain->resource_freq[j] > RESOURCE_FREQUENCY_MAXIMUM) {
3310 "\"%s\": [%s] Resource frequency '%d' "
3311 "outside allowed range",
3312 filename, tsection,
3313 pterrain->resource_freq[j]);
3314 ok = FALSE;
3315 break;
3316 }
3317 }
3318 pterrain->resources[nval] = NULL;
3319 /* Terminating zero technically not necessary */
3320 pterrain->resource_freq[nval] = 0;
3321 free(res);
3322 res = NULL;
3323 free(res_freq);
3324 res_freq = NULL;
3325
3326 if (!ok) {
3327 break;
3328 }
3329
3331 pterrain->road_output_incr_pct[o]
3332 = secfile_lookup_int_default(file, 0, "%s.road_%s_incr_pct",
3335
3336 if (!lookup_time(file, &pterrain->base_time, tsection, "base_time",
3337 filename, NULL, &ok)
3338 || !lookup_time(file, &pterrain->road_time, tsection, "road_time",
3339 filename, NULL, &ok)) {
3341 ok = FALSE;
3342 break;
3343 }
3344
3345 if (!lookup_terrain(file, "cultivate_result", filename, pterrain,
3346 &pterrain->cultivate_result, FALSE)) {
3347 ruleset_error(NULL, LOG_ERROR, "%s: No cultivate_result", tsection);
3348 ok = FALSE;
3349 break;
3350 }
3351 if (pterrain->cultivate_result == pterrain) {
3353 "%s: Cultivating result in terrain itself.",
3354 tsection);
3355 ok = FALSE;
3356 break;
3357 }
3358 if (!secfile_lookup_int(file, &pterrain->irrigation_food_incr,
3359 "%s.irrigation_food_incr", tsection)
3360 || !lookup_time(file, &pterrain->irrigation_time,
3361 tsection, "irrigation_time", filename, NULL, &ok)) {
3363 ok = FALSE;
3364 break;
3365 }
3366
3367 if (!lookup_terrain(file, "plant_result", filename, pterrain,
3368 &pterrain->plant_result, FALSE)) {
3369 ruleset_error(NULL, LOG_ERROR, "%s: No plant_result", tsection);
3370 ok = FALSE;
3371 break;
3372 }
3373 if (pterrain->plant_result == pterrain) {
3375 "%s: Planting result in terrain itself.",
3376 tsection);
3377 ok = FALSE;
3378 break;
3379 }
3380 if (!secfile_lookup_int(file, &pterrain->mining_shield_incr,
3381 "%s.mining_shield_incr", tsection)
3382 || !lookup_time(file, &pterrain->mining_time,
3383 tsection, "mining_time", filename, NULL, &ok)) {
3385 ok = FALSE;
3386 break;
3387 }
3388
3389 if (!lookup_time(file, &pterrain->cultivate_time,
3390 tsection, "cultivate_time", filename, NULL, &ok)) {
3392 "%s: Missing cultivate_time", tsection);
3393 ok = FALSE;
3394 break;
3395 }
3396 if ((pterrain->cultivate_result != NULL
3397 && pterrain->cultivate_time <= 0)
3398 || (pterrain->cultivate_result == NULL
3399 && pterrain->cultivate_time > 0)) {
3401 "%s: cultivate_result and cultivate_time disagree "
3402 "whether cultivating is enabled", tsection);
3403 ok = FALSE;
3404 break;
3405 }
3406
3407 if (!lookup_time(file, &pterrain->plant_time,
3408 tsection, "plant_time", filename, NULL, &ok)) {
3410 "%s: Missing plant_time", tsection);
3411 ok = FALSE;
3412 break;
3413 }
3414 if ((pterrain->plant_result != NULL
3415 && pterrain->plant_time <= 0)
3416 || (pterrain->plant_result == NULL
3417 && pterrain->plant_time > 0)) {
3419 "%s: plant_result and plant_time disagree "
3420 "whether planting is enabled", tsection);
3421 ok = FALSE;
3422 break;
3423 }
3424
3425 res = secfile_lookup_str_vec(file, &nval, "%s.animals", tsection);
3426 pterrain->num_animals = nval;
3427 if (pterrain->num_animals == 0) {
3428 pterrain->animals = nullptr;
3429 } else {
3430 pterrain->animals = fc_calloc(pterrain->num_animals,
3431 sizeof(*pterrain->animals));
3432 for (j = 0; j < pterrain->num_animals; j++) {
3433 pterrain->animals[j] = unit_type_by_rule_name(res[j]);
3434 if (pterrain->animals[j] == NULL) {
3435 ok = FALSE;
3436 break;
3437 }
3438 }
3439 }
3440 free(res);
3441 res = NULL;
3442 if (!ok) {
3443 break;
3444 }
3445
3446 if (!lookup_terrain(file, "transform_result", filename, pterrain,
3447 &pterrain->transform_result, TRUE)) {
3448 ok = FALSE;
3449 break;
3450 }
3451 if (!lookup_time(file, &pterrain->transform_time,
3452 tsection, "transform_time", filename, NULL, &ok)) {
3454 ok = FALSE;
3455 break;
3456 }
3457 if ((pterrain->transform_result != NULL
3458 && pterrain->transform_time <= 0)
3459 || (pterrain->transform_result == NULL
3460 && pterrain->transform_time > 0)) {
3462 "%s: transform_result and transform_time disagree "
3463 "whether transforming is enabled", tsection);
3464 ok = FALSE;
3465 break;
3466 }
3467
3468 pterrain->placing_time = 1; /* Default */
3469 lookup_time(file, &pterrain->placing_time,
3470 tsection, "placing_time", filename, NULL, &ok);
3471
3472 pterrain->pillage_time = 1; /* Default */
3473 lookup_time(file, &pterrain->pillage_time,
3474 tsection, "pillage_time", filename, NULL, &ok);
3475
3476 if (!lookup_terrain(file, "warmer_wetter_result", filename, pterrain,
3477 &pterrain->warmer_wetter_result, TRUE)
3478 || !lookup_terrain(file, "warmer_drier_result", filename, pterrain,
3479 &pterrain->warmer_drier_result, TRUE)
3480 || !lookup_terrain(file, "cooler_wetter_result", filename, pterrain,
3481 &pterrain->cooler_wetter_result, TRUE)
3482 || !lookup_terrain(file, "cooler_drier_result", filename, pterrain,
3483 &pterrain->cooler_drier_result, TRUE)) {
3484 ok = FALSE;
3485 break;
3486 }
3487
3488 /* Set default removal times */
3489 extra_type_iterate(pextra) {
3490 pterrain->extra_removal_times[extra_index(pextra)] = 0;
3492
3493 for (j = 0; (ename = secfile_lookup_str_default(file, NULL,
3494 "%s.extra_settings%d.extra",
3495 tsection, j)); j++) {
3496 const struct extra_type *pextra = extra_type_by_rule_name(ename);
3497
3498 if (pextra != NULL) {
3499 char time_sections[512];
3500
3502 "%s.extra_settings%d", tsection, j);
3503
3504 lookup_time(file, &pterrain->extra_removal_times[extra_index(pextra)],
3505 time_sections, "removal_time", filename, NULL, &ok);
3506 } else {
3508 "\"%s\" [%s] has settings for unknown extra \"%s\".",
3509 filename, tsection, ename);
3510 ok = FALSE;
3511 break;
3512 }
3513 }
3514
3515 if (ok) {
3516 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", tsection);
3517 BV_CLR_ALL(pterrain->flags);
3518 for (j = 0; j < nval; j++) {
3519 const char *sval = slist[j];
3520 enum terrain_flag_id flag
3522
3523 if (!terrain_flag_id_is_valid(flag)) {
3525 "\"%s\" [%s] has unknown flag \"%s\".",
3526 filename, tsection, sval);
3527 ok = FALSE;
3528 break;
3529 } else {
3530 BV_SET(pterrain->flags, flag);
3531 }
3532 }
3533
3534 free(slist);
3535 }
3536
3537 if (!ok) {
3538 break;
3539 }
3540
3541 {
3543
3547 pterrain->property[mtp]
3548 = secfile_lookup_int_default(file, 0, "%s.property_%s", tsection,
3550 }
3551 }
3552
3553 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", tsection);
3554 BV_CLR_ALL(pterrain->native_to);
3555 for (j = 0; j < nval; j++) {
3556 struct unit_class *class = unit_class_by_rule_name(slist[j]);
3557
3558 if (!class) {
3560 "\"%s\" [%s] is native to unknown unit class \"%s\".",
3561 filename, tsection, slist[j]);
3562 ok = FALSE;
3563 break;
3564 } else {
3565 BV_SET(pterrain->native_to, uclass_index(class));
3566 }
3567 }
3568 free(slist);
3569
3570 if (!ok) {
3571 break;
3572 }
3573
3574 /* Get terrain color */
3575 {
3576 fc_assert_ret_val(pterrain->rgb == NULL, FALSE);
3577
3578 if (!rgbcolor_load(file, &pterrain->rgb, "%s.color", tsection)) {
3580 "Missing terrain color definition: %s",
3581 secfile_error());
3582 ok = FALSE;
3583 break;
3584 }
3585 }
3586
3587 pterrain->helptext = lookup_strvec(file, tsection, "helptext");
3589 }
3590
3591 if (ok) {
3592 /* Extra details */
3593 extra_type_iterate(pextra) {
3594 BV_CLR_ALL(pextra->conflicts);
3596
3597 extra_type_iterate(pextra) {
3598 int eidx = extra_index(pextra);
3599 const char *section = &extra_sections[eidx * MAX_SECTION_LABEL];
3600 const char **slist;
3601 struct requirement_vector *reqs;
3602 const char *catname;
3603 int cj;
3604 enum extra_cause cause;
3606 const char *eus_name;
3607 const char *vis_req_name;
3608 const struct advance *vis_req;
3609
3610 catname = secfile_lookup_str(file, "%s.category", section);
3611 if (catname == NULL) {
3613 "\"%s\" extra \"%s\" has no category.",
3614 filename, extra_rule_name(pextra));
3615 ok = FALSE;
3616 break;
3617 }
3618 pextra->category = extra_category_by_name(catname, fc_strcasecmp);
3619 if (!extra_category_is_valid(pextra->category)) {
3621 "\"%s\" extra \"%s\" has invalid category \"%s\".",
3622 filename, extra_rule_name(pextra), catname);
3623 ok = FALSE;
3624 break;
3625 }
3626
3627 slist = secfile_lookup_str_vec(file, &nval, "%s.causes", section);
3628 pextra->causes = 0;
3629 for (cj = 0; cj < nval; cj++) {
3630 const char *sval = slist[cj];
3632
3633 if (!extra_cause_is_valid(cause)) {
3635 "\"%s\" extra \"%s\": unknown cause \"%s\".",
3636 filename, extra_rule_name(pextra), sval);
3637 ok = FALSE;
3638 break;
3639 } else {
3640 pextra->causes |= (1 << cause);
3641 extra_to_caused_by_list(pextra, cause);
3642 }
3643 }
3644
3645 if (pextra->causes == 0) {
3646 /* Extras that do not have any causes added to EC_NONE list */
3648 }
3649
3650 if (!is_extra_caused_by(pextra, EC_BASE)
3651 && !is_extra_caused_by(pextra, EC_ROAD)
3652 && !is_extra_caused_by(pextra, EC_RESOURCE)) {
3653 /* Not a base, road, nor resource, so special */
3654 pextra->data.special_idx = extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL));
3656 }
3657
3658 free(slist);
3659
3660 slist = secfile_lookup_str_vec(file, &nval, "%s.rmcauses", section);
3661 pextra->rmcauses = 0;
3662 for (j = 0; j < nval; j++) {
3663 const char *sval = slist[j];
3664
3666
3669 "\"%s\" extra \"%s\": unknown rmcause \"%s\".",
3670 filename, extra_rule_name(pextra), sval);
3671 ok = FALSE;
3672 break;
3673 } else {
3674 pextra->rmcauses |= (1 << rmcause);
3676 }
3677 }
3678
3679 free(slist);
3680
3681 sz_strlcpy(pextra->activity_gfx,
3683 "%s.activity_gfx", section));
3684 sz_strlcpy(pextra->act_gfx_alt,
3686 "%s.act_gfx_alt", section));
3687 sz_strlcpy(pextra->act_gfx_alt2,
3689 "%s.act_gfx_alt2", section));
3690 sz_strlcpy(pextra->rmact_gfx,
3692 "%s.rmact_gfx", section));
3693 sz_strlcpy(pextra->rmact_gfx_alt,
3695 "%s.rmact_gfx_alt", section));
3696 sz_strlcpy(pextra->rmact_gfx_alt2,
3698 "%s.rmact_gfx_alt2", section));
3699 sz_strlcpy(pextra->graphic_str,
3700 secfile_lookup_str_default(file, "-", "%s.graphic", section));
3701 sz_strlcpy(pextra->graphic_alt,
3703 "%s.graphic_alt", section));
3704
3705 reqs = lookup_req_list(file, section, "reqs", extra_rule_name(pextra));
3706 if (reqs == NULL) {
3707 ok = FALSE;
3708 break;
3709 }
3710 requirement_vector_copy(&pextra->reqs, reqs);
3711
3712 reqs = lookup_req_list(file, section, "rmreqs", extra_rule_name(pextra));
3713 if (reqs == NULL) {
3714 ok = FALSE;
3715 break;
3716 }
3717 requirement_vector_copy(&pextra->rmreqs, reqs);
3718
3719 reqs = lookup_req_list(file, section, "appearance_reqs", extra_rule_name(pextra));
3720 if (reqs == NULL) {
3721 ok = FALSE;
3722 break;
3723 }
3724 requirement_vector_copy(&pextra->appearance_reqs, reqs);
3725
3726 reqs = lookup_req_list(file, section, "disappearance_reqs", extra_rule_name(pextra));
3727 if (reqs == NULL) {
3728 ok = FALSE;
3729 break;
3730 }
3731 requirement_vector_copy(&pextra->disappearance_reqs, reqs);
3732
3733 pextra->buildable = secfile_lookup_bool_default(file,
3735 "%s.buildable", section);
3736 pextra->generated = secfile_lookup_bool_default(file, TRUE,
3737 "%s.generated", section);
3738
3739 pextra->build_time = 0; /* default */
3740 lookup_time(file, &pextra->build_time, section, "build_time",
3741 filename, extra_rule_name(pextra), &ok);
3742 pextra->build_time_factor = secfile_lookup_int_default(file, 1,
3743 "%s.build_time_factor", section);
3744 pextra->removal_time = 0; /* default */
3745 lookup_time(file, &pextra->removal_time, section, "removal_time",
3746 filename, extra_rule_name(pextra), &ok);
3747 pextra->removal_time_factor = secfile_lookup_int_default(file, 1,
3748 "%s.removal_time_factor", section);
3749 pextra->infracost = secfile_lookup_int_default(file, 0,
3750 "%s.infracost", section);
3751 if (pextra->infracost > 0) {
3752 terrain_control.infrapoints = TRUE;
3753 }
3754
3755 pextra->defense_bonus = secfile_lookup_int_default(file, 0,
3756 "%s.defense_bonus",
3757 section);
3758 if (pextra->defense_bonus != 0) {
3759 if (extra_has_flag(pextra, EF_NATURAL_DEFENSE)) {
3761 } else {
3763 }
3764 }
3765
3766 eus_name = secfile_lookup_str_default(file, "Normal", "%s.unit_seen", section);
3768 if (!extra_unit_seen_type_is_valid(pextra->eus)) {
3770 "\"%s\" extra \"%s\" has illegal unit_seen value \"%s\".",
3771 filename, extra_rule_name(pextra), eus_name);
3772 ok = FALSE;
3773 break;
3774 }
3775 if (pextra->eus == EUS_HIDDEN) {
3777 }
3778
3779 pextra->appearance_chance = secfile_lookup_int_default(file, RS_DEFAULT_EXTRA_APPEARANCE,
3780 "%s.appearance_chance",
3781 section);
3782 pextra->disappearance_chance = secfile_lookup_int_default(file,
3784 "%s.disappearance_chance",
3785 section);
3786
3787 pextra->no_aggr_near_city = secfile_lookup_int_default(file, -1,
3788 "%s.no_aggr_near_city",
3789 section);
3790
3791 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", section);
3792 BV_CLR_ALL(pextra->native_to);
3793 for (j = 0; j < nval; j++) {
3794 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
3795
3796 if (uclass == NULL) {
3798 "\"%s\" extra \"%s\" is native to unknown unit class \"%s\".",
3799 filename, extra_rule_name(pextra), slist[j]);
3800 ok = FALSE;
3801 break;
3802 } else {
3803 BV_SET(pextra->native_to, uclass_index(uclass));
3804 }
3805 }
3806 free(slist);
3807
3808 if (!ok) {
3809 break;
3810 }
3811
3812 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
3813 BV_CLR_ALL(pextra->flags);
3814 for (j = 0; j < nval; j++) {
3815 const char *sval = slist[j];
3816 enum extra_flag_id flag;
3817
3819
3820 if (!extra_flag_id_is_valid(flag)) {
3822 "\"%s\" extra \"%s\": unknown flag \"%s\".",
3823 filename, extra_rule_name(pextra), sval);
3824 ok = FALSE;
3825 break;
3826 } else {
3827 BV_SET(pextra->flags, flag);
3828 }
3829 }
3830 free(slist);
3831
3832 if (pextra->no_aggr_near_city >= 0) {
3834 }
3835
3836 if (extra_has_flag(pextra, EF_CAUSE_ZOC)) {
3838 }
3839
3840 if (!ok) {
3841 break;
3842 }
3843
3844 slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
3845 for (j = 0; j < nval; j++) {
3846 const char *sval = slist[j];
3848
3849 if (pextra2 == NULL) {
3851 "\"%s\" extra \"%s\": unknown conflict extra \"%s\".",
3852 filename, extra_rule_name(pextra), sval);
3853 ok = FALSE;
3854 break;
3855 } else {
3856 BV_SET(pextra->conflicts, extra_index(pextra2));
3857 BV_SET(pextra2->conflicts, extra_index(pextra));
3858 }
3859 }
3860
3861 free(slist);
3862
3863 if (!ok) {
3864 break;
3865 }
3866
3867 slist = secfile_lookup_str_vec(file, &nval, "%s.hidden_by", section);
3868 BV_CLR_ALL(pextra->hidden_by);
3869 for (j = 0; j < nval; j++) {
3870 const char *sval = slist[j];
3871 const struct extra_type *top = extra_type_by_rule_name(sval);
3872
3873 if (top == NULL) {
3875 "\"%s\" extra \"%s\" hidden by unknown extra \"%s\".",
3876 filename, extra_rule_name(pextra), sval);
3877 ok = FALSE;
3878 break;
3879 } else {
3880 BV_SET(pextra->hidden_by, extra_index(top));
3881 }
3882 }
3883 free(slist);
3884
3885 if (!ok) {
3886 break;
3887 }
3888
3889 slist = secfile_lookup_str_vec(file, &nval, "%s.bridged_over", section);
3890 BV_CLR_ALL(pextra->bridged_over);
3891 for (j = 0; j < nval; j++) {
3892 const char *sval = slist[j];
3893 const struct extra_type *top = extra_type_by_rule_name(sval);
3894
3895 if (top == NULL) {
3897 "\"%s\" extra \"%s\" bridged over unknown extra \"%s\".",
3898 filename, extra_rule_name(pextra), sval);
3899 ok = FALSE;
3900 break;
3901 } else {
3902 BV_SET(pextra->bridged_over, extra_index(top));
3903 }
3904 }
3905 free(slist);
3906
3907 if (!ok) {
3908 break;
3909 }
3910
3912 "%s.visibility_req", section);
3914
3915 if (vis_req == NULL) {
3917 "\"%s\" %s: unknown visibility_req %s.",
3918 filename, section, vis_req_name);
3919 ok = FALSE;
3920 break;
3921 }
3922
3923 pextra->visibility_req = advance_number(vis_req);
3924
3925 pextra->helptext = lookup_strvec(file, section, "helptext");
3927 }
3928
3929 if (ok) {
3930 int i = 0;
3931 /* Resource details */
3932
3934 char identifier[MAX_LEN_NAME];
3935 const char *id;
3937
3938 if (!presource->data.resource) {
3940 "\"%s\" extra \"%s\" has \"Resource\" cause but no "
3941 "corresponding [resource_*] section",
3942 filename, extra_rule_name(presource));
3943 ok = FALSE;
3944 break;
3945 }
3946
3948 presource->data.resource->output[o] =
3949 secfile_lookup_int_default(file, 0, "%s.%s", rsection,
3952
3953 id = secfile_lookup_str_default(file, NULL, "%s.identifier", rsection);
3954
3955 if (id == NULL) {
3956 presource->data.resource->id_old_save = '\0';
3957 } else {
3958 sz_strlcpy(identifier, id);
3959
3960 presource->data.resource->id_old_save = identifier[0];
3961 if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
3963 "\"%s\" [%s] identifier missing value.",
3964 filename, rsection);
3965 ok = FALSE;
3966 break;
3967 }
3968 if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
3970 "\"%s\" [%s] cannot use '%c' as an identifier;"
3971 " it is reserved.",
3972 filename, rsection, presource->data.resource->id_old_save);
3973 ok = FALSE;
3974 break;
3975 }
3976 }
3977
3978 if (!ok) {
3979 break;
3980 }
3981
3982 i++;
3984
3985 for (j = 0; ok && j < game.control.num_resource_types; j++) {
3986 const char *section = &resource_sections[j * MAX_SECTION_LABEL];
3987 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
3989
3990 if (!is_extra_caused_by(pextra, EC_RESOURCE)) {
3992 "\"%s\" resource section [%s]: extra \"%s\" does not "
3993 "have \"Resource\" in its causes",
3994 filename, section, extra_name);
3995 ok = FALSE;
3996 }
3997 }
3998 }
3999
4000 if (ok) {
4001 /* This can't be part of previous loop as we don't want random data from previous
4002 * ruleset to play havoc on us when we have only some resource identifiers loaded
4003 * from the new ruleset. */
4005 if (pres->data.resource->id_old_save != '\0') {
4007 if (pres->data.resource->id_old_save == pres2->data.resource->id_old_save
4008 && pres != pres2) {
4010 "\"%s\" [%s] has the same identifier as [%s].",
4011 filename,
4014 ok = FALSE;
4015 break;
4016 }
4018
4019 if (!ok) {
4020 break;
4021 }
4022 }
4024 }
4025
4026 if (ok) {
4027 /* Base details */
4029 struct base_type *pbase = extra_base_get(pextra);
4030 const char *section;
4031 const char *gui_str;
4032
4033 if (!pbase) {
4035 "\"%s\" extra \"%s\" has \"Base\" cause but no "
4036 "corresponding [base_*] section",
4037 filename, extra_rule_name(pextra));
4038 ok = FALSE;
4039 break;
4040 }
4042
4043 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4045 if (!base_gui_type_is_valid(pbase->gui_type)) {
4047 "\"%s\" base \"%s\": unknown gui_type \"%s\".",
4048 filename, extra_rule_name(pextra), gui_str);
4049 ok = FALSE;
4050 break;
4051 }
4052
4053 pbase->border_sq = secfile_lookup_int_default(file, -1, "%s.border_sq",
4054 section);
4055 pbase->vision_main_sq = secfile_lookup_int_default(file, -1,
4056 "%s.vision_main_sq",
4057 section);
4058 pbase->vision_invis_sq = secfile_lookup_int_default(file, -1,
4059 "%s.vision_invis_sq",
4060 section);
4061 pbase->vision_subs_sq = secfile_lookup_int_default(file, -1,
4062 "%s.vision_subs_sq",
4063 section);
4064
4065 if (!ok) {
4066 break;
4067 }
4068
4071
4073 struct base_type *pbase2;
4074
4075 if (pextra == pextra2) {
4076 /* End of the fully initialized bases iteration. */
4077 break;
4078 }
4079
4082 BV_SET(pextra->conflicts, extra_index(pextra2));
4083 BV_SET(pextra2->conflicts, extra_index(pextra));
4084 }
4086 }
4088
4089 for (j = 0; ok && j < game.control.num_base_types; j++) {
4090 const char *section = &base_sections[j * MAX_SECTION_LABEL];
4091 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4093
4094 if (!is_extra_caused_by(pextra, EC_BASE)) {
4096 "\"%s\" base section [%s]: extra \"%s\" does not have "
4097 "\"Base\" in its causes",
4098 filename, section, extra_name);
4099 ok = FALSE;
4100 }
4101 }
4102 }
4103
4104 if (ok) {
4106 struct road_type *proad = extra_road_get(pextra);
4107 const char *section;
4108 const char **slist;
4109 const char *special;
4110 const char *modestr;
4111 struct requirement_vector *reqs;
4112 const char *gui_str;
4113
4114 if (!proad) {
4116 "\"%s\" extra \"%s\" has \"Road\" cause but no "
4117 "corresponding [road_*] section",
4118 filename, extra_rule_name(pextra));
4119 ok = FALSE;
4120 break;
4121 }
4123
4124 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4126 if (!road_gui_type_is_valid(proad->gui_type)) {
4128 "\"%s\" road \"%s\": unknown gui_type \"%s\".",
4129 filename, extra_rule_name(pextra), gui_str);
4130 ok = FALSE;
4131 break;
4132 }
4133
4134 reqs = lookup_req_list(file, section, "first_reqs", extra_rule_name(pextra));
4135 if (reqs == NULL) {
4136 ok = FALSE;
4137 break;
4138 }
4139 requirement_vector_copy(&proad->first_reqs, reqs);
4140
4141 if (!secfile_lookup_int(file, &proad->move_cost,
4142 "%s.move_cost", section)) {
4143 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4144 ok = FALSE;
4145 break;
4146 }
4147
4148 modestr = secfile_lookup_str_default(file, "FastAlways", "%s.move_mode",
4149 section);
4151 if (!road_move_mode_is_valid(proad->move_mode)) {
4153 "Illegal move_mode \"%s\" for road \"%s\"",
4154 modestr, extra_rule_name(pextra));
4155 ok = FALSE;
4156 break;
4157 }
4158
4160 proad->tile_incr_const[o] =
4161 secfile_lookup_int_default(file, 0, "%s.%s_incr_const",
4163 proad->tile_incr[o] =
4164 secfile_lookup_int_default(file, 0, "%s.%s_incr",
4166 proad->tile_bonus[o] =
4167 secfile_lookup_int_default(file, 0, "%s.%s_bonus",
4170
4171 special = secfile_lookup_str_default(file, "None", "%s.compat_special", section);
4172 if (!fc_strcasecmp(special, "Road")) {
4173 if (compat_road) {
4175 "Multiple roads marked as compatibility \"Road\"");
4176 ok = FALSE;
4177 }
4178 compat_road = TRUE;
4179 proad->compat = ROCO_ROAD;
4180 } else if (!fc_strcasecmp(special, "Railroad")) {
4181 if (compat_rail) {
4183 "Multiple roads marked as compatibility \"Railroad\"");
4184 ok = FALSE;
4185 }
4186 compat_rail = TRUE;
4187 proad->compat = ROCO_RAILROAD;
4188 } else if (!fc_strcasecmp(special, "River")) {
4189 if (compat_river) {
4191 "Multiple roads marked as compatibility \"River\"");
4192 ok = FALSE;
4193 }
4195 proad->compat = ROCO_RIVER;
4196 } else if (!fc_strcasecmp(special, "None")) {
4197 proad->compat = ROCO_NONE;
4198 } else {
4200 "Illegal compatibility special \"%s\" for road %s",
4201 special, extra_rule_name(pextra));
4202 ok = FALSE;
4203 }
4204
4205 if (!ok) {
4206 break;
4207 }
4208
4209 slist = secfile_lookup_str_vec(file, &nval, "%s.integrates", section);
4210 BV_CLR_ALL(proad->integrates);
4211 for (j = 0; j < nval; j++) {
4212 const char *sval = slist[j];
4214 struct road_type *top = NULL;
4215
4216 if (textra != NULL) {
4217 top = extra_road_get(textra);
4218 }
4219
4220 if (top == NULL) {
4222 "\"%s\" road \"%s\" integrates with unknown road \"%s\".",
4223 filename, extra_rule_name(pextra), sval);
4224 ok = FALSE;
4225 break;
4226 } else {
4227 BV_SET(proad->integrates, road_number(top));
4228 }
4229 }
4230 free(slist);
4231
4232 if (!ok) {
4233 break;
4234 }
4235
4236 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4237 BV_CLR_ALL(proad->flags);
4238 for (j = 0; j < nval; j++) {
4239 const char *sval = slist[j];
4241
4242 if (!road_flag_id_is_valid(flag)) {
4244 "\"%s\" road \"%s\": unknown flag \"%s\".",
4245 filename, extra_rule_name(pextra), sval);
4246 ok = FALSE;
4247 break;
4248 } else {
4249 BV_SET(proad->flags, flag);
4250 }
4251 }
4252 free(slist);
4253
4254 if (!ok) {
4255 break;
4256 }
4258
4259 for (j = 0; ok && j < game.control.num_road_types; j++) {
4260 const char *section = &road_sections[j * MAX_SECTION_LABEL];
4261 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4263
4264 if (!is_extra_caused_by(pextra, EC_ROAD)) {
4266 "\"%s\" road section [%s]: extra \"%s\" does not have "
4267 "\"Road\" in its causes",
4268 filename, section, extra_name);
4269 ok = FALSE;
4270 }
4271 }
4272 }
4273
4274 if (ok) {
4275 extra_type_iterate(pextra) {
4276 pextra->bridged = extra_type_list_new();
4278 if (BV_ISSET(pextra->bridged_over, pbridged->id)) {
4279 extra_type_list_append(pextra->bridged, pbridged);
4280 }
4283 }
4284
4285 if (ok) {
4286 /* Tiledef details */
4288 int tdidx = tiledef_index(td);
4290 const char **slist;
4291 int ej;
4292
4293 slist = secfile_lookup_str_vec(file, &nval, "%s.extras", section);
4294 for (ej = 0; ej < nval; ej++) {
4295 const char *sval = slist[ej];
4296 struct extra_type *pextra = extra_type_by_rule_name(sval);
4297
4298 if (pextra != nullptr) {
4300 if (pextra == old_extra) {
4301 ruleset_error(nullptr, LOG_ERROR,
4302 "%s: Duplicate extra %s.",
4303 section, extra_rule_name(pextra));
4304 ok = FALSE;
4305 break;
4306 }
4308
4309 if (ok) {
4310 extra_type_list_append(td->extras, pextra);
4311 }
4312 } else {
4313 ruleset_error(nullptr, LOG_ERROR,
4314 "%s: Unknown extra name \"%s\".",
4315 section, sval);
4316 ok = FALSE;
4317 }
4318
4319 if (!ok) {
4320 break;
4321 }
4322 }
4324 }
4325
4326 if (ok) {
4328 }
4329
4330 return ok;
4331}
4332
4333/**********************************************************************/
4337static bool load_government_names(struct section_file *file,
4338 struct rscompat_info *compat)
4339{
4340 int nval = 0;
4341 struct section_list *sec;
4342 const char *filename = secfile_name(file);
4343 bool ok = TRUE;
4344 const char *flag;
4345 int i;
4346
4347 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4348 return FALSE;
4349 }
4350
4351 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4352 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4353
4355 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
4356 ruleset_error(NULL, LOG_ERROR, "\"%s\": No governments?!?", filename);
4357 ok = FALSE;
4358 } else if (nval > G_LAST) {
4360 "\"%s\": Too many governments (%d, max %d)",
4361 filename, nval, G_LAST);
4362 ok = FALSE;
4363 }
4364
4365 if (ok) {
4367
4368 /* Government names are needed early so that get_government_by_name will
4369 * work. */
4370 governments_iterate(gov) {
4371 const char *sec_name =
4373
4374 if (!ruleset_load_names(&gov->name, NULL, file, sec_name)) {
4375 ok = FALSE;
4376 break;
4377 }
4379 }
4380
4382
4383 if (ok) {
4385 nval = (NULL != sec ? section_list_size(sec) : 0);
4386
4387 if (nval > MAX_NUM_MULTIPLIERS) {
4389 "\"%s\": Too many multipliers (%d, max %d)",
4390 filename, nval, MAX_NUM_MULTIPLIERS);
4391
4392 ok = FALSE;
4393 } else {
4395 }
4396
4397 if (ok) {
4398 multipliers_iterate(pmul) {
4399 const char *sec_name =
4401
4402 if (!ruleset_load_names(&pmul->name, NULL, file, sec_name)) {
4404 "\"%s\": Cannot load multiplier names",
4405 filename);
4406 ok = FALSE;
4407 break;
4408 }
4410 }
4411 }
4412
4413 /* User government flag names */
4414 for (i = 0;
4415 (flag = secfile_lookup_str_default(file, nullptr,
4416 "control.flags%d.name",
4417 i));
4418 i++) {
4419 const char *helptxt = secfile_lookup_str_default(file, nullptr,
4420 "control.flags%d.helptxt", i);
4421
4423 != gov_flag_id_invalid()) {
4424 ruleset_error(nullptr, LOG_ERROR,
4425 "\"%s\": Duplicate government flag name '%s'",
4426 filename, flag);
4427 ok = FALSE;
4428 break;
4429 }
4432 "\"%s\": Too many user government flags!",
4433 filename);
4434 ok = FALSE;
4435 break;
4436 }
4437
4438 set_user_gov_flag_name(GOVF_USER_FLAG_1 + i, flag, helptxt);
4439 }
4440
4442
4443 return ok;
4444}
4445
4446/**********************************************************************/
4450 struct rscompat_info *compat)
4451{
4452 struct section_list *sec;
4453 const char *filename = secfile_name(file);
4454 bool ok = TRUE;
4455
4457
4459 = lookup_government(file, "governments.during_revolution", filename, NULL);
4461 ok = FALSE;
4462 }
4463
4464 if (ok) {
4467
4468 /* Easy ones: */
4470 const int i = government_index(g);
4471 const char *sec_name = section_name(section_list_get(sec, i));
4472 struct requirement_vector *reqs
4473 = lookup_req_list(file, sec_name, "reqs", government_rule_name(g));
4474 const char **slist;
4475 int j;
4476 const char *sval;
4477 size_t nval;
4478
4479 if (reqs == NULL) {
4480 ok = FALSE;
4481 break;
4482 }
4483
4484 if (NULL != secfile_entry_lookup(file, "%s.ai_better", sec_name)) {
4485 char entry[100];
4486
4487 fc_snprintf(entry, sizeof(entry), "%s.ai_better", sec_name);
4488 g->ai.better = lookup_government(file, entry, filename, NULL);
4489 if (g->ai.better == NULL) {
4490 ok = FALSE;
4491 break;
4492 }
4493 } else {
4494 g->ai.better = NULL;
4495 }
4496 requirement_vector_copy(&g->reqs, reqs);
4497
4498 sz_strlcpy(g->graphic_str,
4499 secfile_lookup_str(file, "%s.graphic", sec_name));
4500 sz_strlcpy(g->graphic_alt,
4501 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
4502 sz_strlcpy(g->sound_str,
4503 secfile_lookup_str_default(file, "-", "%s.sound", sec_name));
4504 sz_strlcpy(g->sound_alt,
4505 secfile_lookup_str_default(file, "-", "%s.sound_alt", sec_name));
4506 sz_strlcpy(g->sound_alt2,
4507 secfile_lookup_str_default(file, "-", "%s.sound_alt2", sec_name));
4508
4509 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
4510 BV_CLR_ALL(g->flags);
4511 for (j = 0; j < nval; j++) {
4512 enum gov_flag_id flag;
4513
4514 sval = slist[j];
4516 if (!gov_flag_id_is_valid(flag)) {
4517 ruleset_error(NULL, LOG_ERROR, "\"%s\" government \"%s\": unknown flag \"%s\".",
4518 filename, government_rule_name(g), sval);
4519 ok = FALSE;
4520 break;
4521 } else {
4522 BV_SET(g->flags, flag);
4523 }
4524 }
4525 free(slist);
4526
4527 g->helptext = lookup_strvec(file, sec_name, "helptext");
4529 }
4530
4531
4532 if (ok) {
4533 /* Titles */
4535 const char *sec_name
4537 const char *male, *female;
4538
4539 if (!(male = secfile_lookup_str(file, "%s.ruler_male_title", sec_name))
4540 || !(female = secfile_lookup_str(file, "%s.ruler_female_title",
4541 sec_name))) {
4543 "Lack of default ruler titles for "
4544 "government \"%s\" (nb %d): %s",
4546 secfile_error());
4547 ok = FALSE;
4548 break;
4549 } else if (NULL == government_ruler_title_new(g, NULL, male, female)) {
4551 "Lack of default ruler titles for "
4552 "government \"%s\" (nb %d).",
4554 ok = FALSE;
4555 break;
4556 }
4558 }
4559
4561
4562 if (ok) {
4564 multipliers_iterate(pmul) {
4565 int id = multiplier_index(pmul);
4566 const char *sec_name = section_name(section_list_get(sec, id));
4567 struct requirement_vector *reqs;
4568
4569 if (!secfile_lookup_int(file, &pmul->start, "%s.start", sec_name)) {
4570 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4571 ok = FALSE;
4572 break;
4573 }
4574 if (!secfile_lookup_int(file, &pmul->stop, "%s.stop", sec_name)) {
4575 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4576 ok = FALSE;
4577 break;
4578 }
4579 if (pmul->stop <= pmul->start) {
4581 "Multiplier \"%s\" stop (%d) must be greater "
4582 "than start (%d)", multiplier_rule_name(pmul),
4583 pmul->stop, pmul->start);
4584 ok = FALSE;
4585 break;
4586 }
4587 if (!secfile_lookup_int(file, &pmul->step, "%s.step", sec_name)) {
4588 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4589 ok = FALSE;
4590 break;
4591 }
4592 if (((pmul->stop - pmul->start) % pmul->step) != 0) {
4594 "Multiplier \"%s\" step (%d) does not fit "
4595 "exactly into interval start-stop (%d to %d)",
4596 multiplier_rule_name(pmul), pmul->step,
4597 pmul->start, pmul->stop);
4598 ok = FALSE;
4599 break;
4600 }
4601 if (!secfile_lookup_int(file, &pmul->def, "%s.default", sec_name)) {
4602 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4603 ok = FALSE;
4604 break;
4605 }
4606 if (pmul->def < pmul->start || pmul->def > pmul->stop) {
4608 "Multiplier \"%s\" default (%d) not within "
4609 "legal range (%d to %d)", multiplier_rule_name(pmul),
4610 pmul->def, pmul->start, pmul->stop);
4611 ok = FALSE;
4612 break;
4613 }
4614 if (((pmul->def - pmul->start) % pmul->step) != 0) {
4616 "Multiplier \"%s\" default (%d) not legal "
4617 "with respect to step size %d",
4618 multiplier_rule_name(pmul), pmul->def, pmul->step);
4619 ok = FALSE;
4620 break;
4621 }
4622 pmul->offset = secfile_lookup_int_default(file, 0,
4623 "%s.offset", sec_name);
4624 pmul->factor = secfile_lookup_int_default(file, 100,
4625 "%s.factor", sec_name);
4626 if (pmul->factor == 0) {
4628 "Multiplier \"%s\" scaling factor must "
4629 "not be zero", multiplier_rule_name(pmul));
4630 ok = FALSE;
4631 break;
4632 }
4633
4634 pmul->minimum_turns = secfile_lookup_int_default(file, 0,
4635 "%s.minimum_turns",
4636 sec_name);
4637
4638 reqs = lookup_req_list(file, sec_name, "reqs",
4639 multiplier_rule_name(pmul));
4640 if (reqs == NULL) {
4641 ok = FALSE;
4642 break;
4643 }
4644 requirement_vector_copy(&pmul->reqs, reqs);
4645
4646 pmul->helptext = lookup_strvec(file, sec_name, "helptext");
4649 }
4650
4651 if (ok) {
4653 }
4654
4655 return ok;
4656}
4657
4658/**********************************************************************/
4669static void send_ruleset_control(struct conn_list *dest)
4670{
4672 int idx = 0;
4673
4675
4676 if (game.ruleset_summary != NULL) {
4677 struct packet_ruleset_summary summary;
4678
4680
4681 lsend_packet_ruleset_summary(dest, &summary);
4682 }
4683
4684 while (desc_left > 0) {
4686 int this_len = desc_left;
4687
4688 if (this_len > MAX_LEN_CONTENT - 21) {
4690 }
4691
4692 part.text[this_len] = '\0';
4693
4695 idx += this_len;
4697
4699 }
4700}
4701
4702/**********************************************************************/
4707static const char *check_leader_names(struct nation_type *pnation)
4708{
4710 const char *name = nation_leader_name(pleader);
4711
4713 if (prev_leader == pleader) {
4714 break;
4715 } else if (0 == fc_strcasecmp(name, nation_leader_name(prev_leader))) {
4716 return name;
4717 }
4720 return NULL;
4721}
4722
4723/**********************************************************************/
4727static bool load_nation_names(struct section_file *file,
4728 struct rscompat_info *compat)
4729{
4730 struct section_list *sec;
4731 int j;
4732 bool ok = TRUE;
4733 const char *filename = secfile_name(file);
4734
4735 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4736 return FALSE;
4737 }
4738
4739 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4740 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4741
4743 if (NULL == sec) {
4745 "No available nations in this ruleset!");
4746 ok = FALSE;
4747 } else if (section_list_size(sec) > MAX_NUM_NATIONS) {
4749 "Too many nations (max %d, we have %d)!",
4751 ok = FALSE;
4752 } else {
4755
4757 const int i = nation_index(pl);
4758 const char *sec_name = section_name(section_list_get(sec, i));
4759 const char *domain = secfile_lookup_str_default(file, NULL,
4760 "%s.translation_domain", sec_name);
4761 const char *noun_plural = secfile_lookup_str(file,
4762 "%s.plural", sec_name);
4763
4764
4765 if (domain == NULL) {
4766 domain = "freeciv-nations";
4767 }
4768
4769 if (!strcmp("freeciv-core", domain)) {
4770 pl->translation_domain = NULL;
4771 } else if (!strcmp("freeciv-nations", domain)) {
4772 pl->translation_domain = fc_strdup(domain);
4773 } else {
4775 "Unsupported translation domain \"%s\" for %s",
4776 domain, sec_name);
4777 ok = FALSE;
4778 break;
4779 }
4780
4781 if (!ruleset_load_names(&pl->adjective, pl->translation_domain, file, sec_name)) {
4782 ok = FALSE;
4783 break;
4784 }
4785 name_set(&pl->noun_plural, pl->translation_domain, noun_plural);
4786
4787 /* Check if nation name is already defined. */
4788 for (j = 0; j < i && ok; j++) {
4789 struct nation_type *n2 = nation_by_number(j);
4790
4791 /* Compare strings after stripping off qualifiers -- we don't want
4792 * two nations to end up with identical adjectives displayed to users.
4793 * (This check only catches English, not localisations, of course.) */
4794 if (0 == strcmp(Qn_(untranslated_name(&n2->adjective)),
4795 Qn_(untranslated_name(&pl->adjective)))) {
4797 "Two nations defined with the same adjective \"%s\": "
4798 "in section \'%s\' and section \'%s\'",
4799 Qn_(untranslated_name(&pl->adjective)),
4801 ok = FALSE;
4802 } else if (!strcmp(rule_name_get(&n2->adjective),
4803 rule_name_get(&pl->adjective))) {
4804 /* We cannot have the same rule name, as the game needs them to be
4805 * distinct. */
4807 "Two nations defined with the same rule_name \"%s\": "
4808 "in section \'%s\' and section \'%s\'",
4809 rule_name_get(&pl->adjective),
4811 ok = FALSE;
4812 } else if (0 == strcmp(Qn_(untranslated_name(&n2->noun_plural)),
4813 Qn_(untranslated_name(&pl->noun_plural)))) {
4814 /* We don't want identical English plural names either. */
4816 "Two nations defined with the same plural name \"%s\": "
4817 "in section \'%s\' and section \'%s\'",
4818 Qn_(untranslated_name(&pl->noun_plural)),
4820 ok = FALSE;
4821 }
4822 }
4823 if (!ok) {
4824 break;
4825 }
4827 }
4828
4830
4831 if (ok) {
4833 if (sec != NULL) {
4835
4836 section_list_iterate(sec, psection) {
4837 struct nation_group *pgroup;
4838 const char *name;
4839
4840 name = secfile_lookup_str(file, "%s.name", section_name(psection));
4841 if (NULL == name) {
4842 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4843 ok = FALSE;
4844 break;
4845 }
4847 if (pgroup == NULL) {
4848 ok = FALSE;
4849 break;
4850 }
4853 sec = NULL;
4854 }
4855 }
4856
4857 return ok;
4858}
4859
4860/**********************************************************************/
4863static bool is_on_allowed_list(const char *name, const char **list, size_t len)
4864{
4865 int i;
4866
4867 for (i = 0; i < len; i++) {
4868 if (!fc_strcasecmp(name, list[i])) {
4869 return TRUE;
4870 }
4871 }
4872 return FALSE;
4873}
4874
4875/**********************************************************************/
4879static bool load_city_name_list(struct section_file *file,
4880 struct nation_type *pnation,
4881 const char *secfile_str1,
4882 const char *secfile_str2,
4883 const char **allowed_terrains,
4884 size_t atcount)
4885{
4886 size_t dim, j;
4887 bool ok = TRUE;
4888 const char **cities = secfile_lookup_str_vec(file, &dim, "%s.%s",
4890
4891 /* Each string will be of the form "<cityname> (<label>, <label>, ...)".
4892 * The cityname is just the name for this city, while each "label" matches
4893 * a terrain type for the city (or "river"), with a preceding ! to negate
4894 * it. The parentheses are optional (but necessary to have the settings,
4895 * of course). Our job is now to parse it. */
4896 for (j = 0; j < dim; j++) {
4897 size_t len = strlen(cities[j]);
4898 char city_name[len + 1], *p, *next, *end;
4899 struct nation_city *pncity;
4900
4902
4903 /* Now we wish to determine values for all of the city labels. A value
4904 * of NCP_NONE means no preference (which is necessary so that the use
4905 * of this is optional); NCP_DISLIKE means the label is negated and
4906 * NCP_LIKE means it's labelled. Mostly the parsing just involves
4907 * a lot of ugly string handling... */
4908 if ((p = strchr(city_name, '('))) {
4909 *p++ = '\0';
4910
4911 if (!(end = strchr(p, ')'))) {
4913 "\"%s\" [%s] %s: city name \"%s\" "
4914 "unmatched parenthesis.", secfile_name(file),
4916 ok = FALSE;
4917 } else {
4918 for (*end++ = '\0'; '\0' != *end; end++) {
4919 if (!fc_isspace(*end)) {
4921 "\"%s\" [%s] %s: city name \"%s\" "
4922 "contains characters after last parenthesis.",
4924 cities[j]);
4925 ok = FALSE;
4926 break;
4927 }
4928 }
4929 }
4930 }
4931
4932 /* Build the nation_city. */
4935 /* The ruleset contains a name that is too long. This shouldn't
4936 * happen - if it does, the author should get immediate feedback. */
4938 "\"%s\" [%s] %s: city name \"%s\" is too long.",
4939 secfile_name(file),
4941 ok = FALSE;
4942 city_name[MAX_LEN_CITYNAME - 1] = '\0';
4943 }
4944 pncity = nation_city_new(pnation, city_name);
4945
4946 if (NULL != p) {
4947 /* Handle the labels one at a time. */
4948 do {
4949 enum nation_city_preference prefer;
4950
4951 if ((next = strchr(p, ','))) {
4952 *next = '\0';
4953 }
4955
4956 /* The ! is used to mark a negative, which is recorded with
4957 * NCP_DISLIKE. Otherwise we use a NCP_LIKE.
4958 */
4959 if (*p == '!') {
4960 p++;
4961 prefer = NCP_DISLIKE;
4962 } else {
4963 prefer = NCP_LIKE;
4964 }
4965
4966 if (0 == fc_strcasecmp(p, "river")) {
4968 && !is_on_allowed_list(p,
4971 "\"%s\" [%s] %s: city \"%s\" "
4972 "has terrain hint \"%s\" not in allowed_terrains.",
4974 city_name, p);
4975 ok = FALSE;
4976 } else {
4978 }
4979 } else {
4980 const struct terrain *pterrain = terrain_by_rule_name(p);
4981
4982 if (NULL == pterrain) {
4983 /* Try with removing frequent trailing 's'. */
4984 size_t l = strlen(p);
4985
4986 if (0 < l && 's' == fc_tolower(p[l - 1])) {
4987 char saved = p[l - 1];
4988
4989 p[l - 1] = '\0';
4990 pterrain = terrain_by_rule_name(p);
4991 if (pterrain == NULL) {
4992 /* Didn't help, restore for later allowed_terrains check */
4993 p[l - 1] = saved;
4994 }
4995 }
4996 }
4997
4998 /* Nationset may have been devised with a specific set of terrains
4999 * in mind which don't quite match this ruleset, in which case we
5000 * (a) quietly ignore any hints mentioned that don't happen to be in
5001 * the current ruleset, (b) enforce that terrains mentioned by nations
5002 * must be on the list */
5003 if (pterrain != NULL && game.server.ruledit.allowed_terrains != NULL) {
5004 if (!is_on_allowed_list(p,
5006 /* Terrain exists, but not intended for these nations */
5008 "\"%s\" [%s] %s: city \"%s\" "
5009 "has terrain hint \"%s\" not in allowed_terrains.",
5011 city_name, p);
5012 ok = FALSE;
5013 break;
5014 }
5015 } else if (!pterrain) {
5016 /* Terrain doesn't exist; only complain if it's not on any list */
5018 || !is_on_allowed_list(p,
5021 "\"%s\" [%s] %s: city \"%s\" "
5022 "has unknown terrain hint \"%s\".",
5024 city_name, p);
5025 ok = FALSE;
5026 break;
5027 }
5028 }
5029 if (NULL != pterrain) {
5030 nation_city_set_terrain_preference(pncity, pterrain, prefer);
5031 }
5032 }
5033
5034 p = next ? next + 1 : NULL;
5035 } while (NULL != p && '\0' != *p);
5036 }
5037 }
5038
5039 if (NULL != cities) {
5040 free(cities);
5041 }
5042
5043 return ok;
5044}
5045
5046/**********************************************************************/
5049static bool load_ruleset_nations(struct section_file *file,
5050 struct rscompat_info *compat)
5051{
5052 struct government *gov;
5053 int j;
5054 size_t dim;
5055 char temp_name[MAX_LEN_NAME];
5056 const char **vec;
5057 const char *name, *bad_leader;
5058 const char *sval;
5059 int default_set;
5060 const char *filename = secfile_name(file);
5061 struct section_list *sec = NULL;
5062 enum trait tr;
5063 bool ok = TRUE;
5064
5065 name = secfile_lookup_str_default(file, NULL, "ruledit.nationlist");
5066 if (name != NULL) {
5068 }
5070 "ruledit.embedded_nations");
5071
5072 if (vec != NULL) {
5073 /* Copy to persistent vector */
5076
5077 for (j = 0; j < game.server.ruledit.embedded_nations_count; j++) {
5079 }
5080
5081 free(vec);
5082 }
5083
5085
5086 ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
5087 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5088 if (game.server.default_traits[tr].min < 0) {
5090 }
5091 if (game.server.default_traits[tr].max < 0) {
5093 }
5094 if (game.server.default_traits[tr].fixed < 0) {
5096
5097 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5099 }
5102 "Default values for trait %s not sane.",
5103 trait_name(tr));
5104 ok = FALSE;
5105 break;
5106 }
5107 }
5108
5109 if (ok) {
5111 "compatibility.allowed_govs");
5112 if (vec != NULL) {
5113 /* Copy to persistent vector */
5115 = fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
5117 (const char **)game.server.ruledit.nc_agovs;
5118
5119 for (j = 0; j < game.server.ruledit.ag_count; j++) {
5121 }
5122
5123 free(vec);
5124 }
5125
5127 "compatibility.allowed_terrains");
5128 if (vec != NULL) {
5129 /* Copy to persistent vector */
5131 = fc_malloc(game.server.ruledit.at_count * sizeof(char *));
5133 (const char **)game.server.ruledit.nc_aterrs;
5134
5135 for (j = 0; j < game.server.ruledit.at_count; j++) {
5137 }
5138
5139 free(vec);
5140 }
5141
5143 "compatibility.allowed_styles");
5144 if (vec != NULL) {
5145 /* Copy to persistent vector */
5147 = fc_malloc(game.server.ruledit.as_count * sizeof(char *));
5149 (const char **)game.server.ruledit.nc_astyles;
5150
5151 for (j = 0; j < game.server.ruledit.as_count; j++) {
5153 }
5154
5155 free(vec);
5156 }
5157
5159 "compatibility.default_government");
5160 /* We deliberately don't check this against allowed_govs. It's only
5161 * specified once so not vulnerable to typos, and may usefully be set in
5162 * a specific ruleset to a gov not explicitly known by the nation set. */
5163 if (sval != NULL) {
5165 if (game.default_government == NULL) {
5167 "Tried to set unknown government type \"%s\" as default_government!",
5168 sval);
5169 ok = FALSE;
5170 } else {
5173 }
5174 }
5175 }
5176
5177 if (ok) {
5179 if (sec != NULL) {
5181
5182 section_list_iterate(sec, psection) {
5183 const char *set_name, *set_rule_name, *set_description;
5184
5185 set_name = secfile_lookup_str(file, "%s.name", section_name(psection));
5187 secfile_lookup_str(file, "%s.rule_name", section_name(psection));
5188 set_description = secfile_lookup_str_default(file, "", "%s.description",
5189 section_name(psection));
5190 if (NULL == set_name || NULL == set_rule_name) {
5191 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5192 ok = FALSE;
5193 break;
5194 }
5196 ok = FALSE;
5197 break;
5198 }
5201 sec = NULL;
5202 } else {
5204 "At least one nation set [" NATION_SET_SECTION_PREFIX "_*] "
5205 "must be defined.");
5206 ok = FALSE;
5207 }
5208 }
5209
5210 if (ok) {
5211 /* Default set that every nation is a member of. */
5213 "compatibility.default_nationset");
5214 if (sval != NULL) {
5216 if (pset != NULL) {
5218 } else {
5220 "Unknown default_nationset \"%s\".", sval);
5221 ok = FALSE;
5222 }
5223 } else if (nation_set_count() == 1) {
5224 /* If there's only one set defined, every nation is implicitly a
5225 * member of that set. */
5226 default_set = 0;
5227 } else {
5228 /* No default nation set; every nation must explicitly specify at
5229 * least one set to be a member of. */
5230 default_set = -1;
5231 }
5232 }
5233
5234 if (ok) {
5236 if (sec) {
5237 section_list_iterate(sec, psection) {
5238 struct nation_group *pgroup;
5239 bool hidden;
5240
5241 name = secfile_lookup_str(file, "%s.name", section_name(psection));
5243 if (pgroup == NULL) {
5244 ok = FALSE;
5245 break;
5246 }
5247
5248 hidden = secfile_lookup_bool_default(file, FALSE, "%s.hidden",
5249 section_name(psection));
5251
5252 if (!secfile_lookup_int(file, &j, "%s.match", section_name(psection))) {
5253 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5254 ok = FALSE;
5255 break;
5256 }
5260 sec = NULL;
5261 }
5262 }
5263
5264 if (ok) {
5266 nations_iterate(pnation) {
5267 struct nation_type *pconflict;
5268 const int i = nation_index(pnation);
5269 char tmp[200] = "\0";
5270 const char *barb_type;
5271 const char *sec_name = section_name(section_list_get(sec, i));
5272 const char *legend;
5273
5274 /* Nation sets and groups. */
5275 if (default_set >= 0) {
5276 nation_set_list_append(pnation->sets,
5278 }
5279 vec = secfile_lookup_str_vec(file, &dim, "%s.groups", sec_name);
5280 for (j = 0; j < dim; j++) {
5281 struct nation_set *pset = nation_set_by_rule_name(vec[j]);
5283
5284 fc_assert(pset == NULL || pgroup == NULL);
5285
5286 if (NULL != pset) {
5287 nation_set_list_append(pnation->sets, pset);
5288 } else if (NULL != pgroup) {
5289 nation_group_list_append(pnation->groups, pgroup);
5290 } else {
5291 /* For nation authors, this would probably be considered an error.
5292 * But it can happen normally. The civ1 compatibility ruleset only
5293 * uses the nations that were in civ1, so not all of the links will
5294 * exist. */
5295 log_verbose("Nation %s: Unknown set/group \"%s\".",
5296 nation_rule_name(pnation), vec[j]);
5297 }
5298 }
5299 if (NULL != vec) {
5300 free(vec);
5301 }
5302 if (nation_set_list_size(pnation->sets) < 1) {
5304 "Nation %s is not a member of any nation set",
5305 nation_rule_name(pnation));
5306 ok = FALSE;
5307 break;
5308 }
5309
5310 /* Nation conflicts. */
5311 vec = secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec_name);
5312 for (j = 0; j < dim; j++) {
5314
5315 if (pnation == pconflict) {
5317 "Nation %s conflicts with itself",
5318 nation_rule_name(pnation));
5319 ok = FALSE;
5320 break;
5321 } else if (NULL != pconflict) {
5322 nation_list_append(pnation->server.conflicts_with, pconflict);
5323 } else {
5324 /* For nation authors, this would probably be considered an error.
5325 * But it can happen normally. The civ1 compatibility ruleset only
5326 * uses the nations that were in civ1, so not all of the links will
5327 * exist. */
5328 log_verbose("Nation %s: conflicts_with nation \"%s\" is unknown.",
5329 nation_rule_name(pnation), vec[j]);
5330 }
5331 }
5332 if (NULL != vec) {
5333 free(vec);
5334 }
5335 if (!ok) {
5336 break;
5337 }
5338
5339 /* Nation leaders. */
5340 for (j = 0; j < MAX_NUM_LEADERS; j++) {
5341 const char *sexstr;
5342 sex_t sex;
5343 bool is_male = FALSE;
5344
5345 name = secfile_lookup_str(file, "%s.leaders%d.name", sec_name, j);
5346 if (NULL == name) {
5347 /* No more to read. */
5348 break;
5349 }
5350
5351 if (check_name(name)) {
5352 /* The ruleset contains a name that is too long. This shouldn't
5353 * happen - if it does, the author should get immediate feedback */
5356 "Nation %s: leader name \"%s\" is too long.",
5357 nation_rule_name(pnation), name);
5358 ok = FALSE;
5359 break;
5360 }
5361
5362 sexstr = secfile_lookup_str(file, "%s.leaders%d.sex", sec_name, j);
5363 if (NULL == sexstr) {
5365 "Nation %s: leader \"%s\": %s.",
5366 nation_rule_name(pnation), name, secfile_error());
5367 ok = FALSE;
5368 break;
5369 }
5370
5372
5373 switch (sex) {
5374 case SEX_MALE:
5375 is_male = TRUE;
5376 break;
5377 case SEX_FEMALE:
5378 is_male = FALSE;
5379 break;
5380 case SEX_UNKNOWN:
5382 "Nation %s: leader \"%s\" has unsupported "
5383 "sex variant \"%s\".",
5384 nation_rule_name(pnation), name, sexstr);
5385 ok = FALSE;
5386 break;
5387 }
5388
5389 if (ok) {
5390 (void) nation_leader_new(pnation, name, is_male);
5391 }
5392 }
5393 if (!ok) {
5394 break;
5395 }
5396
5397 /* Check the number of leaders. */
5398 if (MAX_NUM_LEADERS == j) {
5399 /* Too much leaders, get the real number defined in the ruleset. */
5400 while (NULL != secfile_entry_lookup(file, "%s.leaders%d.name",
5401 sec_name, j)) {
5402 j++;
5403 }
5405 "Nation %s: Too many leaders; max is %d",
5407 ok = FALSE;
5408 break;
5409 } else if (0 == j) {
5411 "Nation %s: no leaders; at least one is required.",
5412 nation_rule_name(pnation));
5413 ok = FALSE;
5414 break;
5415 }
5416
5417 /* Check if leader name is not already defined in this nation. */
5418 if ((bad_leader = check_leader_names(pnation))) {
5420 "Nation %s: leader \"%s\" defined more than once.",
5421 nation_rule_name(pnation), bad_leader);
5422 ok = FALSE;
5423 break;
5424 }
5425
5426 /* Nation player color preference, if any */
5427 fc_assert_ret_val(pnation->server.rgb == NULL, FALSE);
5428 (void) rgbcolor_load(file, &pnation->server.rgb, "%s.color", sec_name);
5429
5430 /* Load nation traits */
5431 ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
5432 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5433 bool server_traits_used = TRUE;
5434
5435 if (pnation->server.traits[tr].min < 0) {
5436 pnation->server.traits[tr].min = game.server.default_traits[tr].min;
5437 } else {
5439 }
5440 if (pnation->server.traits[tr].max < 0) {
5441 pnation->server.traits[tr].max = game.server.default_traits[tr].max;
5442 } else {
5444 }
5445 if (pnation->server.traits[tr].fixed < 0) {
5446 if (server_traits_used) {
5447 pnation->server.traits[tr].fixed = game.server.default_traits[tr].fixed;
5448 } else {
5449 int diff = pnation->server.traits[tr].max - pnation->server.traits[tr].min;
5450
5451 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5452 pnation->server.traits[tr].fixed = diff / 2 + pnation->server.traits[tr].min;
5453 }
5454 }
5455 if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
5457 "%s values for trait %s not sane.",
5458 nation_rule_name(pnation), trait_name(tr));
5459 ok = FALSE;
5460 break;
5461 }
5462 }
5463
5464 if (!ok) {
5465 break;
5466 }
5467
5468 pnation->is_playable =
5469 secfile_lookup_bool_default(file, TRUE, "%s.is_playable", sec_name);
5470
5471 /* Check barbarian type. Default is "None" meaning not a barbarian */
5472 barb_type = secfile_lookup_str_default(file, "None",
5473 "%s.barbarian_type", sec_name);
5474 pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp);
5475 if (!barbarian_type_is_valid(pnation->barb_type)) {
5477 "Nation %s, barbarian_type is invalid (\"%s\")",
5478 nation_rule_name(pnation), barb_type);
5479 ok = FALSE;
5480 break;
5481 }
5482
5483 if (pnation->barb_type != NOT_A_BARBARIAN
5484 && pnation->is_playable) {
5485 /* We can't allow players to use barbarian nations, barbarians
5486 * may run out of nations */
5488 "Nation %s marked both barbarian and playable.",
5489 nation_rule_name(pnation));
5490 ok = FALSE;
5491 break;
5492 }
5493
5494 /* Flags */
5495 sz_strlcpy(pnation->flag_graphic_str,
5496 secfile_lookup_str_default(file, "-", "%s.flag", sec_name));
5497 sz_strlcpy(pnation->flag_graphic_alt,
5499 "%s.flag_alt", sec_name));
5500
5501 /* Ruler titles */
5502 for (j = 0;; j++) {
5503 const char *male, *female;
5504
5506 "%s.ruler_titles%d.government",
5507 sec_name, j);
5508 if (NULL == name) {
5509 /* End of the list of ruler titles. */
5510 break;
5511 }
5512
5513 /* NB: even if the government doesn't exist, we load the entries for
5514 * the ruler titles to avoid warnings about unused entries. */
5515 male = secfile_lookup_str(file, "%s.ruler_titles%d.male_title",
5516 sec_name, j);
5517 female = secfile_lookup_str(file, "%s.ruler_titles%d.female_title",
5518 sec_name, j);
5520
5521 /* Nationset may have been devised with a specific set of govs in
5522 * mind which don't quite match this ruleset, in which case we
5523 * (a) quietly ignore any govs mentioned that don't happen to be in
5524 * the current ruleset, (b) enforce that govs mentioned by nations
5525 * must be on the list */
5526 if (gov != NULL && game.server.ruledit.allowed_govs != NULL) {
5530 /* Gov exists, but not intended for these nations */
5531 gov = NULL;
5533 "Nation %s: government \"%s\" not in allowed_govs.",
5534 nation_rule_name(pnation), name);
5535 ok = FALSE;
5536 break;
5537 }
5538 } else if (!gov) {
5539 /* Gov doesn't exist; only complain if it's not on any list */
5545 "Nation %s: government \"%s\" not found.",
5546 nation_rule_name(pnation), name);
5547 ok = FALSE;
5548 break;
5549 }
5550 }
5551 if (NULL != male && NULL != female) {
5552 if (gov) {
5553 (void) government_ruler_title_new(gov, pnation, male, female);
5554 }
5555 } else {
5557 ok = FALSE;
5558 break;
5559 }
5560 }
5561 if (!ok) {
5562 break;
5563 }
5564
5565 /* City styles */
5566 name = secfile_lookup_str(file, "%s.style", sec_name);
5567 if (!name) {
5569 ok = FALSE;
5570 break;
5571 }
5572 pnation->style = style_by_rule_name(name);
5573 if (pnation->style == NULL) {
5579 "Nation %s: Illegal style \"%s\"",
5580 nation_rule_name(pnation), name);
5581 ok = FALSE;
5582 break;
5583 } else {
5584 log_verbose("Nation %s: style \"%s\" not supported in this "
5585 "ruleset; using default.",
5586 nation_rule_name(pnation), name);
5587 pnation->style = style_by_number(0);
5588 }
5589 }
5590
5591 /* Civilwar nations */
5592 vec = secfile_lookup_str_vec(file, &dim,
5593 "%s.civilwar_nations", sec_name);
5594 for (j = 0; j < dim; j++) {
5596
5597 /* No test for duplicate nations is performed. If there is a duplicate
5598 * entry it will just cause that nation to have an increased
5599 * probability of being chosen. */
5600 if (pconflict == pnation) {
5602 "Nation %s is its own civil war nation",
5603 nation_rule_name(pnation));
5604 ok = FALSE;
5605 break;
5606 } else if (NULL != pconflict) {
5607 nation_list_append(pnation->server.civilwar_nations, pconflict);
5608 nation_list_append(pconflict->server.parent_nations, pnation);
5609 } else {
5610 /* For nation authors, this would probably be considered an error.
5611 * But it can happen normally. The civ1 compatibility ruleset only
5612 * uses the nations that were in civ1, so not all of the links will
5613 * exist. */
5614 log_verbose("Nation %s: civil war nation \"%s\" is unknown.",
5615 nation_rule_name(pnation), vec[j]);
5616 }
5617 }
5618 if (NULL != vec) {
5619 free(vec);
5620 }
5621 if (!ok) {
5622 break;
5623 }
5624
5625 /* Load nation specific initial items */
5626 if (!lookup_tech_list(file, sec_name, "init_techs",
5627 pnation->init_techs, filename)) {
5628 ok = FALSE;
5629 break;
5630 }
5631 if (!lookup_building_list(file, sec_name, "init_buildings",
5632 pnation->init_buildings, filename)) {
5633 ok = FALSE;
5634 break;
5635 }
5636 if (!lookup_unit_list(file, sec_name, "init_units",
5637 pnation->init_units, filename)) {
5638 ok = FALSE;
5639 break;
5640 }
5641 fc_strlcat(tmp, sec_name, 200);
5642 fc_strlcat(tmp, ".init_government", 200);
5643 if (secfile_entry_by_path(file, tmp)) {
5644 pnation->init_government = lookup_government(file, tmp, filename,
5645 NULL);
5646 /* If specified, init_government has to be in this specific ruleset,
5647 * not just allowed_govs */
5648 if (pnation->init_government == NULL) {
5649 ok = FALSE;
5650 break;
5651 }
5652 /* ...but if a list of govs has been specified, enforce that this
5653 * nation's init_government is on the list. */
5655 && !is_on_allowed_list(government_rule_name(pnation->init_government),
5659 "Nation %s: init_government \"%s\" not allowed.",
5660 nation_rule_name(pnation),
5661 government_rule_name(pnation->init_government));
5662 ok = FALSE;
5663 break;
5664 }
5665 }
5666
5667 /* Read default city names. */
5668 if (!load_city_name_list(file, pnation, sec_name, "cities",
5671 ok = FALSE;
5672 break;
5673 }
5674
5675 legend = secfile_lookup_str_default(file, "", "%s.legend", sec_name);
5676 pnation->legend = fc_strdup(legend);
5677 if (check_strlen(pnation->legend, MAX_LEN_MSG, NULL)) {
5679 "Nation %s: legend \"%s\" is too long.",
5680 nation_rule_name(pnation),
5681 pnation->legend);
5682 ok = FALSE;
5683 break;
5684 }
5685
5686 pnation->player = NULL;
5689 sec = NULL;
5690 }
5691
5692 /* Clean up on aborted load */
5693 if (sec != NULL) {
5694 fc_assert(!ok);
5696 }
5697
5698 if (ok) {
5700 }
5701
5702 if (ok) {
5703 /* Update cached number of playable nations in the current set */
5705
5706 /* Sanity checks on all sets */
5709
5710 nations_iterate(pnation) {
5711 if (nation_is_in_set(pnation, pset)) {
5712 switch (nation_barbarian_type(pnation)) {
5713 case NOT_A_BARBARIAN:
5714 if (is_nation_playable(pnation)) {
5715 num_playable++;
5716 }
5717 break;
5718 case LAND_BARBARIAN:
5720 break;
5721 case SEA_BARBARIAN:
5723 break;
5724 case ANIMAL_BARBARIAN:
5725 /* Animals are optional */
5726 break;
5729 break;
5730 default:
5732 }
5733 }
5735 if (num_playable < 1) {
5737 "Nation set \"%s\" has no playable nations. "
5738 "At least one required!", nation_set_rule_name(pset));
5739 ok = FALSE;
5740 break;
5741 }
5742 if (barb_land_count == 0 && barb_both_count == 0) {
5744 "No land barbarian nation defined in set \"%s\". "
5745 "At least one required!", nation_set_rule_name(pset));
5746 ok = FALSE;
5747 break;
5748 }
5749 if (barb_sea_count == 0 && barb_both_count == 0) {
5751 "No sea barbarian nation defined in set \"%s\". "
5752 "At least one required!", nation_set_rule_name(pset));
5753 ok = FALSE;
5754 break;
5755 }
5757 }
5758
5759 return ok;
5760}
5761
5762/**********************************************************************/
5766static bool load_style_names(struct section_file *file,
5767 struct rscompat_info *compat)
5768{
5769 bool ok = TRUE;
5770 struct section_list *sec;
5771 const char *filename = secfile_name(file);
5772
5773 if (!rscompat_check_cap_and_version(file, filename, compat)) {
5774 return FALSE;
5775 }
5776
5777 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
5778 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
5779
5781 if (NULL == sec) {
5783 "No available nation styles in this ruleset!");
5784 ok = FALSE;
5785 } else {
5787
5789
5791 const int i = style_index(ps);
5792 const char *sec_name = section_name(section_list_get(sec, i));
5793
5794 ruleset_load_names(&ps->name, NULL, file, sec_name);
5796 }
5797
5799
5800 if (ok) {
5801 /* The citystyle sections: */
5802 int i = 0;
5803
5805 if (NULL != sec) {
5807 section_list_iterate(sec, style) {
5808 if (!ruleset_load_names(&city_styles[i].name, NULL, file, section_name(style))) {
5809 ok = FALSE;
5810 break;
5811 }
5812 i++;
5814
5816 } else {
5818 }
5819 }
5820
5821 return ok;
5822}
5823
5824/**********************************************************************/
5827static bool load_ruleset_styles(struct section_file *file,
5828 struct rscompat_info *compat)
5829{
5830 struct section_list *sec;
5831 int i;
5832 bool ok = TRUE;
5833
5834 /* City Styles ... */
5835
5837
5838 /* Get rest: */
5839 for (i = 0; i < game.control.num_city_styles; i++) {
5840 struct requirement_vector *reqs;
5841 const char *sec_name = section_name(section_list_get(sec, i));
5842
5843 sz_strlcpy(city_styles[i].graphic,
5844 secfile_lookup_str(file, "%s.graphic", sec_name));
5845 sz_strlcpy(city_styles[i].graphic_alt,
5846 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
5847 sz_strlcpy(city_styles[i].citizens_graphic,
5849 "%s.citizens_graphic", sec_name));
5850
5852 if (reqs == NULL) {
5853 ok = FALSE;
5854 break;
5855 }
5857 }
5858
5860
5861 if (ok) {
5863
5864 if (sec != NULL) {
5865 int musi;
5866
5869 musi = 0;
5870
5871 section_list_iterate(sec, psection) {
5872 struct requirement_vector *reqs;
5874 const char *sec_name = section_name(psection);
5875
5876 sz_strlcpy(pmus->music_peaceful,
5878 "%s.music_peaceful", sec_name));
5879 sz_strlcpy(pmus->music_combat,
5881 "%s.music_combat", sec_name));
5882
5883 reqs = lookup_req_list(file, sec_name, "reqs", "Music Style");
5884 if (reqs == NULL) {
5885 ok = FALSE;
5886 break;
5887 }
5889
5890 musi++;
5892 }
5893
5895 }
5896
5897 return ok;
5898}
5899
5900/**********************************************************************/
5907 const char *uflags_path,
5908 const char *filename)
5909{
5910 /* Add each listed protected unit type flag as a !present
5911 * requirement. */
5912 if (secfile_entry_lookup(file, "%s", uflags_path)) {
5914 size_t psize;
5915 int i;
5916
5919 "%s", uflags_path);
5920
5921 if (!protecor_flag) {
5922 /* Entity exists but couldn't read it. */
5924 "\"%s\": %s: bad unit type flag list.",
5925 filename, uflags_path);
5926
5927 return FALSE;
5928 }
5929
5930 for (i = 0; i < psize; i++) {
5934 FALSE, FALSE, TRUE,
5935 protecor_flag[i]));
5936 }
5937
5939 }
5940
5941 return TRUE;
5942}
5943
5944/**********************************************************************/
5950 const char *actions_path,
5951 const char *filename)
5952{
5953 /* Read the alternative actions. */
5954 if (secfile_entry_lookup(file, "%s", actions_path)) {
5955 enum gen_action *unit_acts;
5956 size_t asize;
5957 int i;
5958
5960 "%s", actions_path);
5961
5962 if (!unit_acts) {
5963 /* Entity exists but couldn't read it. */
5965 "\"%s\": %s: bad action list",
5966 filename, actions_path);
5967
5968 return FALSE;
5969 }
5970
5971 for (i = 0; i < asize; i++) {
5972 auto_perf->alternatives[i] = unit_acts[i];
5973 }
5974
5975 free(unit_acts);
5976 }
5977
5978 return TRUE;
5979}
5980
5981/**********************************************************************/
5986 const char *item,
5987 const char *filename)
5988{
5989 char uflags_path[100];
5990 char action_path[100];
5991
5993 "missing_unit_upkeep.%s_protected", item);
5995 "missing_unit_upkeep.%s_unit_act", item);
5996
5998 filename)
6000 filename));
6001}
6002
6003/**********************************************************************/
6007static bool load_specialist(const struct section *psection,
6008 struct specialist *s,
6009 struct section_file *file)
6010{
6011 struct requirement_vector *reqs;
6012 const char *sec_name = section_name(psection);
6013 const char *item, *tag;
6014
6015 if (!ruleset_load_names(&s->name, nullptr, file, sec_name)) {
6016 return FALSE;
6017 }
6018
6020 "%s.short_name", sec_name);
6021 name_set(&s->abbreviation, nullptr, item);
6022
6023 tag = secfile_lookup_str(file, "%s.graphic", sec_name);
6024 if (nullptr == tag) {
6025 ruleset_error(nullptr, LOG_ERROR,
6026 "\"%s\": No graphic tag for specialist at %s.",
6027 secfile_name(file), sec_name);
6028 return FALSE;
6029 }
6030 sz_strlcpy(s->graphic_str, tag);
6033 "%s.graphic_alt", sec_name));
6034
6036 if (nullptr == reqs) {
6037 return FALSE;
6038 }
6040
6041 s->helptext = lookup_strvec(file, sec_name, "helptext");
6042
6043 return TRUE;
6044}
6045
6046/**********************************************************************/
6049static bool load_ruleset_cities(struct section_file *file,
6050 struct rscompat_info *compat)
6051{
6052 const char *filename = secfile_name(file);
6053 struct section_list *sec, *ssec = nullptr;
6054 int specs_count;
6055 bool ok = TRUE;
6056 int i = 0;
6057
6058 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6059 return FALSE;
6060 }
6061
6062 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6063 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6064
6065 /* Specialist options */
6067
6068 if (!sec) {
6069 ruleset_error(nullptr, LOG_ERROR, "\"%s\": No normal specialists.", filename);
6070
6071 ok = FALSE;
6072 } else {
6075 /* Superspecialists are optional */
6076 if (ssec) {
6078 }
6079 if (specs_count >= SP_MAX) {
6080 ruleset_error(nullptr, LOG_ERROR,
6081 "\"%s\": Too many specialists (%d, max %d).",
6082 filename, specs_count, SP_MAX);
6083 ok = FALSE;
6084 }
6085 }
6086
6087
6088 if (ok) {
6090
6091 section_list_iterate(sec, psection) {
6092 struct specialist *s = specialist_by_number(i);
6093
6094 ok = load_specialist(psection, s, file);
6095
6096 if (!ok) {
6097 break;
6098 }
6099
6100 if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
6102 }
6103 i++;
6105 }
6106
6107 if (ok){
6108 if (DEFAULT_SPECIALIST == -1) {
6109 ruleset_error(nullptr, LOG_ERROR,
6110 "\"%s\": must have zero reqs for at least one "
6111 "specialist type.", filename);
6112 ok = FALSE;
6113 } else {
6115 }
6116 }
6118 sec = nullptr;
6119
6120 if (ssec) {
6121 if (ok) {
6122 section_list_iterate(ssec, psection) {
6123 struct specialist *s = specialist_by_number(i);
6124
6125 ok = load_specialist(psection, s, file);
6126
6127 if (!ok) {
6128 break;
6129 }
6130
6131 i++;
6133 }
6134
6136 ssec = nullptr;
6137 }
6138
6139 if (ok) {
6140 /* City Parameters */
6141
6144 "parameters.celebrate_size_limit");
6146 secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
6149 "parameters.angry_citizens");
6150
6152 secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
6154 secfile_lookup_int_default(file, 0, "parameters.forced_science");
6156 secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
6158 secfile_lookup_int_default(file, 0, "parameters.forced_gold");
6160 + game.info.forced_gold != 100) {
6162 "\"%s\": Forced taxes do not add up in ruleset!",
6163 filename);
6164 ok = FALSE;
6165 }
6166 }
6167
6168 if (ok) {
6169 /* civ1 & 2 didn't reveal tiles */
6172 "parameters.vision_reveal_tiles");
6173
6175 secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
6176
6177 /* Citizens configuration. */
6180 "citizen.nationality");
6183 "citizen.ubuilder_nationality");
6186 "citizen.convert_speed");
6188 secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
6190 secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
6191 }
6192
6193 if (ok) {
6194 /* Missing unit upkeep. */
6196
6197 /* Can't pay food upkeep! */
6199 auto_perf->cause = AAPC_UNIT_UPKEEP;
6200
6201 /* This is about food upkeep. */
6203 req_from_str("OutputType", "Local",
6204 FALSE, TRUE, TRUE,
6205 "Food"));
6206
6207 /* Internally represented as an action auto performer rule. */
6208 if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
6209 ok = FALSE;
6210 }
6211
6214 "missing_unit_upkeep.food_wipe");
6215
6216 /* Can't pay gold upkeep! */
6218 auto_perf->cause = AAPC_UNIT_UPKEEP;
6219
6220 /* This is about gold upkeep. */
6222 req_from_str("OutputType", "Local",
6223 FALSE, TRUE, TRUE,
6224 "Gold"));
6225
6226 /* Internally represented as an action auto performer rule. */
6227 if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
6228 ok = FALSE;
6229 }
6230
6233 "missing_unit_upkeep.gold_wipe");
6234
6235 /* Can't pay shield upkeep! */
6237 auto_perf->cause = AAPC_UNIT_UPKEEP;
6238
6239 /* This is about shield upkeep. */
6241 req_from_str("OutputType", "Local",
6242 FALSE, TRUE, TRUE,
6243 "Shield"));
6244
6245 /* Internally represented as an action auto performer rule. */
6246 if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
6247 ok = FALSE;
6248 }
6249
6252 "missing_unit_upkeep.shield_wipe");
6253 }
6254
6255 if (ok) {
6257 }
6258
6259 return ok;
6260}
6261
6262/**********************************************************************/
6265static bool load_ruleset_effects(struct section_file *file,
6266 struct rscompat_info *compat)
6267{
6268 struct section_list *sec;
6269 const char *filename;
6270 bool ok = TRUE;
6271
6272 filename = secfile_name(file);
6273
6274 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6275 return FALSE;
6276 }
6277
6278 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6279 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6280
6282
6283 if (sec != NULL) {
6284 section_list_iterate(sec, psection) {
6285 const char *sec_name = section_name(psection);
6286 enum effect_type main_type;
6287 enum effect_type ai_valued_as;
6288 const char *type;
6289
6290 type = secfile_lookup_str(file, "%s.type", sec_name);
6291 if (type == NULL) {
6293 "\"%s\" [%s] missing effect type.",
6294 filename, sec_name);
6295 ok = FALSE;
6296 break;
6297 }
6301 "\"%s\" [%s] lists unknown effect type \"%s\".",
6302 filename, sec_name, type);
6303 ok = FALSE;
6304 break;
6305 }
6306 if (!is_user_effect(main_type)) {
6308 "\"%s\" [%s] type \"%s\" is not an user effect.",
6309 filename, sec_name, type);
6310 ok = FALSE;
6311 break;
6312 }
6313
6314 type = secfile_lookup_str(file, "%s.ai_valued_as", sec_name);
6315 if (type == NULL) {
6317 "\"%s\" [%s] missing ai_valued_as.",
6318 filename, sec_name);
6319 ok = FALSE;
6320 break;
6321 }
6325 "\"%s\" [%s] lists unknown ai_valued_as \"%s\".",
6326 filename, sec_name, type);
6327 ok = FALSE;
6328 break;
6329 }
6332 "\"%s\" [%s] ai_valued_as \"%s\" is an user effect.",
6333 filename, sec_name, type);
6334 ok = FALSE;
6335 break;
6336 }
6337
6339 /* It has been set already! */
6341 "\"%s\" [%s] Duplicate \"%s\" entry.",
6342 filename, sec_name, type);
6343 ok = FALSE;
6344 break;
6345 }
6346
6349
6351 }
6352
6353 /* Parse effects and add them to the effects ruleset cache. */
6355 section_list_iterate(sec, psection) {
6356 enum effect_type eff;
6357 int value;
6358 struct multiplier *pmul;
6359 struct effect *peffect;
6360 const char *sec_name = section_name(psection);
6361 struct requirement_vector *reqs;
6362 const char *type;
6363 const char *comment;
6364
6365 type = secfile_lookup_str(file, "%s.type", sec_name);
6366
6367 if (type == NULL) {
6369 "\"%s\" [%s] missing effect type.",
6370 filename, sec_name);
6371 ok = FALSE;
6372 break;
6373 }
6374
6375 if (compat->compat_mode && compat->version < RSFORMAT_3_4) {
6377 }
6378
6380 if (!effect_type_is_valid(eff)) {
6382 "\"%s\" [%s] lists unknown effect type \"%s\".",
6383 filename, sec_name, type);
6384 ok = FALSE;
6385 break;
6386 }
6387
6388 value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
6389
6390 {
6391 const char *multiplier_name
6392 = secfile_lookup_str(file, "%s.multiplier", sec_name);
6393
6394 if (multiplier_name) {
6396 if (!pmul) {
6398 "\"%s\" [%s] has unknown multiplier \"%s\".",
6399 filename, sec_name, multiplier_name);
6400 ok = FALSE;
6401 break;
6402 }
6403 } else {
6404 pmul = NULL;
6405 }
6406 }
6407
6408 peffect = effect_new(eff, value, pmul);
6409
6410 reqs = lookup_req_list(file, sec_name, "reqs", type);
6411 if (reqs == NULL) {
6412 ok = FALSE;
6413 break;
6414 }
6415
6419
6420 comment = secfile_lookup_str_default(file, NULL, "%s.comment", sec_name);
6421
6422 if (comment != NULL) {
6423 peffect->rulesave.comment = fc_strdup(comment);
6424 }
6425
6428
6429 if (ok) {
6431 }
6432
6433 return ok;
6434}
6435
6436/**********************************************************************/
6440 int def, int min, int max,
6441 const char *path, ...)
6442{
6443 char fullpath[256];
6444 int ival;
6445 va_list args;
6446
6447 va_start(args, path);
6448 fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
6449 va_end(args);
6450
6451 if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
6452 ival = def;
6453 }
6454
6455 if (ival < min) {
6457 "\"%s\" should be in the interval [%d, %d] "
6458 "but is %d; using the minimal value.",
6459 fullpath, min, max, ival);
6460 ival = min;
6461 }
6462
6463 if (ival > max) {
6465 "\"%s\" should be in the interval [%d, %d] "
6466 "but is %d; using the maximal value.",
6467 fullpath, min, max, ival);
6468 ival = max;
6469 }
6470
6471 return ival;
6472}
6473
6474/**********************************************************************/
6477static bool load_action_range_max(struct section_file *file, action_id act)
6478{
6479 struct action *paction = action_by_number(act);
6480 const char *vname = action_max_range_ruleset_var_name(act);
6481
6482 if (vname != NULL) {
6483 struct entry *pentry;
6484 int max_range;
6485
6486 pentry = secfile_entry_lookup(file, "actions.%s", vname);
6487
6488 if (pentry == NULL) {
6490 } else {
6491 const char *custom;
6492
6495 /* max_range already assigned */
6496 } else if (entry_type_get(pentry) == ENTRY_STR
6500 } else {
6501 ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
6504
6505 return FALSE;
6506 }
6507 }
6508
6510 }
6511
6512 return TRUE;
6513}
6514
6515/**********************************************************************/
6518static bool load_action_range(struct section_file *file, action_id act)
6519{
6520 struct action *paction = action_by_number(act);
6521 const char *vname;
6522
6523 if (!load_action_range_max(file, act)) {
6524 return FALSE;
6525 }
6526
6528 if (vname != NULL) {
6529 /* Min range can be loaded from the ruleset. */
6533 "actions.%s",
6534 vname);
6535 }
6536
6537 return TRUE;
6538}
6539
6540/**********************************************************************/
6543static bool load_action_kind(struct section_file *file, action_id act)
6544{
6545 struct action *paction = action_by_number(act);
6547
6548 if (var_name != NULL) {
6552 paction->result),
6554 "actions.%s", var_name);
6555 } else {
6558 }
6559
6560 return TRUE;
6561}
6562
6563/**********************************************************************/
6567 action_id act)
6568{
6570 /* Actor consumption can be loaded from the ruleset. */
6573 file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
6575 }
6576
6577 return TRUE;
6578}
6579
6580/**********************************************************************/
6584 const char *filename,
6585 struct action *paction,
6586 struct rscompat_info *compat)
6587{
6589
6590 if (var_name != nullptr) {
6591 /* Action blocking can be loaded from the ruleset. */
6592 char fullpath[1024];
6593
6594 fc_snprintf(fullpath, sizeof(fullpath), "actions.%s", var_name);
6595
6596 if (secfile_entry_by_path(file, fullpath)) {
6598 size_t asize;
6599 int j;
6600
6603
6604 if (!blocking_actions) {
6605 /* Entity exists but couldn't read it. */
6607 "\"%s\": %s: bad action list",
6608 filename, fullpath);
6609
6610 return FALSE;
6611 }
6612
6613 for (j = 0; j < asize; j++) {
6614 BV_SET(paction->blocked_by, blocking_actions[j]);
6615 }
6616
6618 }
6619 }
6620
6621 return TRUE;
6622}
6623
6624/**********************************************************************/
6629 const char *filename,
6630 int performer_slot,
6631 struct action *paction)
6632{
6634 char action_list_path[100];
6635
6637 /* Not relevant. */
6638 return TRUE;
6639 }
6640
6642 auto_perf->cause = AAPC_POST_ACTION;
6643
6644 /* Limit auto performer to this action. */
6647 FALSE, TRUE, TRUE,
6648 paction->id));
6649
6650 /* Load the list of actions. */
6652 "actions.%s",
6655 action_list_path, filename)) {
6656 return FALSE;
6657 }
6658
6659 return TRUE;
6660}
6661
6662/**********************************************************************/
6665static bool lookup_bv_actions(struct section_file *file,
6666 const char *filename,
6667 bv_actions *target,
6668 const char *path)
6669{
6670 if (secfile_entry_by_path(file, path)) {
6672 size_t asize;
6673 int j;
6674
6676 "%s", path);
6677
6678 if (!listed_actions) {
6679 /* Entity exists but couldn't read it. */
6680 ruleset_error(NULL, LOG_ERROR, "\"%s\": %s: bad action list",
6681 filename, path);
6682
6683 return FALSE;
6684 }
6685
6686 for (j = 0; j < asize; j++) {
6687 BV_SET(*target, listed_actions[j]);
6688 }
6689
6691 }
6692
6693 return TRUE;
6694}
6695
6696/**********************************************************************/
6699static bool load_ruleset_game(struct section_file *file, bool act,
6700 struct rscompat_info *compat)
6701{
6702 const char *sval, **svec;
6703 const char *filename;
6704 int *food_ini;
6705 int i;
6706 size_t teams;
6707 const char *pref_text;
6708 size_t gni_tmp;
6709 struct section_list *sec;
6710 size_t nval;
6711 const char *name;
6712 bool ok = TRUE;
6713
6714 if (file == NULL) {
6715 return FALSE;
6716 }
6717 filename = secfile_name(file);
6718
6719 name = secfile_lookup_str_default(file, NULL, "ruledit.description_file");
6720 if (name != NULL) {
6722 }
6724 = secfile_lookup_bool_default(file, FALSE, "ruledit.std_tileset_compat");
6725
6726 /* Section: tileset */
6727 pref_text = secfile_lookup_str_default(file, "", "tileset.preferred");
6728 if (pref_text[0] != '\0') {
6729 /* There was tileset suggestion */
6731 } else {
6732 /* No tileset suggestions */
6733 game.control.preferred_tileset[0] = '\0';
6734 }
6735
6736 /* Section: soundset */
6737 pref_text = secfile_lookup_str_default(file, "", "soundset.preferred");
6738 if (pref_text[0] != '\0') {
6739 /* There was soundset suggestion */
6741 } else {
6742 /* No soundset suggestions */
6744 }
6745
6746 /* Section: musicset */
6747 pref_text = secfile_lookup_str_default(file, "", "musicset.preferred");
6748 if (pref_text[0] != '\0') {
6749 /* There was musicset suggestion */
6751 } else {
6752 /* No musicset suggestions */
6754 }
6755
6756 /* Section: about */
6757 pref_text = secfile_lookup_str(file, "about.name");
6758 /* Ruleset/modpack name found */
6760
6761 pref_text = secfile_lookup_str_default(file, "", "about.version");
6762 if (pref_text[0] != '\0') {
6763 /* Ruleset/modpack version found */
6765 } else {
6766 /* No version information */
6767 game.control.version[0] = '\0';
6768 }
6769
6770 pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
6771 if (pref_text[0] != '\0') {
6772 /* Alt directory definition found. */
6774 } else {
6775 /* No alt directory information */
6776 game.control.alt_dir[0] = '\0';
6777 }
6778
6779 pref_text = secfile_lookup_str_default(file, "", "about.summary");
6780 if (pref_text[0] != '\0') {
6781 int len;
6782
6783 /* Ruleset/modpack summary found */
6784 len = strlen(pref_text);
6787 } else {
6788 /* No summary */
6789 if (game.ruleset_summary != NULL) {
6792 }
6793 }
6794
6795 pref_text = secfile_lookup_str_default(file, "", "about.description");
6796 if (pref_text[0] != '\0') {
6797 int len;
6798
6799 /* Ruleset/modpack description found */
6800 len = strlen(pref_text);
6804 } else {
6805 /* No description */
6806 if (game.ruleset_description != NULL) {
6809 }
6811 }
6812
6813 pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
6814 if (pref_text[0] != '\0') {
6815 int len = strlen(pref_text);
6816
6819 } else {
6821 game.ruleset_capabilities[0] = '\0';
6822 }
6823
6824 /* Section: options */
6825 if (!lookup_tech_list(file, "options", "global_init_techs",
6826 game.rgame.global_init_techs, filename)) {
6827 ok = FALSE;
6828 }
6829
6830 if (ok) {
6831 if (!lookup_building_list(file, "options", "global_init_buildings",
6832 game.rgame.global_init_buildings, filename)) {
6833 ok = FALSE;
6834 }
6835 }
6836
6837 if (ok) {
6838 const char **slist;
6839 int j;
6840
6842 "options.popup_tech_help");
6843
6844 /* section: civstyle */
6847 "civstyle.base_pollution");
6848
6850
6851 slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
6852 for (j = 0; j < nval; j++) {
6853 enum gameloss_style style;
6854
6855 sval = slist[j];
6856 if (strcmp(sval, "") == 0) {
6857 continue;
6858 }
6860 if (!gameloss_style_is_valid(style)) {
6862 "\"%s\": bad value \"%s\" for gameloss_style.",
6863 filename, sval);
6864 ok = FALSE;
6865 break;
6866 } else {
6867 game.info.gameloss_style |= style;
6868 }
6869 }
6870 free(slist);
6871 }
6872
6873 if (ok) {
6879 "civstyle.happy_cost");
6885 "civstyle.food_cost");
6891 "civstyle.base_bribe_cost");
6897 "civstyle.ransom_gold");
6900 "civstyle.pillage_select");
6901
6904 "civstyle.tech_steal_allow_holes");
6907 "civstyle.tech_trade_allow_holes");
6910 "civstyle.tech_trade_loss_allow_holes");
6913 "civstyle.tech_parasite_allow_holes");
6916 "civstyle.tech_loss_allow_holes");
6917
6923 "civstyle.upgrade_veteran_loss");
6929 "civstyle.autoupgrade_veteran_loss");
6930
6936 "research.base_tech_cost");
6937
6943 "research.min_tech_cost");
6944
6946 "civstyle.granary_food_ini");
6948
6951 "Too many granary_food_ini entries (%d, max %d)",
6953 ok = FALSE;
6954 } else if (game.info.granary_num_inis == 0) {
6955 log_error("No values for granary_food_ini. Using default "
6956 "value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
6959 } else {
6960 int gi;
6961
6962 /* check for <= 0 entries */
6963 for (gi = 0; gi < game.info.granary_num_inis; gi++) {
6964 if (food_ini[gi] <= 0) {
6965 if (gi == 0) {
6967 } else {
6968 food_ini[gi] = food_ini[gi - 1];
6969 }
6970 log_error("Bad value for granary_food_ini[%i]. Using %i.",
6971 gi, food_ini[gi]);
6972 }
6974 }
6975 }
6976 free(food_ini);
6977 }
6978
6979 if (ok) {
6985 "civstyle.granary_food_inc");
6986
6993 "civstyle.min_city_center_%s",
6996 }
6997
6998 if (ok) {
6999 const char *tus_text;
7000
7006 "civstyle.init_vis_radius_sq");
7007
7013 "civstyle.init_city_radius_sq");
7014
7016 "civstyle.gold_upkeep_style");
7021 "Unknown gold upkeep style \"%s\"",
7022 tus_text);
7023 ok = FALSE;
7024 }
7025
7026 if (compat->compat_mode
7027 && compat->version < RSFORMAT_3_4) {
7029 = secfile_lookup_bool_default(file, FALSE, "civstyle.homeless_gold_upkeep");
7030
7034 "Cannot have homeless_gold_upkeep while gold_upkeep_style \"City\".");
7035 ok = FALSE;
7036 }
7037 } else {
7039 }
7040
7042 "civstyle.output_granularity");
7043
7045 = secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
7046
7048 = secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
7049
7050 /* Section: wonder_visibility */
7051 if (ok) {
7052 const char *text;
7053
7054 text = secfile_lookup_str_default(file,
7056 "wonder_visibility.small_wonders");
7057
7062 "Unknown wonder visibility type \"%s\"",
7063 text);
7064 ok = FALSE;
7065 }
7066 }
7067
7068 /* section: illness */
7071 "illness.illness_on");
7077 "illness.illness_base_factor");
7083 "illness.illness_min_size");
7089 "illness.illness_trade_infection");
7095 "illness.illness_pollution_factor");
7096
7097 /* section: incite_cost */
7103 "incite_cost.base_incite_cost");
7109 "incite_cost.improvement_factor");
7115 "incite_cost.unit_factor");
7121 "incite_cost.total_factor");
7122 }
7123
7124 if (ok) {
7125 const char *tus_text;
7126
7127 /* Section: combat_rules */
7130 "combat_rules.tired_attack");
7131
7134 "combat_rules.only_killing_makes_veteran");
7135
7138 "combat_rules.only_real_fight_makes_veteran");
7139
7142 "combat_rules.combat_odds_scaled_veterancy");
7143
7146 "combat_rules.damage_reduces_bombard_rate");
7147
7150 "combat_rules.low_firepower_badwallattacker");
7153 "combat_rules.low_firepower_pearl_harbor");
7154
7157 "combat_rules.low_firepower_combat_bonus");
7160 "combat_rules.low_firepower_nonnat_bombard");
7161
7166 "combat_rules.nuke_pop_loss_pct");
7167
7172 "combat_rules.nuke_defender_survival_chance_pct");
7173
7174 /* section: borders */
7180 "borders.radius_sq_city");
7186 "borders.size_effect");
7187
7193 "borders.radius_sq_city_permanent");
7194
7195 /* section: research */
7197 "research.tech_cost_style");
7202 "Unknown tech cost style \"%s\"",
7203 tus_text);
7204 ok = FALSE;
7205 }
7206
7208 "research.tech_leakage");
7213 "Unknown tech leakage \"%s\"",
7214 tus_text);
7215 ok = FALSE;
7216 }
7219 log_error("Only tech_leakage \"%s\" supported with "
7220 "tech_cost_style \"%s\". ",
7223 log_error("Switching to tech_leakage \"%s\".",
7226 }
7232 "research.base_tech_cost");
7233
7235 "research.tech_upkeep_style");
7236
7238
7241 "Unknown tech upkeep style \"%s\"",
7242 tus_text);
7243 ok = FALSE;
7244 }
7245 }
7246
7247 if (ok) {
7253 "research.tech_upkeep_divider");
7254
7255 sval = secfile_lookup_str_default(file, NULL, "research.free_tech_method");
7256 if (sval == NULL) {
7258 "No free_tech_method given");
7259 ok = FALSE;
7260 } else {
7264 "Bad value %s for free_tech_method.", sval);
7265 ok = FALSE;
7266 }
7267 }
7268 }
7269
7270 if (ok) {
7271 int cf;
7272
7273 /* section: culture */
7276 "culture.victory_min_points");
7279 "culture.victory_lead_pct");
7282 "culture.migration_pml");
7285 "culture.history_interest_pml");
7286
7287 /* section: world_peace */
7290 "world_peace.victory_turns");
7291
7292 /* section: calendar */
7295 "calendar.skip_year_0");
7298 "calendar.start_year");
7300 = secfile_lookup_int_default(file, 0, "calendar.fragments");
7301
7304 "Too many calendar fragments. Max is %d",
7306 ok = FALSE;
7308 }
7312 "calendar.positive_label"));
7316 "calendar.negative_label"));
7317
7318 for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
7319 const char *fname;
7320
7321 fname = secfile_lookup_str_default(file, NULL, "calendar.fragment_name%d", cf);
7322 if (fname != NULL) {
7325 }
7326 }
7327 }
7328
7329 if (ok) {
7330 /* section playercolors */
7331 struct rgbcolor *prgbcolor = NULL;
7332 bool color_read = TRUE;
7333
7334 /* Check if the player list is defined and empty. */
7335 if (playercolor_count() != 0) {
7336 ok = FALSE;
7337 } else {
7338 i = 0;
7339
7340 while (color_read) {
7341 prgbcolor = NULL;
7342
7343 color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
7344 if (color_read) {
7346 }
7347
7348 i++;
7349 }
7350
7351 if (playercolor_count() == 0) {
7352 ruleset_error(NULL, LOG_ERROR, "No player colors defined!");
7353 ok = FALSE;
7354 }
7355
7356 if (ok) {
7358 if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
7360 "No background player color defined! (%s)",
7361 secfile_error());
7362 ok = FALSE;
7363 }
7364 }
7365 }
7366 }
7367
7368 if (ok) {
7369 /* section: teams */
7370 svec = secfile_lookup_str_vec(file, &teams, "teams.names");
7371 if (team_slot_count() < teams) {
7373 }
7375 for (i = 0; i < teams; i++) {
7377 }
7378 free(svec);
7379
7381 nval = (NULL != sec ? section_list_size(sec) : 0);
7382 if (nval > MAX_DISASTER_TYPES) {
7383 int num = nval; /* No "size_t" to printf */
7384
7386 "\"%s\": Too many disaster types (%d, max %d)",
7387 filename, num, MAX_DISASTER_TYPES);
7389 ok = FALSE;
7390 } else {
7392 }
7393 }
7394
7395 if (ok) {
7397 int id = disaster_index(pdis);
7398 int j;
7399 size_t eff_count;
7400 struct requirement_vector *reqs;
7401 const char *sec_name = section_name(section_list_get(sec, id));
7402
7403 if (!ruleset_load_names(&pdis->name, NULL, file, sec_name)) {
7405 "\"%s\": Cannot load disaster names",
7406 filename);
7407 ok = FALSE;
7408 break;
7409 }
7410
7412 if (reqs == NULL) {
7413 ok = FALSE;
7414 break;
7415 }
7417
7419 "%s.frequency", sec_name);
7420
7421 svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
7422
7423 BV_CLR_ALL(pdis->effects);
7424 for (j = 0; j < eff_count; j++) {
7425 const char *dsval = svec[j];
7427
7429
7432 "\"%s\" disaster \"%s\": unknown effect \"%s\".",
7433 filename, disaster_rule_name(pdis), dsval);
7434 ok = FALSE;
7435 break;
7436 } else {
7437 BV_SET(pdis->effects, effect);
7438 }
7439 }
7440
7441 free(svec);
7442
7443 if (!ok) {
7444 break;
7445 }
7448 }
7449
7450 if (ok) {
7452
7454 int id = achievement_index(pach);
7455 const char *sec_name = section_name(section_list_get(sec, id));
7456 const char *typename;
7457 const char *msg;
7458
7459 typename = secfile_lookup_str_default(file, NULL, "%s.type", sec_name);
7460
7461 pach->type = achievement_type_by_name(typename, fc_strcasecmp);
7462 if (!achievement_type_is_valid(pach->type)) {
7464 "Achievement has unknown type \"%s\".",
7465 typename != NULL ? typename : "(NULL)");
7466 ok = FALSE;
7467 }
7468
7469 if (ok) {
7471 "%s.unique", sec_name);
7472
7474 "%s.value", sec_name);
7475 pach->culture = secfile_lookup_int_default(file, 0,
7476 "%s.culture", sec_name);
7477
7478 msg = secfile_lookup_str_default(file, NULL, "%s.first_msg", sec_name);
7479 if (msg == NULL) {
7481 "Achievement %s has no first msg!", sec_name);
7482 ok = FALSE;
7483 } else {
7484 pach->first_msg = fc_strdup(msg);
7485 }
7486 }
7487
7488 if (ok) {
7489 msg = secfile_lookup_str_default(file, NULL, "%s.cons_msg", sec_name);
7490 if (msg == NULL) {
7491 if (!pach->unique) {
7493 "Achievement %s has no msg for consecutive gainers!",
7494 sec_name);
7495 ok = FALSE;
7496 }
7497 } else {
7498 pach->cons_msg = fc_strdup(msg);
7499 }
7500 }
7501
7502 if (!ok) {
7503 break;
7504 }
7507 }
7508
7509 if (ok) {
7510 for (i = 0; (name = secfile_lookup_str_default(file, NULL,
7511 "trade.settings%d.type",
7512 i)); i++) {
7514
7515 if (type == TRT_LAST) {
7517 "\"%s\" unknown trade route type \"%s\".",
7518 filename, name);
7519 ok = FALSE;
7520 } else {
7522 const char *cancelling;
7523 const char *bonus;
7524
7525 set->trade_pct = secfile_lookup_int_default(file, 100,
7526 "trade.settings%d.pct", i);
7527 cancelling = secfile_lookup_str_default(file, "Active",
7528 "trade.settings%d.cancelling", i);
7530 if (set->cancelling == TRI_LAST) {
7532 "\"%s\" unknown trade route cancelling type \"%s\".",
7533 filename, cancelling);
7534 ok = FALSE;
7535 }
7536
7537 bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
7538
7540
7543 "\"%s\" unknown trade route bonus type \"%s\".",
7544 filename, bonus);
7545 ok = FALSE;
7546 }
7547 }
7548 }
7549 }
7550
7551 if (ok) {
7552 const char *str;
7553
7555 = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
7556
7559 "trade.reveal_trade_partner");
7560
7563 "trade.goods_selection");
7564
7566
7569 "\"%s\" goods selection method \"%s\" unknown.",
7570 filename, str);
7571 ok = FALSE;
7572 }
7573 }
7574
7575 if (ok) {
7577
7579 int id = goods_index(pgood);
7580 const char *sec_name = section_name(section_list_get(sec, id));
7581 struct requirement_vector *reqs;
7582 const char **slist;
7583 int j;
7584
7586 if (reqs == NULL) {
7587 ok = FALSE;
7588 break;
7589 }
7591
7592 pgood->from_pct = secfile_lookup_int_default(file, 100,
7593 "%s.from_pct", sec_name);
7594 pgood->to_pct = secfile_lookup_int_default(file, 100,
7595 "%s.to_pct", sec_name);
7596 pgood->onetime_pct = secfile_lookup_int_default(file, 100,
7597 "%s.onetime_pct", sec_name);
7598 pgood->select_priority = secfile_lookup_int_default(file, 1,
7599 "%s.select_priority", sec_name);
7600 pgood->replace_priority = secfile_lookup_int_default(file, 1,
7601 "%s.replace_priority", sec_name);
7602
7603 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
7604 BV_CLR_ALL(pgood->flags);
7605 for (j = 0; j < nval; j++) {
7606 enum goods_flag_id flag;
7607
7608 sval = slist[j];
7610 if (!goods_flag_id_is_valid(flag)) {
7611 ruleset_error(NULL, LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
7612 filename, goods_rule_name(pgood), sval);
7613 ok = FALSE;
7614 break;
7615 } else {
7616 BV_SET(pgood->flags, flag);
7617 }
7618 }
7619 free(slist);
7620
7621 pgood->helptext = lookup_strvec(file, sec_name, "helptext");
7624 }
7625
7626 if (ok) {
7627 const char *uname = secfile_lookup_str_default(file, nullptr,
7628 "aarea.access_unit");
7629 const struct unit_type *access_unit = nullptr;
7630
7631 if (uname != nullptr && uname[0] != '\0') {
7632 access_unit = unit_type_by_rule_name(uname);
7633
7634 if (access_unit == nullptr) {
7635 ruleset_error(nullptr, LOG_ERROR, "%s: access unit %s unknown.",
7636 filename, uname);
7637 ok = FALSE;
7638 }
7639 }
7640
7641 access_info_init(access_unit);
7642 }
7643
7644 if (ok) {
7646
7647 if (sec != NULL) {
7648 int num = section_list_size(sec);
7649
7650 for (i = 0; i < num; i++) {
7651 const char *sec_name = section_name(section_list_get(sec, i));
7652 const char *clause_name = secfile_lookup_str_default(file, NULL,
7653 "%s.type", sec_name);
7655 struct clause_info *info;
7656 struct requirement_vector *reqs;
7657
7658 if (!clause_type_is_valid(type)) {
7660 "\"%s\" unknown clause type \"%s\".",
7661 filename, clause_name);
7662 ok = FALSE;
7663 break;
7664 }
7665
7666 info = clause_info_get(type);
7667
7668 if (info->enabled) {
7670 "\"%s\" duplicate clause type \"%s\" definition.",
7671 filename, clause_name);
7672 ok = FALSE;
7673 break;
7674 }
7675
7676 reqs = lookup_req_list(file, sec_name, "giver_reqs", clause_name);
7677 if (reqs == NULL) {
7678 ok = FALSE;
7679 break;
7680 }
7682
7683 reqs = lookup_req_list(file, sec_name, "receiver_reqs", clause_name);
7684 if (reqs == NULL) {
7685 ok = FALSE;
7686 break;
7687 }
7689
7690 reqs = lookup_req_list(file, sec_name, "either_reqs", clause_name);
7691 if (reqs == NULL) {
7692 ok = FALSE;
7693 break;
7694 }
7696
7697 info->enabled = TRUE;
7698 }
7699 }
7701 }
7702
7703 if (ok) {
7705
7706 if (sec != NULL) {
7707 int num = section_list_size(sec);
7708 int curr;
7709
7710 for (curr = 0; curr < num; curr++) {
7711
7712 struct counter *pcount = counter_by_id(curr);
7713 const char *sec_name = section_name(section_list_get(sec, curr));
7714 const char *counter_type = secfile_lookup_str_default(file, NULL,
7715 "%s.type",
7716 sec_name);
7717
7720 if (!counter_behavior_is_valid(cb)) {
7722 "\"%s\" unknown counter type \"%s\".",
7723 filename, counter_type);
7724 ok = FALSE;
7725 break;
7726 }
7727
7728 if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
7730 "\"%s\": Cannot load counter names",
7731 filename);
7732 ok = FALSE;
7733 break;
7734 }
7735
7736 pcount->helptext = lookup_strvec(file, sec_name, "helptext");
7737 pcount->type = cb;
7738 if (!secfile_lookup_int(file, &pcount->checkpoint,
7739 "%s.checkpoint", sec_name)) {
7740
7742 "\"%s\": No checkpoint value",
7743 filename);
7744 ok = FALSE;
7745 break;
7746 }
7747
7748 pcount->target = CTGT_CITY;
7749 pcount->index = curr;
7750 pcount->def = secfile_lookup_int_default(file, 0,
7751 "%s.def",
7752 sec_name);
7754 }
7755 }
7756 }
7757
7758 /* secfile_check_unused() is not here, but only after also settings section
7759 * has been loaded. */
7760
7761 return ok;
7762}
7763
7764/**********************************************************************/
7767static bool load_ruleset_actions(struct section_file *file,
7768 struct section_file *gamefile,
7769 struct rscompat_info *compat)
7770{
7771 bool ok = TRUE;
7772 const char *filename = secfile_name(file);
7773 struct section_list *sec;
7775 struct requirement_vector *reqs;
7776
7777 /* Auto attack. */
7778
7779 /* Action auto performers aren't ready to be exposed in the ruleset
7780 * yet. The behavior when two action auto performers for the same
7781 * cause can fire isn't set in stone yet. How is one of them chosen?
7782 * What if all the actions of the chosen action auto performer turned
7783 * out to be illegal but one of the other action auto performers that
7784 * fired has legal actions? These issues can decide what other action
7785 * rules action auto performers can represent in the future. Deciding
7786 * should therefore wait until a rule needs action auto performers to
7787 * work a certain way. */
7788 /* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
7789 * by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
7790 * requirement vector to the ruleset. */
7791
7792 /* A unit moved next to this unit and the autoattack server setting
7793 * is enabled. */
7796
7797 reqs = lookup_req_list(file,
7798 "auto_attack", "if_attacker",
7799 "auto_attack");
7800 if (reqs == NULL) {
7801 ok = FALSE;
7802 } else {
7804
7806 "auto_attack.attack_actions",
7807 filename)) {
7808 /* Failed to load auto attack actions */
7810 "\"%s\": %s: failed load %s.",
7811 filename, "auto_attack", "attack_actions");
7812 ok = FALSE;
7813 }
7814 }
7815
7816 /* Section: actions */
7817 if (ok) {
7818 action_iterate(act_id) {
7819 struct action *paction = action_by_number(act_id);
7820
7821 if (!load_action_blocked_by_list(file, filename, paction, compat)) {
7822 ok = FALSE;
7823 break;
7824 }
7826
7827 if (ok) {
7828 if (!lookup_bv_actions(file, filename,
7830 "actions.diplchance_initial_odds")) {
7831 ok = FALSE;
7832 }
7833 }
7834
7835 if (ok) {
7836 /* If the "Poison City" action or the "Poison City Escape" action
7837 * should empty the granary. */
7838 /* TODO: empty granary and reduce population should become separate
7839 * action effect flags when actions are generalized. */
7843 "actions.poison_empties_food_stock");
7844
7845 /* If the "Steal Maps" action or the "Steal Maps Escape" action always
7846 * will reveal all cities when successful. */
7850 "actions.steal_maps_reveals_all_cities");
7851
7852 /* Allow setting certain properties for some actions before
7853 * generalized actions. */
7854 action_iterate(act_id) {
7855 if (!load_action_range(file, act_id)) {
7856 ok = FALSE;
7857 } else if (!load_action_kind(file, act_id)) {
7858 ok = FALSE;
7859 } else if (!load_action_actor_consuming_always(file, act_id)) {
7860 ok = FALSE;
7861 }
7862
7863 if (!ok) {
7864 break;
7865 }
7867 }
7868
7869 if (ok) {
7870 /* The quiet (don't auto generate help for) property of all actions
7871 * live in a single enum vector. This avoids generic action
7872 * expectations. */
7873 if (secfile_entry_by_path(file, "actions.quiet_actions")) {
7875 size_t asize;
7876 int j;
7877
7880 "actions.quiet_actions");
7881
7882 if (!quiet_actions) {
7883 /* Entity exists but couldn't read it. */
7885 "\"%s\": actions.quiet_actions: bad action list",
7886 filename);
7887
7888 ok = FALSE;
7889 } else {
7890 for (j = 0; j < asize; j++) {
7891 /* Don't auto generate help text for this action. */
7893 }
7894
7896 }
7897 }
7898 }
7899
7900 if (ok) {
7901 /* Hard code action sub results for now. */
7902
7903 /* Unit Enter Hut */
7905 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
7915
7916 /* Unit Frighten Hut */
7928
7929 /* Unit May Embark */
7930 action_iterate(act_id) {
7931 struct action *paction = action_by_number(act_id);
7932
7934 "civstyle.paradrop_to_transport")
7937 BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
7938 }
7939
7940 /* Embark actions will always embark, not maybe embark. */
7942
7943 /* Non Lethal bombard */
7950 }
7951 }
7952
7953 if (ok) {
7954 /* Forced actions after another action was successfully performed. */
7955
7956 if (!load_action_post_success_force(file, filename,
7960 ok = FALSE;
7961 } else if (!load_action_post_success_force(file, filename,
7965 ok = FALSE;
7966 } else if (!load_action_post_success_force(file, filename,
7969 ACTION_ATTACK))) {
7970 ok = FALSE;
7971 } else if (!load_action_post_success_force(file, filename,
7974 ACTION_ATTACK2))) {
7975 ok = FALSE;
7976 } else if (!load_action_post_success_force(file, filename,
7980 ok = FALSE;
7981 } else if (!load_action_post_success_force(file, filename,
7985 ok = FALSE;
7986 }
7987
7988 /* No "Suicide Attack". Can't act when dead. */
7989 }
7990
7991 if (ok) {
7992 /* The city that made the unit's current tile native is gone.
7993 * Evaluated against an adjacent tile. */
7995 auto_perf->cause = AAPC_CITY_GONE;
7996
7997 /* I have no objections to moving this out of game's actions to
7998 * cities.ruleset, units.ruleset or an other location in game.ruleset
7999 * you find more suitable. -- Sveinung */
8001 "actions.escape_city", filename)) {
8002 ok = FALSE;
8003 }
8004 }
8005
8006 if (ok) {
8007 /* The unit's stack has been defeated and is scheduled for execution
8008 * but the unit has the CanEscape unit type flag.
8009 * Evaluated against an adjacent tile. */
8012
8013 /* I have no objections to moving this out of game's actions to
8014 * cities.ruleset, units.ruleset or an other location in game.ruleset
8015 * you find more suitable. -- Sveinung */
8017 "actions.unit_stack_death", filename)) {
8018 ok = FALSE;
8019 }
8020 }
8021
8022 if (ok) {
8024 if (sec != nullptr) {
8025 section_list_iterate(sec, psection) {
8026 const char *sec_name = section_name(psection);
8027 const char *action_text;
8028 struct action *paction;
8029 const char *ui_name;
8030
8031 action_text = secfile_lookup_str(file, "%s.action", sec_name);
8032
8033 if (action_text == nullptr) {
8034 ruleset_error(nullptr, LOG_ERROR,
8035 "\"%s\" [%s] missing action to configure.",
8036 filename, sec_name);
8037 ok = FALSE;
8038 break;
8039 }
8040
8042 if (paction == nullptr) {
8043 ruleset_error(nullptr, LOG_ERROR,
8044 "\"%s\" [%s] lists unknown action type \"%s\".",
8045 filename, sec_name, action_text);
8046 ok = FALSE;
8047 break;
8048 }
8049
8050 if (paction->configured) {
8051 ruleset_error(nullptr, LOG_ERROR,
8052 "\"%s\" [%s] duplicate configuration for action \"%s\".",
8053 filename, sec_name, action_text);
8054 ok = FALSE;
8055 break;
8056 }
8057
8058 paction->configured = TRUE;
8059
8060 ui_name = secfile_lookup_str_default(file, nullptr,
8061 "%s.ui_name", sec_name);
8062 if (ui_name == nullptr) {
8064 }
8065 sz_strlcpy(paction->ui_name, ui_name);
8067 }
8068 }
8069
8070 if (ok) {
8071 action_iterate(act) {
8072 struct action *paction = action_by_number(act);
8073
8074 if (!paction->configured) {
8076 }
8078 }
8079
8080 if (ok) {
8082
8083 if (sec != nullptr) {
8084 section_list_iterate(sec, psection) {
8085 struct action_enabler *enabler;
8086 const char *sec_name = section_name(psection);
8087 struct action *paction;
8088 struct requirement_vector *actor_reqs;
8089 struct requirement_vector *target_reqs;
8090 const char *action_text;
8091 const char *comment;
8092
8094
8095 action_text = secfile_lookup_str(file, "%s.action", sec_name);
8096
8097 if (action_text == nullptr) {
8098 ruleset_error(nullptr, LOG_ERROR,
8099 "\"%s\" [%s] missing action to enable.",
8100 filename, sec_name);
8101 ok = FALSE;
8102 break;
8103 }
8104
8106 if (paction == nullptr) {
8107 ruleset_error(nullptr, LOG_ERROR,
8108 "\"%s\" [%s] lists unknown action type \"%s\".",
8109 filename, sec_name, action_text);
8110 ok = FALSE;
8111 break;
8112 }
8113
8114 enabler->action = action_id(paction);
8115
8116 actor_reqs = lookup_req_list(file, sec_name, "actor_reqs", action_text);
8117 if (actor_reqs == NULL) {
8118 ok = FALSE;
8119 break;
8120 }
8121
8122 requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
8123
8124 target_reqs = lookup_req_list(file, sec_name, "target_reqs", action_text);
8125 if (target_reqs == NULL) {
8126 ok = FALSE;
8127 break;
8128 }
8129
8130 requirement_vector_copy(&enabler->target_reqs, target_reqs);
8131
8132 comment = secfile_lookup_str(file, "%s.comment", sec_name);
8133 if (comment != nullptr) {
8134 enabler->rulesave.comment = fc_strdup(comment);
8135 }
8136
8139
8141 }
8142 }
8143
8144 return ok;
8145}
8146
8147/**********************************************************************/
8151static void send_ruleset_unit_classes(struct conn_list *dest)
8152{
8153 struct packet_ruleset_unit_class packet;
8155 int i;
8156
8157 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
8158 const char *flagname;
8159 const char *helptxt;
8160
8162
8164 if (flagname == NULL) {
8165 fpacket.name[0] = '\0';
8166 } else {
8168 }
8169
8171 if (helptxt == NULL) {
8172 fpacket.helptxt[0] = '\0';
8173 } else {
8174 sz_strlcpy(fpacket.helptxt, helptxt);
8175 }
8176
8178 }
8179
8181 packet.id = uclass_number(c);
8182 sz_strlcpy(packet.name, untranslated_name(&c->name));
8183 sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
8184 packet.min_speed = c->min_speed;
8185 packet.hp_loss_pct = c->hp_loss_pct;
8186 packet.non_native_def_pct = c->non_native_def_pct;
8187 packet.flags = c->flags;
8188
8189 PACKET_STRVEC_INSERT(packet.helptext, c->helptext);
8190
8191 lsend_packet_ruleset_unit_class(dest, &packet);
8193}
8194
8195/**********************************************************************/
8199static void send_ruleset_units(struct conn_list *dest)
8200{
8201 struct packet_ruleset_unit packet;
8202#ifdef FREECIV_WEB
8204#endif /* FREECIV_WEB */
8206 int i;
8207
8208 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
8209 const char *flagname;
8210 const char *helptxt;
8211
8213
8215 if (flagname == NULL) {
8216 fpacket.name[0] = '\0';
8217 } else {
8219 }
8220
8222 if (helptxt == NULL) {
8223 fpacket.helptxt[0] = '\0';
8224 } else {
8225 sz_strlcpy(fpacket.helptxt, helptxt);
8226 }
8227
8229 }
8230
8232 packet.id = utype_number(u);
8233 sz_strlcpy(packet.name, untranslated_name(&u->name));
8234 sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
8235 sz_strlcpy(packet.sound_move, u->sound_move);
8236 sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
8237 sz_strlcpy(packet.sound_fight, u->sound_fight);
8238 sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
8239 sz_strlcpy(packet.graphic_str, u->graphic_str);
8240 sz_strlcpy(packet.graphic_alt, u->graphic_alt);
8241 sz_strlcpy(packet.graphic_alt2, u->graphic_alt2);
8243 packet.build_cost = u->build_cost;
8244 packet.pop_cost = u->pop_cost;
8245 packet.spectype_id = specialist_index(u->spec_type);
8246 packet.attack_strength = u->attack_strength;
8247 packet.defense_strength = u->defense_strength;
8248 packet.move_rate = u->move_rate;
8249
8250 /* Shallow-copy (borrow) requirement vector */
8251 packet.build_reqs = u->build_reqs;
8252
8253 packet.vision_radius_sq = u->vision_radius_sq;
8254 packet.transport_capacity = u->transport_capacity;
8255 packet.hp = u->hp;
8256 packet.firepower = u->firepower;
8257 packet.obsoleted_by = u->obsoleted_by
8258 ? utype_number(u->obsoleted_by)
8259 : utype_count();
8260 packet.converted_to = u->converted_to
8261 ? utype_number(u->converted_to)
8262 : utype_count();
8263 packet.convert_time = u->convert_time;
8264 packet.fuel = u->fuel;
8265 packet.flags = u->flags;
8266 packet.roles = u->roles;
8267 packet.happy_cost = u->happy_cost;
8269 packet.upkeep[o] = u->upkeep[o];
8271 packet.paratroopers_range = u->paratroopers_range;
8272 packet.bombard_rate = u->bombard_rate;
8273 packet.city_size = u->city_size;
8274 packet.city_slots = u->city_slots;
8275 packet.tp_defense = u->tp_defense;
8276 packet.cargo = u->cargo;
8277 packet.targets = u->targets;
8278 packet.embarks = u->embarks;
8279 packet.disembarks = u->disembarks;
8280 packet.vlayer = u->vlayer;
8281
8282 if (u->veteran == NULL) {
8283 /* Use the default veteran system. */
8284 packet.veteran_levels = 0;
8285 } else {
8286 /* Per unit veteran system definition. */
8288
8289 for (i = 0; i < packet.veteran_levels; i++) {
8290 const struct veteran_level *vlevel = utype_veteran_level(u, i);
8291
8293 packet.power_fact[i] = vlevel->power_fact;
8294 packet.move_bonus[i] = vlevel->move_bonus;
8295 packet.base_raise_chance[i] = vlevel->base_raise_chance;
8296 packet.work_raise_chance[i] = vlevel->work_raise_chance;
8297 }
8298 }
8299 PACKET_STRVEC_INSERT(packet.helptext, u->helptext);
8300
8301 packet.worker = u->adv.worker;
8302
8303#ifdef FREECIV_WEB
8304 web_packet.id = utype_number(u);
8305
8306 BV_CLR_ALL(web_packet.utype_actions);
8307
8308 action_iterate(act) {
8309 if (utype_can_do_action(u, act)) {
8310 BV_SET(web_packet.utype_actions, act);
8311 }
8313#endif /* FREECIV_WEB */
8314
8315 lsend_packet_ruleset_unit(dest, &packet);
8317
8318 combat_bonus_list_iterate(u->bonuses, pbonus) {
8320
8321 bonuspacket.unit = packet.id;
8322 bonuspacket.flag = pbonus->flag;
8323 bonuspacket.type = pbonus->type;
8324 bonuspacket.value = pbonus->value;
8325 bonuspacket.quiet = pbonus->quiet;
8326
8330}
8331
8332/**********************************************************************/
8336static void send_ruleset_specialists(struct conn_list *dest)
8337{
8338 struct packet_ruleset_specialist packet;
8339
8342
8343 packet.id = spec_id;
8345 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
8349
8350 /* Shallow-copy (borrow) requirement vector */
8351 packet.reqs = s->reqs;
8352
8354
8355 lsend_packet_ruleset_specialist(dest, &packet);
8357}
8358/**********************************************************************/
8361static void send_ruleset_tech_classes(struct conn_list *dest)
8362{
8363 struct packet_ruleset_tech_class packet;
8364
8366 packet.id = ptclass->idx;
8367 sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
8368 sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
8369 packet.cost_pct = ptclass->cost_pct;
8370
8371 lsend_packet_ruleset_tech_class(dest, &packet);
8373}
8374
8375/**********************************************************************/
8379static void send_ruleset_techs(struct conn_list *dest)
8380{
8381 struct packet_ruleset_tech packet;
8383 int i;
8384
8385 for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
8386 const char *flagname;
8387 const char *helptxt;
8388
8389 fpacket.id = i + TECH_USER_1;
8390
8392 if (flagname == NULL) {
8393 fpacket.name[0] = '\0';
8394 } else {
8396 }
8397
8399 if (helptxt == NULL) {
8400 fpacket.helptxt[0] = '\0';
8401 } else {
8402 sz_strlcpy(fpacket.helptxt, helptxt);
8403 }
8404
8406 }
8407
8408 /* Since we have to prepend the tech requirements to the requirement
8409 * vector, we need to initialize a separate vector and deep-copy the
8410 * other requirements into it. */
8412
8413 advance_iterate(a) {
8414 packet.id = advance_number(a);
8415 packet.removed = !valid_advance(a);
8416 if (a->tclass == NULL) {
8417 packet.tclass = 0;
8418 } else {
8419 packet.tclass = a->tclass->idx;
8420 }
8421 sz_strlcpy(packet.name, untranslated_name(&a->name));
8422 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8423 sz_strlcpy(packet.graphic_str, a->graphic_str);
8424 sz_strlcpy(packet.graphic_alt, a->graphic_alt);
8425
8426 /* Reset requirement vector. */
8428
8429 /* The requirements req1 and req2 are needed to research a tech. Send
8430 * them in the research_reqs requirement vector. Range is set to player
8431 * since pooled research is configurable. */
8432
8433 if ((a->require[AR_ONE] != A_NEVER)
8434 && advance_number(a->require[AR_ONE]) > A_NONE) {
8435 struct requirement req
8437 FALSE, TRUE, FALSE,
8438 advance_number(a->require[AR_ONE]));
8440 }
8441
8442 if ((a->require[AR_TWO] != A_NEVER)
8443 && advance_number(a->require[AR_TWO]) > A_NONE) {
8444 struct requirement req
8446 FALSE, TRUE, FALSE,
8447 advance_number(a->require[AR_TWO]));
8449 }
8450
8451 /* The requirements of the tech's research_reqs also goes in the
8452 * packet's research_reqs requirement vector. */
8453 requirement_vector_iterate(&a->research_reqs, req) {
8456
8457 packet.root_req = a->require[AR_ROOT]
8458 ? advance_number(a->require[AR_ROOT])
8459 : advance_count();
8460
8461 packet.flags = a->flags;
8462 packet.cost = a->cost;
8463 packet.num_reqs = a->num_reqs;
8464 PACKET_STRVEC_INSERT(packet.helptext, a->helptext);
8465
8466 lsend_packet_ruleset_tech(dest, &packet);
8468
8470}
8471
8472/**********************************************************************/
8475static void send_ruleset_counters(struct conn_list *dest)
8476{
8478 struct packet_ruleset_counter packet;
8479
8480 sz_strlcpy(packet.name, untranslated_name(&pcount->name));
8481 sz_strlcpy(packet.rule_name, rule_name_get(&pcount->name));
8482 packet.checkpoint = pcount->checkpoint;
8483 packet.behavior = pcount->type;
8484 packet.type = pcount->target;
8485 packet.def = pcount->def;
8486
8487 PACKET_STRVEC_INSERT(packet.helptext, pcount->helptext);
8488 lsend_packet_ruleset_counter(dest, &packet);
8490}
8491
8492/**********************************************************************/
8496static void send_ruleset_buildings(struct conn_list *dest)
8497{
8498 int i;
8499
8500 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
8502 const char *flagname;
8503 const char *helptxt;
8504
8506
8508 if (flagname == NULL) {
8509 fpacket.name[0] = '\0';
8510 } else {
8512 }
8513
8515 if (helptxt == NULL) {
8516 fpacket.helptxt[0] = '\0';
8517 } else {
8518 sz_strlcpy(fpacket.helptxt, helptxt);
8519 }
8520
8522 }
8523
8525 struct packet_ruleset_building packet;
8526
8527 packet.id = improvement_number(b);
8528 packet.genus = b->genus;
8529 sz_strlcpy(packet.name, untranslated_name(&b->name));
8530 sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
8531 sz_strlcpy(packet.graphic_str, b->graphic_str);
8532 sz_strlcpy(packet.graphic_alt, b->graphic_alt);
8533 sz_strlcpy(packet.graphic_alt2, b->graphic_alt2);
8534
8535 /* Shallow-copy (borrow) requirement vectors */
8536 packet.reqs = b->reqs;
8537 packet.obs_reqs = b->obsolete_by;
8538
8539 packet.build_cost = b->build_cost;
8540 packet.upkeep = b->upkeep;
8541 packet.sabotage = b->sabotage;
8542 packet.flags = b->flags;
8543 sz_strlcpy(packet.soundtag, b->soundtag);
8544 sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
8545 sz_strlcpy(packet.soundtag_alt2, b->soundtag_alt2);
8546 PACKET_STRVEC_INSERT(packet.helptext, b->helptext);
8547
8548 lsend_packet_ruleset_building(dest, &packet);
8550}
8551
8552/**********************************************************************/
8556static void send_ruleset_terrain(struct conn_list *dest)
8557{
8558 struct packet_ruleset_terrain packet;
8560 int i;
8561
8563
8564 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
8565 const char *flagname;
8566 const char *helptxt;
8567
8568 fpacket.id = i + TER_USER_1;
8569
8571 if (flagname == NULL) {
8572 fpacket.name[0] = '\0';
8573 } else {
8575 }
8576
8578 if (helptxt == NULL) {
8579 fpacket.helptxt[0] = '\0';
8580 } else {
8581 sz_strlcpy(fpacket.helptxt, helptxt);
8582 }
8583
8585 }
8586
8587 terrain_type_iterate(pterrain) {
8588 packet.id = terrain_number(pterrain);
8589 packet.tclass = pterrain->tclass;
8590 packet.native_to = pterrain->native_to;
8591
8592 sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
8593 sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
8594 sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
8595 sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
8596 sz_strlcpy(packet.graphic_alt2, pterrain->graphic_alt2);
8597
8598 packet.movement_cost = pterrain->movement_cost;
8599 packet.defense_bonus = pterrain->defense_bonus;
8600
8602 packet.output[o] = pterrain->output[o];
8604
8605 packet.num_resources = 0;
8606 terrain_resources_iterate(pterrain, res, freq) {
8607 packet.resources[packet.num_resources] = extra_number(res);
8608 packet.resource_freq[packet.num_resources] = freq;
8609 packet.num_resources++;
8611
8613 packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
8615
8616 packet.base_time = pterrain->base_time;
8617 packet.road_time = pterrain->road_time;
8618
8619 packet.cultivate_result = (pterrain->cultivate_result
8620 ? terrain_number(pterrain->cultivate_result)
8621 : terrain_count());
8622 packet.cultivate_time = pterrain->cultivate_time;
8623
8624 packet.plant_result = (pterrain->plant_result
8625 ? terrain_number(pterrain->plant_result)
8626 : terrain_count());
8627 packet.plant_time = pterrain->plant_time;
8628
8629 packet.irrigation_food_incr = pterrain->irrigation_food_incr;
8630 packet.irrigation_time = pterrain->irrigation_time;
8631
8632 packet.mining_shield_incr = pterrain->mining_shield_incr;
8633 packet.mining_time = pterrain->mining_time;
8634
8635 packet.num_animals = 0;
8636 terrain_animals_iterate(pterrain, panimal) {
8637 packet.animals[packet.num_animals] = utype_number(panimal);
8638 packet.num_animals++;
8640
8641 packet.transform_result = (pterrain->transform_result
8642 ? terrain_number(pterrain->transform_result)
8643 : terrain_count());
8644 packet.placing_time = pterrain->placing_time;
8645 packet.pillage_time = pterrain->pillage_time;
8646 packet.transform_time = pterrain->transform_time;
8647
8649 for (i = 0; i < game.control.num_extra_types; i++) {
8650 packet.extra_removal_times[i] = pterrain->extra_removal_times[i];
8651 }
8652
8653 packet.flags = pterrain->flags;
8654
8655 packet.color_red = pterrain->rgb->r;
8656 packet.color_green = pterrain->rgb->g;
8657 packet.color_blue = pterrain->rgb->b;
8658
8659 PACKET_STRVEC_INSERT(packet.helptext, pterrain->helptext);
8660
8661 lsend_packet_ruleset_terrain(dest, &packet);
8663}
8664
8665/**********************************************************************/
8668static void send_ruleset_resources(struct conn_list *dest)
8669{
8670 struct packet_ruleset_resource packet;
8671
8673 packet.id = extra_index(presource);
8674
8676 packet.output[o] = presource->data.resource->output[o];
8678
8679 lsend_packet_ruleset_resource(dest, &packet);
8681}
8682
8683/**********************************************************************/
8687static void send_ruleset_extras(struct conn_list *dest)
8688{
8689 int i;
8690
8691 for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
8693 const char *flagname;
8694 const char *helptxt;
8695
8697
8699 if (flagname == NULL) {
8700 fpacket.name[0] = '\0';
8701 } else {
8703 }
8704
8706 if (helptxt == NULL) {
8707 fpacket.helptxt[0] = '\0';
8708 } else {
8709 sz_strlcpy(fpacket.helptxt, helptxt);
8710 }
8711
8713 }
8714
8716 struct packet_ruleset_extra packet;
8717 int j;
8718
8719 packet.id = extra_number(e);
8720 sz_strlcpy(packet.name, untranslated_name(&e->name));
8721 sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
8722
8723 packet.category = e->category;
8724
8725 BV_CLR_ALL(packet.causes);
8726 for (j = 0; j < EC_COUNT; j++) {
8727 if (is_extra_caused_by(e, j)) {
8728 BV_SET(packet.causes, j);
8729 }
8730 }
8731
8732 BV_CLR_ALL(packet.rmcauses);
8733 for (j = 0; j < ERM_COUNT; j++) {
8734 if (is_extra_removed_by(e, j)) {
8735 BV_SET(packet.rmcauses, j);
8736 }
8737 }
8738
8739 sz_strlcpy(packet.activity_gfx, e->activity_gfx);
8740 sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
8741 sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
8742 sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
8743 sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
8744 sz_strlcpy(packet.rmact_gfx_alt2, e->rmact_gfx_alt2);
8745 sz_strlcpy(packet.graphic_str, e->graphic_str);
8746 sz_strlcpy(packet.graphic_alt, e->graphic_alt);
8747
8748 /* Shallow-copy (borrow) requirement vectors */
8749 packet.reqs = e->reqs;
8750 packet.rmreqs = e->rmreqs;
8751
8752 packet.appearance_chance = e->appearance_chance;
8753 /* Shallow-copy (borrow) requirement vector */
8754 packet.appearance_reqs = e->appearance_reqs;
8755
8756 packet.disappearance_chance = e->disappearance_chance;
8757 /* Shallow-copy (borrow) requirement vector */
8758 packet.disappearance_reqs = e->disappearance_reqs;
8759
8760 packet.visibility_req = e->visibility_req;
8761 packet.buildable = e->buildable;
8762 packet.generated = e->generated;
8763 packet.build_time = e->build_time;
8764 packet.build_time_factor = e->build_time_factor;
8765 packet.removal_time = e->removal_time;
8766 packet.removal_time_factor = e->removal_time_factor;
8767 packet.infracost = e->infracost;
8768 packet.defense_bonus = e->defense_bonus;
8769 packet.eus = e->eus;
8770 packet.no_aggr_near_city = e->no_aggr_near_city;
8771
8772 packet.native_to = e->native_to;
8773
8774 packet.flags = e->flags;
8775 packet.hidden_by = e->hidden_by;
8776 packet.bridged_over = e->bridged_over;
8777 packet.conflicts = e->conflicts;
8778
8779 PACKET_STRVEC_INSERT(packet.helptext, e->helptext);
8780
8781 lsend_packet_ruleset_extra(dest, &packet);
8783}
8784
8785/**********************************************************************/
8789static void send_ruleset_bases(struct conn_list *dest)
8790{
8792 struct base_type *b = extra_base_get(pextra);
8793 struct packet_ruleset_base packet;
8794
8795 packet.id = base_number(b);
8796
8797 packet.gui_type = b->gui_type;
8798 packet.border_sq = b->border_sq;
8799 packet.vision_main_sq = b->vision_main_sq;
8800 packet.vision_invis_sq = b->vision_invis_sq;
8801 packet.vision_subs_sq = b->vision_subs_sq;
8802
8803 lsend_packet_ruleset_base(dest, &packet);
8805}
8806
8807/**********************************************************************/
8811static void send_ruleset_roads(struct conn_list *dest)
8812{
8813 struct packet_ruleset_road packet;
8814
8816 struct road_type *r = extra_road_get(pextra);
8817
8818 packet.id = road_number(r);
8819
8820 packet.gui_type = r->gui_type;
8821
8822 /* Shallow-copy (borrow) requirement vector */
8823 packet.first_reqs = r->first_reqs;
8824
8825 packet.move_cost = r->move_cost;
8826 packet.move_mode = r->move_mode;
8827
8829 packet.tile_incr_const[o] = r->tile_incr_const[o];
8830 packet.tile_incr[o] = r->tile_incr[o];
8831 packet.tile_bonus[o] = r->tile_bonus[o];
8833
8834 packet.compat = r->compat;
8835
8836 packet.integrates = r->integrates;
8837 packet.flags = r->flags;
8838
8839 lsend_packet_ruleset_road(dest, &packet);
8841}
8842
8843/**********************************************************************/
8847static void send_ruleset_tiledefs(struct conn_list *dest)
8848{
8849 struct packet_ruleset_tiledef packet;
8850
8853
8854 packet.id = tiledef_number(td);
8855 sz_strlcpy(packet.name, untranslated_name(&td->name));
8856 sz_strlcpy(packet.rule_name, rule_name_get(&td->name));
8857
8859 extra_type_list_iterate(td->extras, pextra) {
8860 BV_SET(extras, extra_index(pextra));
8862
8863 packet.extras = extras;
8864
8865 lsend_packet_ruleset_tiledef(dest, &packet);
8867}
8868
8869/**********************************************************************/
8873static void send_ruleset_goods(struct conn_list *dest)
8874{
8875 struct packet_ruleset_goods packet;
8876
8878 packet.id = goods_number(g);
8879 sz_strlcpy(packet.name, untranslated_name(&g->name));
8880 sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
8881
8882 /* Shallow-copy (borrow) requirement vector */
8883 packet.reqs = g->reqs;
8884
8885 packet.from_pct = g->from_pct;
8886 packet.to_pct = g->to_pct;
8887 packet.onetime_pct = g->onetime_pct;
8888 packet.select_priority = g->select_priority;
8889 packet.replace_priority = g->replace_priority;
8890 packet.flags = g->flags;
8891
8892 PACKET_STRVEC_INSERT(packet.helptext, g->helptext);
8893
8894 lsend_packet_ruleset_goods(dest, &packet);
8896}
8897
8898/**********************************************************************/
8902static void send_ruleset_disasters(struct conn_list *dest)
8903{
8904 struct packet_ruleset_disaster packet;
8905
8907 packet.id = disaster_number(d);
8908
8909 sz_strlcpy(packet.name, untranslated_name(&d->name));
8910 sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
8911
8912 /* Shallow-copy (borrow) requirement vector */
8913 packet.reqs = d->reqs;
8914
8915 packet.frequency = d->frequency;
8916
8917 packet.effects = d->effects;
8918
8919 lsend_packet_ruleset_disaster(dest, &packet);
8921}
8922
8923/**********************************************************************/
8927static void send_ruleset_achievements(struct conn_list *dest)
8928{
8929 struct packet_ruleset_achievement packet;
8930
8932 packet.id = achievement_number(a);
8933
8934 sz_strlcpy(packet.name, untranslated_name(&a->name));
8935 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8936
8937 packet.type = a->type;
8938 packet.unique = a->unique;
8939 packet.value = a->value;
8940
8941 lsend_packet_ruleset_achievement(dest, &packet);
8943}
8944
8945/**********************************************************************/
8948static void send_ruleset_actions(struct conn_list *dest)
8949{
8950 struct packet_ruleset_action packet;
8951
8952 action_iterate(act) {
8953 struct action *paction = action_by_number(act);
8954
8955 packet.id = act;
8957 packet.quiet = action_by_number(act)->quiet;
8958
8959 packet.result = paction->result;
8960 packet.sub_results = paction->sub_results;
8961 packet.actor_consuming_always = paction->actor_consuming_always;
8962
8963 packet.act_kind = action_by_number(act)->actor_kind;
8964 packet.tgt_kind = action_by_number(act)->target_kind;
8966
8969 packet.blocked_by = action_by_number(act)->blocked_by;
8970
8971 lsend_packet_ruleset_action(dest, &packet);
8973}
8974
8975/**********************************************************************/
8979{
8980 struct packet_ruleset_action_enabler packet;
8981
8984
8985 /* Shallow-copy (borrow) requirement vectors */
8986 packet.actor_reqs = enabler->actor_reqs;
8987 packet.target_reqs = enabler->target_reqs;
8988
8991}
8992
8993/**********************************************************************/
8998{
8999 int counter;
9000 int id;
9001 struct packet_ruleset_action_auto packet;
9002
9003 id = 0;
9005 packet.id = id++;
9006
9007 packet.cause = aperf->cause;
9008
9009 /* Shallow-copy (borrow) requirement vector */
9010 packet.reqs = aperf->reqs;
9011
9012 for (counter = 0;
9013 /* Can't list more actions than all actions. */
9015 /* ACTION_NONE terminates the list. */
9016 && aperf->alternatives[counter] != ACTION_NONE;
9017 counter++) {
9018 packet.alternatives[counter] = aperf->alternatives[counter];
9019 }
9020 packet.alternatives_count = counter;
9021
9022 lsend_packet_ruleset_action_auto(dest, &packet);
9024}
9025
9026/**********************************************************************/
9030static void send_ruleset_trade_routes(struct conn_list *dest)
9031{
9032 struct packet_ruleset_trade packet;
9034
9035 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
9037
9038 packet.id = type;
9039 packet.trade_pct = set->trade_pct;
9040 packet.cancelling = set->cancelling;
9041 packet.bonus_type = set->bonus_type;
9042
9043 lsend_packet_ruleset_trade(dest, &packet);
9044 }
9045}
9046
9047/**********************************************************************/
9051static void send_ruleset_governments(struct conn_list *dest)
9052{
9053 struct packet_ruleset_government gov;
9055 int i;
9056
9057 for (i = 0; i < MAX_NUM_USER_GOVERNMENT_FLAGS; i++) {
9059 const char *flagname;
9060 const char *helptxt;
9061
9063
9065 if (flagname == nullptr) {
9066 fpacket.name[0] = '\0';
9067 } else {
9069 }
9070
9072 if (helptxt == nullptr) {
9073 fpacket.helptxt[0] = '\0';
9074 } else {
9075 sz_strlcpy(fpacket.helptxt, helptxt);
9076 }
9077
9079 }
9080
9082 /* Send one packet_government */
9083 gov.id = government_number(g);
9084
9085 /* Shallow-copy (borrow) requirement vector */
9086 gov.reqs = g->reqs;
9087
9088 gov.flags = g->flags;
9089
9090 sz_strlcpy(gov.name, untranslated_name(&g->name));
9091 sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
9092 sz_strlcpy(gov.graphic_str, g->graphic_str);
9093 sz_strlcpy(gov.graphic_alt, g->graphic_alt);
9094 sz_strlcpy(gov.sound_str, g->sound_str);
9095 sz_strlcpy(gov.sound_alt, g->sound_alt);
9096 sz_strlcpy(gov.sound_alt2, g->sound_alt2);
9097 PACKET_STRVEC_INSERT(gov.helptext, g->helptext);
9098
9100
9101 /* Send one packet_government_ruler_title per ruler title. */
9103 const struct nation_type *pnation = ruler_title_nation(pruler_title);
9104
9105 title.gov = government_number(g);
9106 title.nation = pnation ? nation_number(pnation) : nation_count();
9107 sz_strlcpy(title.male_title,
9109 sz_strlcpy(title.female_title,
9114}
9115
9116/**********************************************************************/
9120static void send_ruleset_nations(struct conn_list *dest)
9121{
9124 struct packet_ruleset_nation packet;
9125 int i;
9126
9128 i = 0;
9133 i++;
9136
9138 i = 0;
9140 sz_strlcpy(groups_packet.groups[i],
9142 groups_packet.hidden[i] = pgroup->hidden;
9143 i++;
9146
9148 packet.id = nation_number(n);
9149 if (n->translation_domain == NULL) {
9150 packet.translation_domain[0] = '\0';
9151 } else {
9152 sz_strlcpy(packet.translation_domain, n->translation_domain);
9153 }
9154 sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
9155 sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
9156 sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
9157 sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
9158 sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
9159
9160 i = 0;
9164 i++;
9166 packet.leader_count = i;
9167
9168 packet.style = style_number(n->style);
9169 packet.is_playable = n->is_playable;
9170 packet.barbarian_type = n->barb_type;
9171
9172 sz_strlcpy(packet.legend, n->legend);
9173
9174 i = 0;
9176 packet.sets[i++] = nation_set_number(pset);
9178 packet.nsets = i;
9179
9180 i = 0;
9182 packet.groups[i++] = nation_group_number(pgroup);
9184 packet.ngroups = i;
9185
9186 packet.init_government_id = n->init_government
9187 ? government_number(n->init_government) : government_count();
9188 fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
9189 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9190 if (n->init_techs[i] != A_LAST) {
9191 packet.init_techs[i] = n->init_techs[i];
9192 } else {
9193 break;
9194 }
9195 }
9196 packet.init_techs_count = i;
9197 fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
9198 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
9199 const struct unit_type *t = n->init_units[i];
9200 if (t) {
9201 packet.init_units[i] = utype_number(t);
9202 } else {
9203 break;
9204 }
9205 }
9206 packet.init_units_count = i;
9208 == ARRAY_SIZE(n->init_buildings));
9209 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9210 if (n->init_buildings[i] != B_LAST) {
9211 /* Impr_type_id to int */
9212 packet.init_buildings[i] = n->init_buildings[i];
9213 } else {
9214 break;
9215 }
9216 }
9217 packet.init_buildings_count = i;
9218
9219 lsend_packet_ruleset_nation(dest, &packet);
9221
9222 /* Send initial values of is_pickable */
9224}
9225
9226/**********************************************************************/
9230static void send_ruleset_styles(struct conn_list *dest)
9231{
9232 struct packet_ruleset_style packet;
9233
9234 styles_iterate(s) {
9235 packet.id = style_index(s);
9236 sz_strlcpy(packet.name, untranslated_name(&s->name));
9237 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
9238
9239 lsend_packet_ruleset_style(dest, &packet);
9241}
9242
9243/**********************************************************************/
9246static void send_ruleset_clauses(struct conn_list *dest)
9247{
9248 struct packet_ruleset_clause packet;
9249 int i;
9250
9251 for (i = 0; i < CLAUSE_COUNT; i++) {
9252 struct clause_info *info = clause_info_get(i);
9253
9254 packet.type = i;
9255 packet.enabled = info->enabled;
9256
9257 /* Shallow-copy (borrow) requirement vectors */
9258 packet.giver_reqs = info->giver_reqs;
9259 packet.receiver_reqs = info->receiver_reqs;
9260 packet.either_reqs = info->either_reqs;
9261
9262 lsend_packet_ruleset_clause(dest, &packet);
9263 }
9264}
9265
9266/**********************************************************************/
9270static void send_ruleset_multipliers(struct conn_list *dest)
9271{
9272 multipliers_iterate(pmul) {
9273 struct packet_ruleset_multiplier packet;
9274
9275 packet.id = multiplier_number(pmul);
9276 packet.start = pmul->start;
9277 packet.stop = pmul->stop;
9278 packet.step = pmul->step;
9279 packet.def = pmul->def;
9280 packet.offset = pmul->offset;
9281 packet.factor = pmul->factor;
9282 packet.minimum_turns = pmul->minimum_turns;
9283
9284 sz_strlcpy(packet.name, untranslated_name(&pmul->name));
9285 sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
9286
9287 /* Shallow-copy (borrow) requirement vector */
9288 packet.reqs = pmul->reqs;
9289
9290 PACKET_STRVEC_INSERT(packet.helptext, pmul->helptext);
9291
9292 lsend_packet_ruleset_multiplier(dest, &packet);
9294}
9295
9296/**********************************************************************/
9300static void send_ruleset_cities(struct conn_list *dest)
9301{
9303 int k;
9304
9305 for (k = 0; k < game.control.num_city_styles; k++) {
9306 city_p.style_id = k;
9307
9308 /* Shallow-copy (borrow) requirement vector */
9309 city_p.reqs = city_styles[k].reqs;
9310
9313 sz_strlcpy(city_p.graphic, city_styles[k].graphic);
9314 sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
9315 sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic);
9316
9318 }
9319}
9320
9321/**********************************************************************/
9325static void send_ruleset_musics(struct conn_list *dest)
9326{
9327 struct packet_ruleset_music packet;
9328
9330 packet.id = pmus->id;
9331
9332 sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
9333 sz_strlcpy(packet.music_combat, pmus->music_combat);
9334
9335 /* Shallow-copy (borrow) requirement vector */
9336 packet.reqs = pmus->reqs;
9337
9338 lsend_packet_ruleset_music(dest, &packet);
9340}
9341
9342/**********************************************************************/
9346static void send_ruleset_game(struct conn_list *dest)
9347{
9349 int i;
9350
9352
9353 /* Per unit veteran system definition. */
9354 misc_p.veteran_levels = game.veteran->levels;
9355
9356 for (i = 0; i < misc_p.veteran_levels; i++) {
9357 const struct veteran_level *vlevel = game.veteran->definitions + i;
9358
9359 sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
9360 misc_p.power_fact[i] = vlevel->power_fact;
9361 misc_p.move_bonus[i] = vlevel->move_bonus;
9362 misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
9363 misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
9364 }
9365
9366 fc_assert(sizeof(misc_p.global_init_techs)
9367 == sizeof(game.rgame.global_init_techs));
9368 fc_assert(ARRAY_SIZE(misc_p.global_init_techs)
9370 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9372 misc_p.global_init_techs[i] = game.rgame.global_init_techs[i];
9373 } else {
9374 break;
9375 }
9376 }
9377 misc_p.global_init_techs_count = i;
9378
9379 fc_assert(ARRAY_SIZE(misc_p.global_init_buildings)
9381 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9383 /* Impr_type_id to int */
9384 misc_p.global_init_buildings[i] =
9386 } else {
9387 break;
9388 }
9389 }
9390 misc_p.global_init_buildings_count = i;
9391
9392 misc_p.default_specialist = DEFAULT_SPECIALIST;
9393
9395
9396 misc_p.background_red = game.plr_bg_color->r;
9397 misc_p.background_green = game.plr_bg_color->g;
9398 misc_p.background_blue = game.plr_bg_color->b;
9399
9401}
9402
9403/**********************************************************************/
9407static void send_ruleset_team_names(struct conn_list *dest)
9408{
9410
9412 const char *name = team_slot_defined_name(tslot);
9413
9414 if (NULL == name) {
9415 /* End of defined names. */
9416 break;
9417 }
9418
9420 sz_strlcpy(team_name_info_p.team_name, name);
9421
9424}
9425
9426/**********************************************************************/
9429static void notify_ruleset_fallback(const char *msg)
9430{
9432}
9433
9434/**********************************************************************/
9437bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
9438 rs_conversion_logger logger,
9439 bool act, bool buffer_script, bool load_luadata)
9440{
9441 set_ruleset_compat_mode(compat_mode);
9442
9443 if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
9444 act, buffer_script, load_luadata)) {
9446 return TRUE;
9447 }
9448
9449 if (alt != NULL) {
9450 if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
9451 load_luadata)) {
9453
9455 return TRUE;
9456 }
9457 }
9458
9459 /* Fallback to previous one. */
9460 if (restore != NULL) {
9461 if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
9463
9464 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
9465
9467
9468 /* We're in sane state as restoring previous ruleset succeeded,
9469 * but return failure to indicate that this is not what caller
9470 * wanted. */
9471 return FALSE;
9472 }
9473 }
9474
9476
9477 /* Fallback to default one, but not if that's what we tried already */
9481 /* We're in sane state as fallback ruleset loading succeeded,
9482 * but return failure to indicate that this is not what caller
9483 * wanted. */
9485
9486 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
9487
9488 return FALSE;
9489 }
9490 }
9491
9492#ifdef FREECIV_WEB
9493 log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
9494 "https://github.com/freeciv/freeciv-web"));
9495#endif /* FREECIV_WEB */
9496
9497 /* Cannot load even default ruleset, we're in completely unusable state */
9499
9501}
9502
9503/**********************************************************************/
9507{
9508 if (file != NULL) {
9509 secfile_destroy(file);
9510 }
9511}
9512
9513/**********************************************************************/
9523
9524/**********************************************************************/
9528static bool load_rulesetdir(const char *rsdir, bool compat_mode,
9529 rs_conversion_logger logger,
9530 bool act, bool buffer_script, bool load_luadata)
9531{
9534 struct section_file *actionfile;
9535 bool ok = TRUE;
9537
9538 log_normal(_("Loading rulesets."));
9539
9541 compat_info.compat_mode = compat_mode;
9542 compat_info.log_cb = logger;
9543
9546 /* Reset the list of available player colors. */
9550
9551 if (script_buffer != NULL) {
9554 }
9555 if (parser_buffer != NULL) {
9558 }
9559
9560 server.playable_nations = 0;
9561
9565 buildfile = openload_ruleset_file("buildings", rsdir);
9566 govfile = openload_ruleset_file("governments", rsdir);
9568 terrfile = openload_ruleset_file("terrain", rsdir);
9573
9574 if (load_luadata) {
9576 } else {
9578 }
9579
9580 if (techfile == NULL
9581 || buildfile == NULL
9582 || govfile == NULL
9583 || unitfile == NULL
9584 || terrfile == NULL
9585 || stylefile == NULL
9586 || cityfile == NULL
9587 || nationfile == NULL
9588 || effectfile == NULL
9589 || actionfile == NULL
9590 || gamefile == NULL) {
9591 ok = FALSE;
9592 }
9593
9594 if (ok) {
9595 /* Note: Keep load_game_names() first so that compat_info.version is
9596 * correctly initialized. */
9606 }
9607
9608 if (ok) {
9610 }
9611
9612 if (ok) {
9614 }
9615 if (ok) {
9617 }
9618 if (ok) {
9620 }
9621 if (ok) {
9623 }
9624 if (ok) {
9625 /* Terrain must precede nations and units */
9627 }
9628 if (ok) {
9630 }
9631 if (ok) {
9633 }
9634 if (ok) {
9636 }
9637 if (ok) {
9639 }
9640 if (ok) {
9642 }
9643 if (ok) {
9645 }
9646
9647 if (ok) {
9648 /* Init nations we just loaded. */
9650
9651 /* Needed by role_unit_precalcs(). */
9653
9654 /* Prepare caches we want to sanity check. */
9658
9661 }
9662
9663 if (ok) {
9664 /* Only load settings for a sane ruleset */
9665 ok = settings_ruleset(gamefile, "settings", act,
9666 compat_info.compat_mode
9667 && compat_info.version < RSFORMAT_CURRENT);
9668
9669 if (ok) {
9671 }
9672 }
9673
9685
9686 if (extra_sections) {
9689 }
9690 if (base_sections) {
9693 }
9694 if (road_sections) {
9697 }
9698 if (resource_sections) {
9701 }
9702 if (terrain_sections) {
9705 }
9706
9707 if (ok) {
9709 }
9710
9711 if (ok) {
9712 char **buffer = buffer_script ? &script_buffer : NULL;
9713
9715
9717
9718 ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
9719 }
9720
9721 if (ok) {
9722 enum fc_tristate pret;
9723 char **buffer = buffer_script ? &parser_buffer : NULL;
9724
9725 pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
9726
9727 if (pret == TRI_MAYBE && buffer_script) {
9729 "-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
9730 }
9731
9732 ok = (pret != TRI_NO);
9733 }
9734
9735 if (ok && !buffer_script) {
9736 ok = (openload_script_file("default", rsdir, NULL, FALSE) == TRI_YES);
9737 }
9738
9739 if (ok && act) {
9740 /* Populate remaining caches. */
9747 ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
9751
9752 /* Build advisors unit class cache corresponding to loaded rulesets */
9754 CALL_FUNC_EACH_AI(units_ruleset_init);
9755
9756 /* We may need to adjust the number of AI players
9757 * if the number of available nations changed. */
9759 }
9760
9761 return ok;
9762}
9763
9764/**********************************************************************/
9768{
9769 struct section_file *file;
9770 bool ok = TRUE;
9771
9773 if (file == NULL) {
9775 "Could not load game.ruleset:\n%s",
9776 secfile_error());
9777 ok = FALSE;
9778 }
9779 if (ok) {
9780 settings_ruleset(file, "settings", TRUE, FALSE);
9781 secfile_destroy(file);
9782 }
9783
9784 return ok;
9785}
9786
9787/**********************************************************************/
9790void send_rulesets(struct conn_list *dest)
9791{
9793
9794 /* ruleset_control also indicates to client that ruleset sending starts. */
9796
9797 /* Currently containing control-kind of data of nation sets and groups,
9798 * this too must be sent before any requirement vector may depend on
9799 * that data. */
9801
9802 send_ruleset_game(dest);
9812 send_ruleset_techs(dest);
9815 send_ruleset_units(dest);
9817 send_ruleset_extras(dest);
9818 send_ruleset_bases(dest);
9819 send_ruleset_roads(dest);
9823 send_ruleset_goods(dest);
9825 send_ruleset_styles(dest);
9827 send_ruleset_cities(dest);
9829 send_ruleset_musics(dest);
9830 send_ruleset_cache(dest);
9831
9832 /* Indicate client that all rulesets have now been sent. */
9834
9835 /* changed game settings will be send in
9836 * connecthand.c:establish_new_connection() */
9837
9839}
void access_info_init(const struct unit_type *aunit)
Definition accessarea.c:40
void access_info_close(void)
Definition accessarea.c:56
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:5956
void actions_rs_pre_san_gen(void)
Definition actions.c:899
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6407
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7125
bool action_is_in_use(struct action *paction)
Definition actions.c:5910
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7321
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:6950
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6587
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6776
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:1547
const char * action_ui_name_default(int act)
Definition actions.c:6039
struct action_enabler * action_enabler_new(void)
Definition actions.c:1496
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5845
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:377
int actres_max_range_default(enum action_result result)
Definition actres.c:467
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:771
void adv_units_ruleset_init(void)
Definition advruleset.c:33
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
#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:3436
void city_production_caravan_shields_init(void)
Definition city.c:1778
const char * city_style_rule_name(const int style)
Definition city.c:1765
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:846
#define output_type_iterate_end
Definition city.h:852
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:1346
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:1357
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:1337
#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:518
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:371
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:331
const char * ruler_title_female_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:389
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:380
const char * gov_flag_helptxt(enum gov_flag_id id)
Definition government.c:660
void governments_alloc(int num)
Definition government.c:535
Government_type_id government_number(const struct government *pgovern)
Definition government.c:93
const struct ruler_title_hash * government_ruler_titles(const struct government *pgovern)
Definition government.c:320
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:135
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:623
#define governments_iterate(NAME_pgov)
Definition government.h:127
#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:130
#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:403
#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:188
struct city_list * cities
Definition packhand.c:120
int len
Definition packhand.c:128
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2647
void playercolor_free(void)
Definition plrhand.c:3348
void playercolor_init(void)
Definition plrhand.c:3338
int playercolor_count(void)
Definition plrhand.c:3387
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3367
void count_playable_nations(void)
Definition plrhand.c:2604
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
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:90
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:493
const char * rscompat_effect_name_3_4(const char *old_name)
Definition rscompat.c:569
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:908
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1622
#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:1277
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:9528
#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:1178
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:1953
static bool load_terrain_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2763
static bool load_style_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5766
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:4449
#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:8379
#define section_strlcpy(dst, src)
Definition ruleload.c:126
static bool load_action_range(struct section_file *file, action_id act)
Definition ruleload.c:6518
#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:6007
static void send_ruleset_units(struct conn_list *dest)
Definition ruleload.c:8199
static void send_ruleset_governments(struct conn_list *dest)
Definition ruleload.c:9051
static bool load_action_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1446
static struct extra_type * lookup_resource(const char *filename, const char *name, const char *jsection)
Definition ruleload.c:1157
static struct section_file * openload_luadata_file(const char *rsdir)
Definition ruleload.c:640
#define TILEDEF_SECTION_PREFIX
Definition ruleload.c:106
static bool load_ruleset_techs(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1584
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:9517
static void send_ruleset_resources(struct conn_list *dest)
Definition ruleload.c:8668
static bool load_ruleset_buildings(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:2639
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:1009
static void nullcheck_secfile_destroy(struct section_file *file)
Definition ruleload.c:9506
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:6439
static void send_ruleset_clauses(struct conn_list *dest)
Definition ruleload.c:9246
static void send_ruleset_game(struct conn_list *dest)
Definition ruleload.c:9346
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:6265
static bool lookup_cbonus_list(struct combat_bonus_list *list, struct section_file *file, const char *sec, const char *sub)
Definition ruleload.c:794
static void send_ruleset_nations(struct conn_list *dest)
Definition ruleload.c:9120
static void send_ruleset_roads(struct conn_list *dest)
Definition ruleload.c:8811
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:4863
static void send_ruleset_tech_classes(struct conn_list *dest)
Definition ruleload.c:8361
static void send_ruleset_action_enablers(struct conn_list *dest)
Definition ruleload.c:8978
static void send_ruleset_control(struct conn_list *dest)
Definition ruleload.c:4669
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:9437
static void send_ruleset_tiledefs(struct conn_list *dest)
Definition ruleload.c:8847
#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:668
static void send_ruleset_musics(struct conn_list *dest)
Definition ruleload.c:9325
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:8873
static const char name_too_long[]
Definition ruleload.c:124
bool reload_rulesets_settings(void)
Definition ruleload.c:9767
static struct strvec * lookup_strvec(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleload.c:1137
#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:853
static bool load_game_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1316
static void send_ruleset_counters(struct conn_list *dest)
Definition ruleload.c:8475
static void send_ruleset_specialists(struct conn_list *dest)
Definition ruleload.c:8336
#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:8997
static bool load_government_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:4337
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:6583
static void send_ruleset_team_names(struct conn_list *dest)
Definition ruleload.c:9407
static void send_ruleset_cities(struct conn_list *dest)
Definition ruleload.c:9300
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:1117
static const char * check_leader_names(struct nation_type *pnation)
Definition ruleload.c:4707
#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:2558
#define EXTRA_SECTION_PREFIX
Definition ruleload.c:102
void send_rulesets(struct conn_list *dest)
Definition ruleload.c:9790
#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:885
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:6049
static bool load_ruleset_styles(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5827
static struct government * lookup_government(struct section_file *file, const char *entry, const char *filename, struct government *fallback)
Definition ruleload.c:1092
#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:2074
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:1228
static void send_ruleset_styles(struct conn_list *dest)
Definition ruleload.c:9230
#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:8902
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:945
#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:6699
static bool load_nation_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:4727
static void send_ruleset_achievements(struct conn_list *dest)
Definition ruleload.c:8927
#define SCRIPT_SUFFIX
Definition ruleload.c:87
static void send_ruleset_bases(struct conn_list *dest)
Definition ruleload.c:8789
static bool load_ruleset_terrain(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:3135
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:6566
static bool load_action_post_success_force(struct section_file *file, const char *filename, int performer_slot, struct action *paction)
Definition ruleload.c:6628
static bool load_tech_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1466
#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:6543
static void send_ruleset_multipliers(struct conn_list *dest)
Definition ruleload.c:9270
char * get_script_buffer(void)
Definition ruleload.c:568
static void send_ruleset_actions(struct conn_list *dest)
Definition ruleload.c:8948
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:4879
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:5905
static bool load_ruleset_nations(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:5049
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:5948
static void send_ruleset_unit_classes(struct conn_list *dest)
Definition ruleload.c:8151
#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:1061
static void send_ruleset_extras(struct conn_list *dest)
Definition ruleload.c:8687
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action)
static void send_ruleset_terrain(struct conn_list *dest)
Definition ruleload.c:8556
#define GOVERNMENT_SECTION_PREFIX
Definition ruleload.c:96
static bool load_unit_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleload.c:1795
static void send_ruleset_trade_routes(struct conn_list *dest)
Definition ruleload.c:9030
static bool load_ruleset_actions(struct section_file *file, struct section_file *gamefile, struct rscompat_info *compat)
Definition ruleload.c:7767
static void notify_ruleset_fallback(const char *msg)
Definition ruleload.c:9429
static bool lookup_bv_actions(struct section_file *file, const char *filename, bv_actions *target, const char *path)
Definition ruleload.c:6665
static void send_ruleset_buildings(struct conn_list *dest)
Definition ruleload.c:8496
#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:1254
#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:6477
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:5984
#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:2509
void update_nations_with_startpos(void)
Definition srv_main.c:2314
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:117
struct nation_style * style_by_number(int id)
Definition style.c:88
void styles_alloc(int count)
Definition style.c:36
struct music_style * music_style_by_number(int id)
Definition style.c:171
int style_number(const struct nation_style *pstyle)
Definition style.c:68
void music_styles_alloc(int count)
Definition style.c:133
int style_index(const struct nation_style *pstyle)
Definition style.c:78
#define music_styles_iterate(_p)
Definition style.h:72
#define music_styles_iterate_end
Definition style.h:79
#define styles_iterate(_p)
Definition style.h:46
#define styles_iterate_end
Definition style.h:52
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
bool fc_isspace(char c)
Definition support.c:1240
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:822
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:886
char fc_tolower(char c)
Definition support.c:1273
#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:175
const char * team_slot_defined_name(const struct team_slot *tslot)
Definition team.c:277
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:288
#define team_slots_iterate_end
Definition team.h:77
#define team_slots_iterate(_tslot)
Definition team.h:72
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
const char * tech_flag_id_name_cb(enum tech_flag_id flag)
Definition tech.c:433
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:404
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
void techs_precalc_data(void)
Definition tech.c:225
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309
const char * tech_flag_helptxt(enum tech_flag_id id)
Definition tech.c:445
struct advance * advance_by_rule_name(const char *name)
Definition tech.c:200
struct tech_class * tech_class_by_rule_name(const char *name)
Definition tech.c:361
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#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:41
#define tiledef_iterate_end
Definition tiledef.h:54
#define tiledef_iterate(_p)
Definition tiledef.h:48
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:2788
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Definition unittype.c:1880
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1793
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:2847
void role_unit_precalcs(void)
Definition unittype.c:2201
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:2717
Unit_type_id utype_count(void)
Definition unittype.c:82
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2657
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:2629
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:1810
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Definition unittype.c:1943
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:1838
struct veteran_system * veteran_system_new(int count)
Definition unittype.c:2686
Unit_Class_id uclass_number(const struct unit_class *pclass)
Definition unittype.c:2497
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:1902
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:889
#define unit_class_iterate(_p)
Definition unittype.h:916
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:883
#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:863
#define U_LAST
Definition unittype.h:40
#define uclass_index(_c_)
Definition unittype.h:749
#define unit_class_iterate_end
Definition unittype.h:923
#define unit_type_iterate_end
Definition unittype.h:870
#define MAX_NUM_USER_UCLASS_FLAGS
Definition unittype.h:128