Freeciv-3.2
Loading...
Searching...
No Matches
ruleset.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 "achievements.h"
36#include "actions.h"
37#include "ai.h"
38#include "base.h"
39#include "capability.h"
40#include "city.h"
41#include "counters.h"
42#include "effects.h"
43#include "extras.h"
44#include "fc_types.h"
45#include "featured_text.h"
46#include "game.h"
47#include "government.h"
48#include "map.h"
49#include "movement.h"
50#include "multipliers.h"
51#include "name_translation.h"
52#include "nation.h"
53#include "packets.h"
54#include "player.h"
55#include "requirements.h"
56#include "rgbcolor.h"
57#include "road.h"
58#include "sex.h"
59#include "specialist.h"
60#include "style.h"
61#include "tech.h"
62#include "traderoutes.h"
63#include "unit.h"
64#include "unittype.h"
65
66/* server */
67#include "citytools.h"
68#include "notify.h"
69#include "plrhand.h"
70#include "rscompat.h"
71#include "rssanity.h"
72#include "settings.h"
73#include "srv_main.h"
74
75/* server/advisors */
76#include "advruleset.h"
77
78/* server/scripting */
79#include "script_server.h"
80
81#include "ruleset.h"
82
83/* RULESET_SUFFIX already used, no leading dot here */
84#define RULES_SUFFIX "ruleset"
85#define SCRIPT_SUFFIX "lua"
86
87#define ADVANCE_SECTION_PREFIX "advance_"
88#define TECH_CLASS_SECTION_PREFIX "techclass_"
89#define BUILDING_SECTION_PREFIX "building_"
90#define CITYSTYLE_SECTION_PREFIX "citystyle_"
91#define MUSICSTYLE_SECTION_PREFIX "musicstyle_"
92#define UEFF_SECTION_PREFIX "ueff_"
93#define EFFECT_SECTION_PREFIX "effect_"
94#define GOVERNMENT_SECTION_PREFIX "government_"
95#define NATION_SET_SECTION_PREFIX "nset" /* without underscore? */
96#define NATION_GROUP_SECTION_PREFIX "ngroup" /* without underscore? */
97#define NATION_SECTION_PREFIX "nation" /* without underscore? */
98#define STYLE_SECTION_PREFIX "style_"
99#define CLAUSE_SECTION_PREFIX "clause_"
100#define EXTRA_SECTION_PREFIX "extra_"
101#define BASE_SECTION_PREFIX "base_"
102#define ROAD_SECTION_PREFIX "road_"
103#define RESOURCE_SECTION_PREFIX "resource_"
104#define GOODS_SECTION_PREFIX "goods_"
105#define SPECIALIST_SECTION_PREFIX "specialist_"
106#define TERRAIN_SECTION_PREFIX "terrain_"
107#define UNIT_CLASS_SECTION_PREFIX "unitclass_"
108#define UNIT_SECTION_PREFIX "unit_"
109#define DISASTER_SECTION_PREFIX "disaster_"
110#define ACHIEVEMENT_SECTION_PREFIX "achievement_"
111#define ACTION_ENABLER_SECTION_PREFIX "actionenabler_"
112#define MULTIPLIER_SECTION_PREFIX "multiplier_"
113#define COUNTER_SECTION_PREFIX "counter_"
114
115#define check_name(name) (check_strlen(name, MAX_LEN_NAME, NULL))
116#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, NULL))
117
118/* avoid re-reading files */
119static const char name_too_long[] = "Name \"%s\" too long; truncating.";
120#define MAX_SECTION_LABEL 64
121#define section_strlcpy(dst, src) \
122 (void) loud_strlcpy(dst, src, MAX_SECTION_LABEL, name_too_long)
123static char *resource_sections = NULL;
124static char *terrain_sections = NULL;
125static char *extra_sections = NULL;
126static char *base_sections = NULL;
127static char *road_sections = NULL;
128
130
131static bool load_rulesetdir(const char *rsdir, bool compat_mode,
133 bool act, bool buffer_script, bool load_luadata);
134static struct section_file *openload_ruleset_file(const char *whichset,
135 const char *rsdir);
136
137static bool load_game_names(struct section_file *file,
138 struct rscompat_info *compat);
139static bool load_action_names(struct section_file *file,
140 struct rscompat_info *compat);
141static bool load_tech_names(struct section_file *file,
142 struct rscompat_info *compat);
143static bool load_unit_names(struct section_file *file,
144 struct rscompat_info *compat);
145static bool load_building_names(struct section_file *file,
146 struct rscompat_info *compat);
147static bool load_government_names(struct section_file *file,
148 struct rscompat_info *compat);
149static bool load_terrain_names(struct section_file *file,
150 struct rscompat_info *compat);
151static bool load_style_names(struct section_file *file,
152 struct rscompat_info *compat);
153static bool load_nation_names(struct section_file *file,
154 struct rscompat_info *compat);
155static bool load_city_name_list(struct section_file *file,
156 struct nation_type *pnation,
157 const char *secfile_str1,
158 const char *secfile_str2,
159 const char **allowed_terrains,
160 size_t atcount);
161
162static bool load_ruleset_techs(struct section_file *file,
163 struct rscompat_info *compat);
164static bool load_ruleset_units(struct section_file *file,
165 struct rscompat_info *compat);
166static bool load_ruleset_buildings(struct section_file *file,
167 struct rscompat_info *compat);
168static bool load_ruleset_governments(struct section_file *file,
169 struct rscompat_info *compat);
170static bool load_ruleset_terrain(struct section_file *file,
171 struct rscompat_info *compat);
172static bool load_ruleset_styles(struct section_file *file,
173 struct rscompat_info *compat);
174static bool load_ruleset_cities(struct section_file *file,
175 struct rscompat_info *compat);
176static bool load_ruleset_effects(struct section_file *file,
177 struct rscompat_info *compat);
178static bool load_ruleset_game(struct section_file *file, bool act,
179 struct rscompat_info *compat);
180static bool load_ruleset_actions(struct section_file *file,
181 struct section_file *gamefile,
182 struct rscompat_info *compat);
183
184static void send_ruleset_tech_classes(struct conn_list *dest);
185static void send_ruleset_techs(struct conn_list *dest);
186static void send_ruleset_unit_classes(struct conn_list *dest);
187static void send_ruleset_units(struct conn_list *dest);
188static void send_ruleset_buildings(struct conn_list *dest);
189static void send_ruleset_terrain(struct conn_list *dest);
190static void send_ruleset_resources(struct conn_list *dest);
191static void send_ruleset_extras(struct conn_list *dest);
192static void send_ruleset_bases(struct conn_list *dest);
193static void send_ruleset_roads(struct conn_list *dest);
194static void send_ruleset_goods(struct conn_list *dest);
195static void send_ruleset_governments(struct conn_list *dest);
196static void send_ruleset_styles(struct conn_list *dest);
197static void send_ruleset_clauses(struct conn_list *dest);
198static void send_ruleset_musics(struct conn_list *dest);
199static void send_ruleset_cities(struct conn_list *dest);
200static void send_ruleset_game(struct conn_list *dest);
201static void send_ruleset_team_names(struct conn_list *dest);
202
203static bool load_ruleset_veteran(struct section_file *file,
204 const char *path,
205 struct veteran_system **vsystem, char *err,
206 size_t err_len);
207
210
211/**********************************************************************/
216 const char *file, const char *function,
217 int line, enum log_level level,
218 const char *format, ...)
219{
220 va_list args;
221 char buf[MAX_LEN_LOG_LINE];
222
223 if (logger == NULL && !log_do_output_for_level(level)) {
224 return;
225 }
226
227 va_start(args, format);
228 if (logger != NULL) {
229 fc_vsnprintf(buf, sizeof(buf), format, args);
230 logger(buf);
231 } else {
232 vdo_log(file, function, line, FALSE, level, buf, sizeof(buf), format, args);
233 }
234 va_end(args);
235
236 if (LOG_FATAL >= level) {
238 }
239}
240
241/**********************************************************************/
245{
246 int purged = 0;
247
248 action_iterate(act_id) {
249 struct action *paction = action_by_number(act_id);
250
252 == 0) {
253 /* Not relevant. */
254 continue;
255 }
256
257 /* Impossible hard requirement. */
259 /* Make sure that all action enablers are disabled. */
261 ae) {
262 ae->ruledit_disabled = TRUE;
263 purged++;
265
266 log_normal("Purged all action enablers for %s",
268 }
269
270 /* Impossible requirement vector requirement. */
272 ae) {
273 if (!ae->ruledit_disabled
275 || req_vec_is_impossible_to_fulfill(&ae->target_reqs))) {
276 ae->ruledit_disabled = TRUE;
277 purged++;
278 log_normal("Purged unused action enabler for %s",
280 }
283
284 return purged;
285}
286
287/**********************************************************************/
291{
292 int purged = 0;
293 enum effect_type type;
294
299 eft->rulesave.do_not_save = TRUE;
300 purged++;
301 log_normal("Purged unused effect for %s",
302 effect_type_name(eft->type));
303 }
305 }
306
307 return purged;
308}
309
310/**********************************************************************/
314{
315 int purged = 0;
316
319
320 return purged;
321}
322
323/**********************************************************************/
328 const char *msg)
329{
330 struct req_vec_problem *problem;
331 bool result;
332
334 reqs);
335
336 if (problem == NULL) {
337 /* No problem. */
338 return FALSE;
339 }
340
341 if (problem->num_suggested_solutions == 0) {
342 /* No solution. */
344 return FALSE;
345 }
346
347 if (problem->num_suggested_solutions == 1
348 && problem->suggested_solutions[0].operation == RVCO_REMOVE) {
349 /* Remove !present req that never is there. */
350 log_normal("%s", msg);
351 result = req_vec_change_apply(&problem->suggested_solutions[0],
354 return result;
355 }
356
357 /* Not handled. Don't know what this is. */
358 fc_assert(problem->num_suggested_solutions == 1);
360 return FALSE;
361}
362
363/**********************************************************************/
368 const char *msg)
369{
370 struct req_vec_problem *problem;
371 bool result;
372
374 reqs);
375
376 if (problem == NULL) {
377 /* No problem. */
378 return FALSE;
379 }
380
381 if (problem->num_suggested_solutions == 0) {
382 /* No solution. */
384 return FALSE;
385 }
386
387 if (problem->num_suggested_solutions == 2
388 && problem->suggested_solutions[0].operation == RVCO_REMOVE
389 && problem->suggested_solutions[1].operation == RVCO_REMOVE
390 && are_requirements_equal(&problem->suggested_solutions[0].req,
391 &problem->suggested_solutions[1].req)) {
392 /* Simple duplication is handled. */
393 log_normal("%s", msg);
394 result = req_vec_change_apply(&problem->suggested_solutions[1],
397 return result;
398 }
399
400 /* Requirements of different kinds making each other redundant isn't
401 * supported yet. It could be done by always removing the most general
402 * requirement. So unit type is kept when redundant with unit flag, unit
403 * class and unit class flag etc. */
405 return FALSE;
406}
407
408/**********************************************************************/
413 const char *msg)
414{
415 return (purge_unused_req_vec(reqs, msg)
417}
418
419/**********************************************************************/
424{
425 int purged = 0;
426
427 action_iterate(act_id) {
428 struct action *paction = action_by_number(act_id);
429 char actor_reqs[MAX_LEN_NAME * 2];
430 char target_reqs[MAX_LEN_NAME * 2];
431
432 /* Error log text */
433 fc_snprintf(actor_reqs, sizeof(actor_reqs),
434 "Purged redundant requirement in"
435 " %s in action enabler for %s",
436 "actor_reqs", action_rule_name(paction));
437 fc_snprintf(target_reqs, sizeof(target_reqs),
438 "Purged redundant requirement in"
439 " %s in action enabler for %s",
440 "target_reqs", action_rule_name(paction));
441
442 /* Do the purging. */
444 ae) {
445 while (!ae->ruledit_disabled
446 && (purge_redundant_req_vec(&ae->actor_reqs, actor_reqs)
447 || purge_redundant_req_vec(&ae->target_reqs,
448 target_reqs))) {
449 purged++;
450 }
453
454 return purged;
455}
456
457/**********************************************************************/
462{
463 int purged = 0;
464 enum effect_type type;
465
468 char msg[MAX_LEN_NAME * 2];
469
470 /* Error log text */
471 fc_snprintf(msg, sizeof(msg),
472 "Purged redundant requirement in effect of type %s",
474
475 /* Do the purging. */
477 while (purge_redundant_req_vec(&eft->reqs, msg)) {
478 purged++;
479 }
481 }
482
483 return purged;
484}
485
486/**********************************************************************/
491{
492 int purged = 0;
493
496
497 if (purged > 0) {
498 /* An unused requirement may be an obligatory hard requirement. */
500 }
501
502 return purged;
503}
504
505/**********************************************************************/
509static const char *valid_ruleset_filename(const char *subdir,
510 const char *name,
511 const char *extension,
512 bool optional)
513{
514 char filename[512];
515 const char *dfilename;
516
518
519 fc_snprintf(filename, sizeof(filename), "%s" DIR_SEPARATOR "%s.%s",
521 log_verbose("Trying \"%s\".", filename);
522 dfilename = fileinfoname(get_data_dirs(), filename);
523 if (dfilename) {
524 return dfilename;
525 }
526
527 fc_snprintf(filename, sizeof(filename), "default" DIR_SEPARATOR "%s.%s", name, extension);
528 log_verbose("Trying \"%s\": default ruleset directory.", filename);
529 dfilename = fileinfoname(get_data_dirs(), filename);
530 if (dfilename) {
531 return dfilename;
532 }
533
534 fc_snprintf(filename, sizeof(filename), "%s_%s.%s",
536 log_verbose("Trying \"%s\": alternative ruleset filename syntax.",
537 filename);
538 dfilename = fileinfoname(get_data_dirs(), filename);
539 if (dfilename) {
540 return dfilename;
541 } else if (!optional) {
543 /* TRANS: message about an installation error. */
544 _("Could not find a readable \"%s.%s\" ruleset file."),
545 name, extension);
546 }
547
548 return NULL;
549}
550
551/**********************************************************************/
555{
556 return script_buffer;
557}
558
559/**********************************************************************/
563{
564 return parser_buffer;
565}
566
567/**********************************************************************/
571static struct section_file *openload_ruleset_file(const char *whichset,
572 const char *rsdir)
573{
574 char sfilename[512];
577 struct section_file *secfile;
578
579 if (dfilename == NULL) {
580 return NULL;
581 }
582
583 /* Need to save a copy of the filename for following message, since
584 section_file_load() may call datafilename() for includes. */
586 secfile = secfile_load(sfilename, FALSE);
587
588 if (secfile == NULL) {
589 ruleset_error(NULL, LOG_ERROR, "Could not load ruleset '%s':\n%s",
591 }
592
593 return secfile;
594}
595
596/**********************************************************************/
599static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir,
600 char **buffer, bool optional)
601{
604
605 if (dfilename == NULL) {
606 return optional ? TRI_MAYBE : TRI_NO;
607 }
608
609 if (buffer == NULL) {
611 ruleset_error(NULL, LOG_ERROR, "\"%s\": could not load ruleset script.",
612 dfilename);
613
614 return TRI_NO;
615 }
616 } else {
618 }
619
620 return TRI_YES;
621}
622
623/**********************************************************************/
626static struct section_file *openload_luadata_file(const char *rsdir)
627{
628 struct section_file *secfile;
629 char sfilename[512];
630 const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
631 "txt", TRUE);
632
633 if (dfilename == NULL) {
634 return NULL;
635 }
636
637 /* Need to save a copy of the filename for following message, since
638 section_file_load() may call datafilename() for includes. */
640 secfile = secfile_load(sfilename, FALSE);
641
642 if (secfile == NULL) {
643 ruleset_error(NULL, LOG_ERROR, "Could not load luadata '%s':\n%s",
645 }
646
647 return secfile;
648}
649
650/**********************************************************************/
655 struct rscompat_info *compat,
656 const char *sec,
657 const char *sub,
658 const char *rfor)
659{
660 const char *type, *name;
661 int j;
662 const char *filename;
663
664 filename = secfile_name(file);
665
667
668 for (j = 0; (type = secfile_lookup_str_default(file, NULL, "%s.%s%d.type",
669 sec, sub, j)); j++) {
670 char buf[MAX_LEN_NAME];
671 const char *range;
672 bool survives, present, quiet;
673 struct entry *pentry;
674 struct requirement req;
675
676 if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name",
677 sec, sub, j))) {
679
680 return NULL;
681 }
682 name = NULL;
683 switch (entry_type_get(pentry)) {
684 case ENTRY_BOOL:
685 {
686 bool val;
687
688 if (entry_bool_get(pentry, &val)) {
689 fc_snprintf(buf, sizeof(buf), "%d", val);
690 name = buf;
691 }
692 }
693 break;
694 case ENTRY_INT:
695 {
696 int val;
697
698 if (entry_int_get(pentry, &val)) {
699 fc_snprintf(buf, sizeof(buf), "%d", val);
700 name = buf;
701 }
702 }
703 break;
704 case ENTRY_STR:
706 break;
707 case ENTRY_FLOAT:
710 "\"%s\": trying to have an floating point entry as a requirement name in '%s.%s%d'.",
711 filename, sec, sub, j);
712 break;
715 break;
718 break;
719 case ENTRY_ILLEGAL:
721 break;
722 }
723 if (NULL == name) {
725 "\"%s\": error in handling requirement name for '%s.%s%d'.",
726 filename, sec, sub, j);
727 return NULL;
728 }
729
730 if (!(range = secfile_lookup_str(file, "%s.%s%d.range", sec, sub, j))) {
732
733 return NULL;
734 }
735
736 if (compat->compat_mode) {
738 }
739
740 survives = FALSE;
741 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.survives",
742 sec, sub, j))
745 "\"%s\": invalid boolean value for survives for "
746 "'%s.%s%d'.", filename, sec, sub, j);
747 }
748
749 present = TRUE;
750 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.present",
751 sec, sub, j))
754 "\"%s\": invalid boolean value for present for "
755 "'%s.%s%d'.", filename, sec, sub, j);
756 }
757 quiet = FALSE;
758 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.quiet",
759 sec, sub, j))
760 && !entry_bool_get(pentry, &quiet)) {
762 "\"%s\": invalid boolean value for quiet for "
763 "'%s.%s%d'.", filename, sec, sub, j);
764 }
765
766 if (compat->compat_mode) {
768 }
769
771 if (req.source.kind == universals_n_invalid()) {
773 "\"%s\" [%s] has invalid or unknown req: "
774 "\"%s\" \"%s\".",
775 filename, sec, type, name);
776
777 return NULL;
778 }
779
781 }
782
783 if (j > MAX_NUM_REQS) {
785 "Too many (%d) requirements for %s. Max is %d",
786 j, rfor, MAX_NUM_REQS);
787
788 return NULL;
789 }
790
791 return &reqs_list;
792}
793
794/**********************************************************************/
798 struct section_file *file,
799 const char *sec,
800 const char *sub)
801{
802 const char *flag;
803 int j;
804 const char *filename;
805 bool success = TRUE;
806
807 filename = secfile_name(file);
808
809 for (j = 0; (flag = secfile_lookup_str_default(file, NULL, "%s.%s%d.flag",
810 sec, sub, j)); j++) {
811 struct combat_bonus *bonus = fc_malloc(sizeof(*bonus));
812 const char *type;
813
815 if (!unit_type_flag_id_is_valid(bonus->flag)) {
816 log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.",
817 filename, flag, sec, sub);
818 FC_FREE(bonus);
819 success = FALSE;
820 continue;
821 }
822 type = secfile_lookup_str(file, "%s.%s%d.type", sec, sub, j);
824 if (!combat_bonus_type_is_valid(bonus->type)) {
825 log_error("\"%s\": unknown bonus type \"%s\" in '%s.%s'.",
826 filename, type, sec, sub);
827 FC_FREE(bonus);
828 success = FALSE;
829 continue;
830 }
831 if (!secfile_lookup_int(file, &bonus->value, "%s.%s%d.value",
832 sec, sub, j)) {
833 log_error("\"%s\": failed to get value from '%s.%s%d'.",
834 filename, sec, sub, j);
835 FC_FREE(bonus);
836 success = FALSE;
837 continue;
838 }
840 "%s.%s%d.quiet",
841 sec, sub, j);
843 }
844
845 return success;
846}
847
848/**********************************************************************/
856static bool lookup_tech(struct section_file *file,
857 struct advance **result,
858 const char *prefix, const char *entry,
859 const char *filename,
860 const char *description)
861{
862 const char *sval;
863
864 sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
865 if (!sval || !strcmp(sval, "Never")) {
866 *result = A_NEVER;
867 } else {
868 *result = advance_by_rule_name(sval);
869
870 if (A_NEVER == *result) {
872 "\"%s\" %s %s: couldn't match \"%s\".",
873 filename, (description ? description : prefix), entry, sval);
874 return FALSE;
875 }
876 }
877
878 return TRUE;
879}
880
881/**********************************************************************/
888static bool lookup_building(struct section_file *file,
889 const char *prefix, const char *entry,
890 struct impr_type **result,
891 const char *filename,
892 const char *description)
893{
894 const char *sval;
895 bool ok = TRUE;
896
897 sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
898 if (!sval || strcmp(sval, "None") == 0) {
899 *result = B_NEVER;
900 } else {
902
903 if (B_NEVER == *result) {
905 "\"%s\" %s %s: couldn't match \"%s\".",
906 filename, (description ? description : prefix), entry, sval);
907 ok = FALSE;
908 }
909 }
910
911 return ok;
912}
913
914/**********************************************************************/
921static bool lookup_unit_list(struct section_file *file, const char *prefix,
922 const char *entry,
923 struct unit_type **output,
924 const char *filename)
925{
926 const char **slist;
927 size_t nval;
928 int i;
929 bool ok = TRUE;
930
931 /* pre-fill with NULL: */
932 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
933 output[i] = NULL;
934 }
935 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
936 if (nval == 0) {
937 /* 'No vector' is considered same as empty vector */
938 if (slist != NULL) {
939 free(slist);
940 }
941 return TRUE;
942 }
943 if (nval > MAX_NUM_UNIT_LIST) {
945 "\"%s\": string vector %s.%s too long (%d, max %d)",
946 filename, prefix, entry, (int) nval, MAX_NUM_UNIT_LIST);
947 ok = FALSE;
948 } else if (nval == 1 && strcmp(slist[0], "") == 0) {
949 free(slist);
950 return TRUE;
951 }
952 if (ok) {
953 for (i = 0; i < nval; i++) {
954 const char *sval = slist[i];
956
957 if (!punittype) {
959 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
960 filename, prefix, entry, i, sval);
961 ok = FALSE;
962 break;
963 }
964 output[i] = punittype;
965 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
967 }
968 }
969 free(slist);
970
971 return ok;
972}
973
974/**********************************************************************/
981static bool lookup_tech_list(struct section_file *file, const char *prefix,
982 const char *entry, int *output,
983 const char *filename)
984{
985 const char **slist;
986 size_t nval;
987 int i;
988 bool ok = TRUE;
989
990 /* pre-fill with A_LAST: */
991 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
992 output[i] = A_LAST;
993 }
994 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
995 if (slist == NULL || nval == 0) {
996 return TRUE;
997 } else if (nval > MAX_NUM_TECH_LIST) {
999 "\"%s\": string vector %s.%s too long (%d, max %d)",
1000 filename, prefix, entry, (int) nval, MAX_NUM_TECH_LIST);
1001 ok = FALSE;
1002 }
1003
1004 if (ok) {
1005 if (nval == 1 && strcmp(slist[0], "") == 0) {
1006 FC_FREE(slist);
1007 return TRUE;
1008 }
1009 for (i = 0; i < nval && ok; i++) {
1010 const char *sval = slist[i];
1012
1013 if (NULL == padvance) {
1015 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1016 filename, prefix, entry, i, sval);
1017 ok = FALSE;
1018 }
1019 if (!valid_advance(padvance)) {
1021 "\"%s\" %s.%s (%d): \"%s\" is removed.",
1022 filename, prefix, entry, i, sval);
1023 ok = FALSE;
1024 }
1025
1026 if (ok) {
1027 output[i] = advance_number(padvance);
1028 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
1030 }
1031 }
1032 }
1033 FC_FREE(slist);
1034
1035 return ok;
1036}
1037
1038/**********************************************************************/
1045static bool lookup_building_list(struct section_file *file,
1046 const char *prefix, const char *entry,
1047 int *output, const char *filename)
1048{
1049 const char **slist;
1050 size_t nval;
1051 int i;
1052 bool ok = TRUE;
1053
1054 /* pre-fill with B_LAST: */
1055 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1056 output[i] = B_LAST;
1057 }
1058 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
1061 "\"%s\": string vector %s.%s too long (%d, max %d)",
1062 filename, prefix, entry, (int) nval, MAX_NUM_BUILDING_LIST);
1063 ok = FALSE;
1064 } else if (nval == 0 || (nval == 1 && strcmp(slist[0], "") == 0)) {
1065 if (slist != NULL) {
1066 FC_FREE(slist);
1067 }
1068 return TRUE;
1069 }
1070 if (ok) {
1071 for (i = 0; i < nval; i++) {
1072 const char *sval = slist[i];
1073 struct impr_type *pimprove = improvement_by_rule_name(sval);
1074
1075 if (NULL == pimprove) {
1077 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1078 filename, prefix, entry, i, sval);
1079 ok = FALSE;
1080 break;
1081 }
1082 output[i] = improvement_number(pimprove);
1083 log_debug("%s.%s,%d %s %d", prefix, entry, i, sval, output[i]);
1084 }
1085 }
1086 free(slist);
1087
1088 return ok;
1089}
1090
1091/**********************************************************************/
1097static bool lookup_unit_type(struct section_file *file,
1098 const char *prefix,
1099 const char *entry,
1100 const struct unit_type **result,
1101 const char *filename,
1102 const char *description)
1103{
1104 const char *sval;
1105
1106 sval = secfile_lookup_str_default(file, "None", "%s.%s", prefix, entry);
1107
1108 if (strcmp(sval, "None") == 0) {
1109 *result = NULL;
1110 } else {
1111 *result = unit_type_by_rule_name(sval);
1112 if (*result == NULL) {
1114 "\"%s\" %s %s: couldn't match \"%s\".",
1115 filename, (description ? description : prefix), entry, sval);
1116
1117 return FALSE;
1118 }
1119 }
1120
1121 return TRUE;
1122}
1123
1124/**********************************************************************/
1128static struct government *lookup_government(struct section_file *file,
1129 const char *entry,
1130 const char *filename,
1131 struct government *fallback)
1132{
1133 const char *sval;
1134 struct government *gov;
1135
1136 sval = secfile_lookup_str_default(file, NULL, "%s", entry);
1137 if (!sval) {
1138 gov = fallback;
1139 } else {
1141 }
1142 if (!gov) {
1144 "\"%s\" %s: couldn't match \"%s\".",
1145 filename, entry, sval);
1146 }
1147 return gov;
1148}
1149
1150/**********************************************************************/
1153static char *lookup_string(struct section_file *file, const char *prefix,
1154 const char *suffix)
1155{
1156 const char *sval = secfile_lookup_str(file, "%s.%s", prefix, suffix);
1157
1158 if (NULL != sval) {
1159 char copy[strlen(sval) + 1];
1160
1161 strcpy(copy, sval);
1163 if (strlen(copy) > 0) {
1164 return fc_strdup(copy);
1165 }
1166 }
1167 return NULL;
1168}
1169
1170/**********************************************************************/
1173static struct strvec *lookup_strvec(struct section_file *file,
1174 const char *prefix, const char *suffix)
1175{
1176 size_t dim;
1177 const char **vec = secfile_lookup_str_vec(file, &dim,
1178 "%s.%s", prefix, suffix);
1179
1180 if (NULL != vec) {
1181 struct strvec *dest = strvec_new();
1182
1183 strvec_store(dest, vec, dim);
1184 free(vec);
1185 return dest;
1186 }
1187 return NULL;
1188}
1189
1190/**********************************************************************/
1193static struct extra_type *lookup_resource(const char *filename,
1194 const char *name,
1195 const char *jsection)
1196{
1197 struct extra_type *pres;
1198
1200
1201 if (pres == NULL) {
1203 "\"%s\" [%s] has unknown \"%s\".",
1204 filename, jsection, name);
1205 }
1206
1207 return pres;
1208}
1209
1210/**********************************************************************/
1214static bool lookup_terrain(struct section_file *file,
1215 const char *entry,
1216 const char *filename,
1217 struct terrain *pthis,
1218 struct terrain **result,
1219 bool null_acceptable)
1220{
1221 const int j = terrain_index(pthis);
1222 const char *jsection = &terrain_sections[j * MAX_SECTION_LABEL];
1223 const char *name = secfile_lookup_str(file, "%s.%s", jsection, entry);
1224 struct terrain *pterr;
1225
1226 if (NULL == name && !null_acceptable) {
1227 return FALSE;
1228 }
1229
1230 if (NULL == name
1231 || *name == '\0'
1232 || (0 == strcmp(name, "none"))
1233 || (0 == strcmp(name, "no"))) {
1234 *result = T_NONE;
1235
1236 return TRUE;
1237 }
1238 if (0 == strcmp(name, "yes")) {
1239 *result = pthis;
1240
1241 return TRUE;
1242 }
1243
1245 *result = pterr;
1246
1247 if (pterr == NULL) {
1249 "\"%s\" [%s] has unknown \"%s\".",
1250 secfile_name(file), jsection, name);
1251 return FALSE;
1252 }
1253
1254 return TRUE;
1255}
1256
1257/**********************************************************************/
1264bool lookup_time(const struct section_file *secfile, int *turns,
1265 const char *sec_name, const char *property_name,
1266 const char *filename, const char *item_name,
1267 bool *ok)
1268{
1269 /* Assumes that PACKET_UNIT_INFO.activity_count in packets.def is UINT16 */
1270 const int max_turns = 65535 / ACTIVITY_FACTOR;
1271
1272 if (!secfile_lookup_int(secfile, turns, "%s.%s", sec_name, property_name)) {
1273 return FALSE;
1274 }
1275
1276 if (*turns > max_turns) {
1278 "\"%s\": \"%s\": \"%s\" value %d too large (max %d)",
1279 filename, item_name ? item_name : sec_name,
1280 property_name, *turns, max_turns);
1281 *ok = FALSE;
1282 }
1283
1284 return TRUE; /* we found _something */
1285}
1286
1287/**********************************************************************/
1291 const char *domain,
1292 struct section_file *file,
1293 const char *sec_name)
1294{
1295 const char *name = secfile_lookup_str(file, "%s.name", sec_name);
1296 const char *rule_name = secfile_lookup_str(file, "%s.rule_name", sec_name);
1297
1298 if (!name) {
1300 "\"%s\" [%s]: no \"name\" specified.",
1301 secfile_name(file), sec_name);
1302 return FALSE;
1303 }
1304
1305 names_set(pname, domain, name, rule_name);
1306
1307 return TRUE;
1308}
1309
1310/**********************************************************************/
1314 struct section_file *file,
1315 const char *secname, const char *field_prefix)
1316{
1317 enum trait tr;
1318
1319 /* FIXME: Use specenum trait names without duplicating them here.
1320 * Just needs to take care of case.
1321 * This list is also duplicated in rulesave.c:save_traits() */
1322 const char *trait_names[] = {
1323 "expansionist",
1324 "trader",
1325 "aggressive",
1326 "builder",
1327 NULL
1328 };
1329
1330 for (tr = trait_begin(); tr != trait_end() && trait_names[tr] != NULL; tr = trait_next(tr)) {
1331 out[tr].min = secfile_lookup_int_default(file, -1, "%s.%s%s_min",
1332 secname,
1334 trait_names[tr]);
1335 out[tr].max = secfile_lookup_int_default(file, -1, "%s.%s%s_max",
1336 secname,
1338 trait_names[tr]);
1339 out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
1340 secname,
1342 trait_names[tr]);
1343 }
1344
1345 fc_assert(tr == trait_end()); /* number of trait_names correct */
1346}
1347
1348/**********************************************************************/
1352static bool load_game_names(struct section_file *file,
1353 struct rscompat_info *compat)
1354{
1355 struct section_list *sec;
1356 int nval;
1357 const char *filename = secfile_name(file);
1358 bool ok = TRUE;
1359
1360 /* section: datafile */
1362 if (compat->version <= 0) {
1363 return FALSE;
1364 }
1365
1366 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1367 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1368
1370 nval = (NULL != sec ? section_list_size(sec) : 0);
1372 int num = nval; /* No "size_t" to printf */
1373
1375 "\"%s\": Too many achievement types (%d, max %d)",
1376 filename, num, MAX_ACHIEVEMENT_TYPES);
1377 ok = FALSE;
1378 } else {
1380 }
1381
1382 if (ok) {
1385
1386 if (!ruleset_load_names(&pach->name, NULL, file, sec_name)) {
1388 "\"%s\": Cannot load achievement names",
1389 filename);
1390 ok = FALSE;
1391 break;
1392 }
1394 }
1395
1397
1398 if (ok) {
1400
1401 nval = (NULL != sec ? section_list_size(sec) : 0);
1402 if (nval > MAX_GOODS_TYPES) {
1403 int num = nval; /* No "size_t" to printf */
1404
1406 "\"%s\": Too many goods types (%d, max %d)",
1407 filename, num, MAX_GOODS_TYPES);
1409 ok = FALSE;
1410 } else if (nval < 1) {
1412 "\"%s\": At least one goods type needed",
1413 filename);
1415 ok = FALSE;
1416 } else {
1418 }
1419
1420 if (ok) {
1422 const char *sec_name
1424
1425 if (!ruleset_load_names(&pgood->name, NULL, file, sec_name)) {
1427 "\"%s\": Cannot load goods names",
1428 filename);
1429 ok = FALSE;
1430 break;
1431 }
1433 }
1435 }
1436
1437 if (ok) {
1438
1440
1441 nval = (NULL != sec ? section_list_size(sec) : 0);
1442 if (nval > MAX_COUNTERS) {
1443 size_t num = nval;
1444
1446 "\"%s\": Too many counters (" SIZE_T_PRINTF ", max %d)",
1447 filename, num, MAX_COUNTERS);
1448 ok = FALSE;
1449 }
1450
1451 if (ok) {
1452 int count_idx;
1453
1455
1456 for (count_idx = 0; count_idx < nval; count_idx++) {
1457
1459 const char *sec_name
1461
1462 if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
1464 "\"%s\": Cannot load counters names",
1465 filename);
1466 ok = FALSE;
1467 break;
1468 }
1469 }
1470 }
1471
1473 }
1474
1475 return ok;
1476}
1477
1478/**********************************************************************/
1482static bool load_action_names(struct section_file *file,
1483 struct rscompat_info *compat)
1484{
1485 const char *filename = secfile_name(file);
1486 bool ok = TRUE;
1487
1488 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1489 return FALSE;
1490 }
1491
1492 (void) secfile_entry_by_path(file, "datafile.description"); /* Unused */
1493 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* Unused */
1494
1495 return ok;
1496}
1497
1498/**********************************************************************/
1502static bool load_tech_names(struct section_file *file,
1503 struct rscompat_info *compat)
1504{
1505 struct section_list *sec = NULL;
1506 /* Number of techs in the ruleset (means without A_NONE). */
1507 int num_techs = 0;
1508 int i;
1509 const char *filename = secfile_name(file);
1510 bool ok = TRUE;
1511 const char *flag;
1512
1513 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1514 return FALSE;
1515 }
1516
1517 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1518 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1519
1520 /* User tech flag names */
1521 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1522 i++) {
1523 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1524 i);
1527 "\"%s\": Duplicate tech flag name '%s'",
1528 filename, flag);
1529 ok = FALSE;
1530 break;
1531 }
1532 if (i > MAX_NUM_USER_TECH_FLAGS) {
1534 "\"%s\": Too many user tech flags!",
1535 filename);
1536 ok = FALSE;
1537 break;
1538 }
1539
1540 set_user_tech_flag_name(TECH_USER_1 + i, flag, helptxt);
1541 }
1542
1543 if (ok) {
1544 size_t nval;
1545
1546 for (; i < MAX_NUM_USER_TECH_FLAGS; i++) {
1548 }
1549
1550 /* Tech classes */
1552
1553 nval = (NULL != sec ? section_list_size(sec) : 0);
1554 if (nval > MAX_NUM_TECH_CLASSES) {
1555 int num = nval; /* No "size_t" to printf */
1556
1558 "\"%s\": Too many tech classes (%d, max %d)",
1559 filename, num, MAX_NUM_TECH_CLASSES);
1561 ok = FALSE;
1562 } else {
1564 }
1565
1566 if (ok) {
1568 const char *sec_name
1570
1571 if (!ruleset_load_names(&ptclass->name, NULL, file, sec_name)) {
1572 ruleset_error(NULL, LOG_ERROR, "\"%s\": Cannot load tech class names",
1573 filename);
1574 ok = FALSE;
1575 break;
1576 }
1578 }
1579 }
1580
1581 if (ok) {
1582 /* The techs: */
1584 if (NULL == sec || 0 == (num_techs = section_list_size(sec))) {
1586 "\"%s\": No Advances?!?", filename);
1587 ok = FALSE;
1588 } else {
1589 log_verbose("%d advances (including possibly unused)", num_techs);
1590 if (num_techs + A_FIRST > A_LAST) {
1592 "\"%s\": Too many advances (%d, max %d)",
1593 filename, num_techs, A_LAST - A_FIRST);
1594 ok = FALSE;
1595 }
1596 }
1597 }
1598
1599 if (ok) {
1600 game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */
1601
1602 i = 0;
1603 advance_iterate(adv) {
1604 if (!ruleset_load_names(&adv->name, NULL, file,
1606 ok = FALSE;
1607 break;
1608 }
1609 i++;
1611 }
1613
1614 return ok;
1615}
1616
1617/**********************************************************************/
1620static bool load_ruleset_techs(struct section_file *file,
1621 struct rscompat_info *compat)
1622{
1623 struct section_list *sec;
1624 const char **slist;
1625 int i;
1626 size_t nval;
1628 const char *filename = secfile_name(file);
1629 bool ok = TRUE;
1630
1632
1633 i = 0;
1635 const char *sec_name = section_name(section_list_get(sec, i));
1636
1637 ptclass->cost_pct = secfile_lookup_int_default(file, 100, "%s.%s",
1638 sec_name, "cost_pct");
1639
1640 i++;
1642
1644
1645 i = 0;
1646 advance_iterate(a) {
1647 const char *sec_name = section_name(section_list_get(sec, i));
1648 const char *sval;
1649 int j, ival;
1650 struct requirement_vector *research_reqs;
1651
1652 if (!lookup_tech(file, &a->require[AR_ONE], sec_name, "req1",
1653 filename, rule_name_get(&a->name))
1654 || !lookup_tech(file, &a->require[AR_TWO], sec_name, "req2",
1655 filename, rule_name_get(&a->name))
1656 || !lookup_tech(file, &a->require[AR_ROOT], sec_name, "root_req",
1657 filename, rule_name_get(&a->name))) {
1658 ok = FALSE;
1659 break;
1660 }
1661
1662 if ((A_NEVER == a->require[AR_ONE] && A_NEVER != a->require[AR_TWO])
1663 || (A_NEVER != a->require[AR_ONE] && A_NEVER == a->require[AR_TWO])) {
1665 "\"%s\" [%s] \"%s\": \"Never\" with non-\"Never\".",
1666 filename, sec_name, rule_name_get(&a->name));
1667 ok = FALSE;
1668 break;
1669 }
1670 if (a_none == a->require[AR_ONE] && a_none != a->require[AR_TWO]) {
1672 "\"%s\" [%s] \"%s\": should have \"None\" second.",
1673 filename, sec_name, rule_name_get(&a->name));
1674 ok = FALSE;
1675 break;
1676 }
1677
1678 if (game.control.num_tech_classes == 0) {
1679 a->tclass = NULL;
1680 } else {
1681 const char *classname;
1682
1683 classname = lookup_string(file, sec_name, "class");
1684 if (classname != NULL) {
1687 if (a->tclass == NULL) {
1689 "\"%s\" [%s] \"%s\": Unknown tech class \"%s\".",
1690 filename, sec_name, rule_name_get(&a->name), classname);
1691 ok = FALSE;
1692 break;
1693 }
1694 } else {
1695 a->tclass = NULL; /* Default */
1696 }
1697 }
1698
1699 research_reqs = lookup_req_list(file, compat, sec_name, "research_reqs",
1700 rule_name_get(&a->name));
1701 if (research_reqs == NULL) {
1702 ok = FALSE;
1703 break;
1704 }
1705
1706 requirement_vector_copy(&a->research_reqs, research_reqs);
1707
1708 BV_CLR_ALL(a->flags);
1709
1710 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
1711 for (j = 0; j < nval; j++) {
1712 sval = slist[j];
1713 if (strcmp(sval, "") == 0) {
1714 continue;
1715 }
1719 "\"%s\" [%s] \"%s\": bad flag name \"%s\".",
1720 filename, sec_name, rule_name_get(&a->name), sval);
1721 ok = FALSE;
1722 break;
1723 } else {
1724 BV_SET(a->flags, ival);
1725 }
1726 }
1727 free(slist);
1728
1729 if (!ok) {
1730 break;
1731 }
1732
1733 sz_strlcpy(a->graphic_str,
1734 secfile_lookup_str_default(file, "-", "%s.graphic", sec_name));
1735 sz_strlcpy(a->graphic_alt,
1737 "%s.graphic_alt", sec_name));
1738
1739 a->helptext = lookup_strvec(file, sec_name, "helptext");
1740 a->bonus_message = lookup_string(file, sec_name, "bonus_message");
1741 a->cost = secfile_lookup_int_default(file, -1, "%s.%s",
1742 sec_name, "cost");
1743 a->num_reqs = 0;
1744
1745 i++;
1747
1748 /* Propagate a root tech up into the tech tree. If a technology
1749 * X has Y has a root tech, then any technology requiring X (in the
1750 * normal way or as a root tech) also has Y as a root tech.
1751 * Later techs may gain a whole set of root techs in this way. The one
1752 * we store in AR_ROOT is a more or less arbitrary one of these,
1753 * also signalling that the set is non-empty; after this, you'll still
1754 * have to walk the tech tree to find them all. */
1755restart:
1756
1757 if (ok) {
1758 advance_iterate(a) {
1759 if (valid_advance(a)
1760 && A_NEVER != a->require[AR_ROOT]) {
1761 bool out_of_order = FALSE;
1762
1763 /* Now find any tech depending on this technology and update its
1764 * root_req. */
1765 advance_iterate(b) {
1766 if (valid_advance(b)
1767 && A_NEVER == b->require[AR_ROOT]
1768 && (a == b->require[AR_ONE] || a == b->require[AR_TWO])) {
1769 b->require[AR_ROOT] = a->require[AR_ROOT];
1770 b->inherited_root_req = TRUE;
1771 if (b < a) {
1773 }
1774 }
1776
1777 if (out_of_order) {
1778 /* HACK: If we just changed the root_tech of a lower-numbered
1779 * technology, we need to go back so that we can propagate the
1780 * root_tech up to that technology's parents... */
1781 goto restart;
1782 }
1783 }
1785
1786 /* Now rename A_NEVER to A_NONE for consistency */
1788 if (A_NEVER == a->require[AR_ROOT]) {
1789 a->require[AR_ROOT] = a_none;
1790 }
1792
1793 /* Some more consistency checking:
1794 Non-removed techs depending on removed techs is too
1795 broken to fix by default, so die.
1796 */
1797 advance_iterate(a) {
1798 if (valid_advance(a)) {
1799 /* We check for recursive tech loops later,
1800 * in build_required_techs_helper. */
1801 if (!valid_advance(a->require[AR_ONE])) {
1803 "\"%s\" tech \"%s\": req1 leads to removed tech.",
1804 filename, advance_rule_name(a));
1805 ok = FALSE;
1806 break;
1807 }
1808 if (!valid_advance(a->require[AR_TWO])) {
1810 "\"%s\" tech \"%s\": req2 leads to removed tech.",
1811 filename, advance_rule_name(a));
1812 ok = FALSE;
1813 break;
1814 }
1815 }
1817 }
1818
1820 if (ok) {
1822 }
1823
1824 return ok;
1825}
1826
1827/**********************************************************************/
1831static bool load_unit_names(struct section_file *file,
1832 struct rscompat_info *compat)
1833{
1834 struct section_list *sec = NULL;
1835 int nval = 0;
1836 int i;
1837 const char *filename = secfile_name(file);
1838 const char *flag;
1839 bool ok = TRUE;
1840
1841 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1842 return FALSE;
1843 }
1844
1845 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1846 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1847
1848 /* User unit flag names */
1849 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1850 i++) {
1851 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1852 i);
1853
1857 "\"%s\": Duplicate unit flag name '%s'",
1858 filename, flag);
1859 ok = FALSE;
1860 break;
1861 }
1862 if (i > MAX_NUM_USER_UNIT_FLAGS) {
1864 "\"%s\": Too many user unit type flags!",
1865 filename);
1866 ok = FALSE;
1867 break;
1868 }
1869
1871 }
1872
1873 if (ok) {
1874 /* Blank the remaining unit type user flags. */
1875 for (; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
1877 }
1878 }
1879
1880 if (ok) {
1881 /* User unit class flag names */
1882 for (i = 0;
1883 (flag = secfile_lookup_str_default(file, NULL,
1884 "control.class_flags%d.name",
1885 i));
1886 i++) {
1887 const char *helptxt = secfile_lookup_str_default(file, NULL,
1888 "control.class_flags%d.helptxt", i);
1889
1893 "\"%s\": Duplicate unit class flag name '%s'",
1894 filename, flag);
1895 ok = FALSE;
1896 break;
1897 }
1900 "\"%s\": Too many user unit class flags!",
1901 filename);
1902 ok = FALSE;
1903 break;
1904 }
1905
1907 }
1908 }
1909
1910 if (ok) {
1911 /* Blank the remaining unit class user flags. */
1912 for (; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
1914 }
1915 }
1916
1917 if (ok) {
1918 /* Unit classes */
1920 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1922 "\"%s\": No unit classes?!?", filename);
1923 ok = FALSE;
1924 } else {
1925 log_verbose("%d unit classes", nval);
1926 if (nval > UCL_LAST) {
1928 "\"%s\": Too many unit classes (%d, max %d)",
1929 filename, nval, UCL_LAST);
1930 ok = FALSE;
1931 }
1932 }
1933 }
1934
1935 if (ok) {
1937
1939 const int pci = uclass_index(punitclass);
1940
1941 if (!ruleset_load_names(&punitclass->name, NULL, file,
1943 ok = FALSE;
1944 break;
1945 }
1947 }
1949 sec = NULL;
1950
1951 /* The names: */
1952 if (ok) {
1954 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1956 "\"%s\": No unit types?!?", filename);
1957 ok = FALSE;
1958 } else {
1959 log_verbose("%d unit types (including possibly unused)", nval);
1960 if (nval > U_LAST) {
1962 "\"%s\": Too many unit types (%d, max %d)",
1963 filename, nval, U_LAST);
1964 ok = FALSE;
1965 }
1966 }
1967 }
1968
1969 if (ok) {
1971
1973 const int utypei = utype_index(punittype);
1974 if (!ruleset_load_names(&punittype->name, NULL, file,
1976 ok = FALSE;
1977 break;
1978 }
1980 }
1982
1983 return ok;
1984}
1985
1986/**********************************************************************/
1989static bool load_ruleset_veteran(struct section_file *file,
1990 const char *path,
1991 struct veteran_system **vsystem, char *err,
1992 size_t err_len)
1993{
1994 const char **vlist_name;
1997 int i;
1998 bool ret = TRUE;
1999
2000 /* The pointer should be uninitialised. */
2001 if (*vsystem != NULL) {
2002 fc_snprintf(err, err_len, "Veteran system is defined?!");
2003 return FALSE;
2004 }
2005
2006 /* Load data. */
2008 "%s.veteran_names", path);
2010 "%s.veteran_power_fact", path);
2012 "%s.veteran_base_raise_chance", path);
2014 "%s.veteran_work_raise_chance",
2015 path);
2017 "%s.veteran_move_bonus", path);
2018
2019 if (count_name > MAX_VET_LEVELS) {
2020 ret = FALSE;
2021 fc_snprintf(err, err_len, "\"%s\": Too many veteran levels (section "
2022 "'%s': %lu, max %d)", secfile_name(file), path,
2023 (long unsigned)count_name, MAX_VET_LEVELS);
2024 } else if (count_name != count_power
2027 || count_name != count_move) {
2028 ret = FALSE;
2029 fc_snprintf(err, err_len, "\"%s\": Different lengths for the veteran "
2030 "settings in section '%s'", secfile_name(file),
2031 path);
2032 } else if (count_name == 0) {
2033 /* Nothing defined. */
2034 *vsystem = NULL;
2035 } else {
2036 /* Generate the veteran system. */
2038
2039#define rs_sanity_veteran(_path, _entry, _i, _condition, _action) \
2040 if (_condition) { \
2041 log_error("Invalid veteran definition '%s.%s[%d]'!", \
2042 _path, _entry, _i); \
2043 log_debug("Failed check: '%s'. Update value: '%s'.", \
2044 #_condition, #_action); \
2045 _action; \
2046 }
2047 for (i = 0; i < count_name; i++) {
2048 /* Some sanity checks. */
2049 rs_sanity_veteran(path, "veteran_power_fact", i,
2050 (vlist_power[i] < 0), vlist_power[i] = 0);
2051 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2052 (vlist_raise[i] < 0), vlist_raise[i] = 0);
2053 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2054 (vlist_wraise[i] < 0), vlist_wraise[i] = 0);
2055 rs_sanity_veteran(path, "veteran_move_bonus", i,
2056 (vlist_move[i] < 0), vlist_move[i] = 0);
2057 if (i == 0) {
2058 /* First element.*/
2059 rs_sanity_veteran(path, "veteran_power_fact", i,
2060 (vlist_power[i] != 100), vlist_power[i] = 100);
2061 } else if (i == count_name - 1) {
2062 /* Last element. */
2063 rs_sanity_veteran(path, "veteran_power_fact", i,
2064 (vlist_power[i] < vlist_power[i - 1]),
2065 vlist_power[i] = vlist_power[i - 1]);
2066 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2067 (vlist_raise[i] != 0), vlist_raise[i] = 0);
2068 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2069 (vlist_wraise[i] != 0), vlist_wraise[i] = 0);
2070 } else {
2071 /* All elements inbetween. */
2072 rs_sanity_veteran(path, "veteran_power_fact", i,
2073 (vlist_power[i] < vlist_power[i - 1]),
2074 vlist_power[i] = vlist_power[i - 1]);
2075 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2076 (vlist_raise[i] > 100), vlist_raise[i] = 100);
2077 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2078 (vlist_wraise[i] > 100), vlist_wraise[i] = 100);
2079 }
2080
2083 vlist_wraise[i]);
2084 }
2085#undef rs_sanity_veteran
2086 }
2087
2088 if (vlist_name) {
2090 }
2091 if (vlist_power) {
2093 }
2094 if (vlist_raise) {
2096 }
2097 if (vlist_wraise) {
2099 }
2100 if (vlist_move) {
2102 }
2103
2104 return ret;
2105}
2106
2107/**********************************************************************/
2110static bool load_ruleset_units(struct section_file *file,
2111 struct rscompat_info *compat)
2112{
2113 int j, ival;
2114 size_t nval;
2115 struct section_list *sec, *csec;
2116 const char *sval, **slist;
2117 const char *filename = secfile_name(file);
2118 char msg[MAX_LEN_MSG];
2119 bool ok = TRUE;
2120
2121 if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg,
2122 sizeof(msg))
2123 || game.veteran == NULL) {
2125 "Error loading the default veteran system: %s",
2126 msg);
2127 ok = FALSE;
2128 }
2129
2131 nval = (NULL != sec ? section_list_size(sec) : 0);
2132
2134 nval = (NULL != csec ? section_list_size(csec) : 0);
2135
2136 if (ok) {
2138 int i = uclass_index(uc);
2139 const char *sec_name = section_name(section_list_get(csec, i));
2140
2141 if (secfile_lookup_int(file, &uc->min_speed, "%s.min_speed", sec_name)) {
2142 uc->min_speed *= SINGLE_MOVE;
2143 } else {
2145 ok = FALSE;
2146 break;
2147 }
2148 if (!secfile_lookup_int(file, &uc->hp_loss_pct,
2149 "%s.hp_loss_pct", sec_name)) {
2151 ok = FALSE;
2152 break;
2153 }
2154
2155 uc->non_native_def_pct = secfile_lookup_int_default(file, 100,
2156 "%s.non_native_def_pct",
2157 sec_name);
2158
2159 BV_CLR_ALL(uc->flags);
2160 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
2161 for (j = 0; j < nval; j++) {
2162 sval = slist[j];
2163 if (strcmp(sval, "") == 0) {
2164 continue;
2165 }
2168 ok = FALSE;
2172 "\"%s\" unit_class \"%s\": unit_type flag \"%s\"!",
2173 filename, uclass_rule_name(uc), sval);
2174 } else {
2176 "\"%s\" unit_class \"%s\": bad flag name \"%s\".",
2177 filename, uclass_rule_name(uc), sval);
2178 }
2179 break;
2180 } else {
2181 BV_SET(uc->flags, ival);
2182 }
2183 }
2184 free(slist);
2185
2186 uc->helptext = lookup_strvec(file, sec_name, "helptext");
2187
2188 if (!ok) {
2189 break;
2190 }
2192 }
2193
2194 if (ok) {
2195 /* Tech and Gov requirements; per unit veteran system */
2197 const int i = utype_index(u);
2198 const struct section *psection = section_list_get(sec, i);
2199 const char *sec_name = section_name(psection);
2200
2201 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
2202 struct advance *adv_req;
2203 struct impr_type *impr_req = NULL;
2204
2205 if (!lookup_tech(file, &adv_req, sec_name,
2206 "tech_req", filename,
2207 rule_name_get(&u->name))) {
2208 ok = FALSE;
2209 break;
2210 }
2211 if (adv_req == A_NEVER) {
2212 ruleset_error(NULL, LOG_ERROR, "%s lacks valid tech_req.",
2213 rule_name_get(&u->name));
2214 ok = FALSE;
2215 break;
2216 } else if (adv_req != advance_by_number(A_NONE)) {
2217 requirement_vector_append(&u->build_reqs,
2219 FALSE, TRUE, FALSE,
2221 }
2222
2223 /* Read the government build requirement from the old ruleset format
2224 * and put it in unit_type's build_reqs requirement vector.
2225 * The build_reqs requirement vector isn't ready to be exposed in the
2226 * ruleset yet.
2227 * Barbarians can build certain units as long as anyone in the world
2228 * has the required tech. Regular players must have the required tech
2229 * them self to build the same unit. One way to solve this is to make
2230 * unit building an action enabler controlled action with a city (not
2231 * unit) actor.
2232 * Putting a requirement vector on unit types in the ruleset will
2233 * force ruleset authors to change all their unit type build
2234 * requirements to a requirement vector. Forcing them to convert their
2235 * unit type requirements again in the next version (should building be
2236 * switched to an action enabler with a city actor) is not good. */
2237 if (NULL != section_entry_by_name(psection, "gov_req")) {
2238 char tmp[200] = "\0";
2240
2241 fc_strlcat(tmp, section_name(psection), sizeof(tmp));
2242 fc_strlcat(tmp, ".gov_req", sizeof(tmp));
2243 need_government = lookup_government(file, tmp, filename, NULL);
2244 if (need_government == NULL) {
2245 ok = FALSE;
2246 break;
2247 }
2250 FALSE, TRUE, FALSE,
2252 }
2253
2254 /* Read the building build requirement from the old ruleset format
2255 * and put it in unit_type's build_reqs requirement vector.
2256 * The build_reqs requirement vector isn't ready to be exposed in the
2257 * ruleset yet.
2258 * See the comment for gov_req above for why. */
2259 if (!lookup_building(file, sec_name, "impr_req",
2260 &impr_req, filename,
2261 rule_name_get(&u->name))) {
2262 ok = FALSE;
2263 break;
2264 }
2265 if (impr_req) {
2268 FALSE, TRUE, FALSE,
2270 }
2271 } else {
2272 /* Freeciv-3.2 format */
2273 struct requirement_vector *reqs;
2274
2275 reqs = lookup_req_list(file, compat, sec_name, "reqs",
2276 utype_rule_name(u));
2277
2278 if (reqs == NULL) {
2279 ok = FALSE;
2280 break;
2281 }
2282
2283 requirement_vector_copy(&u->build_reqs, reqs);
2284 }
2285
2286 if (!load_ruleset_veteran(file, sec_name, &u->veteran,
2287 msg, sizeof(msg))) {
2289 "Error loading the veteran system: %s",
2290 msg);
2291 ok = FALSE;
2292 break;
2293 }
2294
2295 if (!lookup_unit_type(file, sec_name, "obsolete_by",
2296 &u->obsoleted_by, filename,
2297 rule_name_get(&u->name))
2298 || !lookup_unit_type(file, sec_name, "convert_to",
2299 &u->converted_to, filename,
2300 rule_name_get(&u->name))) {
2301 ok = FALSE;
2302 break;
2303 }
2304 u->convert_time = 1; /* default */
2305 lookup_time(file, &u->convert_time, sec_name, "convert_time",
2306 filename, rule_name_get(&u->name), &ok);
2308 }
2309
2310 if (ok) {
2311 /* main stats: */
2313 const int i = utype_index(u);
2314 struct unit_class *pclass;
2315 const char *sec_name = section_name(section_list_get(sec, i));
2316 const char *str;
2317
2318 sval = secfile_lookup_str(file, "%s.class", sec_name);
2320 if (!pclass) {
2322 "\"%s\" unit_type \"%s\": bad class \"%s\".",
2323 filename, utype_rule_name(u), sval);
2324 ok = FALSE;
2325 break;
2326 }
2327 u->uclass = pclass;
2328
2329 sz_strlcpy(u->sound_move,
2330 secfile_lookup_str_default(file, "-", "%s.sound_move",
2331 sec_name));
2332 sz_strlcpy(u->sound_move_alt,
2333 secfile_lookup_str_default(file, "-", "%s.sound_move_alt",
2334 sec_name));
2335 sz_strlcpy(u->sound_fight,
2336 secfile_lookup_str_default(file, "-", "%s.sound_fight",
2337 sec_name));
2338 sz_strlcpy(u->sound_fight_alt,
2339 secfile_lookup_str_default(file, "-", "%s.sound_fight_alt",
2340 sec_name));
2341
2342 if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) {
2343 sz_strlcpy(u->graphic_str, str);
2344 } else {
2346 ok = FALSE;
2347 break;
2348 }
2349 sz_strlcpy(u->graphic_alt,
2350 secfile_lookup_str_default(file, "-", "%s.graphic_alt",
2351 sec_name));
2352 sz_strlcpy(u->graphic_alt2,
2353 secfile_lookup_str_default(file, "-", "%s.graphic_alt2",
2354 sec_name));
2355
2356 if (!secfile_lookup_int(file, &u->build_cost,
2357 "%s.build_cost", sec_name)
2358 || !secfile_lookup_int(file, &u->pop_cost,
2359 "%s.pop_cost", sec_name)
2360 || !secfile_lookup_int(file, &u->attack_strength,
2361 "%s.attack", sec_name)
2362 || !secfile_lookup_int(file, &u->defense_strength,
2363 "%s.defense", sec_name)
2364 || !secfile_lookup_int(file, &u->move_rate,
2365 "%s.move_rate", sec_name)
2366 || !secfile_lookup_int(file, &u->vision_radius_sq,
2367 "%s.vision_radius_sq", sec_name)
2368 || !secfile_lookup_int(file, &u->transport_capacity,
2369 "%s.transport_cap", sec_name)
2370 || !secfile_lookup_int(file, &u->hp,
2371 "%s.hitpoints", sec_name)
2372 || !secfile_lookup_int(file, &u->firepower,
2373 "%s.firepower", sec_name)
2374 || !secfile_lookup_int(file, &u->fuel,
2375 "%s.fuel", sec_name)
2376 || !secfile_lookup_int(file, &u->happy_cost,
2377 "%s.uk_happy", sec_name)) {
2379 ok = FALSE;
2380 break;
2381 }
2382 u->move_rate *= SINGLE_MOVE;
2383
2384 if (u->firepower <= 0) {
2386 "\"%s\" unit_type \"%s\":"
2387 " firepower is %d,"
2388 " but must be at least 1. "
2389 " If you want no attack ability,"
2390 " set the unit's attack strength to 0.",
2391 filename, utype_rule_name(u), u->firepower);
2392 ok = FALSE;
2393 break;
2394 }
2395
2396 lookup_cbonus_list(u->bonuses, file, sec_name, "bonuses");
2397
2399 u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s",
2400 sec_name,
2403
2404 slist = secfile_lookup_str_vec(file, &nval, "%s.cargo", sec_name);
2405 if (u->transport_capacity > 0) {
2406 if (nval == 0) {
2408 "\"%s\" unit type \"%s\" "
2409 "has transport_cap %d, but no cargo unit classes.",
2410 filename, utype_rule_name(u), u->transport_capacity);
2411 ok = FALSE;
2412 break;
2413 }
2414 } else {
2415 if (nval > 0) {
2417 "\"%s\" unit type \"%s\" "
2418 "has cargo defined, but transport_cap is 0.",
2419 filename, utype_rule_name(u));
2420 ok = FALSE;
2421 break;
2422 }
2423 }
2424
2425 BV_CLR_ALL(u->cargo);
2426 for (j = 0; j < nval; j++) {
2427 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2428
2429 if (!uclass) {
2431 "\"%s\" unit_type \"%s\":"
2432 "has unknown unit class %s as cargo.",
2433 filename, utype_rule_name(u), slist[j]);
2434 ok = FALSE;
2435 break;
2436 }
2437
2438 BV_SET(u->cargo, uclass_index(uclass));
2439 }
2440 free(slist);
2441
2442 if (!ok) {
2443 break;
2444 }
2445
2446 slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec_name);
2447 BV_CLR_ALL(u->targets);
2448 for (j = 0; j < nval; j++) {
2449 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2450
2451 if (!uclass) {
2453 "\"%s\" unit_type \"%s\":"
2454 "has unknown unit class %s as target.",
2455 filename, utype_rule_name(u), slist[j]);
2456 ok = FALSE;
2457 break;
2458 }
2459
2460 BV_SET(u->targets, uclass_index(uclass));
2461 }
2462 free(slist);
2463
2464 if (!ok) {
2465 break;
2466 }
2467
2468 slist = secfile_lookup_str_vec(file, &nval, "%s.embarks", sec_name);
2469 BV_CLR_ALL(u->embarks);
2470 for (j = 0; j < nval; j++) {
2471 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2472
2473 if (!uclass) {
2475 "\"%s\" unit_type \"%s\":"
2476 "has unknown unit class %s as embarkable.",
2477 filename, utype_rule_name(u), slist[j]);
2478 ok = FALSE;
2479 break;
2480 }
2481
2482 BV_SET(u->embarks, uclass_index(uclass));
2483 }
2484 free(slist);
2485
2486 if (!ok) {
2487 break;
2488 }
2489
2490 slist = secfile_lookup_str_vec(file, &nval, "%s.disembarks", sec_name);
2491 BV_CLR_ALL(u->disembarks);
2492 for (j = 0; j < nval; j++) {
2493 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2494
2495 if (!uclass) {
2497 "\"%s\" unit_type \"%s\":"
2498 "has unknown unit class %s as disembarkable.",
2499 filename, utype_rule_name(u), slist[j]);
2500 ok = FALSE;
2501 break;
2502 }
2503
2504 BV_SET(u->disembarks, uclass_index(uclass));
2505 }
2506 free(slist);
2507
2508 if (!ok) {
2509 break;
2510 }
2511
2512 /* Set also all classes that are never unreachable as targets,
2513 * embarks, and disembarks. */
2516 BV_SET(u->targets, uclass_index(preachable));
2517 BV_SET(u->embarks, uclass_index(preachable));
2518 BV_SET(u->disembarks, uclass_index(preachable));
2519 }
2521
2522 str = secfile_lookup_str_default(file, "Main", "%s.vision_layer",
2523 sec_name);
2525 if (!vision_layer_is_valid(u->vlayer)) {
2527 "\"%s\" unit_type \"%s\":"
2528 "has unknown vision layer %s.",
2529 filename, utype_rule_name(u), str);
2530 ok = FALSE;
2531 break;
2532 }
2533
2534 u->helptext = lookup_strvec(file, sec_name, "helptext");
2535
2536 u->paratroopers_range = secfile_lookup_int_default(file,
2537 0, "%s.paratroopers_range", sec_name);
2538
2539 u->bombard_rate = secfile_lookup_int_default(file, 0,
2540 "%s.bombard_rate", sec_name);
2541 u->city_slots = secfile_lookup_int_default(file, 0,
2542 "%s.city_slots", sec_name);
2543 u->city_size = secfile_lookup_int_default(file, 1,
2544 "%s.city_size", sec_name);
2545
2547 "%s.tp_defense", sec_name);
2548 u->tp_defense = transp_def_type_by_name(sval, fc_strcasecmp);
2549 if (!transp_def_type_is_valid(u->tp_defense)) {
2551 "\"%s\" unit_type \"%s\":"
2552 " bad tp_defense \"%s\".",
2553 filename, utype_rule_name(u), sval);
2554 ok = FALSE;
2555 break;
2556 }
2558 }
2559
2560 if (ok) {
2561 /* flags */
2563 const int i = utype_index(u);
2564
2565 BV_CLR_ALL(u->flags);
2567
2568 slist = secfile_lookup_str_vec(file, &nval, "%s.flags",
2570 for (j = 0; j < nval; j++) {
2571 sval = slist[j];
2572 if (0 == strcmp(sval, "")) {
2573 continue;
2574 }
2577 ok = FALSE;
2581 "\"%s\" unit_type \"%s\": unit_class flag!",
2582 filename, utype_rule_name(u));
2583 } else {
2585 "\"%s\" unit_type \"%s\": bad flag name \"%s\".",
2586 filename, utype_rule_name(u), sval);
2587 }
2588 break;
2589 } else {
2590 BV_SET(u->flags, ival);
2591 }
2592 }
2593 free(slist);
2594
2595 if (!ok) {
2596 break;
2597 }
2599 }
2600
2601 /* roles */
2602 if (ok) {
2604 const int i = utype_index(u);
2605
2606 BV_CLR_ALL(u->roles);
2607
2608 slist = secfile_lookup_str_vec(file, &nval, "%s.roles",
2610 for (j = 0; j < nval; j++) {
2611 sval = slist[j];
2612 if (strcmp(sval, "") == 0) {
2613 continue;
2614 }
2618 "\"%s\" unit_type \"%s\": bad role name \"%s\".",
2619 filename, utype_rule_name(u), sval);
2620 ok = FALSE;
2621 break;
2622 } else {
2623 BV_SET(u->roles, ival - L_FIRST);
2624 }
2626 }
2627 free(slist);
2629 }
2630
2631 if (ok) {
2632 /* Some more consistency checking: */
2635 if (!valid_advance(padv)) {
2637 "\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
2638 filename, utype_rule_name(u),
2640 ok = FALSE;
2641 break;
2642 }
2644
2645 if (!ok) {
2646 break;
2647 }
2649 }
2650
2653
2654 if (ok) {
2656 }
2657
2658 return ok;
2659}
2660
2661/**********************************************************************/
2665static bool load_building_names(struct section_file *file,
2666 struct rscompat_info *compat)
2667{
2668 struct section_list *sec;
2669 int i, nval = 0;
2670 const char *filename = secfile_name(file);
2671 bool ok = TRUE;
2672 const char *flag;
2673
2674 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2675 return FALSE;
2676 }
2677
2678 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2679 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2680
2681 /* The names: */
2683 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2685 "\"%s\": No improvements?!?", filename);
2686 ok = FALSE;
2687 } else {
2688 log_verbose("%d improvement types (including possibly unused)", nval);
2689 if (nval > B_LAST) {
2691 "\"%s\": Too many improvements (%d, max %d)",
2692 filename, nval, B_LAST);
2693 ok = FALSE;
2694 }
2695 }
2696
2697 if (ok) {
2699
2700 for (i = 0; i < nval; i++) {
2701 struct impr_type *b = improvement_by_number(i);
2702
2703 if (!ruleset_load_names(&b->name, NULL, file, section_name(section_list_get(sec, i)))) {
2704 ok = FALSE;
2705 break;
2706 }
2707 }
2708 }
2709
2710 /* User building flag names */
2711 for (i = 0;
2712 (flag = secfile_lookup_str_default(file, NULL,
2713 "control.building_flags%d.name",
2714 i));
2715 i++) {
2716 const char *helptxt = secfile_lookup_str_default(file, NULL,
2717 "control.building_flags%d.helptxt", i);
2718
2720 != impr_flag_id_invalid()) {
2722 "\"%s\": Duplicate building flag name '%s'",
2723 filename, flag);
2724 ok = FALSE;
2725 break;
2726 }
2729 "\"%s\": Too many user building flags!",
2730 filename);
2731 ok = FALSE;
2732 break;
2733 }
2734
2735 set_user_impr_flag_name(IF_USER_FLAG_1 + i, flag, helptxt);
2736 }
2737
2739
2740 return ok;
2741}
2742
2743/**********************************************************************/
2746static bool load_ruleset_buildings(struct section_file *file,
2747 struct rscompat_info *compat)
2748{
2749 struct section_list *sec;
2750 const char *item;
2751 int i, nval;
2752 const char *filename = secfile_name(file);
2753 bool ok = TRUE;
2754
2756 nval = (NULL != sec ? section_list_size(sec) : 0);
2757
2758 for (i = 0; i < nval && ok; i++) {
2759 struct impr_type *b = improvement_by_number(i);
2760 const char *sec_name = section_name(section_list_get(sec, i));
2761 struct requirement_vector *reqs =
2762 lookup_req_list(file, compat, sec_name, "reqs",
2764
2765 if (reqs == NULL) {
2766 ok = FALSE;
2767 break;
2768 } else {
2769 const char *sval, **slist;
2770 int j, ival;
2771 size_t nflags;
2772
2773 item = secfile_lookup_str(file, "%s.genus", sec_name);
2775 if (!impr_genus_id_is_valid(b->genus)) {
2777 "\"%s\" improvement \"%s\": couldn't match "
2778 "genus \"%s\".", filename,
2780 ok = FALSE;
2781 break;
2782 }
2783
2784 slist = secfile_lookup_str_vec(file, &nflags, "%s.flags", sec_name);
2785 BV_CLR_ALL(b->flags);
2786
2787 for (j = 0; j < nflags; j++) {
2788 sval = slist[j];
2789 if (strcmp(sval, "") == 0) {
2790 continue;
2791 }
2795 "\"%s\" improvement \"%s\": bad flag name \"%s\".",
2796 filename, improvement_rule_name(b), sval);
2797 ok = FALSE;
2798 break;
2799 } else {
2800 BV_SET(b->flags, ival);
2801 }
2802 }
2803 free(slist);
2804
2805 if (!ok) {
2806 break;
2807 }
2808
2809 if (compat->compat_mode) {
2811 }
2812
2814
2815 {
2816 struct requirement_vector *obs_reqs =
2817 lookup_req_list(file, compat, sec_name, "obsolete_by",
2819
2820 if (obs_reqs == NULL) {
2821 ok = FALSE;
2822 break;
2823 } else {
2824 requirement_vector_copy(&b->obsolete_by, obs_reqs);
2825 }
2826 }
2827
2828 if (!secfile_lookup_int(file, &b->build_cost,
2829 "%s.build_cost", sec_name)
2830 || !secfile_lookup_int(file, &b->upkeep,
2831 "%s.upkeep", sec_name)
2832 || !secfile_lookup_int(file, &b->sabotage,
2833 "%s.sabotage", sec_name)) {
2835 ok = FALSE;
2836 break;
2837 }
2838
2841 "%s.graphic", sec_name));
2844 "%s.graphic_alt", sec_name));
2847 "%s.graphic_alt2", sec_name));
2848
2851 "%s.sound", sec_name));
2854 "%s.sound_alt", sec_name));
2857 "%s.sound_alt2", sec_name));
2858 b->helptext = lookup_strvec(file, sec_name, "helptext");
2859 }
2860 }
2861
2863 if (ok) {
2865 }
2866
2867 return ok;
2868}
2869
2870/**********************************************************************/
2874static bool load_terrain_names(struct section_file *file,
2875 struct rscompat_info *compat)
2876{
2877 int nval = 0;
2878 struct section_list *sec = NULL;
2879 const char *flag;
2880 int i;
2881 const char *filename = secfile_name(file);
2882 bool ok = TRUE;
2883
2884 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2885 return FALSE;
2886 }
2887
2888 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2889 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2890
2891 /* User terrain flag names */
2892 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
2893 i++) {
2894 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
2895 i);
2896
2900 "\"%s\": Duplicate terrain flag name '%s'",
2901 filename, flag);
2902 ok = FALSE;
2903 break;
2904 }
2905 if (i > MAX_NUM_USER_TER_FLAGS) {
2907 "\"%s\": Too many user terrain flags!",
2908 filename);
2909 ok = FALSE;
2910 break;
2911 }
2912
2913 set_user_terrain_flag_name(TER_USER_1 + i, flag, helptxt);
2914 }
2915
2916 if (ok) {
2917 /* Blank the remaining terrain user flag slots. */
2918 for (; i < MAX_NUM_USER_TER_FLAGS; i++) {
2920 }
2921 }
2922
2923 /* User extra flag names */
2924 for (i = 0;
2925 (flag = secfile_lookup_str_default(file, NULL,
2926 "control.extra_flags%d.name",
2927 i));
2928 i++) {
2929 const char *helptxt = secfile_lookup_str_default(file, NULL,
2930 "control.extra_flags%d.helptxt", i);
2931
2933 != extra_flag_id_invalid()) {
2935 "\"%s\": Duplicate extra flag name '%s'",
2936 filename, flag);
2937 ok = FALSE;
2938 break;
2939 }
2942 "\"%s\": Too many user extra flags!",
2943 filename);
2944 ok = FALSE;
2945 break;
2946 }
2947
2948 set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt);
2949 }
2950
2951 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
2953 }
2954
2955 if (ok) {
2956 /* Blank the remaining extra user flag slots. */
2957 for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
2959 }
2960
2961 /* terrain names */
2962
2964 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2966 "\"%s\": ruleset doesn't have any terrains.",
2967 filename);
2968 ok = FALSE;
2969 } else {
2970 if (nval > MAX_NUM_TERRAINS) {
2972 "\"%s\": Too many terrains (%d, max %d)",
2973 filename, nval, MAX_NUM_TERRAINS);
2974 ok = FALSE;
2975 }
2976 }
2977 }
2978
2979 if (ok) {
2981
2982 /* avoid re-reading files */
2983 if (terrain_sections) {
2985 }
2987
2988 terrain_type_iterate(pterrain) {
2989 const int terri = terrain_index(pterrain);
2990 const char *sec_name = section_name(section_list_get(sec, terri));
2991
2992 if (!ruleset_load_names(&pterrain->name, NULL, file, sec_name)) {
2993 ok = FALSE;
2994 break;
2995 }
2996
2999 }
3000
3002 sec = NULL;
3003
3004 /* extra names */
3005
3006 if (ok) {
3008 nval = (NULL != sec ? section_list_size(sec) : 0);
3009 if (nval > MAX_EXTRA_TYPES) {
3011 "\"%s\": Too many extra types (%d, max %d)",
3012 filename, nval, MAX_EXTRA_TYPES);
3013 ok = FALSE;
3014 }
3015 }
3016
3017 if (ok) {
3018 int idx;
3019
3021
3022 if (extra_sections) {
3024 }
3026
3027 if (ok) {
3028 for (idx = 0; idx < nval; idx++) {
3029 const char *sec_name = section_name(section_list_get(sec, idx));
3030 struct extra_type *pextra = extra_by_number(idx);
3031
3032 if (!ruleset_load_names(&pextra->name, NULL, file, sec_name)) {
3033 ok = FALSE;
3034 break;
3035 }
3037 }
3038 }
3039 }
3040
3042 sec = NULL;
3043
3044 /* Base names */
3045
3046 if (ok) {
3048 nval = (NULL != sec ? section_list_size(sec) : 0);
3049 if (nval > MAX_EXTRA_TYPES) {
3051 "\"%s\": Too many base types (%d, max %d)",
3052 filename, nval, MAX_EXTRA_TYPES);
3053 ok = FALSE;
3054 }
3055
3057 }
3058
3059 if (ok) {
3060 int idx;
3061
3062 if (base_sections) {
3064 }
3066
3067 /* Cannot use base_type_iterate() before bases are added to
3068 * EC_BASE caused_by list. Have to get them by extra_type_by_rule_name() */
3069 for (idx = 0; idx < nval; idx++) {
3070 const char *sec_name = section_name(section_list_get(sec, idx));
3071 const char *base_name = secfile_lookup_str(file, "%s.extra", sec_name);
3072
3073 if (base_name != NULL) {
3075
3076 if (pextra != NULL) {
3077 base_type_init(pextra, idx);
3079 } else {
3081 "No extra definition matching base definition \"%s\"",
3082 base_name);
3083 ok = FALSE;
3084 }
3085 } else {
3087 "Base section \"%s\" does not associate base with any extra",
3088 sec_name);
3089 ok = FALSE;
3090 }
3091 }
3092 }
3093
3095 sec = NULL;
3096
3097 /* Road names */
3098
3099 if (ok) {
3101 nval = (NULL != sec ? section_list_size(sec) : 0);
3102 if (nval > MAX_EXTRA_TYPES) {
3104 "\"%s\": Too many road types (%d, max %d)",
3105 filename, nval, MAX_EXTRA_TYPES);
3106 ok = FALSE;
3107 }
3108
3110 }
3111
3112 if (ok) {
3113 int idx;
3114
3115 if (road_sections) {
3117 }
3119
3120 /* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to
3121 * EC_ROAD caused_by list. Have to get them by extra_type_by_rule_name() */
3122 for (idx = 0; idx < nval; idx++) {
3123 const char *sec_name = section_name(section_list_get(sec, idx));
3124 const char *road_name = secfile_lookup_str(file, "%s.extra", sec_name);
3125
3126 if (road_name != NULL) {
3128
3129 if (pextra != NULL) {
3130 road_type_init(pextra, idx);
3132 } else {
3134 "No extra definition matching road definition \"%s\"",
3135 road_name);
3136 ok = FALSE;
3137 }
3138 } else {
3140 "Road section \"%s\" does not associate road with any extra",
3141 sec_name);
3142 ok = FALSE;
3143 }
3144 }
3145 }
3146
3148 sec = NULL;
3149
3150 /* Resource names */
3151 if (ok) {
3153 nval = (NULL != sec ? section_list_size(sec) : 0);
3154 if (nval > MAX_EXTRA_TYPES) {
3156 "\"%s\": Too many resource types (%d, max %d)",
3157 filename, nval, MAX_EXTRA_TYPES);
3158 ok = FALSE;
3159 }
3160
3162 }
3163
3164 if (ok) {
3165 int idx;
3166
3167 if (resource_sections) {
3169 }
3171
3172 /* Cannot use resource_type_iterate() before resource are added to
3173 * EC_RESOURCE caused_by list. Have to get them by extra_type_by_rule_name() */
3174 for (idx = 0; idx < nval; idx++) {
3175 const char *sec_name = section_name(section_list_get(sec, idx));
3176 const char *resource_name;
3177 struct extra_type *pextra = NULL;
3178
3180
3181 if (resource_name != NULL) {
3183
3184 if (pextra != NULL) {
3185 resource_type_init(pextra);
3187 } else {
3189 "No extra definition matching resource definition \"%s\"",
3191 ok = FALSE;
3192 }
3193 } else {
3195 "Resource section %s does not list extra this resource belongs to.",
3196 sec_name);
3197 ok = FALSE;
3198 }
3199 }
3200 }
3201
3203
3204 return ok;
3205}
3206
3207/**********************************************************************/
3210static bool load_ruleset_terrain(struct section_file *file,
3211 struct rscompat_info *compat)
3212{
3213 size_t nval, nval2;
3214 int j;
3215 bool compat_road = FALSE;
3216 bool compat_rail = FALSE;
3217 bool compat_river = FALSE;
3218 const char **res;
3219 const char *filename = secfile_name(file);
3220 const char *text;
3221 int *res_freq;
3222 bool ok = TRUE;
3223
3224 /* parameters */
3225
3226 terrain_control.ocean_reclaim_requirement_pct
3227 = secfile_lookup_int_default(file, 101,
3228 "parameters.ocean_reclaim_requirement");
3229 terrain_control.land_channel_requirement_pct
3230 = secfile_lookup_int_default(file, 101,
3231 "parameters.land_channel_requirement");
3232 terrain_control.terrain_thaw_requirement_pct
3233 = secfile_lookup_int_default(file, 101,
3234 "parameters.thaw_requirement");
3235 terrain_control.terrain_freeze_requirement_pct
3236 = secfile_lookup_int_default(file, 101,
3237 "parameters.freeze_requirement");
3238 terrain_control.lake_max_size
3240 "parameters.lake_max_size");
3241 terrain_control.min_start_native_area
3243 "parameters.min_start_native_area");
3244 terrain_control.move_fragments
3246 "parameters.move_fragments");
3247 if (terrain_control.move_fragments < 1) {
3249 "\"%s\": move_fragments must be at least 1",
3250 filename);
3251 ok = FALSE;
3252 }
3254 terrain_control.igter_cost
3256 "parameters.igter_cost");
3257 if (terrain_control.igter_cost < 1) {
3259 "\"%s\": igter_cost must be at least 1",
3260 filename);
3261 ok = FALSE;
3262 }
3263 terrain_control.infrapoints = FALSE; /* This will be updated if we find
3264 * an placeable extra. */
3265
3266 terrain_control.pythagorean_diagonal
3268 "parameters.pythagorean_diagonal");
3269
3272 "parameters.ocean_resources");
3273
3274 text = secfile_lookup_str_default(file,
3275 N_("?gui_type:Build Type A Base"),
3276 "extraui.ui_name_base_fortress");
3277 sz_strlcpy(terrain_control.gui_type_base0, text);
3278
3279 text = secfile_lookup_str_default(file,
3280 N_("?gui_type:Build Type B Base"),
3281 "extraui.ui_name_base_airbase");
3282 sz_strlcpy(terrain_control.gui_type_base1, text);
3283
3284 if (ok) {
3285 /* Terrain details */
3286
3287 terrain_type_iterate(pterrain) {
3288 const char **slist;
3289 const int i = terrain_index(pterrain);
3290 const char *tsection = &terrain_sections[i * MAX_SECTION_LABEL];
3291 const char *cstr;
3292 const char *ename;
3293
3294 sz_strlcpy(pterrain->graphic_str,
3295 secfile_lookup_str(file, "%s.graphic", tsection));
3296 sz_strlcpy(pterrain->graphic_alt,
3298 "%s.graphic_alt", tsection));
3299 sz_strlcpy(pterrain->graphic_alt2,
3301 "%s.graphic_alt2", tsection));
3302
3303 pterrain->identifier
3304 = secfile_lookup_str(file, "%s.identifier", tsection)[0];
3305 if ('\0' == pterrain->identifier) {
3307 "\"%s\" [%s] identifier missing value.",
3308 filename, tsection);
3309 ok = FALSE;
3310 break;
3311 }
3312 if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) {
3314 "\"%s\" [%s] cannot use '%c' as an identifier;"
3315 " it is reserved for unknown terrain.",
3316 filename, tsection, pterrain->identifier);
3317 ok = FALSE;
3318 break;
3319 }
3320 for (j = T_FIRST; j < i; j++) {
3321 if (pterrain->identifier == terrain_by_number(j)->identifier) {
3323 "\"%s\" [%s] has the same identifier as [%s].",
3324 filename, tsection,
3326 ok = FALSE;
3327 break;
3328 }
3329 }
3330
3331 if (!ok) {
3332 break;
3333 }
3334
3335 cstr = secfile_lookup_str(file, "%s.class", tsection);
3336 pterrain->tclass = terrain_class_by_name(cstr, fc_strcasecmp);
3337 if (!terrain_class_is_valid(pterrain->tclass)) {
3339 "\"%s\": [%s] unknown class \"%s\"",
3340 filename, tsection, cstr);
3341 ok = FALSE;
3342 break;
3343 }
3344
3345 if (!secfile_lookup_int(file, &pterrain->movement_cost,
3346 "%s.movement_cost", tsection)
3347 || !secfile_lookup_int(file, &pterrain->defense_bonus,
3348 "%s.defense_bonus", tsection)) {
3350 ok = FALSE;
3351 break;
3352 }
3353
3355 pterrain->output[o]
3356 = secfile_lookup_int_default(file, 0, "%s.%s", tsection,
3359
3360 res = secfile_lookup_str_vec(file, &nval, "%s.resources", tsection);
3362 "%s.resource_freq", tsection);
3363 if (nval2 > 0 && nval2 != nval) {
3365 "\"%s\": [%s] Different lengths for resources "
3366 "and resource frequencies",
3367 filename, tsection);
3368 ok = FALSE;
3369 }
3370 pterrain->resources = fc_calloc(nval + 1, sizeof(*pterrain->resources));
3371 pterrain->resource_freq = fc_calloc(nval + 1,
3372 sizeof(*pterrain->resource_freq));
3373 for (j = 0; j < nval; j++) {
3374 pterrain->resources[j] = lookup_resource(filename, res[j], tsection);
3375 if (pterrain->resources[j] == NULL) {
3376 ok = FALSE;
3377 break;
3378 }
3379 pterrain->resource_freq[j] = j < nval2
3380 ? res_freq[j]
3382 if (pterrain->resource_freq[j] < RESOURCE_FREQUENCY_MINIMUM
3383 || pterrain->resource_freq[j] > RESOURCE_FREQUENCY_MAXIMUM) {
3385 "\"%s\": [%s] Resource frequency '%d' "
3386 "outside allowed range",
3387 filename, tsection,
3388 pterrain->resource_freq[j]);
3389 ok = FALSE;
3390 break;
3391 }
3392 }
3393 pterrain->resources[nval] = NULL;
3394 /* Terminating zero technically not necessary */
3395 pterrain->resource_freq[nval] = 0;
3396 free(res);
3397 res = NULL;
3398 free(res_freq);
3399 res_freq = NULL;
3400
3401 if (!ok) {
3402 break;
3403 }
3404
3406 pterrain->road_output_incr_pct[o]
3407 = secfile_lookup_int_default(file, 0, "%s.road_%s_incr_pct",
3410
3411 if (!lookup_time(file, &pterrain->base_time, tsection, "base_time",
3412 filename, NULL, &ok)
3413 || !lookup_time(file, &pterrain->road_time, tsection, "road_time",
3414 filename, NULL, &ok)) {
3416 ok = FALSE;
3417 break;
3418 }
3419
3420 if (!lookup_terrain(file, "cultivate_result", filename, pterrain,
3421 &pterrain->cultivate_result, FALSE)) {
3422 ruleset_error(NULL, LOG_ERROR, "%s: No cultivate_result", tsection);
3423 ok = FALSE;
3424 break;
3425 }
3426 if (pterrain->cultivate_result == pterrain) {
3428 "%s: Cultivating result in terrain itself.",
3429 tsection);
3430 ok = FALSE;
3431 break;
3432 }
3433 if (!secfile_lookup_int(file, &pterrain->irrigation_food_incr,
3434 "%s.irrigation_food_incr", tsection)
3435 || !lookup_time(file, &pterrain->irrigation_time,
3436 tsection, "irrigation_time", filename, NULL, &ok)) {
3438 ok = FALSE;
3439 break;
3440 }
3441
3442 if (!lookup_terrain(file, "plant_result", filename, pterrain,
3443 &pterrain->plant_result, FALSE)) {
3444 ruleset_error(NULL, LOG_ERROR, "%s: No plant_result", tsection);
3445 ok = FALSE;
3446 break;
3447 }
3448 if (pterrain->plant_result == pterrain) {
3450 "%s: Planting result in terrain itself.",
3451 tsection);
3452 ok = FALSE;
3453 break;
3454 }
3455 if (!secfile_lookup_int(file, &pterrain->mining_shield_incr,
3456 "%s.mining_shield_incr", tsection)
3457 || !lookup_time(file, &pterrain->mining_time,
3458 tsection, "mining_time", filename, NULL, &ok)) {
3460 ok = FALSE;
3461 break;
3462 }
3463
3464 if (!lookup_time(file, &pterrain->cultivate_time,
3465 tsection, "cultivate_time", filename, NULL, &ok)) {
3467 "%s: Missing cultivate_time", tsection);
3468 ok = FALSE;
3469 break;
3470 }
3471 if ((pterrain->cultivate_result != NULL
3472 && pterrain->cultivate_time <= 0)
3473 || (pterrain->cultivate_result == NULL
3474 && pterrain->cultivate_time > 0)) {
3476 "%s: cultivate_result and cultivate_time disagree "
3477 "whether cultivating is enabled", tsection);
3478 ok = FALSE;
3479 break;
3480 }
3481
3482 if (!lookup_time(file, &pterrain->plant_time,
3483 tsection, "plant_time", filename, NULL, &ok)) {
3485 "%s: Missing plant_time", tsection);
3486 ok = FALSE;
3487 break;
3488 }
3489 if ((pterrain->plant_result != NULL
3490 && pterrain->plant_time <= 0)
3491 || (pterrain->plant_result == NULL
3492 && pterrain->plant_time > 0)) {
3494 "%s: plant_result and plant_time disagree "
3495 "whether planting is enabled", tsection);
3496 ok = FALSE;
3497 break;
3498 }
3499
3500 if (!lookup_unit_type(file, tsection, "animal",
3501 &pterrain->animal, filename,
3502 rule_name_get(&pterrain->name))) {
3503 ok = FALSE;
3504 break;
3505 }
3506
3507 if (!lookup_terrain(file, "transform_result", filename, pterrain,
3508 &pterrain->transform_result, TRUE)) {
3509 ok = FALSE;
3510 break;
3511 }
3512 if (!lookup_time(file, &pterrain->transform_time,
3513 tsection, "transform_time", filename, NULL, &ok)) {
3515 ok = FALSE;
3516 break;
3517 }
3518 if ((pterrain->transform_result != NULL
3519 && pterrain->transform_time <= 0)
3520 || (pterrain->transform_result == NULL
3521 && pterrain->transform_time > 0)) {
3523 "%s: transform_result and transform_time disagree "
3524 "whether transforming is enabled", tsection);
3525 ok = FALSE;
3526 break;
3527 }
3528
3529 pterrain->placing_time = 1; /* Default */
3530 lookup_time(file, &pterrain->placing_time,
3531 tsection, "placing_time", filename, NULL, &ok);
3532
3533 pterrain->pillage_time = 1; /* Default */
3534 lookup_time(file, &pterrain->pillage_time,
3535 tsection, "pillage_time", filename, NULL, &ok);
3536
3537 if (!lookup_terrain(file, "warmer_wetter_result", filename, pterrain,
3538 &pterrain->warmer_wetter_result, TRUE)
3539 || !lookup_terrain(file, "warmer_drier_result", filename, pterrain,
3540 &pterrain->warmer_drier_result, TRUE)
3541 || !lookup_terrain(file, "cooler_wetter_result", filename, pterrain,
3542 &pterrain->cooler_wetter_result, TRUE)
3543 || !lookup_terrain(file, "cooler_drier_result", filename, pterrain,
3544 &pterrain->cooler_drier_result, TRUE)) {
3545 ok = FALSE;
3546 break;
3547 }
3548
3549 /* Set default removal times */
3550 extra_type_iterate(pextra) {
3551 pterrain->extra_removal_times[extra_index(pextra)] = 0;
3553
3554 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
3555 if (!rscompat_terrain_extra_rmtime_3_2(file, tsection, pterrain)) {
3556 ok = FALSE;
3557 break;
3558 }
3559 }
3560
3561 for (j = 0; (ename = secfile_lookup_str_default(file, NULL,
3562 "%s.extra_settings%d.extra",
3563 tsection, j)); j++) {
3564 const struct extra_type *pextra = extra_type_by_rule_name(ename);
3565
3566 if (pextra != NULL) {
3567 char time_sections[512];
3568
3570 "%s.extra_settings%d", tsection, j);
3571
3572 lookup_time(file, &pterrain->extra_removal_times[extra_index(pextra)],
3573 time_sections, "removal_time", filename, NULL, &ok);
3574 } else {
3576 "\"%s\" [%s] has settings for unknown extra \"%s\".",
3577 filename, tsection, ename);
3578 ok = FALSE;
3579 break;
3580 }
3581 }
3582
3583 if (ok) {
3584 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", tsection);
3585 BV_CLR_ALL(pterrain->flags);
3586 for (j = 0; j < nval; j++) {
3587 const char *sval = slist[j];
3588 enum terrain_flag_id flag
3590
3591 if (!terrain_flag_id_is_valid(flag)) {
3593 "\"%s\" [%s] has unknown flag \"%s\".",
3594 filename, tsection, sval);
3595 ok = FALSE;
3596 break;
3597 } else {
3598 BV_SET(pterrain->flags, flag);
3599 }
3600 }
3601
3602 free(slist);
3603 }
3604
3605 if (!ok) {
3606 break;
3607 }
3608
3609 {
3611
3615 pterrain->property[mtp]
3616 = secfile_lookup_int_default(file, 0, "%s.property_%s", tsection,
3618 }
3619 }
3620
3621 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", tsection);
3622 BV_CLR_ALL(pterrain->native_to);
3623 for (j = 0; j < nval; j++) {
3624 struct unit_class *class = unit_class_by_rule_name(slist[j]);
3625
3626 if (!class) {
3628 "\"%s\" [%s] is native to unknown unit class \"%s\".",
3629 filename, tsection, slist[j]);
3630 ok = FALSE;
3631 break;
3632 } else {
3633 BV_SET(pterrain->native_to, uclass_index(class));
3634 }
3635 }
3636 free(slist);
3637
3638 if (!ok) {
3639 break;
3640 }
3641
3642 /* Get terrain color */
3643 {
3644 fc_assert_ret_val(pterrain->rgb == NULL, FALSE);
3645
3646 if (!rgbcolor_load(file, &pterrain->rgb, "%s.color", tsection)) {
3648 "Missing terrain color definition: %s",
3649 secfile_error());
3650 ok = FALSE;
3651 break;
3652 }
3653 }
3654
3655 pterrain->helptext = lookup_strvec(file, tsection, "helptext");
3657 }
3658
3659 if (ok) {
3660 /* Extra details */
3661 extra_type_iterate(pextra) {
3662 BV_CLR_ALL(pextra->conflicts);
3664
3665 extra_type_iterate(pextra) {
3666 int eidx = extra_index(pextra);
3667 const char *section = &extra_sections[eidx * MAX_SECTION_LABEL];
3668 const char **slist;
3669 struct requirement_vector *reqs;
3670 const char *catname;
3671 int cj;
3672 enum extra_cause cause;
3674 const char *eus_name;
3675 const char *vis_req_name;
3676 const struct advance *vis_req;
3677
3678 catname = secfile_lookup_str(file, "%s.category", section);
3679 if (catname == NULL) {
3681 "\"%s\" extra \"%s\" has no category.",
3682 filename, extra_rule_name(pextra));
3683 ok = FALSE;
3684 break;
3685 }
3686 pextra->category = extra_category_by_name(catname, fc_strcasecmp);
3687 if (!extra_category_is_valid(pextra->category)) {
3689 "\"%s\" extra \"%s\" has invalid category \"%s\".",
3690 filename, extra_rule_name(pextra), catname);
3691 ok = FALSE;
3692 break;
3693 }
3694
3695 slist = secfile_lookup_str_vec(file, &nval, "%s.causes", section);
3696 pextra->causes = 0;
3697 for (cj = 0; cj < nval; cj++) {
3698 const char *sval = slist[cj];
3700
3701 if (!extra_cause_is_valid(cause)) {
3703 "\"%s\" extra \"%s\": unknown cause \"%s\".",
3704 filename, extra_rule_name(pextra), sval);
3705 ok = FALSE;
3706 break;
3707 } else {
3708 pextra->causes |= (1 << cause);
3709 extra_to_caused_by_list(pextra, cause);
3710 }
3711 }
3712
3713 if (pextra->causes == 0) {
3714 /* Extras that do not have any causes added to EC_NONE list */
3716 }
3717
3718 if (!is_extra_caused_by(pextra, EC_BASE)
3719 && !is_extra_caused_by(pextra, EC_ROAD)
3720 && !is_extra_caused_by(pextra, EC_RESOURCE)) {
3721 /* Not a base, road, nor resource, so special */
3722 pextra->data.special_idx = extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL));
3724 }
3725
3726 free(slist);
3727
3728 /* Handle before rscompat_extra_rmcause_3_2() might need the values */
3729 pextra->removal_time = 0; /* Default */
3730 lookup_time(file, &pextra->removal_time, section, "removal_time",
3731 filename, extra_rule_name(pextra), &ok);
3732 pextra->removal_time_factor
3733 = secfile_lookup_int_default(file, 1, "%s.removal_time_factor",
3734 section);
3735
3736 /* Do not clear after this point.
3737 * rscompat_extra_rmcause_3_2() might set a flag we want to keep. */
3738 BV_CLR_ALL(pextra->flags);
3739
3740 slist = secfile_lookup_str_vec(file, &nval, "%s.rmcauses", section);
3741 pextra->rmcauses = 0;
3742 for (j = 0; j < nval; j++) {
3743 const char *sval = slist[j];
3744
3745 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
3747 }
3748
3750
3753 "\"%s\" extra \"%s\": unknown rmcause \"%s\".",
3754 filename, extra_rule_name(pextra), sval);
3755 ok = FALSE;
3756 break;
3757 } else {
3758 pextra->rmcauses |= (1 << rmcause);
3760 }
3761 }
3762
3763 free(slist);
3764
3765 sz_strlcpy(pextra->activity_gfx,
3767 "%s.activity_gfx", section));
3768 sz_strlcpy(pextra->act_gfx_alt,
3770 "%s.act_gfx_alt", section));
3771 sz_strlcpy(pextra->act_gfx_alt2,
3773 "%s.act_gfx_alt2", section));
3774 sz_strlcpy(pextra->rmact_gfx,
3776 "%s.rmact_gfx", section));
3777 sz_strlcpy(pextra->rmact_gfx_alt,
3779 "%s.rmact_gfx_alt", section));
3780 sz_strlcpy(pextra->rmact_gfx_alt2,
3782 "%s.rmact_gfx_alt2", section));
3783 sz_strlcpy(pextra->graphic_str,
3784 secfile_lookup_str_default(file, "-", "%s.graphic", section));
3785 sz_strlcpy(pextra->graphic_alt,
3787 "%s.graphic_alt", section));
3788
3789 reqs = lookup_req_list(file, compat, section, "reqs", extra_rule_name(pextra));
3790 if (reqs == NULL) {
3791 ok = FALSE;
3792 break;
3793 }
3794 requirement_vector_copy(&pextra->reqs, reqs);
3795
3796 reqs = lookup_req_list(file, compat, section, "rmreqs", extra_rule_name(pextra));
3797 if (reqs == NULL) {
3798 ok = FALSE;
3799 break;
3800 }
3801 requirement_vector_copy(&pextra->rmreqs, reqs);
3802
3803 reqs = lookup_req_list(file, compat, section, "appearance_reqs", extra_rule_name(pextra));
3804 if (reqs == NULL) {
3805 ok = FALSE;
3806 break;
3807 }
3808 requirement_vector_copy(&pextra->appearance_reqs, reqs);
3809
3810 reqs = lookup_req_list(file, compat, section, "disappearance_reqs", extra_rule_name(pextra));
3811 if (reqs == NULL) {
3812 ok = FALSE;
3813 break;
3814 }
3815 requirement_vector_copy(&pextra->disappearance_reqs, reqs);
3816
3817 pextra->buildable = secfile_lookup_bool_default(file,
3819 "%s.buildable", section);
3820 pextra->generated = secfile_lookup_bool_default(file, TRUE,
3821 "%s.generated", section);
3822
3823 pextra->build_time = 0; /* Default */
3824 lookup_time(file, &pextra->build_time, section, "build_time",
3825 filename, extra_rule_name(pextra), &ok);
3826 pextra->build_time_factor = secfile_lookup_int_default(file, 1,
3827 "%s.build_time_factor", section);
3828
3829 /* removal_time handled earlier, so that rscompat_extra_rmcause_3_2()
3830 * can use them. */
3831
3832 pextra->infracost = secfile_lookup_int_default(file, 0,
3833 "%s.infracost", section);
3834 if (pextra->infracost > 0) {
3835 terrain_control.infrapoints = TRUE;
3836 }
3837
3838 pextra->defense_bonus = secfile_lookup_int_default(file, 0,
3839 "%s.defense_bonus",
3840 section);
3841 if (pextra->defense_bonus != 0) {
3842 if (extra_has_flag(pextra, EF_NATURAL_DEFENSE)) {
3844 } else {
3846 }
3847 }
3848
3849 eus_name = secfile_lookup_str_default(file, "Normal", "%s.unit_seen", section);
3851 if (!extra_unit_seen_type_is_valid(pextra->eus)) {
3853 "\"%s\" extra \"%s\" has illegal unit_seen value \"%s\".",
3854 filename, extra_rule_name(pextra), eus_name);
3855 ok = FALSE;
3856 break;
3857 }
3858 if (pextra->eus == EUS_HIDDEN) {
3860 }
3861
3862 pextra->appearance_chance = secfile_lookup_int_default(file, RS_DEFAULT_EXTRA_APPEARANCE,
3863 "%s.appearance_chance",
3864 section);
3865 pextra->disappearance_chance = secfile_lookup_int_default(file,
3867 "%s.disappearance_chance",
3868 section);
3869
3870 pextra->no_aggr_near_city = secfile_lookup_int_default(file, -1,
3871 "%s.no_aggr_near_city",
3872 section);
3873
3874 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", section);
3875 BV_CLR_ALL(pextra->native_to);
3876 for (j = 0; j < nval; j++) {
3877 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
3878
3879 if (uclass == NULL) {
3881 "\"%s\" extra \"%s\" is native to unknown unit class \"%s\".",
3882 filename, extra_rule_name(pextra), slist[j]);
3883 ok = FALSE;
3884 break;
3885 } else {
3886 BV_SET(pextra->native_to, uclass_index(uclass));
3887 }
3888 }
3889 free(slist);
3890
3891 if (!ok) {
3892 break;
3893 }
3894
3895 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
3896 for (j = 0; j < nval; j++) {
3897 const char *sval = slist[j];
3898 enum extra_flag_id flag;
3899
3900 if (compat->compat_mode && compat->version < RSFORMAT_3_2
3901 && !fc_strcasecmp("NoAggressive", sval)) {
3902 if (pextra->no_aggr_near_city >= 0) {
3904 "\"%s\" extra \"%s\" has both no_aggr_near_city set and old style "
3905 "NoAggressive flag",
3906 filename, extra_rule_name(pextra));
3907 ok = FALSE;
3908 break;
3909 }
3910 /* Old NoAggressive flag meant distance of 3. */
3911 pextra->no_aggr_near_city = 3;
3912 } else {
3913
3915
3916 if (!extra_flag_id_is_valid(flag)) {
3918 "\"%s\" extra \"%s\": unknown flag \"%s\".",
3919 filename, extra_rule_name(pextra), sval);
3920 ok = FALSE;
3921 break;
3922 } else {
3923 BV_SET(pextra->flags, flag);
3924 }
3925 }
3926 }
3927 free(slist);
3928
3929 if (pextra->no_aggr_near_city >= 0) {
3931 }
3932
3933 if (extra_has_flag(pextra, EF_CAUSE_ZOC)) {
3935 }
3936
3937 if (!ok) {
3938 break;
3939 }
3940
3941 slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
3942 for (j = 0; j < nval; j++) {
3943 const char *sval = slist[j];
3945
3946 if (pextra2 == NULL) {
3948 "\"%s\" extra \"%s\": unknown conflict extra \"%s\".",
3949 filename, extra_rule_name(pextra), sval);
3950 ok = FALSE;
3951 break;
3952 } else {
3953 BV_SET(pextra->conflicts, extra_index(pextra2));
3954 BV_SET(pextra2->conflicts, extra_index(pextra));
3955 }
3956 }
3957
3958 free(slist);
3959
3960 if (!ok) {
3961 break;
3962 }
3963
3964 slist = secfile_lookup_str_vec(file, &nval, "%s.hidden_by", section);
3965 BV_CLR_ALL(pextra->hidden_by);
3966 for (j = 0; j < nval; j++) {
3967 const char *sval = slist[j];
3968 const struct extra_type *top = extra_type_by_rule_name(sval);
3969
3970 if (top == NULL) {
3972 "\"%s\" extra \"%s\" hidden by unknown extra \"%s\".",
3973 filename, extra_rule_name(pextra), sval);
3974 ok = FALSE;
3975 break;
3976 } else {
3977 BV_SET(pextra->hidden_by, extra_index(top));
3978 }
3979 }
3980 free(slist);
3981
3982 if (!ok) {
3983 break;
3984 }
3985
3986 slist = secfile_lookup_str_vec(file, &nval, "%s.bridged_over", section);
3987 BV_CLR_ALL(pextra->bridged_over);
3988 for (j = 0; j < nval; j++) {
3989 const char *sval = slist[j];
3990 const struct extra_type *top = extra_type_by_rule_name(sval);
3991
3992 if (top == NULL) {
3994 "\"%s\" extra \"%s\" bridged over unknown extra \"%s\".",
3995 filename, extra_rule_name(pextra), sval);
3996 ok = FALSE;
3997 break;
3998 } else {
3999 BV_SET(pextra->bridged_over, extra_index(top));
4000 }
4001 }
4002 free(slist);
4003
4004 if (!ok) {
4005 break;
4006 }
4007
4009 "%s.visibility_req", section);
4011
4012 if (vis_req == NULL) {
4014 "\"%s\" %s: unknown visibility_req %s.",
4015 filename, section, vis_req_name);
4016 ok = FALSE;
4017 break;
4018 }
4019
4020 pextra->visibility_req = advance_number(vis_req);
4021
4022 pextra->helptext = lookup_strvec(file, section, "helptext");
4023
4024 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
4026 }
4028 }
4029
4030 if (ok) {
4031 int i = 0;
4032 /* Resource details */
4033
4035 char identifier[MAX_LEN_NAME];
4036 const char *id;
4038
4039 if (!presource->data.resource) {
4041 "\"%s\" extra \"%s\" has \"Resource\" cause but no "
4042 "corresponding [resource_*] section",
4043 filename, extra_rule_name(presource));
4044 ok = FALSE;
4045 break;
4046 }
4047
4049 presource->data.resource->output[o] =
4050 secfile_lookup_int_default(file, 0, "%s.%s", rsection,
4053
4054 id = secfile_lookup_str_default(file, NULL, "%s.identifier", rsection);
4055
4056 if (id == NULL) {
4057 presource->data.resource->id_old_save = '\0';
4058 } else {
4059 sz_strlcpy(identifier, id);
4060
4061 presource->data.resource->id_old_save = identifier[0];
4062 if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
4064 "\"%s\" [%s] identifier missing value.",
4065 filename, rsection);
4066 ok = FALSE;
4067 break;
4068 }
4069 if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
4071 "\"%s\" [%s] cannot use '%c' as an identifier;"
4072 " it is reserved.",
4073 filename, rsection, presource->data.resource->id_old_save);
4074 ok = FALSE;
4075 break;
4076 }
4077 }
4078
4079 if (!ok) {
4080 break;
4081 }
4082
4083 i++;
4085
4086 for (j = 0; ok && j < game.control.num_resource_types; j++) {
4087 const char *section = &resource_sections[j * MAX_SECTION_LABEL];
4088 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4090
4091 if (!is_extra_caused_by(pextra, EC_RESOURCE)) {
4093 "\"%s\" resource section [%s]: extra \"%s\" does not "
4094 "have \"Resource\" in its causes",
4095 filename, section, extra_name);
4096 ok = FALSE;
4097 }
4098 }
4099 }
4100
4101 if (ok) {
4102 /* This can't be part of previous loop as we don't want random data from previous
4103 * ruleset to play havoc on us when we have only some resource identifiers loaded
4104 * from the new ruleset. */
4106 if (pres->data.resource->id_old_save != '\0') {
4108 if (pres->data.resource->id_old_save == pres2->data.resource->id_old_save
4109 && pres != pres2) {
4111 "\"%s\" [%s] has the same identifier as [%s].",
4112 filename,
4115 ok = FALSE;
4116 break;
4117 }
4119
4120 if (!ok) {
4121 break;
4122 }
4123 }
4125 }
4126
4127 if (ok) {
4128 /* Base details */
4130 struct base_type *pbase = extra_base_get(pextra);
4131 const char *section;
4132 const char *gui_str;
4133
4134 if (!pbase) {
4136 "\"%s\" extra \"%s\" has \"Base\" cause but no "
4137 "corresponding [base_*] section",
4138 filename, extra_rule_name(pextra));
4139 ok = FALSE;
4140 break;
4141 }
4143
4144 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4146 if (!base_gui_type_is_valid(pbase->gui_type)) {
4148 "\"%s\" base \"%s\": unknown gui_type \"%s\".",
4149 filename, extra_rule_name(pextra), gui_str);
4150 ok = FALSE;
4151 break;
4152 }
4153
4154 pbase->border_sq = secfile_lookup_int_default(file, -1, "%s.border_sq",
4155 section);
4156 pbase->vision_main_sq = secfile_lookup_int_default(file, -1,
4157 "%s.vision_main_sq",
4158 section);
4159 pbase->vision_invis_sq = secfile_lookup_int_default(file, -1,
4160 "%s.vision_invis_sq",
4161 section);
4162 pbase->vision_subs_sq = secfile_lookup_int_default(file, -1,
4163 "%s.vision_subs_sq",
4164 section);
4165
4166 if (!ok) {
4167 break;
4168 }
4169
4172
4174 struct base_type *pbase2;
4175
4176 if (pextra == pextra2) {
4177 /* End of the fully initialized bases iteration. */
4178 break;
4179 }
4180
4183 BV_SET(pextra->conflicts, extra_index(pextra2));
4184 BV_SET(pextra2->conflicts, extra_index(pextra));
4185 }
4187 }
4189
4190 for (j = 0; ok && j < game.control.num_base_types; j++) {
4191 const char *section = &base_sections[j * MAX_SECTION_LABEL];
4192 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4194
4195 if (!is_extra_caused_by(pextra, EC_BASE)) {
4197 "\"%s\" base section [%s]: extra \"%s\" does not have "
4198 "\"Base\" in its causes",
4199 filename, section, extra_name);
4200 ok = FALSE;
4201 }
4202 }
4203 }
4204
4205 if (ok) {
4207 struct road_type *proad = extra_road_get(pextra);
4208 const char *section;
4209 const char **slist;
4210 const char *special;
4211 const char *modestr;
4212 struct requirement_vector *reqs;
4213 const char *gui_str;
4214
4215 if (!proad) {
4217 "\"%s\" extra \"%s\" has \"Road\" cause but no "
4218 "corresponding [road_*] section",
4219 filename, extra_rule_name(pextra));
4220 ok = FALSE;
4221 break;
4222 }
4224
4225 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4227 if (!road_gui_type_is_valid(proad->gui_type)) {
4229 "\"%s\" road \"%s\": unknown gui_type \"%s\".",
4230 filename, extra_rule_name(pextra), gui_str);
4231 ok = FALSE;
4232 break;
4233 }
4234
4235 reqs = lookup_req_list(file, compat, section, "first_reqs", extra_rule_name(pextra));
4236 if (reqs == NULL) {
4237 ok = FALSE;
4238 break;
4239 }
4240 requirement_vector_copy(&proad->first_reqs, reqs);
4241
4242 if (!secfile_lookup_int(file, &proad->move_cost,
4243 "%s.move_cost", section)) {
4244 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4245 ok = FALSE;
4246 break;
4247 }
4248
4249 modestr = secfile_lookup_str_default(file, "FastAlways", "%s.move_mode",
4250 section);
4252 if (!road_move_mode_is_valid(proad->move_mode)) {
4254 "Illegal move_mode \"%s\" for road \"%s\"",
4255 modestr, extra_rule_name(pextra));
4256 ok = FALSE;
4257 break;
4258 }
4259
4261 proad->tile_incr_const[o] =
4262 secfile_lookup_int_default(file, 0, "%s.%s_incr_const",
4264 proad->tile_incr[o] =
4265 secfile_lookup_int_default(file, 0, "%s.%s_incr",
4267 proad->tile_bonus[o] =
4268 secfile_lookup_int_default(file, 0, "%s.%s_bonus",
4271
4272 special = secfile_lookup_str_default(file, "None", "%s.compat_special", section);
4273 if (!fc_strcasecmp(special, "Road")) {
4274 if (compat_road) {
4276 "Multiple roads marked as compatibility \"Road\"");
4277 ok = FALSE;
4278 }
4279 compat_road = TRUE;
4280 proad->compat = ROCO_ROAD;
4281 } else if (!fc_strcasecmp(special, "Railroad")) {
4282 if (compat_rail) {
4284 "Multiple roads marked as compatibility \"Railroad\"");
4285 ok = FALSE;
4286 }
4287 compat_rail = TRUE;
4288 proad->compat = ROCO_RAILROAD;
4289 } else if (!fc_strcasecmp(special, "River")) {
4290 if (compat_river) {
4292 "Multiple roads marked as compatibility \"River\"");
4293 ok = FALSE;
4294 }
4296 proad->compat = ROCO_RIVER;
4297 } else if (!fc_strcasecmp(special, "None")) {
4298 proad->compat = ROCO_NONE;
4299 } else {
4301 "Illegal compatibility special \"%s\" for road %s",
4302 special, extra_rule_name(pextra));
4303 ok = FALSE;
4304 }
4305
4306 if (!ok) {
4307 break;
4308 }
4309
4310 slist = secfile_lookup_str_vec(file, &nval, "%s.integrates", section);
4311 BV_CLR_ALL(proad->integrates);
4312 for (j = 0; j < nval; j++) {
4313 const char *sval = slist[j];
4315 struct road_type *top = NULL;
4316
4317 if (textra != NULL) {
4318 top = extra_road_get(textra);
4319 }
4320
4321 if (top == NULL) {
4323 "\"%s\" road \"%s\" integrates with unknown road \"%s\".",
4324 filename, extra_rule_name(pextra), sval);
4325 ok = FALSE;
4326 break;
4327 } else {
4328 BV_SET(proad->integrates, road_number(top));
4329 }
4330 }
4331 free(slist);
4332
4333 if (!ok) {
4334 break;
4335 }
4336
4337 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4338 BV_CLR_ALL(proad->flags);
4339 for (j = 0; j < nval; j++) {
4340 const char *sval = slist[j];
4342
4343 if (!road_flag_id_is_valid(flag)) {
4345 "\"%s\" road \"%s\": unknown flag \"%s\".",
4346 filename, extra_rule_name(pextra), sval);
4347 ok = FALSE;
4348 break;
4349 } else {
4350 BV_SET(proad->flags, flag);
4351 }
4352 }
4353 free(slist);
4354
4355 if (!ok) {
4356 break;
4357 }
4359
4360 for (j = 0; ok && j < game.control.num_road_types; j++) {
4361 const char *section = &road_sections[j * MAX_SECTION_LABEL];
4362 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4364
4365 if (!is_extra_caused_by(pextra, EC_ROAD)) {
4367 "\"%s\" road section [%s]: extra \"%s\" does not have "
4368 "\"Road\" in its causes",
4369 filename, section, extra_name);
4370 ok = FALSE;
4371 }
4372 }
4373 }
4374
4375 if (ok) {
4376 extra_type_iterate(pextra) {
4377 pextra->bridged = extra_type_list_new();
4379 if (BV_ISSET(pextra->bridged_over, pbridged->id)) {
4380 extra_type_list_append(pextra->bridged, pbridged);
4381 }
4384 }
4385
4386 if (ok) {
4388 }
4389
4390 return ok;
4391}
4392
4393/**********************************************************************/
4397static bool load_government_names(struct section_file *file,
4398 struct rscompat_info *compat)
4399{
4400 int nval = 0;
4401 struct section_list *sec;
4402 const char *filename = secfile_name(file);
4403 bool ok = TRUE;
4404
4405 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4406 return FALSE;
4407 }
4408
4409 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4410 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4411
4413 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
4414 ruleset_error(NULL, LOG_ERROR, "\"%s\": No governments?!?", filename);
4415 ok = FALSE;
4416 } else if (nval > G_LAST) {
4418 "\"%s\": Too many governments (%d, max %d)",
4419 filename, nval, G_LAST);
4420 ok = FALSE;
4421 }
4422
4423 if (ok) {
4425
4426 /* Government names are needed early so that get_government_by_name will
4427 * work. */
4428 governments_iterate(gov) {
4429 const char *sec_name =
4431
4432 if (!ruleset_load_names(&gov->name, NULL, file, sec_name)) {
4433 ok = FALSE;
4434 break;
4435 }
4437 }
4438
4440
4441 if (ok) {
4443 nval = (NULL != sec ? section_list_size(sec) : 0);
4444
4445 if (nval > MAX_NUM_MULTIPLIERS) {
4447 "\"%s\": Too many multipliers (%d, max %d)",
4448 filename, nval, MAX_NUM_MULTIPLIERS);
4449
4450 ok = FALSE;
4451 } else {
4453 }
4454
4455 if (ok) {
4456 multipliers_iterate(pmul) {
4457 const char *sec_name =
4459
4460 if (!ruleset_load_names(&pmul->name, NULL, file, sec_name)) {
4462 "\"%s\": Cannot load multiplier names",
4463 filename);
4464 ok = FALSE;
4465 break;
4466 }
4468 }
4469 }
4470
4472
4473 return ok;
4474}
4475
4476/**********************************************************************/
4480 struct rscompat_info *compat)
4481{
4482 struct section_list *sec;
4483 const char *filename = secfile_name(file);
4484 bool ok = TRUE;
4485
4487
4489 = lookup_government(file, "governments.during_revolution", filename, NULL);
4491 ok = FALSE;
4492 }
4493
4494 if (ok) {
4497
4498 /* easy ones: */
4500 const int i = government_index(g);
4501 const char *sec_name = section_name(section_list_get(sec, i));
4502 struct requirement_vector *reqs =
4504
4505 if (reqs == NULL) {
4506 ok = FALSE;
4507 break;
4508 }
4509
4510 if (NULL != secfile_entry_lookup(file, "%s.ai_better", sec_name)) {
4511 char entry[100];
4512
4513 fc_snprintf(entry, sizeof(entry), "%s.ai_better", sec_name);
4514 g->ai.better = lookup_government(file, entry, filename, NULL);
4515 if (g->ai.better == NULL) {
4516 ok = FALSE;
4517 break;
4518 }
4519 } else {
4520 g->ai.better = NULL;
4521 }
4522 requirement_vector_copy(&g->reqs, reqs);
4523
4524 sz_strlcpy(g->graphic_str,
4525 secfile_lookup_str(file, "%s.graphic", sec_name));
4526 sz_strlcpy(g->graphic_alt,
4527 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
4528
4529 g->helptext = lookup_strvec(file, sec_name, "helptext");
4531 }
4532
4533
4534 if (ok) {
4535 /* titles */
4537 const char *sec_name =
4539 const char *male, *female;
4540
4541 if (!(male = secfile_lookup_str(file, "%s.ruler_male_title", sec_name))
4542 || !(female = secfile_lookup_str(file, "%s.ruler_female_title",
4543 sec_name))) {
4545 "Lack of default ruler titles for "
4546 "government \"%s\" (nb %d): %s",
4548 secfile_error());
4549 ok = FALSE;
4550 break;
4551 } else if (NULL == government_ruler_title_new(g, NULL, male, female)) {
4553 "Lack of default ruler titles for "
4554 "government \"%s\" (nb %d).",
4556 ok = FALSE;
4557 break;
4558 }
4560 }
4561
4563
4564 if (ok) {
4566 multipliers_iterate(pmul) {
4567 int id = multiplier_index(pmul);
4568 const char *sec_name = section_name(section_list_get(sec, id));
4569 struct requirement_vector *reqs;
4570
4571 if (!secfile_lookup_int(file, &pmul->start, "%s.start", sec_name)) {
4572 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4573 ok = FALSE;
4574 break;
4575 }
4576 if (!secfile_lookup_int(file, &pmul->stop, "%s.stop", sec_name)) {
4577 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4578 ok = FALSE;
4579 break;
4580 }
4581 if (pmul->stop <= pmul->start) {
4583 "Multiplier \"%s\" stop (%d) must be greater "
4584 "than start (%d)", multiplier_rule_name(pmul),
4585 pmul->stop, pmul->start);
4586 ok = FALSE;
4587 break;
4588 }
4589 if (!secfile_lookup_int(file, &pmul->step, "%s.step", sec_name)) {
4590 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4591 ok = FALSE;
4592 break;
4593 }
4594 if (((pmul->stop - pmul->start) % pmul->step) != 0) {
4596 "Multiplier \"%s\" step (%d) does not fit "
4597 "exactly into interval start-stop (%d to %d)",
4598 multiplier_rule_name(pmul), pmul->step,
4599 pmul->start, pmul->stop);
4600 ok = FALSE;
4601 break;
4602 }
4603 if (!secfile_lookup_int(file, &pmul->def, "%s.default", sec_name)) {
4604 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4605 ok = FALSE;
4606 break;
4607 }
4608 if (pmul->def < pmul->start || pmul->def > pmul->stop) {
4610 "Multiplier \"%s\" default (%d) not within "
4611 "legal range (%d to %d)", multiplier_rule_name(pmul),
4612 pmul->def, pmul->start, pmul->stop);
4613 ok = FALSE;
4614 break;
4615 }
4616 if (((pmul->def - pmul->start) % pmul->step) != 0) {
4618 "Multiplier \"%s\" default (%d) not legal "
4619 "with respect to step size %d",
4620 multiplier_rule_name(pmul), pmul->def, pmul->step);
4621 ok = FALSE;
4622 break;
4623 }
4624 pmul->offset = secfile_lookup_int_default(file, 0,
4625 "%s.offset", sec_name);
4626 pmul->factor = secfile_lookup_int_default(file, 100,
4627 "%s.factor", sec_name);
4628 if (pmul->factor == 0) {
4630 "Multiplier \"%s\" scaling factor must "
4631 "not be zero", multiplier_rule_name(pmul));
4632 ok = FALSE;
4633 break;
4634 }
4635
4636 pmul->minimum_turns = secfile_lookup_int_default(file, 0,
4637 "%s.minimum_turns",
4638 sec_name);
4639
4640 reqs = lookup_req_list(file, compat, sec_name, "reqs",
4641 multiplier_rule_name(pmul));
4642 if (reqs == NULL) {
4643 ok = FALSE;
4644 break;
4645 }
4646 requirement_vector_copy(&pmul->reqs, reqs);
4647
4648 pmul->helptext = lookup_strvec(file, sec_name, "helptext");
4651 }
4652
4653 if (ok) {
4655 }
4656
4657 return ok;
4658}
4659
4660/**********************************************************************/
4671static void send_ruleset_control(struct conn_list *dest)
4672{
4674 int idx = 0;
4675
4677
4678 if (game.ruleset_summary != NULL) {
4679 struct packet_ruleset_summary summary;
4680
4682
4683 lsend_packet_ruleset_summary(dest, &summary);
4684 }
4685
4686 while (desc_left > 0) {
4688 int this_len = desc_left;
4689
4690 if (this_len > MAX_LEN_CONTENT - 21) {
4692 }
4693
4694 part.text[this_len] = '\0';
4695
4697 idx += this_len;
4699
4701 }
4702}
4703
4704/**********************************************************************/
4709static const char *check_leader_names(struct nation_type *pnation)
4710{
4712 const char *name = nation_leader_name(pleader);
4713
4715 if (prev_leader == pleader) {
4716 break;
4717 } else if (0 == fc_strcasecmp(name, nation_leader_name(prev_leader))) {
4718 return name;
4719 }
4722 return NULL;
4723}
4724
4725/**********************************************************************/
4729static bool load_nation_names(struct section_file *file,
4730 struct rscompat_info *compat)
4731{
4732 struct section_list *sec;
4733 int j;
4734 bool ok = TRUE;
4735 const char *filename = secfile_name(file);
4736
4737 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4738 return FALSE;
4739 }
4740
4741 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4742 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4743
4745 if (NULL == sec) {
4747 "No available nations in this ruleset!");
4748 ok = FALSE;
4749 } else if (section_list_size(sec) > MAX_NUM_NATIONS) {
4751 "Too many nations (max %d, we have %d)!",
4753 ok = FALSE;
4754 } else {
4757
4759 const int i = nation_index(pl);
4760 const char *sec_name = section_name(section_list_get(sec, i));
4761 const char *domain = secfile_lookup_str_default(file, NULL,
4762 "%s.translation_domain", sec_name);
4763 const char *noun_plural = secfile_lookup_str(file,
4764 "%s.plural", sec_name);
4765
4766
4767 if (domain == NULL) {
4768 domain = "freeciv-nations";
4769 }
4770
4771 if (!strcmp("freeciv-core", domain)) {
4772 pl->translation_domain = NULL;
4773 } else if (!strcmp("freeciv-nations", domain)) {
4774 pl->translation_domain = fc_strdup(domain);
4775 } else {
4777 "Unsupported translation domain \"%s\" for %s",
4778 domain, sec_name);
4779 ok = FALSE;
4780 break;
4781 }
4782
4783 if (!ruleset_load_names(&pl->adjective, pl->translation_domain, file, sec_name)) {
4784 ok = FALSE;
4785 break;
4786 }
4787 name_set(&pl->noun_plural, pl->translation_domain, noun_plural);
4788
4789 /* Check if nation name is already defined. */
4790 for (j = 0; j < i && ok; j++) {
4791 struct nation_type *n2 = nation_by_number(j);
4792
4793 /* Compare strings after stripping off qualifiers -- we don't want
4794 * two nations to end up with identical adjectives displayed to users.
4795 * (This check only catches English, not localisations, of course.) */
4796 if (0 == strcmp(Qn_(untranslated_name(&n2->adjective)),
4797 Qn_(untranslated_name(&pl->adjective)))) {
4799 "Two nations defined with the same adjective \"%s\": "
4800 "in section \'%s\' and section \'%s\'",
4801 Qn_(untranslated_name(&pl->adjective)),
4803 ok = FALSE;
4804 } else if (!strcmp(rule_name_get(&n2->adjective),
4805 rule_name_get(&pl->adjective))) {
4806 /* We cannot have the same rule name, as the game needs them to be
4807 * distinct. */
4809 "Two nations defined with the same rule_name \"%s\": "
4810 "in section \'%s\' and section \'%s\'",
4811 rule_name_get(&pl->adjective),
4813 ok = FALSE;
4814 } else if (0 == strcmp(Qn_(untranslated_name(&n2->noun_plural)),
4815 Qn_(untranslated_name(&pl->noun_plural)))) {
4816 /* We don't want identical English plural names either. */
4818 "Two nations defined with the same plural name \"%s\": "
4819 "in section \'%s\' and section \'%s\'",
4820 Qn_(untranslated_name(&pl->noun_plural)),
4822 ok = FALSE;
4823 }
4824 }
4825 if (!ok) {
4826 break;
4827 }
4829 }
4830
4832
4833 if (ok) {
4835 if (sec != NULL) {
4837
4838 section_list_iterate(sec, psection) {
4839 struct nation_group *pgroup;
4840 const char *name;
4841
4842 name = secfile_lookup_str(file, "%s.name", section_name(psection));
4843 if (NULL == name) {
4844 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4845 ok = FALSE;
4846 break;
4847 }
4849 if (pgroup == NULL) {
4850 ok = FALSE;
4851 break;
4852 }
4855 sec = NULL;
4856 }
4857 }
4858
4859 return ok;
4860}
4861
4862/**********************************************************************/
4865static bool is_on_allowed_list(const char *name, const char **list, size_t len)
4866{
4867 int i;
4868
4869 for (i = 0; i < len; i++) {
4870 if (!fc_strcasecmp(name, list[i])) {
4871 return TRUE;
4872 }
4873 }
4874 return FALSE;
4875}
4876
4877/**********************************************************************/
4881static bool load_city_name_list(struct section_file *file,
4882 struct nation_type *pnation,
4883 const char *secfile_str1,
4884 const char *secfile_str2,
4885 const char **allowed_terrains,
4886 size_t atcount)
4887{
4888 size_t dim, j;
4889 bool ok = TRUE;
4890 const char **cities = secfile_lookup_str_vec(file, &dim, "%s.%s",
4892
4893 /* Each string will be of the form "<cityname> (<label>, <label>, ...)".
4894 * The cityname is just the name for this city, while each "label" matches
4895 * a terrain type for the city (or "river"), with a preceeding ! to negate
4896 * it. The parentheses are optional (but necessary to have the settings,
4897 * of course). Our job is now to parse it. */
4898 for (j = 0; j < dim; j++) {
4899 size_t len = strlen(cities[j]);
4900 char city_name[len + 1], *p, *next, *end;
4901 struct nation_city *pncity;
4902
4904
4905 /* Now we wish to determine values for all of the city labels. A value
4906 * of NCP_NONE means no preference (which is necessary so that the use
4907 * of this is optional); NCP_DISLIKE means the label is negated and
4908 * NCP_LIKE means it's labelled. Mostly the parsing just involves
4909 * a lot of ugly string handling... */
4910 if ((p = strchr(city_name, '('))) {
4911 *p++ = '\0';
4912
4913 if (!(end = strchr(p, ')'))) {
4915 "\"%s\" [%s] %s: city name \"%s\" "
4916 "unmatched parenthesis.", secfile_name(file),
4918 ok = FALSE;
4919 } else {
4920 for (*end++ = '\0'; '\0' != *end; end++) {
4921 if (!fc_isspace(*end)) {
4923 "\"%s\" [%s] %s: city name \"%s\" "
4924 "contains characters after last parenthesis.",
4926 cities[j]);
4927 ok = FALSE;
4928 break;
4929 }
4930 }
4931 }
4932 }
4933
4934 /* Build the nation_city. */
4937 /* The ruleset contains a name that is too long. This shouldn't
4938 * happen - if it does, the author should get immediate feedback. */
4940 "\"%s\" [%s] %s: city name \"%s\" is too long.",
4941 secfile_name(file),
4943 ok = FALSE;
4944 city_name[MAX_LEN_CITYNAME - 1] = '\0';
4945 }
4946 pncity = nation_city_new(pnation, city_name);
4947
4948 if (NULL != p) {
4949 /* Handle the labels one at a time. */
4950 do {
4951 enum nation_city_preference prefer;
4952
4953 if ((next = strchr(p, ','))) {
4954 *next = '\0';
4955 }
4957
4958 /* The ! is used to mark a negative, which is recorded with
4959 * NCP_DISLIKE. Otherwise we use a NCP_LIKE.
4960 */
4961 if (*p == '!') {
4962 p++;
4963 prefer = NCP_DISLIKE;
4964 } else {
4965 prefer = NCP_LIKE;
4966 }
4967
4968 if (0 == fc_strcasecmp(p, "river")) {
4970 && !is_on_allowed_list(p,
4973 "\"%s\" [%s] %s: city \"%s\" "
4974 "has terrain hint \"%s\" not in allowed_terrains.",
4976 city_name, p);
4977 ok = FALSE;
4978 } else {
4980 }
4981 } else {
4982 const struct terrain *pterrain = terrain_by_rule_name(p);
4983
4984 if (NULL == pterrain) {
4985 /* Try with removing frequent trailing 's'. */
4986 size_t l = strlen(p);
4987
4988 if (0 < l && 's' == fc_tolower(p[l - 1])) {
4989 char saved = p[l - 1];
4990
4991 p[l - 1] = '\0';
4992 pterrain = terrain_by_rule_name(p);
4993 if (pterrain == NULL) {
4994 /* Didn't help, restore for later allowed_terrains check */
4995 p[l - 1] = saved;
4996 }
4997 }
4998 }
4999
5000 /* Nationset may have been devised with a specific set of terrains
5001 * in mind which don't quite match this ruleset, in which case we
5002 * (a) quietly ignore any hints mentioned that don't happen to be in
5003 * the current ruleset, (b) enforce that terrains mentioned by nations
5004 * must be on the list */
5005 if (pterrain != NULL && game.server.ruledit.allowed_terrains != NULL) {
5006 if (!is_on_allowed_list(p,
5008 /* Terrain exists, but not intended for these nations */
5010 "\"%s\" [%s] %s: city \"%s\" "
5011 "has terrain hint \"%s\" not in allowed_terrains.",
5013 city_name, p);
5014 ok = FALSE;
5015 break;
5016 }
5017 } else if (!pterrain) {
5018 /* Terrain doesn't exist; only complain if it's not on any list */
5020 || !is_on_allowed_list(p,
5023 "\"%s\" [%s] %s: city \"%s\" "
5024 "has unknown terrain hint \"%s\".",
5026 city_name, p);
5027 ok = FALSE;
5028 break;
5029 }
5030 }
5031 if (NULL != pterrain) {
5032 nation_city_set_terrain_preference(pncity, pterrain, prefer);
5033 }
5034 }
5035
5036 p = next ? next + 1 : NULL;
5037 } while (NULL != p && '\0' != *p);
5038 }
5039 }
5040
5041 if (NULL != cities) {
5042 free(cities);
5043 }
5044
5045 return ok;
5046}
5047
5048/**********************************************************************/
5051static bool load_ruleset_nations(struct section_file *file,
5052 struct rscompat_info *compat)
5053{
5054 struct government *gov;
5055 int j;
5056 size_t dim;
5057 char temp_name[MAX_LEN_NAME];
5058 const char **vec;
5059 const char *name, *bad_leader;
5060 const char *sval;
5061 int default_set;
5062 const char *filename = secfile_name(file);
5063 struct section_list *sec = NULL;
5064 enum trait tr;
5065 bool ok = TRUE;
5066
5067 name = secfile_lookup_str_default(file, NULL, "ruledit.nationlist");
5068 if (name != NULL) {
5070 }
5072 "ruledit.embedded_nations");
5073
5074 if (vec != NULL) {
5075 /* Copy to persistent vector */
5078
5079 for (j = 0; j < game.server.ruledit.embedded_nations_count; j++) {
5081 }
5082
5083 free(vec);
5084 }
5085
5087
5088 ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
5089 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5090 if (game.server.default_traits[tr].min < 0) {
5092 }
5093 if (game.server.default_traits[tr].max < 0) {
5095 }
5096 if (game.server.default_traits[tr].fixed < 0) {
5098
5099 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5101 }
5104 "Default values for trait %s not sane.",
5105 trait_name(tr));
5106 ok = FALSE;
5107 break;
5108 }
5109 }
5110
5111 if (ok) {
5113 "compatibility.allowed_govs");
5114 if (vec != NULL) {
5115 /* Copy to persistent vector */
5117 = fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
5119 (const char **)game.server.ruledit.nc_agovs;
5120
5121 for (j = 0; j < game.server.ruledit.ag_count; j++) {
5123 }
5124
5125 free(vec);
5126 }
5127
5129 "compatibility.allowed_terrains");
5130 if (vec != NULL) {
5131 /* Copy to persistent vector */
5133 = fc_malloc(game.server.ruledit.at_count * sizeof(char *));
5135 (const char **)game.server.ruledit.nc_aterrs;
5136
5137 for (j = 0; j < game.server.ruledit.at_count; j++) {
5139 }
5140
5141 free(vec);
5142 }
5143
5145 "compatibility.allowed_styles");
5146 if (vec != NULL) {
5147 /* Copy to persistent vector */
5149 = fc_malloc(game.server.ruledit.as_count * sizeof(char *));
5151 (const char **)game.server.ruledit.nc_astyles;
5152
5153 for (j = 0; j < game.server.ruledit.as_count; j++) {
5155 }
5156
5157 free(vec);
5158 }
5159
5161 "compatibility.default_government");
5162 /* We deliberately don't check this against allowed_govs. It's only
5163 * specified once so not vulnerable to typos, and may usefully be set in
5164 * a specific ruleset to a gov not explicitly known by the nation set. */
5165 if (sval != NULL) {
5167 if (game.default_government == NULL) {
5169 "Tried to set unknown government type \"%s\" as default_government!",
5170 sval);
5171 ok = FALSE;
5172 } else {
5175 }
5176 }
5177 }
5178
5179 if (ok) {
5181 if (sec != NULL) {
5183
5184 section_list_iterate(sec, psection) {
5185 const char *set_name, *set_rule_name, *set_description;
5186
5187 set_name = secfile_lookup_str(file, "%s.name", section_name(psection));
5189 secfile_lookup_str(file, "%s.rule_name", section_name(psection));
5190 set_description = secfile_lookup_str_default(file, "", "%s.description",
5191 section_name(psection));
5192 if (NULL == set_name || NULL == set_rule_name) {
5193 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5194 ok = FALSE;
5195 break;
5196 }
5198 ok = FALSE;
5199 break;
5200 }
5203 sec = NULL;
5204 } else {
5206 "At least one nation set [" NATION_SET_SECTION_PREFIX "_*] "
5207 "must be defined.");
5208 ok = FALSE;
5209 }
5210 }
5211
5212 if (ok) {
5213 /* Default set that every nation is a member of. */
5215 "compatibility.default_nationset");
5216 if (sval != NULL) {
5218 if (pset != NULL) {
5220 } else {
5222 "Unknown default_nationset \"%s\".", sval);
5223 ok = FALSE;
5224 }
5225 } else if (nation_set_count() == 1) {
5226 /* If there's only one set defined, every nation is implicitly a
5227 * member of that set. */
5228 default_set = 0;
5229 } else {
5230 /* No default nation set; every nation must explicitly specify at
5231 * least one set to be a member of. */
5232 default_set = -1;
5233 }
5234 }
5235
5236 if (ok) {
5238 if (sec) {
5239 section_list_iterate(sec, psection) {
5240 struct nation_group *pgroup;
5241 bool hidden;
5242
5243 name = secfile_lookup_str(file, "%s.name", section_name(psection));
5245 if (pgroup == NULL) {
5246 ok = FALSE;
5247 break;
5248 }
5249
5250 hidden = secfile_lookup_bool_default(file, FALSE, "%s.hidden",
5251 section_name(psection));
5253
5254 if (!secfile_lookup_int(file, &j, "%s.match", section_name(psection))) {
5255 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5256 ok = FALSE;
5257 break;
5258 }
5262 sec = NULL;
5263 }
5264 }
5265
5266 if (ok) {
5268 nations_iterate(pnation) {
5269 struct nation_type *pconflict;
5270 const int i = nation_index(pnation);
5271 char tmp[200] = "\0";
5272 const char *barb_type;
5273 const char *sec_name = section_name(section_list_get(sec, i));
5274 const char *legend;
5275
5276 /* Nation sets and groups. */
5277 if (default_set >= 0) {
5278 nation_set_list_append(pnation->sets,
5280 }
5281 vec = secfile_lookup_str_vec(file, &dim, "%s.groups", sec_name);
5282 for (j = 0; j < dim; j++) {
5283 struct nation_set *pset = nation_set_by_rule_name(vec[j]);
5285
5286 fc_assert(pset == NULL || pgroup == NULL);
5287
5288 if (NULL != pset) {
5289 nation_set_list_append(pnation->sets, pset);
5290 } else if (NULL != pgroup) {
5291 nation_group_list_append(pnation->groups, pgroup);
5292 } else {
5293 /* For nation authors, this would probably be considered an error.
5294 * But it can happen normally. The civ1 compatibility ruleset only
5295 * uses the nations that were in civ1, so not all of the links will
5296 * exist. */
5297 log_verbose("Nation %s: Unknown set/group \"%s\".",
5298 nation_rule_name(pnation), vec[j]);
5299 }
5300 }
5301 if (NULL != vec) {
5302 free(vec);
5303 }
5304 if (nation_set_list_size(pnation->sets) < 1) {
5306 "Nation %s is not a member of any nation set",
5307 nation_rule_name(pnation));
5308 ok = FALSE;
5309 break;
5310 }
5311
5312 /* Nation conflicts. */
5313 vec = secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec_name);
5314 for (j = 0; j < dim; j++) {
5316
5317 if (pnation == pconflict) {
5319 "Nation %s conflicts with itself",
5320 nation_rule_name(pnation));
5321 ok = FALSE;
5322 break;
5323 } else if (NULL != pconflict) {
5324 nation_list_append(pnation->server.conflicts_with, pconflict);
5325 } else {
5326 /* For nation authors, this would probably be considered an error.
5327 * But it can happen normally. The civ1 compatibility ruleset only
5328 * uses the nations that were in civ1, so not all of the links will
5329 * exist. */
5330 log_verbose("Nation %s: conflicts_with nation \"%s\" is unknown.",
5331 nation_rule_name(pnation), vec[j]);
5332 }
5333 }
5334 if (NULL != vec) {
5335 free(vec);
5336 }
5337 if (!ok) {
5338 break;
5339 }
5340
5341 /* Nation leaders. */
5342 for (j = 0; j < MAX_NUM_LEADERS; j++) {
5343 const char *sexstr;
5344 sex_t sex;
5345 bool is_male = FALSE;
5346
5347 name = secfile_lookup_str(file, "%s.leaders%d.name", sec_name, j);
5348 if (NULL == name) {
5349 /* No more to read. */
5350 break;
5351 }
5352
5353 if (check_name(name)) {
5354 /* The ruleset contains a name that is too long. This shouldn't
5355 * happen - if it does, the author should get immediate feedback */
5358 "Nation %s: leader name \"%s\" is too long.",
5359 nation_rule_name(pnation), name);
5360 ok = FALSE;
5361 break;
5362 }
5363
5364 sexstr = secfile_lookup_str(file, "%s.leaders%d.sex", sec_name, j);
5365 if (NULL == sexstr) {
5367 "Nation %s: leader \"%s\": %s.",
5368 nation_rule_name(pnation), name, secfile_error());
5369 ok = FALSE;
5370 break;
5371 }
5372
5374
5375 switch (sex) {
5376 case SEX_MALE:
5377 is_male = TRUE;
5378 break;
5379 case SEX_FEMALE:
5380 is_male = FALSE;
5381 break;
5382 case SEX_UNKNOWN:
5384 "Nation %s: leader \"%s\" has unsupported "
5385 "sex variant \"%s\".",
5386 nation_rule_name(pnation), name, sexstr);
5387 ok = FALSE;
5388 break;
5389 }
5390
5391 if (ok) {
5392 (void) nation_leader_new(pnation, name, is_male);
5393 }
5394 }
5395 if (!ok) {
5396 break;
5397 }
5398
5399 /* Check the number of leaders. */
5400 if (MAX_NUM_LEADERS == j) {
5401 /* Too much leaders, get the real number defined in the ruleset. */
5402 while (NULL != secfile_entry_lookup(file, "%s.leaders%d.name",
5403 sec_name, j)) {
5404 j++;
5405 }
5407 "Nation %s: Too many leaders; max is %d",
5409 ok = FALSE;
5410 break;
5411 } else if (0 == j) {
5413 "Nation %s: no leaders; at least one is required.",
5414 nation_rule_name(pnation));
5415 ok = FALSE;
5416 break;
5417 }
5418
5419 /* Check if leader name is not already defined in this nation. */
5420 if ((bad_leader = check_leader_names(pnation))) {
5422 "Nation %s: leader \"%s\" defined more than once.",
5423 nation_rule_name(pnation), bad_leader);
5424 ok = FALSE;
5425 break;
5426 }
5427
5428 /* Nation player color preference, if any */
5429 fc_assert_ret_val(pnation->server.rgb == NULL, FALSE);
5430 (void) rgbcolor_load(file, &pnation->server.rgb, "%s.color", sec_name);
5431
5432 /* Load nation traits */
5433 ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
5434 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5435 bool server_traits_used = TRUE;
5436
5437 if (pnation->server.traits[tr].min < 0) {
5438 pnation->server.traits[tr].min = game.server.default_traits[tr].min;
5439 } else {
5441 }
5442 if (pnation->server.traits[tr].max < 0) {
5443 pnation->server.traits[tr].max = game.server.default_traits[tr].max;
5444 } else {
5446 }
5447 if (pnation->server.traits[tr].fixed < 0) {
5448 if (server_traits_used) {
5449 pnation->server.traits[tr].fixed = game.server.default_traits[tr].fixed;
5450 } else {
5451 int diff = pnation->server.traits[tr].max - pnation->server.traits[tr].min;
5452
5453 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5454 pnation->server.traits[tr].fixed = diff / 2 + pnation->server.traits[tr].min;
5455 }
5456 }
5457 if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
5459 "%s values for trait %s not sane.",
5460 nation_rule_name(pnation), trait_name(tr));
5461 ok = FALSE;
5462 break;
5463 }
5464 }
5465
5466 if (!ok) {
5467 break;
5468 }
5469
5470 pnation->is_playable =
5471 secfile_lookup_bool_default(file, TRUE, "%s.is_playable", sec_name);
5472
5473 /* Check barbarian type. Default is "None" meaning not a barbarian */
5474 barb_type = secfile_lookup_str_default(file, "None",
5475 "%s.barbarian_type", sec_name);
5476 pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp);
5477 if (!barbarian_type_is_valid(pnation->barb_type)) {
5479 "Nation %s, barbarian_type is invalid (\"%s\")",
5480 nation_rule_name(pnation), barb_type);
5481 ok = FALSE;
5482 break;
5483 }
5484
5485 if (pnation->barb_type != NOT_A_BARBARIAN
5486 && pnation->is_playable) {
5487 /* We can't allow players to use barbarian nations, barbarians
5488 * may run out of nations */
5490 "Nation %s marked both barbarian and playable.",
5491 nation_rule_name(pnation));
5492 ok = FALSE;
5493 break;
5494 }
5495
5496 /* Flags */
5497 sz_strlcpy(pnation->flag_graphic_str,
5498 secfile_lookup_str_default(file, "-", "%s.flag", sec_name));
5499 sz_strlcpy(pnation->flag_graphic_alt,
5501 "%s.flag_alt", sec_name));
5502
5503 /* Ruler titles */
5504 for (j = 0;; j++) {
5505 const char *male, *female;
5506
5508 "%s.ruler_titles%d.government",
5509 sec_name, j);
5510 if (NULL == name) {
5511 /* End of the list of ruler titles. */
5512 break;
5513 }
5514
5515 /* NB: even if the government doesn't exist, we load the entries for
5516 * the ruler titles to avoid warnings about unused entries. */
5517 male = secfile_lookup_str(file, "%s.ruler_titles%d.male_title",
5518 sec_name, j);
5519 female = secfile_lookup_str(file, "%s.ruler_titles%d.female_title",
5520 sec_name, j);
5522
5523 /* Nationset may have been devised with a specific set of govs in
5524 * mind which don't quite match this ruleset, in which case we
5525 * (a) quietly ignore any govs mentioned that don't happen to be in
5526 * the current ruleset, (b) enforce that govs mentioned by nations
5527 * must be on the list */
5528 if (gov != NULL && game.server.ruledit.allowed_govs != NULL) {
5532 /* Gov exists, but not intended for these nations */
5533 gov = NULL;
5535 "Nation %s: government \"%s\" not in allowed_govs.",
5536 nation_rule_name(pnation), name);
5537 ok = FALSE;
5538 break;
5539 }
5540 } else if (!gov) {
5541 /* Gov doesn't exist; only complain if it's not on any list */
5547 "Nation %s: government \"%s\" not found.",
5548 nation_rule_name(pnation), name);
5549 ok = FALSE;
5550 break;
5551 }
5552 }
5553 if (NULL != male && NULL != female) {
5554 if (gov) {
5555 (void) government_ruler_title_new(gov, pnation, male, female);
5556 }
5557 } else {
5559 ok = FALSE;
5560 break;
5561 }
5562 }
5563 if (!ok) {
5564 break;
5565 }
5566
5567 /* City styles */
5568 name = secfile_lookup_str(file, "%s.style", sec_name);
5569 if (!name) {
5571 ok = FALSE;
5572 break;
5573 }
5574 pnation->style = style_by_rule_name(name);
5575 if (pnation->style == NULL) {
5581 "Nation %s: Illegal style \"%s\"",
5582 nation_rule_name(pnation), name);
5583 ok = FALSE;
5584 break;
5585 } else {
5586 log_verbose("Nation %s: style \"%s\" not supported in this "
5587 "ruleset; using default.",
5588 nation_rule_name(pnation), name);
5589 pnation->style = style_by_number(0);
5590 }
5591 }
5592
5593 /* Civilwar nations */
5594 vec = secfile_lookup_str_vec(file, &dim,
5595 "%s.civilwar_nations", sec_name);
5596 for (j = 0; j < dim; j++) {
5598
5599 /* No test for duplicate nations is performed. If there is a duplicate
5600 * entry it will just cause that nation to have an increased
5601 * probability of being chosen. */
5602 if (pconflict == pnation) {
5604 "Nation %s is its own civil war nation",
5605 nation_rule_name(pnation));
5606 ok = FALSE;
5607 break;
5608 } else if (NULL != pconflict) {
5609 nation_list_append(pnation->server.civilwar_nations, pconflict);
5610 nation_list_append(pconflict->server.parent_nations, pnation);
5611 } else {
5612 /* For nation authors, this would probably be considered an error.
5613 * But it can happen normally. The civ1 compatibility ruleset only
5614 * uses the nations that were in civ1, so not all of the links will
5615 * exist. */
5616 log_verbose("Nation %s: civil war nation \"%s\" is unknown.",
5617 nation_rule_name(pnation), vec[j]);
5618 }
5619 }
5620 if (NULL != vec) {
5621 free(vec);
5622 }
5623 if (!ok) {
5624 break;
5625 }
5626
5627 /* Load nation specific initial items */
5628 if (!lookup_tech_list(file, sec_name, "init_techs",
5629 pnation->init_techs, filename)) {
5630 ok = FALSE;
5631 break;
5632 }
5633 if (!lookup_building_list(file, sec_name, "init_buildings",
5634 pnation->init_buildings, filename)) {
5635 ok = FALSE;
5636 break;
5637 }
5638 if (!lookup_unit_list(file, sec_name, "init_units",
5639 pnation->init_units, filename)) {
5640 ok = FALSE;
5641 break;
5642 }
5643 fc_strlcat(tmp, sec_name, 200);
5644 fc_strlcat(tmp, ".init_government", 200);
5645 if (secfile_entry_by_path(file, tmp)) {
5646 pnation->init_government = lookup_government(file, tmp, filename,
5647 NULL);
5648 /* If specified, init_government has to be in this specific ruleset,
5649 * not just allowed_govs */
5650 if (pnation->init_government == NULL) {
5651 ok = FALSE;
5652 break;
5653 }
5654 /* ...but if a list of govs has been specified, enforce that this
5655 * nation's init_government is on the list. */
5657 && !is_on_allowed_list(government_rule_name(pnation->init_government),
5661 "Nation %s: init_government \"%s\" not allowed.",
5662 nation_rule_name(pnation),
5663 government_rule_name(pnation->init_government));
5664 ok = FALSE;
5665 break;
5666 }
5667 }
5668
5669 /* Read default city names. */
5670 if (!load_city_name_list(file, pnation, sec_name, "cities",
5673 ok = FALSE;
5674 break;
5675 }
5676
5677 legend = secfile_lookup_str_default(file, "", "%s.legend", sec_name);
5678 pnation->legend = fc_strdup(legend);
5679 if (check_strlen(pnation->legend, MAX_LEN_MSG, NULL)) {
5681 "Nation %s: legend \"%s\" is too long.",
5682 nation_rule_name(pnation),
5683 pnation->legend);
5684 ok = FALSE;
5685 break;
5686 }
5687
5688 pnation->player = NULL;
5691 sec = NULL;
5692 }
5693
5694 /* Clean up on aborted load */
5695 if (sec != NULL) {
5696 fc_assert(!ok);
5698 }
5699
5700 if (ok) {
5702 }
5703
5704 if (ok) {
5705 /* Update cached number of playable nations in the current set */
5707
5708 /* Sanity checks on all sets */
5711
5712 nations_iterate(pnation) {
5713 if (nation_is_in_set(pnation, pset)) {
5714 switch (nation_barbarian_type(pnation)) {
5715 case NOT_A_BARBARIAN:
5716 if (is_nation_playable(pnation)) {
5717 num_playable++;
5718 }
5719 break;
5720 case LAND_BARBARIAN:
5722 break;
5723 case SEA_BARBARIAN:
5725 break;
5726 case ANIMAL_BARBARIAN:
5727 /* Animals are optional */
5728 break;
5731 break;
5732 default:
5734 }
5735 }
5737 if (num_playable < 1) {
5739 "Nation set \"%s\" has no playable nations. "
5740 "At least one required!", nation_set_rule_name(pset));
5741 ok = FALSE;
5742 break;
5743 }
5744 if (barb_land_count == 0 && barb_both_count == 0) {
5746 "No land barbarian nation defined in set \"%s\". "
5747 "At least one required!", nation_set_rule_name(pset));
5748 ok = FALSE;
5749 break;
5750 }
5751 if (barb_sea_count == 0 && barb_both_count == 0) {
5753 "No sea barbarian nation defined in set \"%s\". "
5754 "At least one required!", nation_set_rule_name(pset));
5755 ok = FALSE;
5756 break;
5757 }
5759 }
5760
5761 return ok;
5762}
5763
5764/**********************************************************************/
5768static bool load_style_names(struct section_file *file,
5769 struct rscompat_info *compat)
5770{
5771 bool ok = TRUE;
5772 struct section_list *sec;
5773 const char *filename = secfile_name(file);
5774
5775 if (!rscompat_check_cap_and_version(file, filename, compat)) {
5776 return FALSE;
5777 }
5778
5779 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
5780 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
5781
5783 if (NULL == sec) {
5785 "No available nation styles in this ruleset!");
5786 ok = FALSE;
5787 } else {
5789
5791
5793 const int i = style_index(ps);
5794 const char *sec_name = section_name(section_list_get(sec, i));
5795
5796 ruleset_load_names(&ps->name, NULL, file, sec_name);
5798 }
5799
5801
5802 if (ok) {
5803 /* The citystyle sections: */
5804 int i = 0;
5805
5807 if (NULL != sec) {
5809 section_list_iterate(sec, style) {
5810 if (!ruleset_load_names(&city_styles[i].name, NULL, file, section_name(style))) {
5811 ok = FALSE;
5812 break;
5813 }
5814 i++;
5816
5818 } else {
5820 }
5821 }
5822
5823 return ok;
5824}
5825
5826/**********************************************************************/
5829static bool load_ruleset_styles(struct section_file *file,
5830 struct rscompat_info *compat)
5831{
5832 struct section_list *sec;
5833 int i;
5834 bool ok = TRUE;
5835
5836 /* City Styles ... */
5837
5839
5840 /* Get rest: */
5841 for (i = 0; i < game.control.num_city_styles; i++) {
5842 struct requirement_vector *reqs;
5843 const char *sec_name = section_name(section_list_get(sec, i));
5844
5845 sz_strlcpy(city_styles[i].graphic,
5846 secfile_lookup_str(file, "%s.graphic", sec_name));
5847 sz_strlcpy(city_styles[i].graphic_alt,
5848 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
5849 sz_strlcpy(city_styles[i].citizens_graphic,
5851 "%s.citizens_graphic", sec_name));
5852
5854 if (reqs == NULL) {
5855 ok = FALSE;
5856 break;
5857 }
5859 }
5860
5862
5863 if (ok) {
5865
5866 if (sec != NULL) {
5867 int musi;
5868
5871 musi = 0;
5872
5873 section_list_iterate(sec, psection) {
5874 struct requirement_vector *reqs;
5876 const char *sec_name = section_name(psection);
5877
5878 sz_strlcpy(pmus->music_peaceful,
5880 "%s.music_peaceful", sec_name));
5881 sz_strlcpy(pmus->music_combat,
5883 "%s.music_combat", sec_name));
5884
5885 reqs = lookup_req_list(file, compat, sec_name, "reqs", "Music Style");
5886 if (reqs == NULL) {
5887 ok = FALSE;
5888 break;
5889 }
5891
5892 musi++;
5894 }
5895
5897 }
5898
5899 return ok;
5900}
5901
5902/**********************************************************************/
5909 const char *uflags_path,
5910 const char *filename)
5911{
5912 /* Add each listed protected unit type flag as a !present
5913 * requirement. */
5914 if (secfile_entry_lookup(file, "%s", uflags_path)) {
5916 size_t psize;
5917 int i;
5918
5921 "%s", uflags_path);
5922
5923 if (!protecor_flag) {
5924 /* Entity exists but couldn't read it. */
5926 "\"%s\": %s: bad unit type flag list.",
5927 filename, uflags_path);
5928
5929 return FALSE;
5930 }
5931
5932 for (i = 0; i < psize; i++) {
5936 FALSE, FALSE, TRUE,
5937 protecor_flag[i]));
5938 }
5939
5941 }
5942
5943 return TRUE;
5944}
5945
5946/**********************************************************************/
5952 const char *actions_path,
5953 const char *filename)
5954{
5955 /* Read the alternative actions. */
5956 if (secfile_entry_lookup(file, "%s", actions_path)) {
5957 enum gen_action *unit_acts;
5958 size_t asize;
5959 int i;
5960
5962 "%s", actions_path);
5963
5964 if (!unit_acts) {
5965 /* Entity exists but couldn't read it. */
5967 "\"%s\": %s: bad action list",
5968 filename, actions_path);
5969
5970 return FALSE;
5971 }
5972
5973 for (i = 0; i < asize; i++) {
5974 auto_perf->alternatives[i] = unit_acts[i];
5975 }
5976
5977 free(unit_acts);
5978 }
5979
5980 return TRUE;
5981}
5982
5983/**********************************************************************/
5988 const char *item,
5989 const char *filename)
5990{
5991 char uflags_path[100];
5992 char action_path[100];
5993
5995 "missing_unit_upkeep.%s_protected", item);
5997 "missing_unit_upkeep.%s_unit_act", item);
5998
6000 filename)
6002 filename));
6003}
6004
6005/**********************************************************************/
6008static bool load_ruleset_cities(struct section_file *file,
6009 struct rscompat_info *compat)
6010{
6011 const char *filename = secfile_name(file);
6012 const char *item;
6013 struct section_list *sec;
6014 bool ok = TRUE;
6015
6016 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6017 return FALSE;
6018 }
6019
6020 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6021 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6022
6023 /* Specialist options */
6025 if (section_list_size(sec) >= SP_MAX) {
6027 "\"%s\": Too many specialists (%d, max %d).",
6028 filename, section_list_size(sec), SP_MAX);
6029 ok = FALSE;
6030 }
6031
6032 if (ok) {
6033 int i = 0;
6034 const char *tag;
6035
6037
6038 section_list_iterate(sec, psection) {
6039 struct specialist *s = specialist_by_number(i);
6040 struct requirement_vector *reqs;
6041 const char *sec_name = section_name(psection);
6042
6043 if (!ruleset_load_names(&s->name, NULL, file, sec_name)) {
6044 ok = FALSE;
6045 break;
6046 }
6047
6049 "%s.short_name", sec_name);
6051
6052 tag = secfile_lookup_str(file, "%s.graphic", sec_name);
6053 if (tag == NULL) {
6055 "\"%s\": No graphic tag for specialist at %s.",
6056 filename, sec_name);
6057 ok = FALSE;
6058 break;
6059 }
6060 sz_strlcpy(s->graphic_str, tag);
6063 "%s.graphic_alt", sec_name));
6064
6066 if (reqs == NULL) {
6067 ok = FALSE;
6068 break;
6069 }
6071
6072 s->helptext = lookup_strvec(file, sec_name, "helptext");
6073
6074 if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
6076 }
6077 i++;
6079 }
6080
6081 if (ok && DEFAULT_SPECIALIST == -1) {
6083 "\"%s\": must give a min_size of 0 for at least one "
6084 "specialist type.", filename);
6085 ok = FALSE;
6086 }
6088 sec = NULL;
6089
6090 if (ok) {
6091 /* City Parameters */
6092
6095 "parameters.celebrate_size_limit");
6097 secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
6100 "parameters.angry_citizens");
6101
6103 secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
6105 secfile_lookup_int_default(file, 0, "parameters.forced_science");
6107 secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
6109 secfile_lookup_int_default(file, 0, "parameters.forced_gold");
6111 + game.info.forced_gold != 100) {
6113 "\"%s\": Forced taxes do not add up in ruleset!",
6114 filename);
6115 ok = FALSE;
6116 }
6117 }
6118
6119 if (ok) {
6121
6122 /* civ1 & 2 didn't reveal tiles */
6125 "parameters.vision_reveal_tiles");
6126
6128 secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
6129
6130 /* Citizens configuration. */
6133 "citizen.nationality");
6134
6135 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
6136 /* Same as old hardcoded behavior */
6138 }
6141 "citizen.ubuilder_nationality");
6144 "citizen.convert_speed");
6146 secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
6148 secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
6149 }
6150
6151 if (ok) {
6152 /* Missing unit upkeep. */
6154
6155 /* Can't pay food upkeep! */
6157 auto_perf->cause = AAPC_UNIT_UPKEEP;
6158
6159 /* This is about food upkeep. */
6161 req_from_str("OutputType", "Local",
6162 FALSE, TRUE, TRUE,
6163 "Food"));
6164
6165 /* Internally represented as an action auto performer rule. */
6166 if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
6167 ok = FALSE;
6168 }
6169
6172 "missing_unit_upkeep.food_wipe");
6173
6174 /* Can't pay gold upkeep! */
6176 auto_perf->cause = AAPC_UNIT_UPKEEP;
6177
6178 /* This is about gold upkeep. */
6180 req_from_str("OutputType", "Local",
6181 FALSE, TRUE, TRUE,
6182 "Gold"));
6183
6184 /* Internally represented as an action auto performer rule. */
6185 if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
6186 ok = FALSE;
6187 }
6188
6191 "missing_unit_upkeep.gold_wipe");
6192
6193 /* Can't pay shield upkeep! */
6195 auto_perf->cause = AAPC_UNIT_UPKEEP;
6196
6197 /* This is about shield upkeep. */
6199 req_from_str("OutputType", "Local",
6200 FALSE, TRUE, TRUE,
6201 "Shield"));
6202
6203 /* Internally represented as an action auto performer rule. */
6204 if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
6205 ok = FALSE;
6206 }
6207
6210 "missing_unit_upkeep.shield_wipe");
6211 }
6212
6213 if (ok) {
6215 }
6216
6217 return ok;
6218}
6219
6220/**********************************************************************/
6223static bool load_ruleset_effects(struct section_file *file,
6224 struct rscompat_info *compat)
6225{
6226 struct section_list *sec;
6227 const char *filename;
6228 bool ok = TRUE;
6229
6230 filename = secfile_name(file);
6231
6232 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6233 return FALSE;
6234 }
6235
6236 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6237 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6238
6240
6241 if (sec != NULL) {
6242 section_list_iterate(sec, psection) {
6243 const char *sec_name = section_name(psection);
6244 enum effect_type main_type;
6245 enum effect_type ai_valued_as;
6246 const char *type;
6247
6248 type = secfile_lookup_str(file, "%s.type", sec_name);
6249 if (type == NULL) {
6251 "\"%s\" [%s] missing effect type.",
6252 filename, sec_name);
6253 ok = FALSE;
6254 break;
6255 }
6259 "\"%s\" [%s] lists unknown effect type \"%s\".",
6260 filename, sec_name, type);
6261 ok = FALSE;
6262 break;
6263 }
6264 if (!is_user_effect(main_type)) {
6266 "\"%s\" [%s] type \"%s\" is not an user effect.",
6267 filename, sec_name, type);
6268 ok = FALSE;
6269 break;
6270 }
6271
6272 type = secfile_lookup_str(file, "%s.ai_valued_as", sec_name);
6273 if (type == NULL) {
6275 "\"%s\" [%s] missing ai_valued_as.",
6276 filename, sec_name);
6277 ok = FALSE;
6278 break;
6279 }
6283 "\"%s\" [%s] lists unknown ai_valued_as \"%s\".",
6284 filename, sec_name, type);
6285 ok = FALSE;
6286 break;
6287 }
6290 "\"%s\" [%s] ai_valued_as \"%s\" is an user effect.",
6291 filename, sec_name, type);
6292 ok = FALSE;
6293 break;
6294 }
6295
6297 /* It has been set already! */
6299 "\"%s\" [%s] Duplicate \"%s\" entry.",
6300 filename, sec_name, type);
6301 ok = FALSE;
6302 break;
6303 }
6304
6307
6309 }
6310
6311 /* Parse effects and add them to the effects ruleset cache. */
6313 section_list_iterate(sec, psection) {
6314 enum effect_type eff;
6315 int value;
6316 struct multiplier *pmul;
6317 struct effect *peffect;
6318 const char *sec_name = section_name(psection);
6319 struct requirement_vector *reqs;
6320 const char *type;
6321 const char *comment;
6322
6323 type = secfile_lookup_str(file, "%s.type", sec_name);
6324
6325 if (type == NULL) {
6327 "\"%s\" [%s] missing effect type.",
6328 filename, sec_name);
6329 ok = FALSE;
6330 break;
6331 }
6332
6334 if (!effect_type_is_valid(eff)) {
6336 "\"%s\" [%s] lists unknown effect type \"%s\".",
6337 filename, sec_name, type);
6338 ok = FALSE;
6339 break;
6340 }
6341
6342 value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
6343
6344 {
6345 const char *multiplier_name
6346 = secfile_lookup_str(file, "%s.multiplier", sec_name);
6347
6348 if (multiplier_name) {
6350 if (!pmul) {
6352 "\"%s\" [%s] has unknown multiplier \"%s\".",
6353 filename, sec_name, multiplier_name);
6354 ok = FALSE;
6355 break;
6356 }
6357 } else {
6358 pmul = NULL;
6359 }
6360 }
6361
6362 peffect = effect_new(eff, value, pmul);
6363
6364 reqs = lookup_req_list(file, compat, sec_name, "reqs", type);
6365 if (reqs == NULL) {
6366 ok = FALSE;
6367 break;
6368 }
6369
6373
6374 comment = secfile_lookup_str_default(file, NULL, "%s.comment", sec_name);
6375
6376 if (comment != NULL) {
6377 peffect->rulesave.comment = fc_strdup(comment);
6378 }
6379
6382
6383 if (ok) {
6385 }
6386
6387 return ok;
6388}
6389
6390/**********************************************************************/
6393static int secfile_lookup_int_default_min_max(struct section_file *file,
6394 int def, int min, int max,
6395 const char *path, ...)
6398 int def, int min, int max,
6399 const char *path, ...)
6400{
6401 char fullpath[256];
6402 int ival;
6403 va_list args;
6404
6405 va_start(args, path);
6406 fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
6407 va_end(args);
6408
6409 if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
6410 ival = def;
6411 }
6412
6413 if (ival < min) {
6415 "\"%s\" should be in the interval [%d, %d] "
6416 "but is %d; using the minimal value.",
6417 fullpath, min, max, ival);
6418 ival = min;
6419 }
6420
6421 if (ival > max) {
6423 "\"%s\" should be in the interval [%d, %d] "
6424 "but is %d; using the maximal value.",
6425 fullpath, min, max, ival);
6426 ival = max;
6427 }
6428
6429 return ival;
6430}
6431
6432/**********************************************************************/
6435static bool load_action_ui_name(struct section_file *file, int act,
6436 const char *entry_name,
6437 const char *compat_name)
6438{
6439 const char *text;
6440 const char *def = action_ui_name_default(act);
6441
6442 if (compat_name != NULL) {
6443 def = secfile_lookup_str_default(file, def,
6444 "actions.%s", compat_name);
6445 }
6446
6447 text = secfile_lookup_str_default(file, def,
6448 "actions.%s", entry_name);
6449 sz_strlcpy(action_by_number(act)->ui_name, text);
6450
6451 return TRUE;
6452}
6453
6454/**********************************************************************/
6457static bool load_action_range_max(struct section_file *file, action_id act)
6458{
6459 struct action *paction = action_by_number(act);
6460 const char *vname = action_max_range_ruleset_var_name(act);
6461
6462 if (vname != NULL) {
6463 struct entry *pentry;
6464 int max_range;
6465
6466 pentry = secfile_entry_lookup(file, "actions.%s", vname);
6467
6468 if (pentry == NULL) {
6470 } else {
6471 const char *custom;
6472
6475 /* max_range already assigned */
6476 } else if (entry_type_get(pentry) == ENTRY_STR
6480 } else {
6481 ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
6484
6485 return FALSE;
6486 }
6487 }
6488
6490 }
6491
6492 return TRUE;
6493}
6494
6495/**********************************************************************/
6498static bool load_action_range(struct section_file *file, action_id act)
6499{
6500 struct action *paction = action_by_number(act);
6501 const char *vname;
6502
6503 if (!load_action_range_max(file, act)) {
6504 return FALSE;
6505 }
6506
6508 if (vname != NULL) {
6509 /* Min range can be loaded from the ruleset. */
6513 "actions.%s",
6514 vname);
6515 }
6516
6517 return TRUE;
6518}
6519
6520/**********************************************************************/
6523static bool load_action_kind(struct section_file *file, action_id act)
6524{
6525 struct action *paction = action_by_number(act);
6526
6528 /* Target kind can't be loaded from the ruleset. */
6529 }
6530
6534 paction->result),
6536 "actions.%s",
6538
6539 return TRUE;
6540}
6541
6542/**********************************************************************/
6546 action_id act)
6547{
6549 /* Actor consumption can be loaded from the ruleset. */
6552 file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
6554 }
6555
6556 return TRUE;
6557}
6558
6559/**********************************************************************/
6563 const char *filename,
6564 struct action *paction)
6565{
6567 /* Action blocking can be loaded from the ruleset. */
6568
6569 char fullpath[1024];
6570
6571 fc_snprintf(fullpath, sizeof(fullpath), "actions.%s",
6573
6574 if (secfile_entry_by_path(file, fullpath)) {
6576 size_t asize;
6577 int j;
6578
6581
6582 if (!blocking_actions) {
6583 /* Entity exists but couldn't read it. */
6585 "\"%s\": %s: bad action list",
6586 filename, fullpath);
6587
6588 return FALSE;
6589 }
6590
6591 for (j = 0; j < asize; j++) {
6592 BV_SET(paction->blocked_by, blocking_actions[j]);
6593 }
6594
6596 }
6597 }
6598
6599 return TRUE;
6600}
6601
6602/**********************************************************************/
6607 const char *filename,
6608 int performer_slot,
6609 struct action *paction)
6610{
6612 char action_list_path[100];
6613
6615 /* Not relevant. */
6616 return TRUE;
6617 }
6618
6620 auto_perf->cause = AAPC_POST_ACTION;
6621
6622 /* Limit auto performer to this action. */
6625 FALSE, TRUE, TRUE,
6626 paction->id));
6627
6628 /* Load the list of actions. */
6630 "actions.%s",
6633 action_list_path, filename)) {
6634 return FALSE;
6635 }
6636
6637 return TRUE;
6638}
6639
6640/**********************************************************************/
6643static bool lookup_bv_actions(struct section_file *file,
6644 const char *filename,
6645 bv_actions *target,
6646 const char *path)
6647{
6648 if (secfile_entry_by_path(file, path)) {
6650 size_t asize;
6651 int j;
6652
6654 "%s", path);
6655
6656 if (!listed_actions) {
6657 /* Entity exists but couldn't read it. */
6658 ruleset_error(NULL, LOG_ERROR, "\"%s\": %s: bad action list",
6659 filename, path);
6660
6661 return FALSE;
6662 }
6663
6664 for (j = 0; j < asize; j++) {
6665 BV_SET(*target, listed_actions[j]);
6666 }
6667
6669 }
6670
6671 return TRUE;
6672}
6673
6674/**********************************************************************/
6677static bool load_ruleset_game(struct section_file *file, bool act,
6678 struct rscompat_info *compat)
6679{
6680 const char *sval, **svec;
6681 const char *filename;
6682 int *food_ini;
6683 int i;
6684 size_t teams;
6685 const char *pref_text;
6686 size_t gni_tmp;
6687 struct section_list *sec;
6688 size_t nval;
6689 const char *name;
6690 bool ok = TRUE;
6691
6692 if (file == NULL) {
6693 return FALSE;
6694 }
6695 filename = secfile_name(file);
6696
6697 name = secfile_lookup_str_default(file, NULL, "ruledit.description_file");
6698 if (name != NULL) {
6700 }
6701
6702 /* Section: tileset */
6703 pref_text = secfile_lookup_str_default(file, "", "tileset.prefered");
6704 if (pref_text[0] != '\0') {
6705 log_deprecation("Entry tileset.prefered in game.ruleset."
6706 " Use correct spelling tileset.preferred instead");
6707 }
6708 pref_text = secfile_lookup_str_default(file, pref_text, "tileset.preferred");
6709 if (pref_text[0] != '\0') {
6710 /* There was tileset suggestion */
6712 } else {
6713 /* No tileset suggestions */
6714 game.control.preferred_tileset[0] = '\0';
6715 }
6716
6717 /* Section: soundset */
6718 pref_text = secfile_lookup_str_default(file, "", "soundset.prefered");
6719 if (pref_text[0] != '\0') {
6720 log_deprecation("Entry soundset.prefered in game.ruleset."
6721 " Use correct spelling soundset.preferred instead");
6722 }
6723 pref_text = secfile_lookup_str_default(file, pref_text, "soundset.preferred");
6724 if (pref_text[0] != '\0') {
6725 /* There was soundset suggestion */
6727 } else {
6728 /* No soundset suggestions */
6730 }
6731
6732 /* Section: musicset */
6733 pref_text = secfile_lookup_str_default(file, "", "musicset.prefered");
6734 if (pref_text[0] != '\0') {
6735 log_deprecation("Entry musicset.prefered in game.ruleset."
6736 " Use correct spelling musicset.preferred instead");
6737 }
6738 pref_text = secfile_lookup_str_default(file, pref_text, "musicset.preferred");
6739 if (pref_text[0] != '\0') {
6740 /* There was musicset suggestion */
6742 } else {
6743 /* No musicset suggestions */
6745 }
6746
6747 /* Section: about */
6748 pref_text = secfile_lookup_str(file, "about.name");
6749 /* Ruleset/modpack name found */
6751
6752 pref_text = secfile_lookup_str_default(file, "", "about.version");
6753 if (pref_text[0] != '\0') {
6754 /* Ruleset/modpack version found */
6756 } else {
6757 /* No version information */
6758 game.control.version[0] = '\0';
6759 }
6760
6761 pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
6762 if (pref_text[0] != '\0') {
6763 /* Alt directory definition found. */
6765 } else {
6766 /* No alt directory information */
6767 game.control.alt_dir[0] = '\0';
6768 }
6769
6770 pref_text = secfile_lookup_str_default(file, "", "about.summary");
6771 if (pref_text[0] != '\0') {
6772 int len;
6773
6774 /* Ruleset/modpack summary found */
6775 len = strlen(pref_text);
6778 } else {
6779 /* No summary */
6780 if (game.ruleset_summary != NULL) {
6783 }
6784 }
6785
6786 pref_text = secfile_lookup_str_default(file, "", "about.description");
6787 if (pref_text[0] != '\0') {
6788 int len;
6789
6790 /* Ruleset/modpack description found */
6791 len = strlen(pref_text);
6795 } else {
6796 /* No description */
6797 if (game.ruleset_description != NULL) {
6800 }
6802 }
6803
6804 pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
6805 if (pref_text[0] != '\0') {
6806 int len = strlen(pref_text);
6807
6810 } else {
6812 game.ruleset_capabilities[0] = '\0';
6813 }
6814
6815 /* Section: options */
6816 if (!lookup_tech_list(file, "options", "global_init_techs",
6817 game.rgame.global_init_techs, filename)) {
6818 ok = FALSE;
6819 }
6820
6821 if (ok) {
6822 if (!lookup_building_list(file, "options", "global_init_buildings",
6823 game.rgame.global_init_buildings, filename)) {
6824 ok = FALSE;
6825 }
6826 }
6827
6828 if (ok) {
6829 const char **slist;
6830 int j;
6831
6833 "options.popup_tech_help");
6834
6835 /* section: civstyle */
6838 "civstyle.base_pollution");
6839
6841
6842 slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
6843 for (j = 0; j < nval; j++) {
6844 enum gameloss_style style;
6845
6846 sval = slist[j];
6847 if (strcmp(sval, "") == 0) {
6848 continue;
6849 }
6851 if (!gameloss_style_is_valid(style)) {
6853 "\"%s\": bad value \"%s\" for gameloss_style.",
6854 filename, sval);
6855 ok = FALSE;
6856 break;
6857 } else {
6858 game.info.gameloss_style |= style;
6859 }
6860 }
6861 free(slist);
6862 }
6863
6864 if (ok) {
6870 "civstyle.happy_cost");
6876 "civstyle.food_cost");
6878 = secfile_lookup_bool_default(file, TRUE, "civstyle.civil_war_enabled");
6879
6882 "civstyle.civil_war_bonus_celebrating");
6883
6886 "civstyle.civil_war_bonus_unhappy");
6887
6893 "civstyle.base_bribe_cost");
6899 "civstyle.ransom_gold");
6902 "civstyle.pillage_select");
6903
6906 "civstyle.tech_steal_allow_holes");
6909 "civstyle.tech_trade_allow_holes");
6912 "civstyle.tech_trade_loss_allow_holes");
6915 "civstyle.tech_parasite_allow_holes");
6918 "civstyle.tech_loss_allow_holes");
6919
6925 "civstyle.upgrade_veteran_loss");
6931 "civstyle.autoupgrade_veteran_loss");
6932
6938 "research.base_tech_cost");
6939
6940 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
6941 /* base_tech_cost used to be used for this too. */
6947 "research.min_tech_cost");
6948 } else {
6954 "research.min_tech_cost");
6955 }
6956
6958 "civstyle.granary_food_ini");
6960
6963 "Too many granary_food_ini entries (%d, max %d)",
6965 ok = FALSE;
6966 } else if (game.info.granary_num_inis == 0) {
6967 log_error("No values for granary_food_ini. Using default "
6968 "value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
6971 } else {
6972 int gi;
6973
6974 /* check for <= 0 entries */
6975 for (gi = 0; gi < game.info.granary_num_inis; gi++) {
6976 if (food_ini[gi] <= 0) {
6977 if (gi == 0) {
6979 } else {
6980 food_ini[gi] = food_ini[gi - 1];
6981 }
6982 log_error("Bad value for granary_food_ini[%i]. Using %i.",
6983 gi, food_ini[gi]);
6984 }
6986 }
6987 }
6988 free(food_ini);
6989 }
6990
6991 if (ok) {
6997 "civstyle.granary_food_inc");
6998
7005 "civstyle.min_city_center_%s",
7008 }
7009
7010 if (ok) {
7011 const char *tus_text;
7012
7018 "civstyle.init_vis_radius_sq");
7019
7025 "civstyle.init_city_radius_sq");
7026
7028 "civstyle.gold_upkeep_style");
7033 "Unknown gold upkeep style \"%s\"",
7034 tus_text);
7035 ok = FALSE;
7036 }
7037
7039 = secfile_lookup_bool_default(file, FALSE, "civstyle.homeless_gold_upkeep");
7040
7044 "Cannot have homeless_gold_upkeep while gold_upkeep_style \"City\".");
7045 ok = FALSE;
7046 }
7047
7049 "civstyle.output_granularity");
7050
7052 = secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
7053
7055 = secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
7056
7057 /* section: wonder_visibility */
7058 if (ok) {
7059 const char *text;
7060
7061 text = secfile_lookup_str_default(file,
7063 "wonder_visibility.small_wonders");
7064
7069 "Unknown wonder visibility typpe \"%s\"",
7070 text);
7071 ok = FALSE;
7072 }
7073 }
7074
7075 /* section: illness */
7078 "illness.illness_on");
7084 "illness.illness_base_factor");
7090 "illness.illness_min_size");
7096 "illness.illness_trade_infection");
7102 "illness.illness_pollution_factor");
7103
7104 /* section: incite_cost */
7110 "incite_cost.base_incite_cost");
7116 "incite_cost.improvement_factor");
7122 "incite_cost.unit_factor");
7128 "incite_cost.total_factor");
7129 }
7130
7131 if (ok) {
7132 const char *tus_text;
7133
7134 /* section: combat_rules */
7137 "combat_rules.tired_attack");
7138
7141 "combat_rules.only_killing_makes_veteran");
7142
7145 "combat_rules.only_real_fight_makes_veteran");
7146
7149 "combat_rules.combat_odds_scaled_veterancy");
7150
7153 "combat_rules.damage_reduces_bombard_rate");
7154
7157 "combat_rules.low_firepower_badwallattacker");
7160 "combat_rules.low_firepower_pearl_harbour");
7163 "combat_rules.low_firepower_combat_bonus");
7166 "combat_rules.low_firepower_nonnat_bombard");
7167
7172 "combat_rules.nuke_pop_loss_pct");
7173
7178 "combat_rules.nuke_defender_survival_chance_pct");
7179
7180 /* section: borders */
7186 "borders.radius_sq_city");
7192 "borders.size_effect");
7193
7199 "borders.radius_sq_city_permanent");
7200
7201 /* section: research */
7203 "research.tech_cost_style");
7208 "Unknown tech cost style \"%s\"",
7209 tus_text);
7210 ok = FALSE;
7211 }
7212
7214 "research.tech_leakage");
7219 "Unknown tech leakage \"%s\"",
7220 tus_text);
7221 ok = FALSE;
7222 }
7225 log_error("Only tech_leakage \"%s\" supported with "
7226 "tech_cost_style \"%s\". ",
7229 log_error("Switching to tech_leakage \"%s\".",
7232 }
7238 "research.base_tech_cost");
7239
7241 "research.tech_upkeep_style");
7242
7244
7247 "Unknown tech upkeep style \"%s\"",
7248 tus_text);
7249 ok = FALSE;
7250 }
7251 }
7252
7253 if (ok) {
7259 "research.tech_upkeep_divider");
7260
7261 sval = secfile_lookup_str_default(file, NULL, "research.free_tech_method");
7262 if (sval == NULL) {
7264 "No free_tech_method given");
7265 ok = FALSE;
7266 } else {
7270 "Bad value %s for free_tech_method.", sval);
7271 ok = FALSE;
7272 }
7273 }
7274 }
7275
7276 if (ok) {
7277 int cf;
7278
7279 /* section: culture */
7282 "culture.victory_min_points");
7285 "culture.victory_lead_pct");
7288 "culture.migration_pml");
7291 "culture.history_interest_pml");
7292
7293 /* section: calendar */
7296 "calendar.skip_year_0");
7299 "calendar.start_year");
7301 = secfile_lookup_int_default(file, 0, "calendar.fragments");
7302
7305 "Too many calendar fragments. Max is %d",
7307 ok = FALSE;
7309 }
7313 "calendar.positive_label"));
7317 "calendar.negative_label"));
7318
7319 for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
7320 const char *fname;
7321
7322 fname = secfile_lookup_str_default(file, NULL, "calendar.fragment_name%d", cf);
7323 if (fname != NULL) {
7326 }
7327 }
7328 }
7329
7330 if (ok) {
7331 /* section playercolors */
7332 struct rgbcolor *prgbcolor = NULL;
7333 bool color_read = TRUE;
7334
7335 /* Check if the player list is defined and empty. */
7336 if (playercolor_count() != 0) {
7337 ok = FALSE;
7338 } else {
7339 i = 0;
7340
7341 while (color_read) {
7342 prgbcolor = NULL;
7343
7344 color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
7345 if (color_read) {
7347 }
7348
7349 i++;
7350 }
7351
7352 if (playercolor_count() == 0) {
7353 ruleset_error(NULL, LOG_ERROR, "No player colors defined!");
7354 ok = FALSE;
7355 }
7356
7357 if (ok) {
7359 if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
7361 "No background player color defined! (%s)",
7362 secfile_error());
7363 ok = FALSE;
7364 }
7365 }
7366 }
7367 }
7368
7369 if (ok) {
7370 /* section: teams */
7371 svec = secfile_lookup_str_vec(file, &teams, "teams.names");
7372 if (team_slot_count() < teams) {
7374 }
7376 for (i = 0; i < teams; i++) {
7378 }
7379 free(svec);
7380
7382 nval = (NULL != sec ? section_list_size(sec) : 0);
7383 if (nval > MAX_DISASTER_TYPES) {
7384 int num = nval; /* No "size_t" to printf */
7385
7387 "\"%s\": Too many disaster types (%d, max %d)",
7388 filename, num, MAX_DISASTER_TYPES);
7390 ok = FALSE;
7391 } else {
7393 }
7394 }
7395
7396 if (ok) {
7398 int id = disaster_index(pdis);
7399 int j;
7400 size_t eff_count;
7401 struct requirement_vector *reqs;
7402 const char *sec_name = section_name(section_list_get(sec, id));
7403
7404 if (!ruleset_load_names(&pdis->name, NULL, file, sec_name)) {
7406 "\"%s\": Cannot load disaster names",
7407 filename);
7408 ok = FALSE;
7409 break;
7410 }
7411
7413 if (reqs == NULL) {
7414 ok = FALSE;
7415 break;
7416 }
7418
7420 "%s.frequency", sec_name);
7421
7422 svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
7423
7424 BV_CLR_ALL(pdis->effects);
7425 for (j = 0; j < eff_count; j++) {
7426 const char *dsval = svec[j];
7428
7430
7433 "\"%s\" disaster \"%s\": unknown effect \"%s\".",
7434 filename, disaster_rule_name(pdis), dsval);
7435 ok = FALSE;
7436 break;
7437 } else {
7438 BV_SET(pdis->effects, effect);
7439 }
7440 }
7441
7442 free(svec);
7443
7444 if (!ok) {
7445 break;
7446 }
7449 }
7450
7451 if (ok) {
7453
7455 int id = achievement_index(pach);
7456 const char *sec_name = section_name(section_list_get(sec, id));
7457 const char *typename;
7458 const char *msg;
7459
7460 typename = secfile_lookup_str_default(file, NULL, "%s.type", sec_name);
7461
7462 pach->type = achievement_type_by_name(typename, fc_strcasecmp);
7463 if (!achievement_type_is_valid(pach->type)) {
7465 "Achievement has unknown type \"%s\".",
7466 typename != NULL ? typename : "(NULL)");
7467 ok = FALSE;
7468 }
7469
7470 if (ok) {
7472 "%s.unique", sec_name);
7473
7475 "%s.value", sec_name);
7476 pach->culture = secfile_lookup_int_default(file, 0,
7477 "%s.culture", sec_name);
7478
7479 msg = secfile_lookup_str_default(file, NULL, "%s.first_msg", sec_name);
7480 if (msg == NULL) {
7482 "Achievement %s has no first msg!", sec_name);
7483 ok = FALSE;
7484 } else {
7485 pach->first_msg = fc_strdup(msg);
7486 }
7487 }
7488
7489 if (ok) {
7490 msg = secfile_lookup_str_default(file, NULL, "%s.cons_msg", sec_name);
7491 if (msg == NULL) {
7492 if (!pach->unique) {
7494 "Achievement %s has no msg for consecutive gainers!",
7495 sec_name);
7496 ok = FALSE;
7497 }
7498 } else {
7499 pach->cons_msg = fc_strdup(msg);
7500 }
7501 }
7502
7503 if (!ok) {
7504 break;
7505 }
7508 }
7509
7510 if (ok) {
7511 for (i = 0; (name = secfile_lookup_str_default(file, NULL,
7512 "trade.settings%d.type",
7513 i)); i++) {
7515
7516 if (type == TRT_LAST) {
7518 "\"%s\" unknown trade route type \"%s\".",
7519 filename, name);
7520 ok = FALSE;
7521 } else {
7523 const char *cancelling;
7524 const char *bonus;
7525
7526 set->trade_pct = secfile_lookup_int_default(file, 100,
7527 "trade.settings%d.pct", i);
7528 cancelling = secfile_lookup_str_default(file, "Active",
7529 "trade.settings%d.cancelling", i);
7531 if (set->cancelling == TRI_LAST) {
7533 "\"%s\" unknown trade route cancelling type \"%s\".",
7534 filename, cancelling);
7535 ok = FALSE;
7536 }
7537
7538 bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
7539
7541
7544 "\"%s\" unknown trade route bonus type \"%s\".",
7545 filename, bonus);
7546 ok = FALSE;
7547 }
7548 }
7549 }
7550 }
7551
7552 if (ok) {
7553 const char *str;
7554 bool reveal_default = FALSE;
7555
7557 = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
7558
7559 if (compat->compat_mode && compat->version < RSFORMAT_3_2) {
7560 /* Old hardcoded behavior was to reveal the trade partner. */
7562 }
7563
7566 "trade.reveal_trade_partner");
7567
7570 "trade.goods_selection");
7571
7573
7576 "\"%s\" goods selection method \"%s\" unknown.",
7577 filename, str);
7578 ok = FALSE;
7579 }
7580 }
7581
7582 if (ok) {
7584
7586 int id = goods_index(pgood);
7587 const char *sec_name = section_name(section_list_get(sec, id));
7588 struct requirement_vector *reqs;
7589 const char **slist;
7590 int j;
7591
7593 if (reqs == NULL) {
7594 ok = FALSE;
7595 break;
7596 }
7598
7599 pgood->from_pct = secfile_lookup_int_default(file, 100,
7600 "%s.from_pct", sec_name);
7601 pgood->to_pct = secfile_lookup_int_default(file, 100,
7602 "%s.to_pct", sec_name);
7603 pgood->onetime_pct = secfile_lookup_int_default(file, 100,
7604 "%s.onetime_pct", sec_name);
7605
7606 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
7607 BV_CLR_ALL(pgood->flags);
7608 for (j = 0; j < nval; j++) {
7609 enum goods_flag_id flag;
7610
7611 sval = slist[j];
7613 if (!goods_flag_id_is_valid(flag)) {
7614 ruleset_error(NULL, LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
7615 filename, goods_rule_name(pgood), sval);
7616 ok = FALSE;
7617 break;
7618 } else {
7619 BV_SET(pgood->flags, flag);
7620 }
7621 }
7622 free(slist);
7623
7624 pgood->helptext = lookup_strvec(file, sec_name, "helptext");
7627 }
7628
7629 if (ok) {
7631
7632 if (sec != NULL) {
7633 int num = section_list_size(sec);
7634
7635 for (i = 0; i < num; i++) {
7636 const char *sec_name = section_name(section_list_get(sec, i));
7637 const char *clause_name = secfile_lookup_str_default(file, NULL,
7638 "%s.type", sec_name);
7640 struct clause_info *info;
7641 struct requirement_vector *reqs;
7642
7643 if (!clause_type_is_valid(type)) {
7645 "\"%s\" unknown clause type \"%s\".",
7646 filename, clause_name);
7647 ok = FALSE;
7648 break;
7649 }
7650
7651 info = clause_info_get(type);
7652
7653 if (info->enabled) {
7655 "\"%s\" dublicate clause type \"%s\" definition.",
7656 filename, clause_name);
7657 ok = FALSE;
7658 break;
7659 }
7660
7661 reqs = lookup_req_list(file, compat, sec_name, "giver_reqs", clause_name);
7662 if (reqs == NULL) {
7663 ok = FALSE;
7664 break;
7665 }
7667
7668 reqs = lookup_req_list(file, compat, sec_name, "receiver_reqs", clause_name);
7669 if (reqs == NULL) {
7670 ok = FALSE;
7671 break;
7672 }
7674
7675 info->enabled = TRUE;
7676 }
7677 }
7679 }
7680
7681 if (ok) {
7683
7684 if (sec != NULL) {
7685 int num = section_list_size(sec);
7686 int curr;
7687
7688 for (curr = 0; curr < num; curr++) {
7689
7690 struct counter *pcount = counter_by_id(curr);
7691 const char *sec_name = section_name(section_list_get(sec, curr));
7692 const char *counter_type = secfile_lookup_str_default(file, NULL,
7693 "%s.type",
7694 sec_name);
7695
7698 if (!counter_behaviour_is_valid(cb)) {
7700 "\"%s\" unknown counter type \"%s\".",
7701 filename, counter_type);
7702 ok = FALSE;
7703 break;
7704 }
7705
7706 if (!ruleset_load_names(&pcount->name, NULL, file, sec_name)) {
7708 "\"%s\": Cannot load counter names",
7709 filename);
7710 ok = FALSE;
7711 break;
7712 }
7713
7714 pcount->helptext = lookup_strvec(file, sec_name, "helptext");
7715 pcount->type = cb;
7716 if (!secfile_lookup_int(file, &pcount->checkpoint,
7717 "%s.checkpoint", sec_name)) {
7718
7720 "\"%s\": No checkpoint value",
7721 filename);
7722 ok = FALSE;
7723 break;
7724 }
7725
7726 pcount->target = CTGT_CITY;
7727 pcount->index = curr;
7728 pcount->def = secfile_lookup_int_default(file, 0,
7729 "%s.def",
7730 sec_name);
7732 }
7733 }
7734 }
7735
7736 /* secfile_check_unused() is not here, but only after also settings section
7737 * has been loaded. */
7738
7739 return ok;
7740}
7741
7742/**********************************************************************/
7745static bool load_ruleset_actions(struct section_file *file,
7746 struct section_file *gamefile,
7747 struct rscompat_info *compat)
7748{
7749 bool ok = TRUE;
7750 const char *filename = secfile_name(file);
7751 struct section_list *sec;
7753 struct requirement_vector *reqs;
7754
7755 /* Auto attack. */
7756
7757 /* Action auto performers aren't ready to be exposed in the ruleset
7758 * yet. The behavior when two action auto performers for the same
7759 * cause can fire isn't set in stone yet. How is one of them chosen?
7760 * What if all the actions of the chosen action auto performer turned
7761 * out to be illegal but one of the other action auto performers that
7762 * fired has legal actions? These issues can decide what other action
7763 * rules action auto performers can represent in the future. Deciding
7764 * should therefore wait until a rule needs action auto performers to
7765 * work a certain way. */
7766 /* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
7767 * by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
7768 * requirement vector to the ruleset. */
7769
7770 /* A unit moved next to this unit and the autoattack server setting
7771 * is enabled. */
7774
7775 reqs = lookup_req_list(file, compat,
7776 "auto_attack", "if_attacker",
7777 "auto_attack");
7778 if (reqs == NULL) {
7779 ok = FALSE;
7780 } else {
7782
7784 "auto_attack.attack_actions",
7785 filename)) {
7786 /* Failed to load auto attack actions */
7788 "\"%s\": %s: failed load %s.",
7789 filename, "auto_attack", "attack_actions");
7790 ok = FALSE;
7791 }
7792 }
7793
7794 /* Section: actions */
7795 if (ok) {
7796 action_iterate(act_id) {
7797 struct action *paction = action_by_number(act_id);
7798
7799 if (!load_action_blocked_by_list(file, filename, paction)) {
7800 ok = FALSE;
7801 break;
7802 }
7804
7805 if (ok) {
7806 if (!lookup_bv_actions(file, filename,
7808 "actions.diplchance_initial_odds")) {
7809 ok = FALSE;
7810 }
7811 }
7812
7813 if (ok) {
7814 /* If the "Poison City" action or the "Poison City Escape" action
7815 * should empty the granary. */
7816 /* TODO: empty granary and reduce population should become separate
7817 * action effect flags when actions are generalized. */
7821 "actions.poison_empties_food_stock");
7822
7823 /* If the "Steal Maps" action or the "Steal Maps Escape" action always
7824 * will reveal all cities when successful. */
7828 "actions.steal_maps_reveals_all_cities");
7829
7830 /* Allow setting certain properties for some actions before
7831 * generalized actions. */
7832 action_iterate(act_id) {
7833 if (!load_action_range(file, act_id)) {
7834 ok = FALSE;
7835 } else if (!load_action_kind(file, act_id)) {
7836 ok = FALSE;
7837 } else if (!load_action_actor_consuming_always(file, act_id)) {
7838 ok = FALSE;
7839 } else {
7840 load_action_ui_name(file, act_id,
7843 }
7844
7845 if (!ok) {
7846 break;
7847 }
7849 }
7850
7851 if (ok) {
7852 /* The quiet (don't auto generate help for) property of all actions
7853 * live in a single enum vector. This avoids generic action
7854 * expectations. */
7855 if (secfile_entry_by_path(file, "actions.quiet_actions")) {
7857 size_t asize;
7858 int j;
7859
7862 "actions.quiet_actions");
7863
7864 if (!quiet_actions) {
7865 /* Entity exists but couldn't read it. */
7867 "\"%s\": actions.quiet_actions: bad action list",
7868 filename);
7869
7870 ok = FALSE;
7871 } else {
7872 for (j = 0; j < asize; j++) {
7873 /* Don't auto generate help text for this action. */
7875 }
7876
7878 }
7879 }
7880 }
7881
7882 if (ok) {
7883 /* Hard code action sub results for now. */
7884
7885 /* Unit Enter Hut */
7887 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
7897
7898 /* Unit Frighten Hut */
7910
7911 /* Unit May Embark */
7912 action_iterate(act_id) {
7913 struct action *paction = action_by_number(act_id);
7914
7916 "civstyle.paradrop_to_transport")
7919 BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
7920 }
7921
7922 /* Embark actions will always embark, not maybe embark. */
7924
7925 /* Non Lethal bombard */
7932 }
7933 }
7934
7935 if (ok) {
7936 /* Forced actions after another action was successfully performed. */
7937
7938 if (!load_action_post_success_force(file, filename,
7942 ok = FALSE;
7943 } else if (!load_action_post_success_force(file, filename,
7946 ACTION_ATTACK))) {
7947 ok = FALSE;
7948 } else if (!load_action_post_success_force(file, filename,
7951 ACTION_ATTACK2))) {
7952 ok = FALSE;
7953 } else if (!load_action_post_success_force(file, filename,
7957 ok = FALSE;
7958 } else if (!load_action_post_success_force(file, filename,
7962 ok = FALSE;
7963 }
7964
7965 /* No "Suicide Attack". Can't act when dead. */
7966 }
7967
7968 if (ok) {
7969 /* The city that made the unit's current tile native is gone.
7970 * Evaluated against an adjacent tile. */
7972 auto_perf->cause = AAPC_CITY_GONE;
7973
7974 /* I have no objections to moving this out of game's actions to
7975 * cities.ruleset, units.ruleset or an other location in game.ruleset
7976 * you find more suitable. -- Sveinung */
7978 "actions.escape_city", filename)) {
7979 ok = FALSE;
7980 }
7981 }
7982
7983 if (ok) {
7984 /* The unit's stack has been defeated and is scheduled for execution
7985 * but the unit has the CanEscape unit type flag.
7986 * Evaluated against an adjacent tile. */
7989
7990 /* I have no objections to moving this out of game's actions to
7991 * cities.ruleset, units.ruleset or an other location in game.ruleset
7992 * you find more suitable. -- Sveinung */
7994 "actions.unit_stack_death", filename)) {
7995 ok = FALSE;
7996 }
7997 }
7998
7999 if (ok) {
8002
8003 if (sec) {
8004 section_list_iterate(sec, psection) {
8005 struct action_enabler *enabler;
8006 const char *sec_name = section_name(psection);
8007 struct action *paction;
8008 struct requirement_vector *actor_reqs;
8009 struct requirement_vector *target_reqs;
8010 const char *action_text;
8011 const char *orig_name;
8012
8014
8015 orig_name = secfile_lookup_str(file, "%s.action", sec_name);
8016
8018
8019 if (action_text == NULL) {
8021 "\"%s\" [%s] missing action to enable.",
8022 filename, sec_name);
8023 ok = FALSE;
8024 break;
8025 }
8026
8028 if (!paction) {
8030 "\"%s\" [%s] lists unknown action type \"%s\".",
8031 filename, sec_name, action_text);
8032 ok = FALSE;
8033 break;
8034 }
8035
8036 enabler->action = action_id(paction);
8037
8038 actor_reqs = lookup_req_list(file, compat, sec_name, "actor_reqs", action_text);
8039 if (actor_reqs == NULL) {
8040 ok = FALSE;
8041 break;
8042 }
8043
8044 requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
8045
8046 target_reqs = lookup_req_list(file, compat, sec_name, "target_reqs", action_text);
8047 if (target_reqs == NULL) {
8048 ok = FALSE;
8049 break;
8050 }
8051
8052 requirement_vector_copy(&enabler->target_reqs, target_reqs);
8053
8055
8058
8060 }
8061 }
8062
8063 return ok;
8064}
8065
8066/**********************************************************************/
8070static void send_ruleset_unit_classes(struct conn_list *dest)
8071{
8072 struct packet_ruleset_unit_class packet;
8074 int i;
8075
8076 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
8077 const char *flagname;
8078 const char *helptxt;
8079
8081
8083 if (flagname == NULL) {
8084 fpacket.name[0] = '\0';
8085 } else {
8087 }
8088
8090 if (helptxt == NULL) {
8091 fpacket.helptxt[0] = '\0';
8092 } else {
8093 sz_strlcpy(fpacket.helptxt, helptxt);
8094 }
8095
8097 }
8098
8100 packet.id = uclass_number(c);
8101 sz_strlcpy(packet.name, untranslated_name(&c->name));
8102 sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
8103 packet.min_speed = c->min_speed;
8104 packet.hp_loss_pct = c->hp_loss_pct;
8105 packet.non_native_def_pct = c->non_native_def_pct;
8106 packet.flags = c->flags;
8107
8108 PACKET_STRVEC_COMPUTE(packet.helptext, c->helptext);
8109
8110 lsend_packet_ruleset_unit_class(dest, &packet);
8112}
8113
8114/**********************************************************************/
8118static void send_ruleset_units(struct conn_list *dest)
8119{
8120 struct packet_ruleset_unit packet;
8121#ifdef FREECIV_WEB
8123#endif /* FREECIV_WEB */
8125 int i;
8126
8127 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
8128 const char *flagname;
8129 const char *helptxt;
8130
8132
8134 if (flagname == NULL) {
8135 fpacket.name[0] = '\0';
8136 } else {
8138 }
8139
8141 if (helptxt == NULL) {
8142 fpacket.helptxt[0] = '\0';
8143 } else {
8144 sz_strlcpy(fpacket.helptxt, helptxt);
8145 }
8146
8148 }
8149
8151 packet.id = utype_number(u);
8152 sz_strlcpy(packet.name, untranslated_name(&u->name));
8153 sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
8154 sz_strlcpy(packet.sound_move, u->sound_move);
8155 sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
8156 sz_strlcpy(packet.sound_fight, u->sound_fight);
8157 sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
8158 sz_strlcpy(packet.graphic_str, u->graphic_str);
8159 sz_strlcpy(packet.graphic_alt, u->graphic_alt);
8160 sz_strlcpy(packet.graphic_alt2, u->graphic_alt2);
8162 packet.build_cost = u->build_cost;
8163 packet.pop_cost = u->pop_cost;
8164 packet.attack_strength = u->attack_strength;
8165 packet.defense_strength = u->defense_strength;
8166 packet.move_rate = u->move_rate;
8167
8168 i = 0;
8169 requirement_vector_iterate(&u->build_reqs, req) {
8170 packet.build_reqs[i++] = *req;
8172 packet.build_reqs_count = i;
8173
8174 packet.vision_radius_sq = u->vision_radius_sq;
8175 packet.transport_capacity = u->transport_capacity;
8176 packet.hp = u->hp;
8177 packet.firepower = u->firepower;
8178 packet.obsoleted_by = u->obsoleted_by
8179 ? utype_number(u->obsoleted_by)
8180 : utype_count();
8181 packet.converted_to = u->converted_to
8182 ? utype_number(u->converted_to)
8183 : utype_count();
8184 packet.convert_time = u->convert_time;
8185 packet.fuel = u->fuel;
8186 packet.flags = u->flags;
8187 packet.roles = u->roles;
8188 packet.happy_cost = u->happy_cost;
8190 packet.upkeep[o] = u->upkeep[o];
8192 packet.paratroopers_range = u->paratroopers_range;
8193 packet.bombard_rate = u->bombard_rate;
8194 packet.city_size = u->city_size;
8195 packet.city_slots = u->city_slots;
8196 packet.tp_defense = u->tp_defense;
8197 packet.cargo = u->cargo;
8198 packet.targets = u->targets;
8199 packet.embarks = u->embarks;
8200 packet.disembarks = u->disembarks;
8201 packet.vlayer = u->vlayer;
8202
8203 if (u->veteran == NULL) {
8204 /* Use the default veteran system. */
8205 packet.veteran_levels = 0;
8206 } else {
8207 /* Per unit veteran system definition. */
8209
8210 for (i = 0; i < packet.veteran_levels; i++) {
8211 const struct veteran_level *vlevel = utype_veteran_level(u, i);
8212
8214 packet.power_fact[i] = vlevel->power_fact;
8215 packet.move_bonus[i] = vlevel->move_bonus;
8216 packet.base_raise_chance[i] = vlevel->base_raise_chance;
8217 packet.work_raise_chance[i] = vlevel->work_raise_chance;
8218 }
8219 }
8220 PACKET_STRVEC_COMPUTE(packet.helptext, u->helptext);
8221
8222 packet.worker = u->adv.worker;
8223
8224#ifdef FREECIV_WEB
8225 web_packet.id = utype_number(u);
8226
8227 BV_CLR_ALL(web_packet.utype_actions);
8228
8229 action_iterate(act) {
8230 if (utype_can_do_action(u, act)) {
8231 BV_SET(web_packet.utype_actions, act);
8232 }
8234#endif /* FREECIV_WEB */
8235
8236 lsend_packet_ruleset_unit(dest, &packet);
8238
8239 combat_bonus_list_iterate(u->bonuses, pbonus) {
8241
8242 bonuspacket.unit = packet.id;
8243 bonuspacket.flag = pbonus->flag;
8244 bonuspacket.type = pbonus->type;
8245 bonuspacket.value = pbonus->value;
8246 bonuspacket.quiet = pbonus->quiet;
8247
8251}
8252
8253/**********************************************************************/
8257static void send_ruleset_specialists(struct conn_list *dest)
8258{
8259 struct packet_ruleset_specialist packet;
8260
8263 int j;
8264
8265 packet.id = spec_id;
8267 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
8271 j = 0;
8273 packet.reqs[j++] = *preq;
8275 packet.reqs_count = j;
8276
8278
8279 lsend_packet_ruleset_specialist(dest, &packet);
8281}
8282/**********************************************************************/
8285static void send_ruleset_tech_classes(struct conn_list *dest)
8286{
8287 struct packet_ruleset_tech_class packet;
8288
8290 packet.id = ptclass->idx;
8291 sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
8292 sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
8293 packet.cost_pct = ptclass->cost_pct;
8294
8295 lsend_packet_ruleset_tech_class(dest, &packet);
8297}
8298
8299/**********************************************************************/
8303static void send_ruleset_techs(struct conn_list *dest)
8304{
8305 struct packet_ruleset_tech packet;
8307 int i;
8308
8309 for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
8310 const char *flagname;
8311 const char *helptxt;
8312
8313 fpacket.id = i + TECH_USER_1;
8314
8316 if (flagname == NULL) {
8317 fpacket.name[0] = '\0';
8318 } else {
8320 }
8321
8323 if (helptxt == NULL) {
8324 fpacket.helptxt[0] = '\0';
8325 } else {
8326 sz_strlcpy(fpacket.helptxt, helptxt);
8327 }
8328
8330 }
8331
8332 advance_iterate(a) {
8333 packet.id = advance_number(a);
8334 packet.removed = !valid_advance(a);
8335 if (a->tclass == NULL) {
8336 packet.tclass = 0;
8337 } else {
8338 packet.tclass = a->tclass->idx;
8339 }
8340 sz_strlcpy(packet.name, untranslated_name(&a->name));
8341 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8342 sz_strlcpy(packet.graphic_str, a->graphic_str);
8343 sz_strlcpy(packet.graphic_alt, a->graphic_alt);
8344
8345 /* Current size of the packet's research_reqs requirement vector. */
8346 i = 0;
8347
8348 /* The requirements req1 and req2 are needed to research a tech. Send
8349 * them in the research_reqs requirement vector. Range is set to player
8350 * since pooled research is configurable. */
8351
8352 if ((a->require[AR_ONE] != A_NEVER)
8353 && advance_number(a->require[AR_ONE]) > A_NONE) {
8354 packet.research_reqs[i++]
8356 FALSE, TRUE, FALSE,
8357 advance_number(a->require[AR_ONE]));
8358 }
8359
8360 if ((a->require[AR_TWO] != A_NEVER)
8361 && advance_number(a->require[AR_TWO]) > A_NONE) {
8362 packet.research_reqs[i++]
8364 FALSE, TRUE, FALSE,
8365 advance_number(a->require[AR_TWO]));;
8366 }
8367
8368 /* The requirements of the tech's research_reqs also goes in the
8369 * packet's research_reqs requirement vector. */
8370 requirement_vector_iterate(&a->research_reqs, req) {
8371 packet.research_reqs[i++] = *req;
8373
8374 /* The packet's research_reqs should contain req1, req2 and the
8375 * requirements of the tech's research_reqs. */
8376 packet.research_reqs_count = i;
8377
8378 packet.root_req = a->require[AR_ROOT]
8379 ? advance_number(a->require[AR_ROOT])
8380 : advance_count();
8381
8382 packet.flags = a->flags;
8383 packet.cost = a->cost;
8384 packet.num_reqs = a->num_reqs;
8385 PACKET_STRVEC_COMPUTE(packet.helptext, a->helptext);
8386
8387 lsend_packet_ruleset_tech(dest, &packet);
8389}
8390
8391/**********************************************************************/
8394static void send_ruleset_counters(struct conn_list *dest)
8395{
8397 struct packet_ruleset_counter packet;
8398
8399 sz_strlcpy(packet.name, untranslated_name(&pcount->name));
8400 sz_strlcpy(packet.rule_name, rule_name_get(&pcount->name));
8401 packet.checkpoint = pcount->checkpoint;
8402 packet.behaviour = pcount->type;
8403 packet.type = pcount->target;
8404 packet.def = pcount->def;
8405
8406 PACKET_STRVEC_COMPUTE(packet.helptext, pcount->helptext);
8407 lsend_packet_ruleset_counter(dest, &packet);
8409}
8410
8411/**********************************************************************/
8415static void send_ruleset_buildings(struct conn_list *dest)
8416{
8417 int i;
8418
8419 for (i = 0; i < MAX_NUM_USER_BUILDING_FLAGS; i++) {
8421 const char *flagname;
8422 const char *helptxt;
8423
8425
8427 if (flagname == NULL) {
8428 fpacket.name[0] = '\0';
8429 } else {
8431 }
8432
8434 if (helptxt == NULL) {
8435 fpacket.helptxt[0] = '\0';
8436 } else {
8437 sz_strlcpy(fpacket.helptxt, helptxt);
8438 }
8439
8441 }
8442
8444 struct packet_ruleset_building packet;
8445 int j;
8446
8447 packet.id = improvement_number(b);
8448 packet.genus = b->genus;
8449 sz_strlcpy(packet.name, untranslated_name(&b->name));
8450 sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
8451 sz_strlcpy(packet.graphic_str, b->graphic_str);
8452 sz_strlcpy(packet.graphic_alt, b->graphic_alt);
8453 sz_strlcpy(packet.graphic_alt2, b->graphic_alt2);
8454 j = 0;
8455 requirement_vector_iterate(&b->reqs, preq) {
8456 packet.reqs[j++] = *preq;
8458 packet.reqs_count = j;
8459 j = 0;
8460 requirement_vector_iterate(&b->obsolete_by, pobs) {
8461 packet.obs_reqs[j++] = *pobs;
8463 packet.obs_count = j;
8464 packet.build_cost = b->build_cost;
8465 packet.upkeep = b->upkeep;
8466 packet.sabotage = b->sabotage;
8467 packet.flags = b->flags;
8468 sz_strlcpy(packet.soundtag, b->soundtag);
8469 sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
8470 sz_strlcpy(packet.soundtag_alt2, b->soundtag_alt2);
8471 PACKET_STRVEC_COMPUTE(packet.helptext, b->helptext);
8472
8473 lsend_packet_ruleset_building(dest, &packet);
8475}
8476
8477/**********************************************************************/
8481static void send_ruleset_terrain(struct conn_list *dest)
8482{
8483 struct packet_ruleset_terrain packet;
8485 int i;
8486
8488
8489 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
8490 const char *flagname;
8491 const char *helptxt;
8492
8493 fpacket.id = i + TER_USER_1;
8494
8496 if (flagname == NULL) {
8497 fpacket.name[0] = '\0';
8498 } else {
8500 }
8501
8503 if (helptxt == NULL) {
8504 fpacket.helptxt[0] = '\0';
8505 } else {
8506 sz_strlcpy(fpacket.helptxt, helptxt);
8507 }
8508
8510 }
8511
8512 terrain_type_iterate(pterrain) {
8513 packet.id = terrain_number(pterrain);
8514 packet.tclass = pterrain->tclass;
8515 packet.native_to = pterrain->native_to;
8516
8517 sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
8518 sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
8519 sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
8520 sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
8521 sz_strlcpy(packet.graphic_alt2, pterrain->graphic_alt2);
8522
8523 packet.movement_cost = pterrain->movement_cost;
8524 packet.defense_bonus = pterrain->defense_bonus;
8525
8527 packet.output[o] = pterrain->output[o];
8529
8530 packet.num_resources = 0;
8531 terrain_resources_iterate(pterrain, res, freq) {
8532 packet.resources[packet.num_resources] = extra_number(res);
8533 packet.resource_freq[packet.num_resources] = freq;
8534 packet.num_resources++;
8536
8538 packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
8540
8541 packet.base_time = pterrain->base_time;
8542 packet.road_time = pterrain->road_time;
8543
8544 packet.cultivate_result = (pterrain->cultivate_result
8545 ? terrain_number(pterrain->cultivate_result)
8546 : terrain_count());
8547 packet.cultivate_time = pterrain->cultivate_time;
8548
8549 packet.plant_result = (pterrain->plant_result
8550 ? terrain_number(pterrain->plant_result)
8551 : terrain_count());
8552 packet.plant_time = pterrain->plant_time;
8553
8554 packet.irrigation_food_incr = pterrain->irrigation_food_incr;
8555 packet.irrigation_time = pterrain->irrigation_time;
8556
8557 packet.mining_shield_incr = pterrain->mining_shield_incr;
8558 packet.mining_time = pterrain->mining_time;
8559
8560 packet.animal = (pterrain->animal == NULL ? -1 : utype_number(pterrain->animal));
8561 packet.transform_result = (pterrain->transform_result
8562 ? terrain_number(pterrain->transform_result)
8563 : terrain_count());
8564 packet.placing_time = pterrain->placing_time;
8565 packet.pillage_time = pterrain->pillage_time;
8566 packet.transform_time = pterrain->transform_time;
8567
8569 for (i = 0; i < game.control.num_extra_types; i++) {
8570 packet.extra_removal_times[i] = pterrain->extra_removal_times[i];
8571 }
8572
8573 packet.flags = pterrain->flags;
8574
8575 packet.color_red = pterrain->rgb->r;
8576 packet.color_green = pterrain->rgb->g;
8577 packet.color_blue = pterrain->rgb->b;
8578
8579 PACKET_STRVEC_COMPUTE(packet.helptext, pterrain->helptext);
8580
8581 lsend_packet_ruleset_terrain(dest, &packet);
8583}
8584
8585/**********************************************************************/
8588static void send_ruleset_resources(struct conn_list *dest)
8589{
8590 struct packet_ruleset_resource packet;
8591
8593 packet.id = extra_index(presource);
8594
8596 packet.output[o] = presource->data.resource->output[o];
8598
8599 lsend_packet_ruleset_resource(dest, &packet);
8601}
8602
8603/**********************************************************************/
8607static void send_ruleset_extras(struct conn_list *dest)
8608{
8609 int i;
8610
8611 for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
8613 const char *flagname;
8614 const char *helptxt;
8615
8617
8619 if (flagname == NULL) {
8620 fpacket.name[0] = '\0';
8621 } else {
8623 }
8624
8626 if (helptxt == NULL) {
8627 fpacket.helptxt[0] = '\0';
8628 } else {
8629 sz_strlcpy(fpacket.helptxt, helptxt);
8630 }
8631
8633 }
8634
8636 struct packet_ruleset_extra packet;
8637 int j;
8638
8639 packet.id = extra_number(e);
8640 sz_strlcpy(packet.name, untranslated_name(&e->name));
8641 sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
8642
8643 packet.category = e->category;
8644
8645 BV_CLR_ALL(packet.causes);
8646 for (j = 0; j < EC_COUNT; j++) {
8647 if (is_extra_caused_by(e, j)) {
8648 BV_SET(packet.causes, j);
8649 }
8650 }
8651
8652 BV_CLR_ALL(packet.rmcauses);
8653 for (j = 0; j < ERM_COUNT; j++) {
8654 if (is_extra_removed_by(e, j)) {
8655 BV_SET(packet.rmcauses, j);
8656 }
8657 }
8658
8659 sz_strlcpy(packet.activity_gfx, e->activity_gfx);
8660 sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
8661 sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
8662 sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
8663 sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
8664 sz_strlcpy(packet.rmact_gfx_alt2, e->rmact_gfx_alt2);
8665 sz_strlcpy(packet.graphic_str, e->graphic_str);
8666 sz_strlcpy(packet.graphic_alt, e->graphic_alt);
8667
8668 j = 0;
8669 requirement_vector_iterate(&e->reqs, preq) {
8670 packet.reqs[j++] = *preq;
8672 packet.reqs_count = j;
8673
8674 j = 0;
8675 requirement_vector_iterate(&e->rmreqs, preq) {
8676 packet.rmreqs[j++] = *preq;
8678 packet.rmreqs_count = j;
8679
8680 packet.appearance_chance = e->appearance_chance;
8681 j = 0;
8682 requirement_vector_iterate(&e->appearance_reqs, preq) {
8683 packet.appearance_reqs[j++] = *preq;
8685 packet.appearance_reqs_count = j;
8686
8687 packet.disappearance_chance = e->disappearance_chance;
8688 j = 0;
8689 requirement_vector_iterate(&e->disappearance_reqs, preq) {
8690 packet.disappearance_reqs[j++] = *preq;
8692 packet.disappearance_reqs_count = j;
8693
8694 packet.visibility_req = e->visibility_req;
8695 packet.buildable = e->buildable;
8696 packet.generated = e->generated;
8697 packet.build_time = e->build_time;
8698 packet.build_time_factor = e->build_time_factor;
8699 packet.removal_time = e->removal_time;
8700 packet.removal_time_factor = e->removal_time_factor;
8701 packet.infracost = e->infracost;
8702 packet.defense_bonus = e->defense_bonus;
8703 packet.eus = e->eus;
8704 packet.no_aggr_near_city = e->no_aggr_near_city;
8705
8706 packet.native_to = e->native_to;
8707
8708 packet.flags = e->flags;
8709 packet.hidden_by = e->hidden_by;
8710 packet.bridged_over = e->bridged_over;
8711 packet.conflicts = e->conflicts;
8712
8713 PACKET_STRVEC_COMPUTE(packet.helptext, e->helptext);
8714
8715 lsend_packet_ruleset_extra(dest, &packet);
8717}
8718
8719/**********************************************************************/
8723static void send_ruleset_bases(struct conn_list *dest)
8724{
8726 struct base_type *b = extra_base_get(pextra);
8727 struct packet_ruleset_base packet;
8728
8729 packet.id = base_number(b);
8730
8731 packet.gui_type = b->gui_type;
8732 packet.border_sq = b->border_sq;
8733 packet.vision_main_sq = b->vision_main_sq;
8734 packet.vision_invis_sq = b->vision_invis_sq;
8735 packet.vision_subs_sq = b->vision_subs_sq;
8736
8737 lsend_packet_ruleset_base(dest, &packet);
8739}
8740
8741/**********************************************************************/
8745static void send_ruleset_roads(struct conn_list *dest)
8746{
8747 struct packet_ruleset_road packet;
8748
8750 struct road_type *r = extra_road_get(pextra);
8751 int j;
8752
8753 packet.id = road_number(r);
8754
8755 packet.gui_type = r->gui_type;
8756
8757 j = 0;
8759 packet.first_reqs[j++] = *preq;
8761 packet.first_reqs_count = j;
8762
8763 packet.move_cost = r->move_cost;
8764 packet.move_mode = r->move_mode;
8765
8767 packet.tile_incr_const[o] = r->tile_incr_const[o];
8768 packet.tile_incr[o] = r->tile_incr[o];
8769 packet.tile_bonus[o] = r->tile_bonus[o];
8771
8772 packet.compat = r->compat;
8773
8774 packet.integrates = r->integrates;
8775 packet.flags = r->flags;
8776
8777 lsend_packet_ruleset_road(dest, &packet);
8779}
8780
8781/**********************************************************************/
8785static void send_ruleset_goods(struct conn_list *dest)
8786{
8787 struct packet_ruleset_goods packet;
8788
8790 int j;
8791
8792 packet.id = goods_number(g);
8793 sz_strlcpy(packet.name, untranslated_name(&g->name));
8794 sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
8795
8796 j = 0;
8797 requirement_vector_iterate(&g->reqs, preq) {
8798 packet.reqs[j++] = *preq;
8800 packet.reqs_count = j;
8801
8802 packet.from_pct = g->from_pct;
8803 packet.to_pct = g->to_pct;
8804 packet.onetime_pct = g->onetime_pct;
8805 packet.flags = g->flags;
8806
8807 PACKET_STRVEC_COMPUTE(packet.helptext, g->helptext);
8808
8809 lsend_packet_ruleset_goods(dest, &packet);
8811}
8812
8813/**********************************************************************/
8817static void send_ruleset_disasters(struct conn_list *dest)
8818{
8819 struct packet_ruleset_disaster packet;
8820
8822 int j;
8823
8824 packet.id = disaster_number(d);
8825
8826 sz_strlcpy(packet.name, untranslated_name(&d->name));
8827 sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
8828
8829 j = 0;
8830 requirement_vector_iterate(&d->reqs, preq) {
8831 packet.reqs[j++] = *preq;
8833 packet.reqs_count = j;
8834
8835 packet.frequency = d->frequency;
8836
8837 packet.effects = d->effects;
8838
8839 lsend_packet_ruleset_disaster(dest, &packet);
8841}
8842
8843/**********************************************************************/
8847static void send_ruleset_achievements(struct conn_list *dest)
8848{
8849 struct packet_ruleset_achievement packet;
8850
8852 packet.id = achievement_number(a);
8853
8854 sz_strlcpy(packet.name, untranslated_name(&a->name));
8855 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8856
8857 packet.type = a->type;
8858 packet.unique = a->unique;
8859 packet.value = a->value;
8860
8861 lsend_packet_ruleset_achievement(dest, &packet);
8863}
8864
8865/**********************************************************************/
8868static void send_ruleset_actions(struct conn_list *dest)
8869{
8870 struct packet_ruleset_action packet;
8871
8872 action_iterate(act) {
8873 struct action *paction = action_by_number(act);
8874
8875 packet.id = act;
8877 packet.quiet = action_by_number(act)->quiet;
8878
8879 packet.result = paction->result;
8880 packet.sub_results = paction->sub_results;
8881 packet.actor_consuming_always = paction->actor_consuming_always;
8882
8883 packet.act_kind = action_by_number(act)->actor_kind;
8884 packet.tgt_kind = action_by_number(act)->target_kind;
8886
8889 packet.blocked_by = action_by_number(act)->blocked_by;
8890
8891 lsend_packet_ruleset_action(dest, &packet);
8893}
8894
8895/**********************************************************************/
8899{
8900 int counter;
8901 struct packet_ruleset_action_enabler packet;
8902
8905
8906 counter = 0;
8907 requirement_vector_iterate(&enabler->actor_reqs, req) {
8908 packet.actor_reqs[counter++] = *req;
8910 packet.actor_reqs_count = counter;
8911
8912 counter = 0;
8913 requirement_vector_iterate(&enabler->target_reqs, req) {
8914 packet.target_reqs[counter++] = *req;
8916 packet.target_reqs_count = counter;
8917
8920}
8921
8922/**********************************************************************/
8927{
8928 int counter;
8929 int id;
8930 struct packet_ruleset_action_auto packet;
8931
8932 id = 0;
8934 packet.id = id++;
8935
8936 packet.cause = aperf->cause;
8937
8938 counter = 0;
8939 requirement_vector_iterate(&aperf->reqs, req) {
8940 packet.reqs[counter++] = *req;
8942 packet.reqs_count = counter;
8943
8944 for (counter = 0;
8945 /* Can't list more actions than all actions. */
8947 /* ACTION_NONE terminates the list. */
8948 && aperf->alternatives[counter] != ACTION_NONE;
8949 counter++) {
8950 packet.alternatives[counter] = aperf->alternatives[counter];
8951 }
8952 packet.alternatives_count = counter;
8953
8954 lsend_packet_ruleset_action_auto(dest, &packet);
8956}
8957
8958/**********************************************************************/
8962static void send_ruleset_trade_routes(struct conn_list *dest)
8963{
8964 struct packet_ruleset_trade packet;
8966
8967 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
8969
8970 packet.id = type;
8971 packet.trade_pct = set->trade_pct;
8972 packet.cancelling = set->cancelling;
8973 packet.bonus_type = set->bonus_type;
8974
8975 lsend_packet_ruleset_trade(dest, &packet);
8976 }
8977}
8978
8979/**********************************************************************/
8983static void send_ruleset_governments(struct conn_list *dest)
8984{
8985 struct packet_ruleset_government gov;
8987 int j;
8988
8990 /* send one packet_government */
8991 gov.id = government_number(g);
8992
8993 j = 0;
8994 requirement_vector_iterate(&g->reqs, preq) {
8995 gov.reqs[j++] = *preq;
8997 gov.reqs_count = j;
8998
8999 sz_strlcpy(gov.name, untranslated_name(&g->name));
9000 sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
9001 sz_strlcpy(gov.graphic_str, g->graphic_str);
9002 sz_strlcpy(gov.graphic_alt, g->graphic_alt);
9003 PACKET_STRVEC_COMPUTE(gov.helptext, g->helptext);
9004
9006
9007 /* Send one packet_government_ruler_title per ruler title. */
9009 const struct nation_type *pnation = ruler_title_nation(pruler_title);
9010
9011 title.gov = government_number(g);
9012 title.nation = pnation ? nation_number(pnation) : nation_count();
9013 sz_strlcpy(title.male_title,
9015 sz_strlcpy(title.female_title,
9020}
9021
9022/**********************************************************************/
9026static void send_ruleset_nations(struct conn_list *dest)
9027{
9030 struct packet_ruleset_nation packet;
9031 int i;
9032
9034 i = 0;
9039 i++;
9042
9044 i = 0;
9046 sz_strlcpy(groups_packet.groups[i],
9048 groups_packet.hidden[i] = pgroup->hidden;
9049 i++;
9052
9054 packet.id = nation_number(n);
9055 if (n->translation_domain == NULL) {
9056 packet.translation_domain[0] = '\0';
9057 } else {
9058 sz_strlcpy(packet.translation_domain, n->translation_domain);
9059 }
9060 sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
9061 sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
9062 sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
9063 sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
9064 sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
9065
9066 i = 0;
9070 i++;
9072 packet.leader_count = i;
9073
9074 packet.style = style_number(n->style);
9075 packet.is_playable = n->is_playable;
9076 packet.barbarian_type = n->barb_type;
9077
9078 sz_strlcpy(packet.legend, n->legend);
9079
9080 i = 0;
9082 packet.sets[i++] = nation_set_number(pset);
9084 packet.nsets = i;
9085
9086 i = 0;
9088 packet.groups[i++] = nation_group_number(pgroup);
9090 packet.ngroups = i;
9091
9092 packet.init_government_id = n->init_government
9093 ? government_number(n->init_government) : government_count();
9094 fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
9095 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9096 if (n->init_techs[i] != A_LAST) {
9097 packet.init_techs[i] = n->init_techs[i];
9098 } else {
9099 break;
9100 }
9101 }
9102 packet.init_techs_count = i;
9103 fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
9104 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
9105 const struct unit_type *t = n->init_units[i];
9106 if (t) {
9107 packet.init_units[i] = utype_number(t);
9108 } else {
9109 break;
9110 }
9111 }
9112 packet.init_units_count = i;
9114 == ARRAY_SIZE(n->init_buildings));
9115 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9116 if (n->init_buildings[i] != B_LAST) {
9117 /* Impr_type_id to int */
9118 packet.init_buildings[i] = n->init_buildings[i];
9119 } else {
9120 break;
9121 }
9122 }
9123 packet.init_buildings_count = i;
9124
9125 lsend_packet_ruleset_nation(dest, &packet);
9127
9128 /* Send initial values of is_pickable */
9130}
9131
9132/**********************************************************************/
9136static void send_ruleset_styles(struct conn_list *dest)
9137{
9138 struct packet_ruleset_style packet;
9139
9140 styles_iterate(s) {
9141 packet.id = style_index(s);
9142 sz_strlcpy(packet.name, untranslated_name(&s->name));
9143 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
9144
9145 lsend_packet_ruleset_style(dest, &packet);
9147}
9148
9149/**********************************************************************/
9152static void send_ruleset_clauses(struct conn_list *dest)
9153{
9154 struct packet_ruleset_clause packet;
9155 int i;
9156
9157 for (i = 0; i < CLAUSE_COUNT; i++) {
9158 struct clause_info *info = clause_info_get(i);
9159 int j;
9160
9161 packet.type = i;
9162 packet.enabled = info->enabled;
9163
9164 j = 0;
9166 packet.giver_reqs[j++] = *preq;
9168 packet.giver_reqs_count = j;
9169
9170 j = 0;
9172 packet.receiver_reqs[j++] = *preq;
9174 packet.receiver_reqs_count = j;
9175
9176 lsend_packet_ruleset_clause(dest, &packet);
9177 }
9178}
9179
9180/**********************************************************************/
9184static void send_ruleset_multipliers(struct conn_list *dest)
9185{
9186 multipliers_iterate(pmul) {
9187 int j;
9188 struct packet_ruleset_multiplier packet;
9189
9190 packet.id = multiplier_number(pmul);
9191 packet.start = pmul->start;
9192 packet.stop = pmul->stop;
9193 packet.step = pmul->step;
9194 packet.def = pmul->def;
9195 packet.offset = pmul->offset;
9196 packet.factor = pmul->factor;
9197 packet.minimum_turns = pmul->minimum_turns;
9198
9199 sz_strlcpy(packet.name, untranslated_name(&pmul->name));
9200 sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
9201
9202 j = 0;
9203 requirement_vector_iterate(&pmul->reqs, preq) {
9204 packet.reqs[j++] = *preq;
9206 packet.reqs_count = j;
9207
9208 PACKET_STRVEC_COMPUTE(packet.helptext, pmul->helptext);
9209
9210 lsend_packet_ruleset_multiplier(dest, &packet);
9212}
9213
9214/**********************************************************************/
9218static void send_ruleset_cities(struct conn_list *dest)
9219{
9221 int k, j;
9222
9223 for (k = 0; k < game.control.num_city_styles; k++) {
9224 city_p.style_id = k;
9225
9226 j = 0;
9228 city_p.reqs[j++] = *preq;
9230 city_p.reqs_count = j;
9231
9234 sz_strlcpy(city_p.graphic, city_styles[k].graphic);
9235 sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
9236 sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic);
9237
9239 }
9240}
9241
9242/**********************************************************************/
9246static void send_ruleset_musics(struct conn_list *dest)
9247{
9248 struct packet_ruleset_music packet;
9249
9251 int j;
9252
9253 packet.id = pmus->id;
9254
9255 sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
9256 sz_strlcpy(packet.music_combat, pmus->music_combat);
9257
9258 j = 0;
9260 packet.reqs[j++] = *preq;
9262 packet.reqs_count = j;
9263
9264 lsend_packet_ruleset_music(dest, &packet);
9266}
9267
9268/**********************************************************************/
9272static void send_ruleset_game(struct conn_list *dest)
9273{
9275 int i;
9276
9278
9279 /* Per unit veteran system definition. */
9280 misc_p.veteran_levels = game.veteran->levels;
9281
9282 for (i = 0; i < misc_p.veteran_levels; i++) {
9283 const struct veteran_level *vlevel = game.veteran->definitions + i;
9284
9285 sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
9286 misc_p.power_fact[i] = vlevel->power_fact;
9287 misc_p.move_bonus[i] = vlevel->move_bonus;
9288 misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
9289 misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
9290 }
9291
9292 fc_assert(sizeof(misc_p.global_init_techs)
9293 == sizeof(game.rgame.global_init_techs));
9294 fc_assert(ARRAY_SIZE(misc_p.global_init_techs)
9296 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9298 misc_p.global_init_techs[i] = game.rgame.global_init_techs[i];
9299 } else {
9300 break;
9301 }
9302 }
9303 misc_p.global_init_techs_count = i;
9304
9305 fc_assert(ARRAY_SIZE(misc_p.global_init_buildings)
9307 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9309 /* Impr_type_id to int */
9310 misc_p.global_init_buildings[i] =
9312 } else {
9313 break;
9314 }
9315 }
9316 misc_p.global_init_buildings_count = i;
9317
9318 misc_p.default_specialist = DEFAULT_SPECIALIST;
9319
9321
9322 misc_p.background_red = game.plr_bg_color->r;
9323 misc_p.background_green = game.plr_bg_color->g;
9324 misc_p.background_blue = game.plr_bg_color->b;
9325
9327}
9328
9329/**********************************************************************/
9333static void send_ruleset_team_names(struct conn_list *dest)
9334{
9336
9338 const char *name = team_slot_defined_name(tslot);
9339
9340 if (NULL == name) {
9341 /* End of defined names. */
9342 break;
9343 }
9344
9346 sz_strlcpy(team_name_info_p.team_name, name);
9347
9350}
9351
9352/**********************************************************************/
9355static void notify_ruleset_fallback(const char *msg)
9356{
9358}
9359
9360/**********************************************************************/
9363bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
9364 rs_conversion_logger logger,
9365 bool act, bool buffer_script, bool load_luadata)
9366{
9367 set_ruleset_compat_mode(compat_mode);
9368
9369 if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
9370 act, buffer_script, load_luadata)) {
9372 return TRUE;
9373 }
9374
9375 if (alt != NULL) {
9376 if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
9377 load_luadata)) {
9379
9381 return TRUE;
9382 }
9383 }
9384
9385 /* Fallback to previous one. */
9386 if (restore != NULL) {
9387 if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
9389
9390 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
9391
9393
9394 /* We're in sane state as restoring previous ruleset succeeded,
9395 * but return failure to indicate that this is not what caller
9396 * wanted. */
9397 return FALSE;
9398 }
9399 }
9400
9402
9403 /* Fallback to default one, but not if that's what we tried already */
9407 /* We're in sane state as fallback ruleset loading succeeded,
9408 * but return failure to indicate that this is not what caller
9409 * wanted. */
9411
9412 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
9413
9414 return FALSE;
9415 }
9416 }
9417
9418#ifdef FREECIV_WEB
9419 log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
9420 "https://github.com/freeciv/freeciv-web"));
9421#endif /* FREECIV_WEB */
9422
9423 /* Cannot load even default ruleset, we're in completely unusable state */
9425
9427}
9428
9429/**********************************************************************/
9433{
9434 if (file != NULL) {
9435 secfile_destroy(file);
9436 }
9437}
9438
9439/**********************************************************************/
9448
9449/**********************************************************************/
9453static bool load_rulesetdir(const char *rsdir, bool compat_mode,
9454 rs_conversion_logger logger,
9455 bool act, bool buffer_script, bool load_luadata)
9456{
9459 struct section_file *actionfile;
9460 bool ok = TRUE;
9462
9463 log_normal(_("Loading rulesets."));
9464
9466 compat_info.compat_mode = compat_mode;
9467 compat_info.log_cb = logger;
9468
9470 /* Reset the list of available player colors. */
9474
9475 if (script_buffer != NULL) {
9478 }
9479 if (parser_buffer != NULL) {
9482 }
9483
9484 server.playable_nations = 0;
9485
9487
9488 if (gamefile != NULL) {
9489 /* Needed here to fill compat_info. RSFORMAT_3_2 specific arrangement. */
9491 } else {
9492 ok = FALSE;
9493 }
9494
9496
9497 if (compat_info.version >= RSFORMAT_3_2) {
9499 } else {
9500 actionfile = NULL;
9501 }
9502
9503 buildfile = openload_ruleset_file("buildings", rsdir);
9504 govfile = openload_ruleset_file("governments", rsdir);
9506 terrfile = openload_ruleset_file("terrain", rsdir);
9511
9512 if (load_luadata) {
9514 } else {
9516 }
9517
9518 if (techfile == NULL
9519 || buildfile == NULL
9520 || govfile == NULL
9521 || unitfile == NULL
9522 || terrfile == NULL
9523 || stylefile == NULL
9524 || cityfile == NULL
9525 || nationfile == NULL
9526 || effectfile == NULL
9527 || (actionfile == NULL && (!compat_info.compat_mode || compat_info.version >= RSFORMAT_3_2))
9528 || gamefile == NULL) {
9529 ok = FALSE;
9530 }
9531
9532 if (ok) {
9533 /* Note: Keep load_game_names() first so that compat_info.version is
9534 * correctly initialized. (Currently handled above already) */
9543 }
9544
9545 if (ok) {
9546 /* 3.1 rulesets have no actions.ruleset. */
9547 if (compat_info.compat_mode && compat_info.version < RSFORMAT_3_2) {
9549 } else {
9551 }
9552 }
9553
9554 if (ok) {
9556 }
9557
9558 if (ok) {
9560 }
9561 if (ok) {
9563 }
9564 if (ok) {
9566 }
9567 if (ok) {
9569 }
9570 if (ok) {
9571 /* Terrain must precede nations and units */
9573 }
9574 if (ok) {
9576 }
9577 if (ok) {
9579 }
9580 if (ok) {
9582 }
9583 if (ok) {
9585 }
9586 if (ok) {
9588 }
9589
9590 if (ok) {
9591 /* Init nations we just loaded. */
9593
9594 /* Needed by role_unit_precalcs(). */
9596
9597 /* Prepare caches we want to sanity check. */
9601
9604 }
9605
9606 if (ok) {
9607 /* Only load settings for a sane ruleset */
9608 ok = settings_ruleset(gamefile, "settings", act,
9609 compat_info.compat_mode
9610 && compat_info.version < RSFORMAT_3_2);
9611
9612 if (ok) {
9614 }
9615 }
9616
9628
9629 if (extra_sections) {
9632 }
9633 if (base_sections) {
9636 }
9637 if (road_sections) {
9640 }
9641 if (resource_sections) {
9644 }
9645 if (terrain_sections) {
9648 }
9649
9650 if (ok) {
9652 }
9653
9654 if (ok) {
9655 char **buffer = buffer_script ? &script_buffer : NULL;
9656
9658
9660
9661 ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
9662 }
9663
9664 if (ok) {
9665 enum fc_tristate pret;
9666 char **buffer = buffer_script ? &parser_buffer : NULL;
9667
9668 pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
9669
9670 if (pret == TRI_MAYBE && buffer_script) {
9672 "-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
9673 }
9674
9675 ok = (pret != TRI_NO);
9676 }
9677
9678 if (ok && !buffer_script) {
9679 ok = (openload_script_file("default", rsdir, NULL, FALSE) == TRI_YES);
9680 }
9681
9682 if (ok && act) {
9683 /* Populate remaining caches. */
9690 ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
9694
9695 /* Build advisors unit class cache corresponding to loaded rulesets */
9697 CALL_FUNC_EACH_AI(units_ruleset_init);
9698
9699 /* We may need to adjust the number of AI players
9700 * if the number of available nations changed. */
9702 }
9703
9704 return ok;
9705}
9706
9707/**********************************************************************/
9711{
9712 struct section_file *file;
9713 bool ok = TRUE;
9714
9716 if (file == NULL) {
9718 "Could not load game.ruleset:\n%s",
9719 secfile_error());
9720 ok = FALSE;
9721 }
9722 if (ok) {
9723 settings_ruleset(file, "settings", TRUE, FALSE);
9724 secfile_destroy(file);
9725 }
9726
9727 return ok;
9728}
9729
9730/**********************************************************************/
9733void send_rulesets(struct conn_list *dest)
9734{
9736
9737 /* ruleset_control also indicates to client that ruleset sending starts. */
9739
9740 /* Currently containing control-kind of data of nation sets and groups,
9741 * this too must be sent before any requirement vector may depend on
9742 * that data. */
9744
9745 send_ruleset_game(dest);
9755 send_ruleset_techs(dest);
9758 send_ruleset_units(dest);
9760 send_ruleset_extras(dest);
9761 send_ruleset_bases(dest);
9762 send_ruleset_roads(dest);
9765 send_ruleset_goods(dest);
9767 send_ruleset_styles(dest);
9769 send_ruleset_cities(dest);
9771 send_ruleset_musics(dest);
9772 send_ruleset_cache(dest);
9773
9774 /* Indicate client that all rulesets have now been sent. */
9776
9777 /* changed game settings will be send in
9778 * connecthand.c:establish_new_connection() */
9779
9781}
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:6423
void actions_rs_pre_san_gen(void)
Definition actions.c:1645
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:7113
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7749
bool action_is_in_use(struct action *paction)
Definition actions.c:6400
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7923
struct action * action_by_rule_name(const char *name)
Definition actions.c:1831
const char * action_rule_name(const struct action *action)
Definition actions.c:1968
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:7593
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:7272
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:7439
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:2273
const char * action_ui_name_default(int act)
Definition actions.c:6773
struct action_enabler * action_enabler_new(void)
Definition actions.c:2227
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:6344
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2306
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:6508
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:479
#define action_auto_perf_iterate_end
Definition actions.h:584
#define action_enablers_iterate_end
Definition actions.h:517
#define ACTION_AUTO_MOVED_ADJ
Definition actions.h:609
#define action_id_get_sub_target_kind(act_id)
Definition actions.h:654
#define ACTION_AUTO_UPKEEP_GOLD
Definition actions.h:607
#define enabler_get_action_id(_enabler_)
Definition actions.h:432
static struct action * action_by_number(action_id act_id)
Definition actions.h:633
#define NUM_ACTIONS
Definition actions.h:313
#define ACTION_AUTO_ESCAPE_STACK
Definition actions.h:615
#define action_has_result(_act_, _res_)
Definition actions.h:429
#define ACTION_AUTO_ESCAPE_CITY
Definition actions.h:614
#define action_enabler_list_iterate_end
Definition actions.h:439
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:355
#define action_by_result_iterate_end
Definition actions.h:483
#define ACTION_AUTO_POST_WIPE_UNITS
Definition actions.h:616
#define ACTION_AUTO_UPKEEP_SHIELD
Definition actions.h:608
#define ACTION_AUTO_POST_BRIBE
Definition actions.h:610
#define action_iterate_end
Definition actions.h:463
#define action_enablers_iterate(_enabler_)
Definition actions.h:511
#define ACTION_AUTO_POST_ATTACK2
Definition actions.h:612
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:437
#define action_id(_act_)
Definition actions.h:659
#define action_iterate(_act_)
Definition actions.h:459
#define action_auto_perf_iterate(_act_perf_)
Definition actions.h:572
#define ACTION_AUTO_UPKEEP_FOOD
Definition actions.h:606
#define ACTION_AUTO_POST_ATTACK
Definition actions.h:611
#define ACTION_AUTO_POST_COLLECT_RANSOM
Definition actions.h:613
#define ACTION_NONE
Definition actions.h:309
int actres_min_range_default(enum action_result result)
Definition actres.c:376
int actres_max_range_default(enum action_result result)
Definition actres.c:465
enum action_target_kind actres_target_kind_default(enum action_result result)
Definition actres.c:766
void adv_units_ruleset_init(void)
Definition advruleset.c:33
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
#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:92
void base_type_init(struct extra_type *pextra, int idx)
Definition base.c:117
bool territory_claiming_base(const struct base_type *pbase)
Definition base.c:158
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
void city_styles_alloc(int num)
Definition city.c:3384
void city_production_caravan_shields_init(void)
Definition city.c:1770
const char * city_style_rule_name(const int style)
Definition city.c:1757
const char * get_output_identifier(Output_type_id output)
Definition city.c:618
static const struct city struct citystyle * city_styles
Definition city.c:83
#define output_type_iterate(output)
Definition city.h:833
#define output_type_iterate_end
Definition city.h:839
static struct fc_sockaddr_list * list
Definition clinet.c:102
char * incite_cost
Definition comments.c:74
#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:732
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:720
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
#define log_deprecation(message,...)
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:276
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:80
#define disaster_type_iterate_end
Definition disaster.h:86
int int id
Definition editgui_g.h:28
struct @21::@22 reqs
void send_ruleset_cache(struct conn_list *dest)
Definition effects.c:610
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:1348
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:1359
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:1339
#define effect_list_iterate_end
Definition effects.h:406
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:404
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:974
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Definition extras.c:933
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Definition extras.c:1032
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:861
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
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_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_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:681
#define MAX_DISASTER_TYPES
Definition fc_types.h:52
#define MAX_VET_LEVELS
Definition fc_types.h:49
@ ROCO_RAILROAD
Definition fc_types.h:1254
@ ROCO_NONE
Definition fc_types.h:1254
@ ROCO_RIVER
Definition fc_types.h:1254
@ ROCO_ROAD
Definition fc_types.h:1254
#define MAX_GRANARY_INIS
Definition fc_types.h:72
#define MAX_NUM_NATIONS
Definition fc_types.h:60
#define MAX_NUM_BUILDING_LIST
Definition fc_types.h:46
#define MAX_NUM_REQS
Definition fc_types.h:413
#define MAX_GOODS_TYPES
Definition fc_types.h:51
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:1117
#define EC_SPECIAL
Definition fc_types.h:1115
int action_id
Definition fc_types.h:392
#define SP_MAX
Definition fc_types.h:412
#define EC_NONE
Definition fc_types.h:1114
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:1118
#define EC_DEFENSIVE
Definition fc_types.h:1116
#define MAX_CALENDAR_FRAGMENTS
Definition fc_types.h:62
#define MAX_NUM_TECH_CLASSES
Definition fc_types.h:63
#define MAX_NUM_LEADERS
Definition fc_types.h:56
#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:126
#define MAX_ACHIEVEMENT_TYPES
Definition fc_types.h:53
#define MAX_LEN_NAME
Definition fc_types.h:66
#define MAX_NUM_TECH_LIST
Definition fc_types.h:44
#define MAX_LEN_CITYNAME
Definition fc_types.h:67
#define MAX_COUNTERS
Definition fc_types.h:106
#define UCL_LAST
Definition fc_types.h:420
#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:510
void game_ruleset_free(void)
Definition game.c:559
struct world wld
Definition game.c:63
#define RS_DEFAULT_RANSOM_GOLD
Definition game.h:864
#define RS_DEFAULT_GRANARY_FOOD_INI
Definition game.h:813
#define RS_DEFAULT_CIVIL_WAR_UNHAPPY
Definition game.h:850
#define RS_DEFAULT_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:856
#define RS_MIN_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:794
#define RS_MAX_TECH_UPKEEP_DIVIDER
Definition game.h:876
#define RS_MIN_ILLNESS_POLLUTION_PCT
Definition game.h:780
#define RS_DEFAULT_NUKE_POP_LOSS_PCT
Definition game.h:853
#define RS_MAX_BORDER_RADIUS_SQ_CITY
Definition game.h:787
#define RS_DEFAULT_BASE_POLLUTION
Definition game.h:836
#define RS_MIN_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:776
#define RS_MAX_ILLNESS_BASE_FACTOR
Definition game.h:769
#define RS_DEFAULT_INCITE_TOTAL_FCT
Definition game.h:809
#define RS_DEFAULT_ILLNESS_BASE_FACTOR
Definition game.h:767
#define RS_DEFAULT_NEG_YEAR_LABEL
Definition game.h:763
#define RS_MIN_NUKE_POP_LOSS_PCT
Definition game.h:854
#define RS_MIN_INCITE_IMPROVEMENT_FCT
Definition game.h:802
#define RS_MIN_FOOD_COST
Definition game.h:846
#define RS_MIN_BASE_BRIBE_COST
Definition game.h:861
#define RS_MAX_NUKE_POP_LOSS_PCT
Definition game.h:855
#define RS_DEFAULT_INCITE_IMPROVEMENT_FCT
Definition game.h:801
#define RS_MAX_INCITE_IMPROVEMENT_FCT
Definition game.h:803
#define RS_MIN_RANSOM_GOLD
Definition game.h:865
#define RS_ACTION_NO_MAX_DISTANCE
Definition game.h:888
#define RS_DEFAULT_BASE_BRIBE_COST
Definition game.h:860
#define RS_MAX_INCITE_BASE_COST
Definition game.h:799
#define RS_DEFAULT_TECH_UPKEEP_DIVIDER
Definition game.h:874
#define RS_DEFAULT_HAPPY_COST
Definition game.h:841
#define RS_MIN_UPGRADE_VETERAN_LOSS
Definition game.h:871
#define RS_MIN_ILLNESS_MIN_SIZE
Definition game.h:772
#define RS_DEFAULT_POISON_EMPTIES_FOOD_STOCK
Definition game.h:878
#define RS_DEFAULT_GRANARY_FOOD_INC
Definition game.h:815
#define RS_DEFAULT_ILLNESS_ON
Definition game.h:765
#define RS_MAX_FOOD_COST
Definition game.h:847
#define RS_MAX_HAPPY_COST
Definition game.h:843
#define GAME_DEFAULT_CELEBRATESIZE
Definition game.h:498
#define RS_MIN_ILLNESS_BASE_FACTOR
Definition game.h:768
#define RS_DEFAULT_STEAL_MAP_REVEALS_CITIES
Definition game.h:879
#define RS_MIN_TECH_UPKEEP_DIVIDER
Definition game.h:875
#define RS_MAX_RANSOM_GOLD
Definition game.h:866
#define RS_MIN_HAPPY_COST
Definition game.h:842
#define RS_MIN_BORDER_RADIUS_SQ_CITY
Definition game.h:786
#define GAME_DEFAULT_RULESETDIR
Definition game.h:672
#define RS_DEFAULT_CIVIL_WAR_CELEB
Definition game.h:849
#define RS_MIN_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:857
#define RS_MAX_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:795
#define RS_DEFAULT_UPGRADE_VETERAN_LOSS
Definition game.h:870
#define RS_MAX_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:858
#define RS_MAX_INCITE_UNIT_FCT
Definition game.h:807
#define RS_MIN_VIS_RADIUS_SQ
Definition game.h:833
#define RS_DEFAULT_CALENDAR_SKIP_0
Definition game.h:783
#define RS_MAX_ILLNESS_MIN_SIZE
Definition game.h:773
#define RS_DEFAULT_CITY_RADIUS_SQ
Definition game.h:828
#define GAME_DEFAULT_START_YEAR
Definition game.h:739
#define RS_MAX_BORDER_SIZE_EFFECT
Definition game.h:791
#define RS_DEFAULT_BORDER_SIZE_EFFECT
Definition game.h:789
#define RS_MAX_BASE_BRIBE_COST
Definition game.h:862
#define RS_MIN_INCITE_BASE_COST
Definition game.h:798
#define RS_DEFAULT_PILLAGE_SELECT
Definition game.h:868
#define RS_MIN_CITY_RADIUS_SQ
Definition game.h:829
#define RS_MIN_CITY_CENTER_OUTPUT
Definition game.h:820
#define RS_MAX_GRANARY_FOOD_INC
Definition game.h:817
#define RS_MAX_CITY_CENTER_OUTPUT
Definition game.h:821
#define RS_MAX_CITY_RADIUS_SQ
Definition game.h:830
#define RS_DEFAULT_POS_YEAR_LABEL
Definition game.h:761
#define RS_MIN_INCITE_UNIT_FCT
Definition game.h:806
#define RS_MIN_BORDER_SIZE_EFFECT
Definition game.h:790
#define RS_DEFAULT_VIS_RADIUS_SQ
Definition game.h:832
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:793
#define RS_DEFAULT_TIRED_ATTACK
Definition game.h:852
#define RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS
Definition game.h:880
#define RS_MAX_ILLNESS_POLLUTION_PCT
Definition game.h:781
#define RS_DEFAULT_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:775
#define RS_DEFAULT_FOOD_COST
Definition game.h:845
#define RS_DEFAULT_INCITE_UNIT_FCT
Definition game.h:805
#define RS_MAX_INCITE_TOTAL_FCT
Definition game.h:811
#define RS_DEFAULT_INCITE_BASE_COST
Definition game.h:797
#define GAME_DEFAULT_ANGRYCITIZEN
Definition game.h:389
#define RS_DEFAULT_CITY_CENTER_OUTPUT
Definition game.h:819
#define RS_MIN_INCITE_TOTAL_FCT
Definition game.h:810
#define RS_DEFAULT_ILLNESS_POLLUTION_PCT
Definition game.h:779
#define RS_MAX_UPGRADE_VETERAN_LOSS
Definition game.h:872
static void set_ruleset_compat_mode(bool active)
Definition game.h:353
#define RS_MAX_VIS_RADIUS_SQ
Definition game.h:834
#define RS_MIN_GRANARY_FOOD_INC
Definition game.h:816
#define RS_MAX_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:777
#define RS_DEFAULT_ILLNESS_MIN_SIZE
Definition game.h:771
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY
Definition game.h:785
const struct nation_type * ruler_title_nation(const struct ruler_title *pruler_title)
Definition government.c:365
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:325
const char * ruler_title_female_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:383
Government_type_id government_count(void)
Definition government.c:71
const char * ruler_title_male_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:374
void governments_alloc(int num)
Definition government.c:528
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
const struct ruler_title_hash * government_ruler_titles(const struct government *pgovern)
Definition government.c:314
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
struct government * government_by_rule_name(const char *name)
Definition government.c:55
#define governments_iterate(NAME_pgov)
Definition government.h:120
#define G_LAST
Definition government.h:48
#define ruler_titles_iterate(ARG_hash, NAME_rule_title)
Definition government.h:38
#define ruler_titles_iterate_end
Definition government.h:41
#define governments_iterate_end
Definition government.h:123
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_NEVER
Definition improvement.h:44
#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:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define MAX_LEN_LOG_LINE
Definition log.h:26
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_do_output_for_level(level)
Definition log.h:89
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
log_level
Definition log.h:28
@ LOG_ERROR
Definition log.h:30
@ LOG_FATAL
Definition log.h:29
#define log_error(message,...)
Definition log.h:103
struct terrain_misc terrain_control
Definition map.c:69
#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:105
void init_move_fragments(void)
Definition movement.c:927
#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:1047
const char * nation_group_untranslated_name(const struct nation_group *pgroup)
Definition nation.c:1069
struct nation_group * nation_group_by_rule_name(const char *name)
Definition nation.c:1021
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
Nation_type_id nation_count(void)
Definition nation.c:507
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
struct nation_group * nation_group_new(const char *name)
Definition nation.c:960
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:290
struct nation_set * nation_set_new(const char *set_name, const char *set_rule_name, const char *set_description)
Definition nation.c:716
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:475
struct nation_city * nation_city_new(struct nation_type *pnation, const char *name)
Definition nation.c:342
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:230
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:200
int nation_set_number(const struct nation_set *pset)
Definition nation.c:708
void nation_city_set_terrain_preference(struct nation_city *pncity, const struct terrain *pterrain, enum nation_city_preference prefer)
Definition nation.c:390
void nation_city_set_river_preference(struct nation_city *pncity, enum nation_city_preference prefer)
Definition nation.c:402
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:837
const char * nation_set_description(const struct nation_set *pset)
Definition nation.c:828
int nation_set_count(void)
Definition nation.c:691
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:498
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:281
int nation_group_count(void)
Definition nation.c:935
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:807
struct nation_leader * nation_leader_new(struct nation_type *pnation, const char *name, bool is_male)
Definition nation.c:239
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
Definition nation.c:1037
void nations_alloc(int num)
Definition nation.c:622
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
int nation_group_number(const struct nation_group *pgroup)
Definition nation.c:952
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:57
#define nation_sets_iterate_end
Definition nation.h:305
#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:301
#define nations_iterate_end
Definition nation.h:336
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:333
#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:311
#define nation_groups_iterate_end
Definition nation.h:315
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:239
#define web_lsend_packet(packetname,...)
Definition packets.h:57
#define PACKET_STRVEC_COMPUTE(str, strvec)
Definition packets.h:182
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_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_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 city_list * cities
Definition packhand.c:119
int len
Definition packhand.c:127
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2637
void playercolor_free(void)
Definition plrhand.c:3337
void playercolor_init(void)
Definition plrhand.c:3328
int playercolor_count(void)
Definition plrhand.c:3376
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3356
void count_playable_nations(void)
Definition plrhand.c:2594
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:50
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,...)
const char * entry_name(const struct entry *pentry)
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,...)
struct entry * section_entry_by_name(const struct section *psection, const char *name)
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
const char * rscompat_req_range_3_2(struct rscompat_info *compat, const char *type, const char *old_range)
Definition rscompat.c:466
int add_user_extra_flags_3_2(int start)
Definition rscompat.c:559
const char * rscompat_action_ui_name_3_2(struct rscompat_info *compat, int act_id)
Definition rscompat.c:778
bool rscompat_terrain_extra_rmtime_3_2(struct section_file *file, const char *tsection, struct terrain *pterrain)
Definition rscompat.c:708
bool rscompat_names(struct rscompat_info *info)
Definition rscompat.c:330
void rscompat_postprocess(struct rscompat_info *info)
Definition rscompat.c:381
int rscompat_check_capabilities(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:66
void rscompat_extra_adjust_3_2(struct extra_type *pextra)
Definition rscompat.c:598
void rscompat_enablers_add_obligatory_hard_reqs(void)
Definition rscompat.c:286
const char * rscompat_action_rule_name_3_2(struct rscompat_info *compat, const char *orig)
Definition rscompat.c:748
void rscompat_req_adjust_3_2(const struct rscompat_info *compat, const char **ptype, const char **pname, bool *ppresent, const char *sec_name)
Definition rscompat.c:493
enum impr_genus_id rscompat_genus_3_2(struct rscompat_info *compat, const bv_impr_flags flags, enum impr_genus_id old_genus)
Definition rscompat.c:450
void rscompat_action_enabler_adjust_3_2(struct rscompat_info *compat, struct action_enabler *enabler, const char *orig_name)
Definition rscompat.c:763
const char * rscompat_extra_rmcause_3_2(struct extra_type *pextra, const char *old_name)
Definition rscompat.c:572
void rscompat_init_info(struct rscompat_info *info)
Definition rscompat.c:57
bool rscompat_check_cap_and_version(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:131
bool sanity_check_ruleset_data(struct rscompat_info *compat)
Definition rssanity.c:848
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1541
#define check_cityname(name)
Definition ruleset.c:116
static int ruleset_purge_redundant_reqs_enablers(void)
Definition ruleset.c:423
static void ruleset_load_traits(struct trait_limits *out, struct section_file *file, const char *secname, const char *field_prefix)
Definition ruleset.c:1313
static bool load_rulesetdir(const char *rsdir, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleset.c:9453
#define STYLE_SECTION_PREFIX
Definition ruleset.c:98
static bool lookup_terrain(struct section_file *file, const char *entry, const char *filename, struct terrain *pthis, struct terrain **result, bool null_acceptable)
Definition ruleset.c:1214
static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, size_t err_len)
Definition ruleset.c:1989
static bool load_terrain_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2874
static bool load_style_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5768
int ruleset_purge_unused_entities(void)
Definition ruleset.c:313
#define MUSICSTYLE_SECTION_PREFIX
Definition ruleset.c:91
static char * road_sections
Definition ruleset.c:127
static bool load_ruleset_governments(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4479
#define MULTIPLIER_SECTION_PREFIX
Definition ruleset.c:112
static struct requirement_vector reqs_list
Definition ruleset.c:129
static void send_ruleset_techs(struct conn_list *dest)
Definition ruleset.c:8303
#define section_strlcpy(dst, src)
Definition ruleset.c:121
static bool load_action_range(struct section_file *file, action_id act)
Definition ruleset.c:6498
#define check_name(name)
Definition ruleset.c:115
static void send_ruleset_units(struct conn_list *dest)
Definition ruleset.c:8118
static void send_ruleset_governments(struct conn_list *dest)
Definition ruleset.c:8983
static bool load_action_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1482
static struct extra_type * lookup_resource(const char *filename, const char *name, const char *jsection)
Definition ruleset.c:1193
static struct section_file * openload_luadata_file(const char *rsdir)
Definition ruleset.c:626
static bool load_ruleset_techs(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1620
static bool purge_unused_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:327
void rulesets_deinit(void)
Definition ruleset.c:9443
static bool load_action_ui_name(struct section_file *file, int act, const char *entry_name, const char *compat_name)
Definition ruleset.c:6435
static void send_ruleset_resources(struct conn_list *dest)
Definition ruleset.c:8588
static bool load_ruleset_buildings(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2746
static char * terrain_sections
Definition ruleset.c:124
static bool lookup_building_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleset.c:1045
static void nullcheck_secfile_destroy(struct section_file *file)
Definition ruleset.c:9432
static void send_ruleset_clauses(struct conn_list *dest)
Definition ruleset.c:9152
static void send_ruleset_game(struct conn_list *dest)
Definition ruleset.c:9272
char * parser_buffer
Definition ruleset.c:209
#define NATION_SECTION_PREFIX
Definition ruleset.c:97
static bool load_ruleset_effects(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:6223
static bool lookup_cbonus_list(struct combat_bonus_list *list, struct section_file *file, const char *sec, const char *sub)
Definition ruleset.c:797
static void send_ruleset_nations(struct conn_list *dest)
Definition ruleset.c:9026
static void send_ruleset_roads(struct conn_list *dest)
Definition ruleset.c:8745
static int ruleset_purge_unused_enablers(void)
Definition ruleset.c:244
#define UEFF_SECTION_PREFIX
Definition ruleset.c:92
static bool is_on_allowed_list(const char *name, const char **list, size_t len)
Definition ruleset.c:4865
static void send_ruleset_tech_classes(struct conn_list *dest)
Definition ruleset.c:8285
static void send_ruleset_action_enablers(struct conn_list *dest)
Definition ruleset.c:8898
static void send_ruleset_control(struct conn_list *dest)
Definition ruleset.c:4671
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 ruleset.c:9363
#define GOODS_SECTION_PREFIX
Definition ruleset.c:104
void ruleset_error_real(rs_conversion_logger logger, const char *file, const char *function, int line, enum log_level level, const char *format,...)
Definition ruleset.c:215
#define TERRAIN_SECTION_PREFIX
Definition ruleset.c:106
static struct section_file * openload_ruleset_file(const char *whichset, const char *rsdir)
Definition ruleset.c:571
static void send_ruleset_musics(struct conn_list *dest)
Definition ruleset.c:9246
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 ruleset.c:1264
int ruleset_purge_redundant_reqs(void)
Definition ruleset.c:490
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 ruleset.c:6397
static char * base_sections
Definition ruleset.c:126
#define DISASTER_SECTION_PREFIX
Definition ruleset.c:109
static void send_ruleset_goods(struct conn_list *dest)
Definition ruleset.c:8785
static const char name_too_long[]
Definition ruleset.c:119
bool reload_rulesets_settings(void)
Definition ruleset.c:9710
static struct strvec * lookup_strvec(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleset.c:1173
#define CITYSTYLE_SECTION_PREFIX
Definition ruleset.c:90
static bool lookup_tech(struct section_file *file, struct advance **result, const char *prefix, const char *entry, const char *filename, const char *description)
Definition ruleset.c:856
static bool load_game_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1352
static void send_ruleset_counters(struct conn_list *dest)
Definition ruleset.c:8394
static void send_ruleset_specialists(struct conn_list *dest)
Definition ruleset.c:8257
#define ADVANCE_SECTION_PREFIX
Definition ruleset.c:87
#define EFFECT_SECTION_PREFIX
Definition ruleset.c:93
static void send_ruleset_action_auto_performers(struct conn_list *dest)
Definition ruleset.c:8926
static bool load_government_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4397
static void send_ruleset_team_names(struct conn_list *dest)
Definition ruleset.c:9333
static void send_ruleset_cities(struct conn_list *dest)
Definition ruleset.c:9218
static bool lookup_building(struct section_file *file, const char *prefix, const char *entry, struct impr_type **result, const char *filename, const char *description)
Definition ruleset.c:888
static bool purge_redundant_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:412
static char * lookup_string(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleset.c:1153
static const char * check_leader_names(struct nation_type *pnation)
Definition ruleset.c:4709
#define ACTION_ENABLER_SECTION_PREFIX
Definition ruleset.c:111
#define BASE_SECTION_PREFIX
Definition ruleset.c:101
static int ruleset_purge_redundant_reqs_effects(void)
Definition ruleset.c:461
static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir, char **buffer, bool optional)
Definition ruleset.c:599
char * get_parser_buffer(void)
Definition ruleset.c:562
static bool load_building_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2665
#define EXTRA_SECTION_PREFIX
Definition ruleset.c:100
void send_rulesets(struct conn_list *dest)
Definition ruleset.c:9733
#define CLAUSE_SECTION_PREFIX
Definition ruleset.c:99
static bool lookup_unit_list(struct section_file *file, const char *prefix, const char *entry, struct unit_type **output, const char *filename)
Definition ruleset.c:921
static char * resource_sections
Definition ruleset.c:123
#define UNIT_SECTION_PREFIX
Definition ruleset.c:108
#define ACHIEVEMENT_SECTION_PREFIX
Definition ruleset.c:110
static bool load_ruleset_cities(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:6008
static bool load_ruleset_styles(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5829
static struct government * lookup_government(struct section_file *file, const char *entry, const char *filename, struct government *fallback)
Definition ruleset.c:1128
static bool load_ruleset_units(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2110
char * script_buffer
Definition ruleset.c:208
static bool load_action_blocked_by_list(struct section_file *file, const char *filename, struct action *paction)
Definition ruleset.c:6562
static void send_ruleset_styles(struct conn_list *dest)
Definition ruleset.c:9136
#define NATION_GROUP_SECTION_PREFIX
Definition ruleset.c:96
static char * extra_sections
Definition ruleset.c:125
#define RULES_SUFFIX
Definition ruleset.c:84
struct requirement_vector * lookup_req_list(struct section_file *file, struct rscompat_info *compat, const char *sec, const char *sub, const char *rfor)
Definition ruleset.c:654
static void send_ruleset_disasters(struct conn_list *dest)
Definition ruleset.c:8817
static bool purge_duplicate_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:367
static bool lookup_tech_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleset.c:981
#define MAX_SECTION_LABEL
Definition ruleset.c:120
#define BUILDING_SECTION_PREFIX
Definition ruleset.c:89
static bool load_ruleset_game(struct section_file *file, bool act, struct rscompat_info *compat)
Definition ruleset.c:6677
static bool load_nation_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4729
static void send_ruleset_achievements(struct conn_list *dest)
Definition ruleset.c:8847
#define SCRIPT_SUFFIX
Definition ruleset.c:85
static void send_ruleset_bases(struct conn_list *dest)
Definition ruleset.c:8723
static bool load_ruleset_terrain(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:3210
static int ruleset_purge_unused_effects(void)
Definition ruleset.c:290
static bool load_action_actor_consuming_always(struct section_file *file, action_id act)
Definition ruleset.c:6545
static bool load_action_post_success_force(struct section_file *file, const char *filename, int performer_slot, struct action *paction)
Definition ruleset.c:6606
static bool load_tech_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1502
#define SPECIALIST_SECTION_PREFIX
Definition ruleset.c:105
#define COUNTER_SECTION_PREFIX
Definition ruleset.c:113
static bool load_action_kind(struct section_file *file, action_id act)
Definition ruleset.c:6523
static void send_ruleset_multipliers(struct conn_list *dest)
Definition ruleset.c:9184
char * get_script_buffer(void)
Definition ruleset.c:554
static void send_ruleset_actions(struct conn_list *dest)
Definition ruleset.c:8868
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 ruleset.c:4881
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 ruleset.c:5907
static bool load_ruleset_nations(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5051
static bool load_action_auto_actions(struct section_file *file, struct action_auto_perf *auto_perf, const char *actions_path, const char *filename)
Definition ruleset.c:5950
static void send_ruleset_unit_classes(struct conn_list *dest)
Definition ruleset.c:8070
#define TECH_CLASS_SECTION_PREFIX
Definition ruleset.c:88
#define RESOURCE_SECTION_PREFIX
Definition ruleset.c:103
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 ruleset.c:1097
static void send_ruleset_extras(struct conn_list *dest)
Definition ruleset.c:8607
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action)
static void send_ruleset_terrain(struct conn_list *dest)
Definition ruleset.c:8481
#define GOVERNMENT_SECTION_PREFIX
Definition ruleset.c:94
static bool load_unit_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1831
static void send_ruleset_trade_routes(struct conn_list *dest)
Definition ruleset.c:8962
static bool load_ruleset_actions(struct section_file *file, struct section_file *gamefile, struct rscompat_info *compat)
Definition ruleset.c:7745
static void notify_ruleset_fallback(const char *msg)
Definition ruleset.c:9355
static bool lookup_bv_actions(struct section_file *file, const char *filename, bv_actions *target, const char *path)
Definition ruleset.c:6643
static void send_ruleset_buildings(struct conn_list *dest)
Definition ruleset.c:8415
#define UNIT_CLASS_SECTION_PREFIX
Definition ruleset.c:107
static bool ruleset_load_names(struct name_translation *pname, const char *domain, struct section_file *file, const char *sec_name)
Definition ruleset.c:1290
#define ROAD_SECTION_PREFIX
Definition ruleset.c:102
static const char * valid_ruleset_filename(const char *subdir, const char *name, const char *extension, bool optional)
Definition ruleset.c:509
static bool load_action_range_max(struct section_file *file, action_id act)
Definition ruleset.c:6457
static bool load_muuk_as_action_auto(struct section_file *file, struct action_auto_perf *auto_perf, const char *item, const char *filename)
Definition ruleset.c:5986
#define NATION_SET_SECTION_PREFIX
Definition ruleset.c:95
#define RS_DEFAULT_CONVERT_SPEED
Definition ruleset.h:119
#define RS_DEFAULT_UBUILD_NAT
Definition ruleset.h:118
#define RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE
Definition ruleset.h:105
#define RS_DEFAULT_TECH_TRADE_LOSS_HOLES
Definition ruleset.h:82
#define RS_DEFAULT_TECH_COST_STYLE
Definition ruleset.h:88
#define RS_DEFAULT_EXTRA_APPEARANCE
Definition ruleset.h:99
#define RS_DEFAULT_TECH_PARASITE_HOLES
Definition ruleset.h:83
#define GAME_DEFAULT_ACH_VALUE
Definition ruleset.h:76
#define RS_DEFAULT_TECH_TRADE_HOLES
Definition ruleset.h:81
#define RS_DEFAULT_CULTURE_VIC_POINTS
Definition ruleset.h:92
#define RS_DEFAULT_CULTURE_MIGRATION_PML
Definition ruleset.h:94
void(* rs_conversion_logger)(const char *msg)
Definition ruleset.h:40
#define RS_DEFAULT_SMALL_WONDER_VISIBILITY
Definition ruleset.h:107
#define ruleset_error(logger, level, format,...)
Definition ruleset.h:57
#define RS_DEFAULT_ONLY_KILLING_VETERAN
Definition ruleset.h:102
#define RS_DEFAULT_TECH_LOSS_HOLES
Definition ruleset.h:84
#define RS_DEFAULT_HISTORY_INTEREST_PML
Definition ruleset.h:95
#define RS_DEFAULT_TECH_UPKEEP_STYLE
Definition ruleset.h:90
#define RS_DEFAULT_GOODS_SELECTION
Definition ruleset.h:97
#define RS_DEFAULT_PYTHAGOREAN_DIAGONAL
Definition ruleset.h:85
#define RS_DEFAULT_TECH_STEAL_HOLES
Definition ruleset.h:80
#define RS_MIN_MIN_TECH_COST
Definition ruleset.h:114
#define GAME_DEFAULT_ACH_UNIQUE
Definition ruleset.h:75
#define RS_MAX_BASE_TECH_COST
Definition ruleset.h:111
#define RS_DEFAULT_COMBAT_ODDS_SCALED_VETERANCY
Definition ruleset.h:104
#define RS_DEFAULT_MUUK_FOOD_WIPE
Definition ruleset.h:77
#define RS_DEFAULT_MUUK_GOLD_WIPE
Definition ruleset.h:78
#define RS_DEFAULT_BASE_TECH_COST
Definition ruleset.h:109
#define RSFORMAT_3_2
Definition ruleset.h:36
#define RS_DEFAULT_NATIONALITY
Definition ruleset.h:117
#define GAME_DEFAULT_CHANGABLE_TAX
Definition ruleset.h:72
#define RS_DEFAULT_MUUK_SHIELD_WIPE
Definition ruleset.h:79
#define RS_DEFAULT_GOLD_UPKEEP_STYLE
Definition ruleset.h:87
#define GAME_DEFAULT_ADDTOSIZE
Definition ruleset.h:71
#define RS_DEFAULT_ONLY_REAL_FIGHT_VETERAN
Definition ruleset.h:103
#define RS_DEFAULT_EXTRA_DISAPPEARANCE
Definition ruleset.h:100
#define RS_MAX_MIN_TECH_COST
Definition ruleset.h:115
#define RS_DEFAULT_MIN_TECH_COST
Definition ruleset.h:113
#define GAME_DEFAULT_VISION_REVEAL_TILES
Definition ruleset.h:73
#define RS_DEFAULT_CULTURE_VIC_LEAD
Definition ruleset.h:93
#define RS_DEFAULT_TECH_LEAKAGE
Definition ruleset.h:89
#define GAME_DEFAULT_DISASTER_FREQ
Definition ruleset.h:74
#define RS_MIN_BASE_TECH_COST
Definition ruleset.h:110
static struct compatibility compat[]
Definition savecompat.c:110
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:4369
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:495
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1101
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
const struct strvec * get_data_dirs(void)
Definition shared.c:893
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_number(const Specialist_type_id id)
Definition specialist.c:100
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
#define DEFAULT_SPECIALIST
Definition specialist.h:43
const char * aifill(int amount)
Definition srv_main.c:2464
void update_nations_with_startpos(void)
Definition srv_main.c:2269
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:393
int max_distance
Definition actions.h:376
bool quiet
Definition actions.h:383
char ui_name[MAX_LEN_NAME]
Definition actions.h:379
bv_action_sub_results sub_results
Definition actions.h:364
enum action_actor_kind actor_kind
Definition actions.h:366
bv_actions blocked_by
Definition actions.h:387
enum action_target_kind target_kind
Definition actions.h:367
int min_distance
Definition actions.h:376
struct advance * require[AR_SIZE]
Definition tech.h:132
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:281
int named_teams
Definition game.h:293
size_t as_count
Definition game.h:292
const char ** allowed_govs
Definition game.h:284
int upgrade_veteran_loss
Definition game.h:199
struct rgbcolor * plr_bg_color
Definition game.h:103
int incite_total_factor
Definition game.h:150
int init_vis_radius_sq
Definition game.h:152
bool vision_reveal_tiles
Definition game.h:200
char * description_file
Definition game.h:280
struct packet_ruleset_control control
Definition game.h:83
char * ruleset_summary
Definition game.h:84
char ** nc_agovs
Definition game.h:285
int base_incite_cost
Definition game.h:134
int global_init_techs[MAX_NUM_TECH_LIST]
Definition game.h:108
struct packet_game_info info
Definition game.h:89
int autoupgrade_veteran_loss
Definition game.h:132
char rulesetdir[MAX_LEN_NAME]
Definition game.h:238
int start_year
Definition game.h:191
int incite_improvement_factor
Definition game.h:149
struct section_file * luadata
Definition game.h:246
char ** embedded_nations
Definition game.h:282
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:109
struct trait_limits default_traits[TRAIT_COUNT]
Definition game.h:273
char ** nc_astyles
Definition game.h:291
const char ** allowed_terrains
Definition game.h:287
struct civ_game::@31::@35::@40 ruledit
char * ruleset_description
Definition game.h:85
size_t ag_count
Definition game.h:286
const char ** allowed_styles
Definition game.h:290
struct civ_game::@31::@35 server
char ** nc_aterrs
Definition game.h:288
size_t embedded_nations_count
Definition game.h:283
int incite_unit_factor
Definition game.h:151
char * ruleset_capabilities
Definition game.h:86
struct civ_game::@30 rgame
int ransom_gold
Definition game.h:175
size_t at_count
Definition game.h:289
struct veteran_system * veteran
Definition game.h:101
struct packet_calendar_info calendar
Definition game.h:90
struct government * default_government
Definition game.h:93
struct government * government_during_revolution
Definition game.h:94
struct civ_map::@42::@44 server
bool ocean_resources
Definition map_types.h:106
struct requirement_vector receiver_reqs
Definition diptreaty.h:59
struct requirement_vector giver_reqs
Definition diptreaty.h:58
bool enabled
Definition diptreaty.h:57
enum unit_type_flag_id flag
Definition unittype.h:467
enum combat_bonus_type type
Definition unittype.h:468
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:80
bool hidden
Definition nation.h:169
char * legend
Definition nation.h:107
enum barbarian_type barb_type
Definition nation.h:110
char positive_year_label[MAX_LEN_NAME]
char negative_year_label[MAX_LEN_NAME]
char calendar_fragment_name[MAX_CALENDAR_FRAGMENTS][MAX_LEN_NAME]
bool tech_steal_allow_holes
enum gameloss_style gameloss_style
enum goods_selection_method goods_selection
Government_type_id government_during_revolution_id
enum gold_upkeep_style gold_upkeep_style
bool damage_reduces_bombard_rate
int nuke_defender_survival_chance_pct
enum tech_upkeep_style tech_upkeep_style
bool tech_trade_loss_allow_holes
int granary_food_ini[MAX_GRANARY_INIS]
enum free_tech_method free_tech_method
bool steal_maps_reveals_all_cities
bool only_real_fight_makes_veteran
int low_firepower_pearl_harbour
enum tech_leakage_style tech_leakage
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
int civil_war_bonus_celebrating
Government_type_id default_government_id
int min_city_center_output[O_LAST]
char rule_name[MAX_LEN_NAME]
enum achievement_type type
char name[MAX_LEN_NAME]
action_id alternatives[MAX_NUM_ACTIONS]
struct requirement reqs[MAX_NUM_REQS]
enum action_auto_perf_cause cause
struct requirement actor_reqs[MAX_NUM_REQS]
struct requirement target_reqs[MAX_NUM_REQS]
enum action_sub_target_kind sub_tgt_kind
enum action_actor_kind act_kind
bv_action_sub_results sub_results
char ui_name[MAX_LEN_NAME]
enum action_target_kind tgt_kind
enum action_result result
enum base_gui_type gui_type
char helptext[MAX_LEN_PACKET]
struct requirement obs_reqs[MAX_NUM_REQS]
char soundtag_alt[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
enum impr_genus_id genus
char name[MAX_LEN_NAME]
char soundtag[MAX_LEN_NAME]
char soundtag_alt2[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char graphic_alt2[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
enum clause_type type
struct requirement receiver_reqs[MAX_NUM_REQS]
struct requirement giver_reqs[MAX_NUM_REQS]
char preferred_soundset[MAX_LEN_NAME]
char version[MAX_LEN_NAME]
char preferred_tileset[MAX_LEN_NAME]
char alt_dir[MAX_LEN_NAME]
char preferred_musicset[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
enum counter_behaviour behaviour
enum counter_target type
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char helptext[MAX_LEN_PACKET]
char rule_name[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
bv_disaster_effects effects
char name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
bv_unit_classes native_to
char rmact_gfx_alt2[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
char graphic_alt[MAX_LEN_NAME]
char act_gfx_alt2[MAX_LEN_NAME]
struct requirement disappearance_reqs[MAX_NUM_REQS]
bv_extra_flags flags
char act_gfx_alt[MAX_LEN_NAME]
char activity_gfx[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
enum extra_unit_seen_type eus
struct requirement appearance_reqs[MAX_NUM_REQS]
char name[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char rmact_gfx_alt[MAX_LEN_NAME]
char rmact_gfx[MAX_LEN_NAME]
struct requirement rmreqs[MAX_NUM_REQS]
char helptext[MAX_LEN_PACKET]
char helptext[MAX_LEN_PACKET]
bv_goods_flags flags
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
char helptxt[MAX_LEN_PACKET]
char name[MAX_LEN_NAME]
Multiplier_type_id id
struct requirement reqs[MAX_NUM_REQS]
char rule_name[MAX_LEN_NAME]
char helptext[MAX_LEN_PACKET]
char music_combat[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
char music_peaceful[MAX_LEN_NAME]
int init_techs[MAX_NUM_TECH_LIST]
char leader_name[MAX_NUM_LEADERS][MAX_LEN_NAME]
char noun_plural[MAX_LEN_NAME]
char adjective[MAX_LEN_NAME]
Impr_type_id init_buildings[MAX_NUM_BUILDING_LIST]
Unit_type_id init_units[MAX_NUM_UNIT_LIST]
bool leader_is_male[MAX_NUM_LEADERS]
char translation_domain[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
Government_type_id init_government_id
int groups[MAX_NUM_NATION_GROUPS]
enum barbarian_type barbarian_type
int sets[MAX_NUM_NATION_SETS]
char graphic_alt[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char legend[MAX_LEN_MSG]
bv_road_flags flags
int tile_incr_const[O_LAST]
enum road_gui_type gui_type
bv_max_extras integrates
enum road_compat compat
enum road_move_mode move_mode
int tile_bonus[O_LAST]
int tile_incr[O_LAST]
struct requirement first_reqs[MAX_NUM_REQS]
char rule_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
Specialist_type_id id
char helptext[MAX_LEN_PACKET]
char short_name[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char plural_name[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char text[MAX_LEN_CONTENT]
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
char name[MAX_LEN_NAME]
struct requirement research_reqs[MAX_NUM_REQS]
char graphic_str[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
bv_tech_flags flags
char helptext[MAX_LEN_PACKET]
char helptxt[MAX_LEN_PACKET]
int extra_removal_times[MAX_EXTRA_TYPES]
Terrain_type_id transform_result
int resource_freq[MAX_EXTRA_TYPES]
char helptext[MAX_LEN_PACKET]
Resource_type_id resources[MAX_EXTRA_TYPES]
bv_terrain_flags flags
char graphic_str[MAX_LEN_NAME]
bv_unit_classes native_to
Terrain_type_id cultivate_result
Terrain_type_id plant_result
char name[MAX_LEN_NAME]
int road_output_incr_pct[O_LAST]
char graphic_alt[MAX_LEN_NAME]
char graphic_alt2[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
enum trade_route_illegal_cancelling cancelling
enum trade_route_bonus_type bonus_type
char helptxt[MAX_LEN_PACKET]
char rule_name[MAX_LEN_NAME]
bv_unit_class_flags flags
char name[MAX_LEN_NAME]
char helptext[MAX_LEN_PACKET]
char helptxt[MAX_LEN_PACKET]
char graphic_alt[MAX_LEN_NAME]
enum vision_layer vlayer
enum transp_def_type tp_defense
char rule_name[MAX_LEN_NAME]
int power_fact[MAX_VET_LEVELS]
char name[MAX_LEN_NAME]
char graphic_alt2[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char sound_fight_alt[MAX_LEN_NAME]
bv_unit_classes disembarks
bv_unit_classes cargo
bv_unit_type_flags flags
char sound_move_alt[MAX_LEN_NAME]
bv_unit_classes targets
struct requirement build_reqs[MAX_NUM_REQS]
int base_raise_chance[MAX_VET_LEVELS]
int work_raise_chance[MAX_VET_LEVELS]
char sound_fight[MAX_LEN_NAME]
bv_unit_classes embarks
char veteran_name[MAX_VET_LEVELS][MAX_LEN_NAME]
char sound_move[MAX_LEN_NAME]
char helptext[MAX_LEN_PACKET]
bv_unit_type_roles roles
int move_bonus[MAX_VET_LEVELS]
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:903
struct veteran_level * definitions
Definition unittype.h:497
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:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
bool fc_isspace(char c)
Definition support.c:1254
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:836
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:900
char fc_tolower(char c)
Definition support.c:1287
#define sz_strlcpy(dest, src)
Definition support.h:189
#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:423
void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const char *helptxt)
Definition tech.c:394
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:299
const char * tech_flag_helptxt(enum tech_flag_id id)
Definition tech.c:435
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:351
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define tech_class_index(_ptclass_)
Definition tech.h:193
#define A_NEVER
Definition tech.h:51
#define tech_class_iterate_end
Definition tech.h:204
#define MAX_NUM_USER_TECH_FLAGS
Definition tech.h:108
#define advance_iterate_all_end
Definition tech.h:279
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
#define advance_iterate_all(_p)
Definition tech.h:278
static Tech_type_id advance_count(void)
Definition tech.h:170
#define A_FIRST
Definition tech.h:44
#define A_NONE
Definition tech.h:43
#define advance_iterate(_p)
Definition tech.h:275
#define tech_class_iterate(_p)
Definition tech.h:198
#define advance_iterate_end
Definition tech.h:276
#define A_LAST
Definition tech.h:45
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:186
Terrain_type_id terrain_count(void)
Definition terrain.c:118
const char * terrain_flag_id_name_cb(enum terrain_flag_id flag)
Definition terrain.c:817
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:138
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:156
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:829
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:272
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:788
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:147
#define RESOURCE_FREQUENCY_MAXIMUM
Definition terrain.h:209
#define terrain_type_iterate(_p)
Definition terrain.h:373
#define T_NONE
Definition terrain.h:56
#define TERRAIN_UNKNOWN_IDENTIFIER
Definition terrain.h:195
#define terrain_type_iterate_end
Definition terrain.h:379
#define RESOURCE_NONE_IDENTIFIER
Definition terrain.h:47
#define RESOURCE_NULL_IDENTIFIER
Definition terrain.h:46
#define RESOURCE_FREQUENCY_MINIMUM
Definition terrain.h:207
#define MAX_NUM_TERRAINS
Definition terrain.h:64
#define T_FIRST
Definition terrain.h:60
#define MAX_NUM_USER_TER_FLAGS
Definition terrain.h:152
#define terrain_resources_iterate_end
Definition terrain.h:401
#define terrain_resources_iterate(pterrain, _res, _freq)
Definition terrain.h:392
#define RESOURCE_FREQUENCY_DEFAULT
Definition terrain.h:208
#define ACTIVITY_FACTOR
Definition tile.h:165
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:2742
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Definition unittype.c:1854
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1767
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:199
void unit_type_action_cache_init(void)
Definition unittype.c:931
void set_unit_type_caches(struct unit_type *ptype)
Definition unittype.c:2801
void role_unit_precalcs(void)
Definition unittype.c:2175
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:2671
Unit_type_id utype_count(void)
Definition unittype.c:80
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2613
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2583
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1641
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
struct unit_class * unit_class_by_rule_name(const char *s)
Definition unittype.c:1784
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Definition unittype.c:1917
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
void set_user_unit_class_flag_name(enum unit_class_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1812
struct veteran_system * veteran_system_new(int count)
Definition unittype.c:2640
Unit_Class_id uclass_number(const struct unit_class *pclass)
Definition unittype.c:2467
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:371
void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1876
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:766
#define utype_class(_t_)
Definition unittype.h:749
#define combat_bonus_list_iterate_end
Definition unittype.h:482
#define L_FIRST
Definition unittype.h:349
#define combat_bonus_list_iterate(bonuslist, pbonus)
Definition unittype.h:480
#define unit_tech_reqs_iterate_end
Definition unittype.h:878
#define unit_class_iterate(_p)
Definition unittype.h:905
#define unit_tech_reqs_iterate(_utype_, _p)
Definition unittype.h:872
#define MAX_NUM_USER_UNIT_FLAGS
Definition unittype.h:332
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:617
#define UTYF_LAST_USER_FLAG
Definition unittype.h:331
#define unit_type_iterate(_p)
Definition unittype.h:852
#define U_LAST
Definition unittype.h:40
#define uclass_index(_c_)
Definition unittype.h:742
#define unit_class_iterate_end
Definition unittype.h:912
#define unit_type_iterate_end
Definition unittype.h:859
#define MAX_NUM_USER_UCLASS_FLAGS
Definition unittype.h:128