Freeciv-3.1
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 "effects.h"
42#include "extras.h"
43#include "fc_types.h"
44#include "featured_text.h"
45#include "game.h"
46#include "government.h"
47#include "map.h"
48#include "movement.h"
49#include "multipliers.h"
50#include "name_translation.h"
51#include "nation.h"
52#include "packets.h"
53#include "player.h"
54#include "requirements.h"
55#include "rgbcolor.h"
56#include "road.h"
57#include "specialist.h"
58#include "style.h"
59#include "tech.h"
60#include "traderoutes.h"
61#include "unit.h"
62#include "unittype.h"
63
64/* server */
65#include "citytools.h"
66#include "notify.h"
67#include "plrhand.h"
68#include "rscompat.h"
69#include "rssanity.h"
70#include "settings.h"
71#include "srv_main.h"
72
73/* server/advisors */
74#include "advruleset.h"
75
76/* server/scripting */
77#include "script_server.h"
78
79#include "ruleset.h"
80
81/* RULESET_SUFFIX already used, no leading dot here */
82#define RULES_SUFFIX "ruleset"
83#define SCRIPT_SUFFIX "lua"
84
85#define ADVANCE_SECTION_PREFIX "advance_"
86#define TECH_CLASS_SECTION_PREFIX "techclass_"
87#define BUILDING_SECTION_PREFIX "building_"
88#define CITYSTYLE_SECTION_PREFIX "citystyle_"
89#define MUSICSTYLE_SECTION_PREFIX "musicstyle_"
90#define EFFECT_SECTION_PREFIX "effect_"
91#define GOVERNMENT_SECTION_PREFIX "government_"
92#define NATION_SET_SECTION_PREFIX "nset" /* without underscore? */
93#define NATION_GROUP_SECTION_PREFIX "ngroup" /* without underscore? */
94#define NATION_SECTION_PREFIX "nation" /* without underscore? */
95#define STYLE_SECTION_PREFIX "style_"
96#define CLAUSE_SECTION_PREFIX "clause_"
97#define EXTRA_SECTION_PREFIX "extra_"
98#define BASE_SECTION_PREFIX "base_"
99#define ROAD_SECTION_PREFIX "road_"
100#define RESOURCE_SECTION_PREFIX "resource_"
101#define GOODS_SECTION_PREFIX "goods_"
102#define SPECIALIST_SECTION_PREFIX "specialist_"
103#define TERRAIN_SECTION_PREFIX "terrain_"
104#define UNIT_CLASS_SECTION_PREFIX "unitclass_"
105#define UNIT_SECTION_PREFIX "unit_"
106#define DISASTER_SECTION_PREFIX "disaster_"
107#define ACHIEVEMENT_SECTION_PREFIX "achievement_"
108#define ACTION_ENABLER_SECTION_PREFIX "actionenabler_"
109#define MULTIPLIER_SECTION_PREFIX "multiplier_"
110
111#define check_name(name) (check_strlen(name, MAX_LEN_NAME, NULL))
112#define check_cityname(name) (check_strlen(name, MAX_LEN_CITYNAME, NULL))
113
114/* avoid re-reading files */
115static const char name_too_long[] = "Name \"%s\" too long; truncating.";
116#define MAX_SECTION_LABEL 64
117#define section_strlcpy(dst, src) \
118 (void) loud_strlcpy(dst, src, MAX_SECTION_LABEL, name_too_long)
119static char *resource_sections = NULL;
120static char *terrain_sections = NULL;
121static char *extra_sections = NULL;
122static char *base_sections = NULL;
123static char *road_sections = NULL;
124
125static struct requirement_vector reqs_list;
126
127static bool load_rulesetdir(const char *rsdir, bool compat_mode,
129 bool act, bool buffer_script, bool load_luadata);
130static struct section_file *openload_ruleset_file(const char *whichset,
131 const char *rsdir);
132
133static bool load_game_names(struct section_file *file,
134 struct rscompat_info *compat);
135static bool load_tech_names(struct section_file *file,
136 struct rscompat_info *compat);
137static bool load_unit_names(struct section_file *file,
138 struct rscompat_info *compat);
139static bool load_building_names(struct section_file *file,
140 struct rscompat_info *compat);
141static bool load_government_names(struct section_file *file,
142 struct rscompat_info *compat);
143static bool load_terrain_names(struct section_file *file,
144 struct rscompat_info *compat);
145static bool load_style_names(struct section_file *file,
146 struct rscompat_info *compat);
147static bool load_nation_names(struct section_file *file,
148 struct rscompat_info *compat);
149static bool load_city_name_list(struct section_file *file,
150 struct nation_type *pnation,
151 const char *secfile_str1,
152 const char *secfile_str2,
153 const char **allowed_terrains,
154 size_t atcount);
155
156static bool load_ruleset_techs(struct section_file *file,
157 struct rscompat_info *compat);
158static bool load_ruleset_units(struct section_file *file,
159 struct rscompat_info *compat);
160static bool load_ruleset_buildings(struct section_file *file,
161 struct rscompat_info *compat);
162static bool load_ruleset_governments(struct section_file *file,
163 struct rscompat_info *compat);
164static bool load_ruleset_terrain(struct section_file *file,
165 struct rscompat_info *compat);
166static bool load_ruleset_styles(struct section_file *file,
167 struct rscompat_info *compat);
168static bool load_ruleset_cities(struct section_file *file,
169 struct rscompat_info *compat);
170static bool load_ruleset_effects(struct section_file *file,
171 struct rscompat_info *compat);
172static bool load_ruleset_game(struct section_file *file, bool act,
173 struct rscompat_info *compat);
174
175static void send_ruleset_tech_classes(struct conn_list *dest);
176static void send_ruleset_techs(struct conn_list *dest);
177static void send_ruleset_unit_classes(struct conn_list *dest);
178static void send_ruleset_units(struct conn_list *dest);
179static void send_ruleset_buildings(struct conn_list *dest);
180static void send_ruleset_terrain(struct conn_list *dest);
181static void send_ruleset_resources(struct conn_list *dest);
182static void send_ruleset_extras(struct conn_list *dest);
183static void send_ruleset_bases(struct conn_list *dest);
184static void send_ruleset_roads(struct conn_list *dest);
185static void send_ruleset_goods(struct conn_list *dest);
186static void send_ruleset_governments(struct conn_list *dest);
187static void send_ruleset_styles(struct conn_list *dest);
188static void send_ruleset_clauses(struct conn_list *dest);
189static void send_ruleset_musics(struct conn_list *dest);
190static void send_ruleset_cities(struct conn_list *dest);
191static void send_ruleset_game(struct conn_list *dest);
192static void send_ruleset_team_names(struct conn_list *dest);
193
194static bool load_ruleset_veteran(struct section_file *file,
195 const char *path,
196 struct veteran_system **vsystem, char *err,
197 size_t err_len, struct rscompat_info *compat);
198
199char *script_buffer = NULL;
200char *parser_buffer = NULL;
201
202/**********************************************************************/
207 const char *file, const char *function,
208 int line, enum log_level level,
209 const char *format, ...)
210{
211 va_list args;
212 char buf[MAX_LEN_LOG_LINE];
213
214 if (logger == NULL && !log_do_output_for_level(level)) {
215 return;
216 }
217
218 va_start(args, format);
219 if (logger != NULL) {
220 fc_vsnprintf(buf, sizeof(buf), format, args);
221 logger(buf);
222 } else {
223 vdo_log(file, function, line, FALSE, level, buf, sizeof(buf), format, args);
224 }
225 va_end(args);
226
227 if (LOG_FATAL >= level) {
228 exit(EXIT_FAILURE);
229 }
230}
231
232/**********************************************************************/
236{
237 int purged = 0;
238
239 action_iterate(act_id) {
240 struct action *paction = action_by_number(act_id);
241
242 if (action_enabler_list_size(action_enablers_for_action(paction->id))
243 == 0) {
244 /* Not relevant. */
245 continue;
246 }
247
248 /* Impossible hard requirement. */
249 if (!action_is_in_use(paction)) {
250 /* Make sure that all action enablers are disabled. */
252 ae) {
253 ae->ruledit_disabled = TRUE;
254 purged++;
256
257 log_normal("Purged all action enablers for %s",
258 action_rule_name(paction));
259 }
260
261 /* Impossible requirement vector requirement. */
263 ae) {
264 if (!ae->ruledit_disabled
266 || req_vec_is_impossible_to_fulfill(&ae->target_reqs))) {
267 ae->ruledit_disabled = TRUE;
268 purged++;
269 log_normal("Purged unused action enabler for %s",
270 action_rule_name(paction));
271 }
274
275 return purged;
276}
277
278/**********************************************************************/
282{
283 int purged = 0;
284 enum effect_type type;
285
286 for (type = effect_type_begin(); type != effect_type_end();
287 type = effect_type_next(type)) {
289 if (req_vec_is_impossible_to_fulfill(&eft->reqs)) {
290 eft->ruledit_do_not_save = TRUE;
291 purged++;
292 log_normal("Purged unused effect for %s",
293 effect_type_name(eft->type));
294 }
296 }
297
298 return purged;
299}
300
301/**********************************************************************/
305{
306 int purged = 0;
307
310
311 return purged;
312}
313
314/**********************************************************************/
318static bool purge_unused_req_vec(const struct requirement_vector *reqs,
319 const char *msg)
320{
321 struct req_vec_problem *problem;
322 bool result;
323
325 reqs);
326
327 if (problem == NULL) {
328 /* No problem. */
329 return FALSE;
330 }
331
332 if (problem->num_suggested_solutions == 0) {
333 /* No solution. */
334 req_vec_problem_free(problem);
335 return FALSE;
336 }
337
338 if (problem->num_suggested_solutions == 1
339 && problem->suggested_solutions[0].operation == RVCO_REMOVE) {
340 /* Remove !present req that never is there. */
341 log_normal("%s", msg);
342 result = req_vec_change_apply(&problem->suggested_solutions[0],
344 req_vec_problem_free(problem);
345 return result;
346 }
347
348 /* Not handled. Don't know what this is. */
349 fc_assert(problem->num_suggested_solutions == 1);
350 req_vec_problem_free(problem);
351 return FALSE;
352}
353
354/**********************************************************************/
358static bool purge_duplicate_req_vec(const struct requirement_vector *reqs,
359 const char *msg)
360{
361 struct req_vec_problem *problem;
362 bool result;
363
365 reqs);
366
367 if (problem == NULL) {
368 /* No problem. */
369 return FALSE;
370 }
371
372 if (problem->num_suggested_solutions == 0) {
373 /* No solution. */
374 req_vec_problem_free(problem);
375 return FALSE;
376 }
377
378 if (problem->num_suggested_solutions == 2
379 && problem->suggested_solutions[0].operation == RVCO_REMOVE
380 && problem->suggested_solutions[1].operation == RVCO_REMOVE
382 &problem->suggested_solutions[1].req)) {
383 /* Simple duplication is handled. */
384 log_normal("%s", msg);
385 result = req_vec_change_apply(&problem->suggested_solutions[1],
387 req_vec_problem_free(problem);
388 return result;
389 }
390
391 /* Requirements of different kinds making each other redundant isn't
392 * supported yet. It could be done by always removing the most general
393 * requirement. So unit type is kept when redundant with unit flag, unit
394 * class and unit class flag etc. */
395 req_vec_problem_free(problem);
396 return FALSE;
397}
398
399/**********************************************************************/
403static bool purge_redundant_req_vec(const struct requirement_vector *reqs,
404 const char *msg)
405{
406 return (purge_unused_req_vec(reqs, msg)
408}
409
410/**********************************************************************/
415{
416 int purged = 0;
417
418 action_iterate(act_id) {
419 struct action *paction = action_by_number(act_id);
420 char actor_reqs[MAX_LEN_NAME * 2];
421 char target_reqs[MAX_LEN_NAME * 2];
422
423 /* Error log text */
424 fc_snprintf(actor_reqs, sizeof(actor_reqs),
425 "Purged redundant requirement in"
426 " %s in action enabler for %s",
427 "actor_reqs", action_rule_name(paction));
428 fc_snprintf(target_reqs, sizeof(target_reqs),
429 "Purged redundant requirement in"
430 " %s in action enabler for %s",
431 "target_reqs", action_rule_name(paction));
432
433 /* Do the purging. */
435 ae) {
436 while (!ae->ruledit_disabled
437 && (purge_redundant_req_vec(&ae->actor_reqs, actor_reqs)
438 || purge_redundant_req_vec(&ae->target_reqs,
439 target_reqs))) {
440 purged++;
441 }
444
445 return purged;
446}
447
448/**********************************************************************/
453{
454 int purged = 0;
455 enum effect_type type;
456
457 for (type = effect_type_begin(); type != effect_type_end();
458 type = effect_type_next(type)) {
459 char msg[MAX_LEN_NAME * 2];
460
461 /* Error log text */
462 fc_snprintf(msg, sizeof(msg),
463 "Purged redundant requirement in effect of type %s",
464 effect_type_name(type));
465
466 /* Do the purging. */
468 while (purge_redundant_req_vec(&eft->reqs, msg)) {
469 purged++;
470 }
472 }
473
474 return purged;
475}
476
477/**********************************************************************/
482{
483 int purged = 0;
484
487
488 if (purged > 0) {
489 /* An unused requirement may be an obligatory hard requirement. */
491 }
492
493 return purged;
494}
495
496/**********************************************************************/
500static const char *valid_ruleset_filename(const char *subdir,
501 const char *name,
502 const char *extension,
503 bool optional)
504{
505 char filename[512];
506 const char *dfilename;
507
508 fc_assert_ret_val(subdir && name && extension, NULL);
509
510 fc_snprintf(filename, sizeof(filename), "%s" DIR_SEPARATOR "%s.%s",
511 subdir, name, extension);
512 log_verbose("Trying \"%s\".", filename);
513 dfilename = fileinfoname(get_data_dirs(), filename);
514 if (dfilename) {
515 return dfilename;
516 }
517
518 fc_snprintf(filename, sizeof(filename), "default" DIR_SEPARATOR "%s.%s", name, extension);
519 log_verbose("Trying \"%s\": default ruleset directory.", filename);
520 dfilename = fileinfoname(get_data_dirs(), filename);
521 if (dfilename) {
522 return dfilename;
523 }
524
525 fc_snprintf(filename, sizeof(filename), "%s_%s.%s",
526 subdir, name, extension);
527 log_verbose("Trying \"%s\": alternative ruleset filename syntax.",
528 filename);
529 dfilename = fileinfoname(get_data_dirs(), filename);
530 if (dfilename) {
531 return dfilename;
532 } else if (!optional) {
534 /* TRANS: message about an installation error. */
535 _("Could not find a readable \"%s.%s\" ruleset file."),
536 name, extension);
537 }
538
539 return NULL;
540}
541
542/**********************************************************************/
546{
547 return script_buffer;
548}
549
550/**********************************************************************/
554{
555 return parser_buffer;
556}
557
558/**********************************************************************/
562static struct section_file *openload_ruleset_file(const char *whichset,
563 const char *rsdir)
564{
565 char sfilename[512];
566 const char *dfilename = valid_ruleset_filename(rsdir, whichset,
568 struct section_file *secfile;
569
570 if (dfilename == NULL) {
571 return NULL;
572 }
573
574 /* Need to save a copy of the filename for following message, since
575 section_file_load() may call datafilename() for includes. */
576 sz_strlcpy(sfilename, dfilename);
577 secfile = secfile_load(sfilename, FALSE);
578
579 if (secfile == NULL) {
580 ruleset_error(NULL, LOG_ERROR, "Could not load ruleset '%s':\n%s",
581 sfilename, secfile_error());
582 }
583
584 return secfile;
585}
586
587/**********************************************************************/
590static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir,
591 char **buffer, bool optional)
592{
593 const char *dfilename = valid_ruleset_filename(rsdir, whichset,
594 SCRIPT_SUFFIX, optional);
595
596 if (dfilename == NULL) {
597 return optional ? TRI_MAYBE : TRI_NO;
598 }
599
600 if (buffer == NULL) {
601 if (!script_server_do_file(NULL, dfilename)) {
602 ruleset_error(NULL, LOG_ERROR, "\"%s\": could not load ruleset script.",
603 dfilename);
604
605 return TRI_NO;
606 }
607 } else {
608 script_server_load_file(dfilename, buffer);
609 }
610
611 return TRI_YES;
612}
613
614/**********************************************************************/
617static struct section_file *openload_luadata_file(const char *rsdir)
618{
619 struct section_file *secfile;
620 char sfilename[512];
621 const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
622 "txt", TRUE);
623
624 if (dfilename == NULL) {
625 return NULL;
626 }
627
628 /* Need to save a copy of the filename for following message, since
629 section_file_load() may call datafilename() for includes. */
630 sz_strlcpy(sfilename, dfilename);
631 secfile = secfile_load(sfilename, FALSE);
632
633 if (secfile == NULL) {
634 ruleset_error(NULL, LOG_ERROR, "Could not load luadata '%s':\n%s",
635 sfilename, secfile_error());
636 }
637
638 return secfile;
639}
640
641/**********************************************************************/
645struct requirement_vector *lookup_req_list(struct section_file *file,
646 struct rscompat_info *compat,
647 const char *sec,
648 const char *sub,
649 const char *rfor)
650{
651 const char *type, *name;
652 int j;
653 const char *filename;
654
655 filename = secfile_name(file);
656
657 requirement_vector_reserve(&reqs_list, 0);
658
659 for (j = 0; (type = secfile_lookup_str_default(file, NULL, "%s.%s%d.type",
660 sec, sub, j)); j++) {
661 char buf[MAX_LEN_NAME];
662 const char *range;
663 bool survives, present, quiet;
664 struct entry *pentry;
665 struct requirement req;
666
667 if (compat->compat_mode) {
669 }
670
671 if (!(pentry = secfile_entry_lookup(file, "%s.%s%d.name",
672 sec, sub, j))) {
673 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
674
675 return NULL;
676 }
677 name = NULL;
678 switch (entry_type_get(pentry)) {
679 case ENTRY_BOOL:
680 {
681 bool val;
682
683 if (entry_bool_get(pentry, &val)) {
684 fc_snprintf(buf, sizeof(buf), "%d", val);
685 name = buf;
686 }
687 }
688 break;
689 case ENTRY_INT:
690 {
691 int val;
692
693 if (entry_int_get(pentry, &val)) {
694 fc_snprintf(buf, sizeof(buf), "%d", val);
695 name = buf;
696 }
697 }
698 break;
699 case ENTRY_STR:
700 (void) entry_str_get(pentry, &name);
701 break;
702 case ENTRY_FLOAT:
705 "\"%s\": trying to have an floating point entry as a requirement name in '%s.%s%d'.",
706 filename, sec, sub, j);
707 break;
710 break;
711 case ENTRY_ILLEGAL:
713 break;
714 }
715 if (NULL == name) {
717 "\"%s\": error in handling requirement name for '%s.%s%d'.",
718 filename, sec, sub, j);
719 return NULL;
720 }
721
722 if (!(range = secfile_lookup_str(file, "%s.%s%d.range", sec, sub, j))) {
723 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
724
725 return NULL;
726 }
727
728 survives = FALSE;
729 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.survives",
730 sec, sub, j))
731 && !entry_bool_get(pentry, &survives)) {
733 "\"%s\": invalid boolean value for survives for "
734 "'%s.%s%d'.", filename, sec, sub, j);
735 }
736
737 present = TRUE;
738 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.present",
739 sec, sub, j))
740 && !entry_bool_get(pentry, &present)) {
742 "\"%s\": invalid boolean value for present for "
743 "'%s.%s%d'.", filename, sec, sub, j);
744 }
745 quiet = FALSE;
746 if ((pentry = secfile_entry_lookup(file, "%s.%s%d.quiet",
747 sec, sub, j))
748 && !entry_bool_get(pentry, &quiet)) {
750 "\"%s\": invalid boolean value for quiet for "
751 "'%s.%s%d'.", filename, sec, sub, j);
752 }
753
754 if (compat->compat_mode) {
755 if (!fc_strcasecmp(type, universals_n_name(VUT_UTFLAG))) {
757 }
758 }
759
760 if (compat->compat_mode) {
762 }
763
764 if (compat->compat_mode) {
765 if (!fc_strcasecmp(type, "UnitState")
766 && !fc_strcasecmp(name, "OnDomesticTile")) {
767 type = "DiplRelTile";
768 name = "Foreign";
769 present = !present;
770 }
771 }
772
774 if (req.source.kind == universals_n_invalid()) {
776 "\"%s\" [%s] has invalid or unknown req: "
777 "\"%s\" \"%s\".",
778 filename, sec, type, name);
779
780 return NULL;
781 }
782
783 requirement_vector_append(&reqs_list, req);
784 }
785
786 if (compat->compat_mode) {
788 filename, sec, sub, rfor);
789 }
790
791 if (j > MAX_NUM_REQS) {
793 "Too many (%d) requirements for %s. Max is %d",
794 j, rfor, MAX_NUM_REQS);
795
796 return NULL;
797 }
798
799 return &reqs_list;
800}
801
802/**********************************************************************/
806 struct combat_bonus_list *list,
807 struct section_file *file,
808 const char *sec,
809 const char *sub)
810{
811 const char *flag;
812 int j;
813 const char *filename;
814 bool success = TRUE;
815
816 filename = secfile_name(file);
817
818 for (j = 0; (flag = secfile_lookup_str_default(file, NULL, "%s.%s%d.flag",
819 sec, sub, j)); j++) {
820 struct combat_bonus *bonus = fc_malloc(sizeof(*bonus));
821 const char *type;
822
823 bonus->flag = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, flag),
825 if (!unit_type_flag_id_is_valid(bonus->flag)) {
826 log_error("\"%s\": unknown flag name \"%s\" in '%s.%s'.",
827 filename, flag, sec, sub);
828 FC_FREE(bonus);
829 success = FALSE;
830 continue;
831 }
832 type = secfile_lookup_str(file, "%s.%s%d.type", sec, sub, j);
834 bonus->type = combat_bonus_type_by_name(type, fc_strcasecmp);
835 if (!combat_bonus_type_is_valid(bonus->type)) {
836 log_error("\"%s\": unknown bonus type \"%s\" in '%s.%s'.",
837 filename, type, sec, sub);
838 FC_FREE(bonus);
839 success = FALSE;
840 continue;
841 }
842 if (!secfile_lookup_int(file, &bonus->value, "%s.%s%d.value",
843 sec, sub, j)) {
844 log_error("\"%s\": failed to get value from '%s.%s%d'.",
845 filename, sec, sub, j);
846 FC_FREE(bonus);
847 success = FALSE;
848 continue;
849 }
851 "%s.%s%d.quiet",
852 sec, sub, j);
853 combat_bonus_list_append(list, bonus);
854 }
855
856 return success;
857}
858
859/**********************************************************************/
867static bool lookup_tech(struct section_file *file,
868 struct advance **result,
869 const char *prefix, const char *entry,
870 const char *filename,
871 const char *description)
872{
873 const char *sval;
874
875 sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
876 if (!sval || !strcmp(sval, "Never")) {
877 *result = A_NEVER;
878 } else {
879 *result = advance_by_rule_name(sval);
880
881 if (A_NEVER == *result) {
883 "\"%s\" %s %s: couldn't match \"%s\".",
884 filename, (description ? description : prefix), entry, sval);
885 return FALSE;
886 }
887 }
888
889 return TRUE;
890}
891
892/**********************************************************************/
899static bool lookup_building(struct section_file *file,
900 const char *prefix, const char *entry,
901 struct impr_type **result,
902 const char *filename,
903 const char *description)
904{
905 const char *sval;
906 bool ok = TRUE;
907
908 sval = secfile_lookup_str_default(file, NULL, "%s.%s", prefix, entry);
909 if (!sval || strcmp(sval, "None") == 0) {
910 *result = B_NEVER;
911 } else {
912 *result = improvement_by_rule_name(sval);
913
914 if (B_NEVER == *result) {
916 "\"%s\" %s %s: couldn't match \"%s\".",
917 filename, (description ? description : prefix), entry, sval);
918 ok = FALSE;
919 }
920 }
921
922 return ok;
923}
924
925/**********************************************************************/
932static bool lookup_unit_list(struct section_file *file, const char *prefix,
933 const char *entry,
934 struct unit_type **output,
935 const char *filename)
936{
937 const char **slist;
938 size_t nval;
939 int i;
940 bool ok = TRUE;
941
942 /* pre-fill with NULL: */
943 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
944 output[i] = NULL;
945 }
946 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
947 if (nval == 0) {
948 /* 'No vector' is considered same as empty vector */
949 if (slist != NULL) {
950 free(slist);
951 }
952 return TRUE;
953 }
954 if (nval > MAX_NUM_UNIT_LIST) {
956 "\"%s\": string vector %s.%s too long (%d, max %d)",
957 filename, prefix, entry, (int) nval, MAX_NUM_UNIT_LIST);
958 ok = FALSE;
959 } else if (nval == 1 && strcmp(slist[0], "") == 0) {
960 free(slist);
961 return TRUE;
962 }
963 if (ok) {
964 for (i = 0; i < nval; i++) {
965 const char *sval = slist[i];
966 struct unit_type *punittype = unit_type_by_rule_name(sval);
967
968 if (!punittype) {
970 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
971 filename, prefix, entry, i, sval);
972 ok = FALSE;
973 break;
974 }
975 output[i] = punittype;
976 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
977 utype_number(punittype));
978 }
979 }
980 free(slist);
981
982 return ok;
983}
984
985/**********************************************************************/
992static bool lookup_tech_list(struct section_file *file, const char *prefix,
993 const char *entry, int *output,
994 const char *filename)
995{
996 const char **slist;
997 size_t nval;
998 int i;
999 bool ok = TRUE;
1000
1001 /* pre-fill with A_LAST: */
1002 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
1003 output[i] = A_LAST;
1004 }
1005 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
1006 if (slist == NULL || nval == 0) {
1007 return TRUE;
1008 } else if (nval > MAX_NUM_TECH_LIST) {
1010 "\"%s\": string vector %s.%s too long (%d, max %d)",
1011 filename, prefix, entry, (int) nval, MAX_NUM_TECH_LIST);
1012 ok = FALSE;
1013 }
1014
1015 if (ok) {
1016 if (nval == 1 && strcmp(slist[0], "") == 0) {
1017 FC_FREE(slist);
1018 return TRUE;
1019 }
1020 for (i = 0; i < nval && ok; i++) {
1021 const char *sval = slist[i];
1022 struct advance *padvance = advance_by_rule_name(sval);
1023
1024 if (NULL == padvance) {
1026 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1027 filename, prefix, entry, i, sval);
1028 ok = FALSE;
1029 }
1030 if (!valid_advance(padvance)) {
1032 "\"%s\" %s.%s (%d): \"%s\" is removed.",
1033 filename, prefix, entry, i, sval);
1034 ok = FALSE;
1035 }
1036
1037 if (ok) {
1038 output[i] = advance_number(padvance);
1039 log_debug("\"%s\" %s.%s (%d): %s (%d)", filename, prefix, entry, i, sval,
1040 advance_number(padvance));
1041 }
1042 }
1043 }
1044 FC_FREE(slist);
1045
1046 return ok;
1047}
1048
1049/**********************************************************************/
1056static bool lookup_building_list(struct section_file *file,
1057 const char *prefix, const char *entry,
1058 int *output, const char *filename)
1059{
1060 const char **slist;
1061 size_t nval;
1062 int i;
1063 bool ok = TRUE;
1064
1065 /* pre-fill with B_LAST: */
1066 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
1067 output[i] = B_LAST;
1068 }
1069 slist = secfile_lookup_str_vec(file, &nval, "%s.%s", prefix, entry);
1070 if (nval > MAX_NUM_BUILDING_LIST) {
1072 "\"%s\": string vector %s.%s too long (%d, max %d)",
1073 filename, prefix, entry, (int) nval, MAX_NUM_BUILDING_LIST);
1074 ok = FALSE;
1075 } else if (nval == 0 || (nval == 1 && strcmp(slist[0], "") == 0)) {
1076 if (slist != NULL) {
1077 FC_FREE(slist);
1078 }
1079 return TRUE;
1080 }
1081 if (ok) {
1082 for (i = 0; i < nval; i++) {
1083 const char *sval = slist[i];
1084 struct impr_type *pimprove = improvement_by_rule_name(sval);
1085
1086 if (NULL == pimprove) {
1088 "\"%s\" %s.%s (%d): couldn't match \"%s\".",
1089 filename, prefix, entry, i, sval);
1090 ok = FALSE;
1091 break;
1092 }
1093 output[i] = improvement_number(pimprove);
1094 log_debug("%s.%s,%d %s %d", prefix, entry, i, sval, output[i]);
1095 }
1096 }
1097 free(slist);
1098
1099 return ok;
1100}
1101
1102/**********************************************************************/
1108static bool lookup_unit_type(struct section_file *file,
1109 const char *prefix,
1110 const char *entry,
1111 const struct unit_type **result,
1112 const char *filename,
1113 const char *description)
1114{
1115 const char *sval;
1116
1117 sval = secfile_lookup_str_default(file, "None", "%s.%s", prefix, entry);
1118
1119 if (strcmp(sval, "None") == 0) {
1120 *result = NULL;
1121 } else {
1122 *result = unit_type_by_rule_name(sval);
1123 if (*result == NULL) {
1125 "\"%s\" %s %s: couldn't match \"%s\".",
1126 filename, (description ? description : prefix), entry, sval);
1127
1128 return FALSE;
1129 }
1130 }
1131
1132 return TRUE;
1133}
1134
1135/**********************************************************************/
1139static struct government *lookup_government(struct section_file *file,
1140 const char *entry,
1141 const char *filename,
1142 struct government *fallback)
1143{
1144 const char *sval;
1145 struct government *gov;
1146
1147 sval = secfile_lookup_str_default(file, NULL, "%s", entry);
1148 if (!sval) {
1149 gov = fallback;
1150 } else {
1151 gov = government_by_rule_name(sval);
1152 }
1153 if (!gov) {
1155 "\"%s\" %s: couldn't match \"%s\".",
1156 filename, entry, sval);
1157 }
1158 return gov;
1159}
1160
1161/**********************************************************************/
1164static char *lookup_string(struct section_file *file, const char *prefix,
1165 const char *suffix)
1166{
1167 const char *sval = secfile_lookup_str(file, "%s.%s", prefix, suffix);
1168
1169 if (NULL != sval) {
1170 char copy[strlen(sval) + 1];
1171
1172 strcpy(copy, sval);
1174 if (strlen(copy) > 0) {
1175 return fc_strdup(copy);
1176 }
1177 }
1178 return NULL;
1179}
1180
1181/**********************************************************************/
1184static struct strvec *lookup_strvec(struct section_file *file,
1185 const char *prefix, const char *suffix)
1186{
1187 size_t dim;
1188 const char **vec = secfile_lookup_str_vec(file, &dim,
1189 "%s.%s", prefix, suffix);
1190
1191 if (NULL != vec) {
1192 struct strvec *dest = strvec_new();
1193
1194 strvec_store(dest, vec, dim);
1195 free(vec);
1196 return dest;
1197 }
1198 return NULL;
1199}
1200
1201/**********************************************************************/
1204static struct extra_type *lookup_resource(const char *filename,
1205 const char *name,
1206 const char *jsection)
1207{
1208 struct extra_type *pres;
1209
1211
1212 if (pres == NULL) {
1214 "\"%s\" [%s] has unknown \"%s\".",
1215 filename, jsection, name);
1216 }
1217
1218 return pres;
1219}
1220
1221/**********************************************************************/
1225static bool lookup_terrain(struct section_file *file,
1226 const char *entry,
1227 const char *filename,
1228 struct terrain *pthis,
1229 struct terrain **result,
1230 bool null_acceptable)
1231{
1232 const int j = terrain_index(pthis);
1233 const char *jsection = &terrain_sections[j * MAX_SECTION_LABEL];
1234 const char *name = secfile_lookup_str(file, "%s.%s", jsection, entry);
1235 struct terrain *pterr;
1236
1237 if (NULL == name && !null_acceptable) {
1238 return FALSE;
1239 }
1240
1241 if (NULL == name
1242 || *name == '\0'
1243 || (0 == strcmp(name, "none"))
1244 || (0 == strcmp(name, "no"))) {
1245 *result = T_NONE;
1246
1247 return TRUE;
1248 }
1249 if (0 == strcmp(name, "yes")) {
1250 *result = pthis;
1251
1252 return TRUE;
1253 }
1254
1255 pterr = terrain_by_rule_name(name);
1256 *result = pterr;
1257
1258 if (pterr == NULL) {
1260 "\"%s\" [%s] has unknown \"%s\".",
1261 secfile_name(file), jsection, name);
1262 return FALSE;
1263 }
1264
1265 return TRUE;
1266}
1267
1268/**********************************************************************/
1275static bool lookup_time(const struct section_file *secfile, int *turns,
1276 const char *sec_name, const char *property_name,
1277 const char *filename, const char *item_name,
1278 bool *ok)
1279{
1280 /* Assumes that PACKET_UNIT_INFO.activity_count in packets.def is UINT16 */
1281 const int max_turns = 65535 / ACTIVITY_FACTOR;
1282
1283 if (!secfile_lookup_int(secfile, turns, "%s.%s", sec_name, property_name)) {
1284 return FALSE;
1285 }
1286
1287 if (*turns > max_turns) {
1289 "\"%s\": \"%s\": \"%s\" value %d too large (max %d)",
1290 filename, item_name ? item_name : sec_name,
1291 property_name, *turns, max_turns);
1292 *ok = FALSE;
1293 }
1294
1295 return TRUE; /* we found _something */
1296}
1297
1298/**********************************************************************/
1301static bool ruleset_load_names(struct name_translation *pname,
1302 const char *domain,
1303 struct section_file *file,
1304 const char *sec_name)
1305{
1306 const char *name = secfile_lookup_str(file, "%s.name", sec_name);
1307 const char *rule_name = secfile_lookup_str(file, "%s.rule_name", sec_name);
1308
1309 if (!name) {
1311 "\"%s\" [%s]: no \"name\" specified.",
1312 secfile_name(file), sec_name);
1313 return FALSE;
1314 }
1315
1316 names_set(pname, domain, name, rule_name);
1317
1318 return TRUE;
1319}
1320
1321/**********************************************************************/
1324static void ruleset_load_traits(struct trait_limits *out,
1325 struct section_file *file,
1326 const char *secname, const char *field_prefix)
1327{
1328 enum trait tr;
1329
1330 /* FIXME: Use specenum trait names without duplicating them here.
1331 * Just needs to take care of case.
1332 * This list is also duplicated in rulesave.c:save_traits() */
1333 const char *trait_names[] = {
1334 "expansionist",
1335 "trader",
1336 "aggressive",
1337 "builder",
1338 NULL
1339 };
1340
1341 for (tr = trait_begin(); tr != trait_end() && trait_names[tr] != NULL; tr = trait_next(tr)) {
1342 out[tr].min = secfile_lookup_int_default(file, -1, "%s.%s%s_min",
1343 secname,
1344 field_prefix,
1345 trait_names[tr]);
1346 out[tr].max = secfile_lookup_int_default(file, -1, "%s.%s%s_max",
1347 secname,
1348 field_prefix,
1349 trait_names[tr]);
1350 out[tr].fixed = secfile_lookup_int_default(file, -1, "%s.%s%s_default",
1351 secname,
1352 field_prefix,
1353 trait_names[tr]);
1354 }
1355
1356 fc_assert(tr == trait_end()); /* number of trait_names correct */
1357}
1358
1359/**********************************************************************/
1363static bool load_game_names(struct section_file *file,
1364 struct rscompat_info *compat)
1365{
1366 struct section_list *sec;
1367 int nval;
1368 const char *filename = secfile_name(file);
1369 bool ok = TRUE;
1370
1371 /* section: datafile */
1373 if (compat->version <= 0) {
1374 return FALSE;
1375 }
1376
1377 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1378 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1379
1381 nval = (NULL != sec ? section_list_size(sec) : 0);
1382 if (nval > MAX_ACHIEVEMENT_TYPES) {
1383 int num = nval; /* No "size_t" to printf */
1384
1386 "\"%s\": Too many achievement types (%d, max %d)",
1387 filename, num, MAX_ACHIEVEMENT_TYPES);
1388 ok = FALSE;
1389 } else {
1391 }
1392
1393 if (ok) {
1394 achievements_iterate(pach) {
1395 const char *sec_name = section_name(section_list_get(sec, achievement_index(pach)));
1396
1397 if (!ruleset_load_names(&pach->name, NULL, file, sec_name)) {
1399 "\"%s\": Cannot load achievement names",
1400 filename);
1401 ok = FALSE;
1402 break;
1403 }
1405 }
1406
1407 section_list_destroy(sec);
1408
1409 if (ok) {
1411
1412 nval = (NULL != sec ? section_list_size(sec) : 0);
1413 if (nval > MAX_GOODS_TYPES) {
1414 int num = nval; /* No "size_t" to printf */
1415
1417 "\"%s\": Too many goods types (%d, max %d)",
1418 filename, num, MAX_GOODS_TYPES);
1419 section_list_destroy(sec);
1420 ok = FALSE;
1421 } else if (nval < 1) {
1423 "\"%s\": At least one goods type needed",
1424 filename);
1425 section_list_destroy(sec);
1426 ok = FALSE;
1427 } else {
1429 }
1430
1431 if (ok) {
1432 goods_type_iterate(pgood) {
1433 const char *sec_name
1434 = section_name(section_list_get(sec, goods_index(pgood)));
1435
1436 if (!ruleset_load_names(&pgood->name, NULL, file, sec_name)) {
1438 "\"%s\": Cannot load goods names",
1439 filename);
1440 ok = FALSE;
1441 break;
1442 }
1444 }
1445 section_list_destroy(sec);
1446 }
1447
1448 return ok;
1449}
1450
1451
1452/**********************************************************************/
1456static bool load_tech_names(struct section_file *file,
1457 struct rscompat_info *compat)
1458{
1459 struct section_list *sec = NULL;
1460 /* Number of techs in the ruleset (means without A_NONE). */
1461 int num_techs = 0;
1462 int i;
1463 const char *filename = secfile_name(file);
1464 bool ok = TRUE;
1465 const char *flag;
1466
1467 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1468 return FALSE;
1469 }
1470
1471 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1472 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1473
1474 /* User tech flag names */
1475 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1476 i++) {
1477 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1478 i);
1479 if (tech_flag_id_by_name(flag, fc_strcasecmp) != tech_flag_id_invalid()) {
1481 "\"%s\": Duplicate tech flag name '%s'",
1482 filename, flag);
1483 ok = FALSE;
1484 break;
1485 }
1486 if (i > MAX_NUM_USER_TECH_FLAGS) {
1488 "\"%s\": Too many user tech flags!",
1489 filename);
1490 ok = FALSE;
1491 break;
1492 }
1493
1494 set_user_tech_flag_name(TECH_USER_1 + i, flag, helptxt);
1495 }
1496
1497 if (ok) {
1498 size_t nval;
1499
1500 for (; i < MAX_NUM_USER_TECH_FLAGS; i++) {
1501 set_user_tech_flag_name(TECH_USER_1 + i, NULL, NULL);
1502 }
1503
1504 /* Tech classes */
1506
1507 nval = (NULL != sec ? section_list_size(sec) : 0);
1508 if (nval > MAX_NUM_TECH_CLASSES) {
1509 int num = nval; /* No "size_t" to printf */
1510
1512 "\"%s\": Too many tech classes (%d, max %d)",
1513 filename, num, MAX_NUM_TECH_CLASSES);
1514 section_list_destroy(sec);
1515 ok = FALSE;
1516 } else {
1518 }
1519
1520 if (ok) {
1521 tech_class_iterate(ptclass) {
1522 const char *sec_name
1523 = section_name(section_list_get(sec, tech_class_index(ptclass)));
1524
1525 if (!ruleset_load_names(&ptclass->name, NULL, file, sec_name)) {
1526 ruleset_error(NULL, LOG_ERROR, "\"%s\": Cannot load tech class names",
1527 filename);
1528 ok = FALSE;
1529 break;
1530 }
1532 }
1533 }
1534
1535 if (ok) {
1536 /* The techs: */
1538 if (NULL == sec || 0 == (num_techs = section_list_size(sec))) {
1540 "\"%s\": No Advances?!?", filename);
1541 ok = FALSE;
1542 } else {
1543 log_verbose("%d advances (including possibly unused)", num_techs);
1544 if (num_techs + A_FIRST > A_LAST) {
1546 "\"%s\": Too many advances (%d, max %d)",
1547 filename, num_techs, A_LAST - A_FIRST);
1548 ok = FALSE;
1549 }
1550 }
1551 }
1552
1553 if (ok) {
1554 game.control.num_tech_types = num_techs + A_FIRST; /* includes A_NONE */
1555
1556 i = 0;
1558 if (!ruleset_load_names(&a->name, NULL, file, section_name(section_list_get(sec, i)))) {
1559 ok = FALSE;
1560 break;
1561 }
1562 i++;
1564 }
1565 section_list_destroy(sec);
1566
1567 return ok;
1568}
1569
1570/**********************************************************************/
1573static bool load_ruleset_techs(struct section_file *file,
1574 struct rscompat_info *compat)
1575{
1576 struct section_list *sec;
1577 const char **slist;
1578 int i;
1579 size_t nval;
1580 struct advance *a_none = advance_by_number(A_NONE);
1581 const char *filename = secfile_name(file);
1582 bool ok = TRUE;
1583
1585
1586 i = 0;
1587 tech_class_iterate(ptclass) {
1588 const char *sec_name = section_name(section_list_get(sec, i));
1589
1590 ptclass->cost_pct = secfile_lookup_int_default(file, 100, "%s.%s",
1591 sec_name, "cost_pct");
1592
1593 i++;
1595
1597
1598 i = 0;
1600 const char *sec_name = section_name(section_list_get(sec, i));
1601 const char *sval;
1602 int j, ival;
1603 struct requirement_vector *research_reqs;
1604
1605 if (!lookup_tech(file, &a->require[AR_ONE], sec_name, "req1",
1606 filename, rule_name_get(&a->name))
1607 || !lookup_tech(file, &a->require[AR_TWO], sec_name, "req2",
1608 filename, rule_name_get(&a->name))
1609 || !lookup_tech(file, &a->require[AR_ROOT], sec_name, "root_req",
1610 filename, rule_name_get(&a->name))) {
1611 ok = FALSE;
1612 break;
1613 }
1614
1615 if ((A_NEVER == a->require[AR_ONE] && A_NEVER != a->require[AR_TWO])
1616 || (A_NEVER != a->require[AR_ONE] && A_NEVER == a->require[AR_TWO])) {
1618 "\"%s\" [%s] \"%s\": \"Never\" with non-\"Never\".",
1619 filename, sec_name, rule_name_get(&a->name));
1620 ok = FALSE;
1621 break;
1622 }
1623 if (a_none == a->require[AR_ONE] && a_none != a->require[AR_TWO]) {
1625 "\"%s\" [%s] \"%s\": should have \"None\" second.",
1626 filename, sec_name, rule_name_get(&a->name));
1627 ok = FALSE;
1628 break;
1629 }
1630
1631 if (game.control.num_tech_classes == 0) {
1632 a->tclass = NULL;
1633 } else {
1634 const char *classname;
1635
1636 classname = lookup_string(file, sec_name, "class");
1637 if (classname != NULL) {
1638 classname = Q_(classname);
1639 a->tclass = tech_class_by_rule_name(classname);
1640 if (a->tclass == NULL) {
1642 "\"%s\" [%s] \"%s\": Unknown tech class \"%s\".",
1643 filename, sec_name, rule_name_get(&a->name), classname);
1644 ok = FALSE;
1645 break;
1646 }
1647 } else {
1648 a->tclass = NULL; /* Default */
1649 }
1650 }
1651
1652 research_reqs = lookup_req_list(file, compat, sec_name, "research_reqs",
1653 rule_name_get(&a->name));
1654 if (research_reqs == NULL) {
1655 ok = FALSE;
1656 break;
1657 }
1658
1659 requirement_vector_copy(&a->research_reqs, research_reqs);
1660
1661 BV_CLR_ALL(a->flags);
1662
1663 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
1664 for (j = 0; j < nval; j++) {
1665 sval = slist[j];
1666 if (strcmp(sval, "") == 0) {
1667 continue;
1668 }
1669 ival = tech_flag_id_by_name(sval, fc_strcasecmp);
1670 if (!tech_flag_id_is_valid(ival)) {
1672 "\"%s\" [%s] \"%s\": bad flag name \"%s\".",
1673 filename, sec_name, rule_name_get(&a->name), sval);
1674 ok = FALSE;
1675 break;
1676 } else {
1677 BV_SET(a->flags, ival);
1678 }
1679 }
1680 free(slist);
1681
1682 if (!ok) {
1683 break;
1684 }
1685
1686 sz_strlcpy(a->graphic_str,
1687 secfile_lookup_str_default(file, "-", "%s.graphic", sec_name));
1688 sz_strlcpy(a->graphic_alt,
1690 "%s.graphic_alt", sec_name));
1691
1692 a->helptext = lookup_strvec(file, sec_name, "helptext");
1693 a->bonus_message = lookup_string(file, sec_name, "bonus_message");
1694 a->cost = secfile_lookup_int_default(file, -1, "%s.%s",
1695 sec_name, "cost");
1696 a->num_reqs = 0;
1697
1698 i++;
1700
1701 /* Propagate a root tech up into the tech tree. If a technology
1702 * X has Y has a root tech, then any technology requiring X (in the
1703 * normal way or as a root tech) also has Y as a root tech.
1704 * Later techs may gain a whole set of root techs in this way. The one
1705 * we store in AR_ROOT is a more or less arbitrary one of these,
1706 * also signalling that the set is non-empty; after this, you'll still
1707 * have to walk the tech tree to find them all. */
1708restart:
1709
1710 if (ok) {
1712 if (valid_advance(a)
1713 && A_NEVER != a->require[AR_ROOT]) {
1714 bool out_of_order = FALSE;
1715
1716 /* Now find any tech depending on this technology and update its
1717 * root_req. */
1719 if (valid_advance(b)
1720 && A_NEVER == b->require[AR_ROOT]
1721 && (a == b->require[AR_ONE] || a == b->require[AR_TWO])) {
1722 b->require[AR_ROOT] = a->require[AR_ROOT];
1723 b->inherited_root_req = TRUE;
1724 if (b < a) {
1725 out_of_order = TRUE;
1726 }
1727 }
1729
1730 if (out_of_order) {
1731 /* HACK: If we just changed the root_tech of a lower-numbered
1732 * technology, we need to go back so that we can propagate the
1733 * root_tech up to that technology's parents... */
1734 goto restart;
1735 }
1736 }
1738
1739 /* Now rename A_NEVER to A_NONE for consistency */
1741 if (A_NEVER == a->require[AR_ROOT]) {
1742 a->require[AR_ROOT] = a_none;
1743 }
1745
1746 /* Some more consistency checking:
1747 Non-removed techs depending on removed techs is too
1748 broken to fix by default, so die.
1749 */
1751 if (valid_advance(a)) {
1752 /* We check for recursive tech loops later,
1753 * in build_required_techs_helper. */
1754 if (!valid_advance(a->require[AR_ONE])) {
1756 "\"%s\" tech \"%s\": req1 leads to removed tech.",
1757 filename, advance_rule_name(a));
1758 ok = FALSE;
1759 break;
1760 }
1761 if (!valid_advance(a->require[AR_TWO])) {
1763 "\"%s\" tech \"%s\": req2 leads to removed tech.",
1764 filename, advance_rule_name(a));
1765 ok = FALSE;
1766 break;
1767 }
1768 }
1770 }
1771
1772 section_list_destroy(sec);
1773 if (ok) {
1775 }
1776
1777 return ok;
1778}
1779
1780/**********************************************************************/
1784static bool load_unit_names(struct section_file *file,
1785 struct rscompat_info *compat)
1786{
1787 struct section_list *sec = NULL;
1788 int nval = 0;
1789 int i;
1790 const char *filename = secfile_name(file);
1791 const char *flag;
1792 bool ok = TRUE;
1793
1794 if (!rscompat_check_cap_and_version(file, filename, compat)) {
1795 return FALSE;
1796 }
1797
1798 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
1799 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
1800
1801 /* User unit flag names */
1802 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
1803 i++) {
1804 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
1805 i);
1806
1807 if (unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, flag),
1809 != unit_type_flag_id_invalid()) {
1811 "\"%s\": Duplicate unit flag name '%s'",
1812 filename, flag);
1813 ok = FALSE;
1814 break;
1815 }
1816 if (i > MAX_NUM_USER_UNIT_FLAGS) {
1818 "\"%s\": Too many user unit type flags!",
1819 filename);
1820 ok = FALSE;
1821 break;
1822 }
1823
1824 set_user_unit_type_flag_name(UTYF_USER_FLAG_1 + i, flag, helptxt);
1825 }
1826
1827 if (ok) {
1828 /* Blank the remaining unit type user flags. */
1829 for (; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
1830 set_user_unit_type_flag_name(UTYF_USER_FLAG_1 + i, NULL, NULL);
1831 }
1832 }
1833
1834 if (ok) {
1835 /* User unit class flag names */
1836 for (i = 0;
1837 (flag = secfile_lookup_str_default(file, NULL,
1838 "control.class_flags%d.name",
1839 i));
1840 i++) {
1841 const char *helptxt = secfile_lookup_str_default(file, NULL,
1842 "control.class_flags%d.helptxt", i);
1843
1844 if (unit_class_flag_id_by_name(flag, fc_strcasecmp)
1845 != unit_class_flag_id_invalid()) {
1847 "\"%s\": Duplicate unit class flag name '%s'",
1848 filename, flag);
1849 ok = FALSE;
1850 break;
1851 }
1852 if (i > MAX_NUM_USER_UCLASS_FLAGS) {
1854 "\"%s\": Too many user unit class flags!",
1855 filename);
1856 ok = FALSE;
1857 break;
1858 }
1859
1860 set_user_unit_class_flag_name(UCF_USER_FLAG_1 + i, flag, helptxt);
1861 }
1862 }
1863
1864 if (ok) {
1865 /* Blank the remaining unit class user flags. */
1866 for (; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
1867 set_user_unit_class_flag_name(UCF_USER_FLAG_1 + i, NULL, NULL);
1868 }
1869 }
1870
1871 if (ok) {
1872 /* Unit classes */
1874 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1876 "\"%s\": No unit classes?!?", filename);
1877 ok = FALSE;
1878 } else {
1879 log_verbose("%d unit classes", nval);
1880 if (nval > UCL_LAST) {
1882 "\"%s\": Too many unit classes (%d, max %d)",
1883 filename, nval, UCL_LAST);
1884 ok = FALSE;
1885 }
1886 }
1887 }
1888
1889 if (ok) {
1891
1892 unit_class_iterate(punitclass) {
1893 const int pci = uclass_index(punitclass);
1894
1895 if (!ruleset_load_names(&punitclass->name, NULL, file,
1896 section_name(section_list_get(sec, pci)))) {
1897 ok = FALSE;
1898 break;
1899 }
1901 }
1902 section_list_destroy(sec);
1903 sec = NULL;
1904
1905 /* The names: */
1906 if (ok) {
1908 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
1910 "\"%s\": No unit types?!?", filename);
1911 ok = FALSE;
1912 } else {
1913 log_verbose("%d unit types (including possibly unused)", nval);
1914 if (nval > U_LAST) {
1916 "\"%s\": Too many unit types (%d, max %d)",
1917 filename, nval, U_LAST);
1918 ok = FALSE;
1919 }
1920 }
1921 }
1922
1923 if (ok) {
1925
1926 unit_type_iterate(punittype) {
1927 const int utypei = utype_index(punittype);
1928 if (!ruleset_load_names(&punittype->name, NULL, file,
1929 section_name(section_list_get(sec, utypei)))) {
1930 ok = FALSE;
1931 break;
1932 }
1934 }
1935 section_list_destroy(sec);
1936
1937 return ok;
1938}
1939
1940/**********************************************************************/
1943static bool load_ruleset_veteran(struct section_file *file,
1944 const char *path,
1945 struct veteran_system **vsystem, char *err,
1946 size_t err_len, struct rscompat_info *compat)
1947{
1948 const char **vlist_name;
1949 int *vlist_power, *vlist_raise, *vlist_wraise, *vlist_move;
1950 size_t count_name, count_power, count_raise, count_wraise, count_move;
1951 int i;
1952 bool ret = TRUE;
1953
1954 /* The pointer should be uninitialised. */
1955 if (*vsystem != NULL) {
1956 fc_snprintf(err, err_len, "Veteran system is defined?!");
1957 return FALSE;
1958 }
1959
1960 /* Load data. */
1961 vlist_name = secfile_lookup_str_vec(file, &count_name,
1962 "%s.veteran_names", path);
1963 vlist_power = secfile_lookup_int_vec(file, &count_power,
1964 "%s.veteran_power_fact", path);
1965 vlist_raise = secfile_lookup_int_vec(file, &count_raise,
1966 "%s.veteran_base_raise_chance", path);
1967 if (vlist_raise == NULL) {
1968 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
1969 vlist_raise = secfile_lookup_int_vec(file, &count_raise,
1970 "%s.veteran_raise_chance", path);
1971 } else {
1972 fc_assert(count_raise == 0); /* Should be so from an attempt to
1973 * read veteran_base_raise_chance */
1974 count_raise = 0; /* ...but clang analyzer doesn't see it, or
1975 * sees something I don't. */
1976 }
1977 }
1978 vlist_wraise = secfile_lookup_int_vec(file, &count_wraise,
1979 "%s.veteran_work_raise_chance",
1980 path);
1981 vlist_move = secfile_lookup_int_vec(file, &count_move,
1982 "%s.veteran_move_bonus", path);
1983
1984 if (count_name > MAX_VET_LEVELS) {
1985 ret = FALSE;
1986 fc_snprintf(err, err_len, "\"%s\": Too many veteran levels (section "
1987 "'%s': %lu, max %d)", secfile_name(file), path,
1988 (long unsigned)count_name, MAX_VET_LEVELS);
1989 } else if (count_name != count_power
1990 || count_name != count_raise
1991 || count_name != count_wraise
1992 || count_name != count_move) {
1993 ret = FALSE;
1994 fc_snprintf(err, err_len, "\"%s\": Different lengths for the veteran "
1995 "settings in section '%s'", secfile_name(file),
1996 path);
1997 } else if (count_name == 0) {
1998 /* Nothing defined. */
1999 *vsystem = NULL;
2000 } else {
2001 /* Generate the veteran system. */
2002 *vsystem = veteran_system_new((int)count_name);
2003
2004#define rs_sanity_veteran(_path, _entry, _i, _condition, _action) \
2005 if (_condition) { \
2006 log_error("Invalid veteran definition '%s.%s[%d]'!", \
2007 _path, _entry, _i); \
2008 log_debug("Failed check: '%s'. Update value: '%s'.", \
2009 #_condition, #_action); \
2010 _action; \
2011 }
2012 for (i = 0; i < count_name; i++) {
2013 /* Some sanity checks. */
2014 rs_sanity_veteran(path, "veteran_power_fact", i,
2015 (vlist_power[i] < 0), vlist_power[i] = 0);
2016 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2017 (vlist_raise[i] < 0), vlist_raise[i] = 0);
2018 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2019 (vlist_wraise[i] < 0), vlist_wraise[i] = 0);
2020 rs_sanity_veteran(path, "veteran_move_bonus", i,
2021 (vlist_move[i] < 0), vlist_move[i] = 0);
2022 if (i == 0) {
2023 /* First element.*/
2024 rs_sanity_veteran(path, "veteran_power_fact", i,
2025 (vlist_power[i] != 100), vlist_power[i] = 100);
2026 } else if (i == count_name - 1) {
2027 /* Last element. */
2028 rs_sanity_veteran(path, "veteran_power_fact", i,
2029 (vlist_power[i] < vlist_power[i - 1]),
2030 vlist_power[i] = vlist_power[i - 1]);
2031 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2032 (vlist_raise[i] != 0), vlist_raise[i] = 0);
2033 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2034 (vlist_wraise[i] != 0), vlist_wraise[i] = 0);
2035 } else {
2036 /* All elements in between. */
2037 rs_sanity_veteran(path, "veteran_power_fact", i,
2038 (vlist_power[i] < vlist_power[i - 1]),
2039 vlist_power[i] = vlist_power[i - 1]);
2040 rs_sanity_veteran(path, "veteran_base_raise_chance", i,
2041 (vlist_raise[i] > 100), vlist_raise[i] = 100);
2042 rs_sanity_veteran(path, "veteran_work_raise_chance", i,
2043 (vlist_wraise[i] > 100), vlist_wraise[i] = 100);
2044 }
2045
2046 veteran_system_definition(*vsystem, i, vlist_name[i], vlist_power[i],
2047 vlist_move[i], vlist_raise[i],
2048 vlist_wraise[i]);
2049 }
2050#undef rs_sanity_veteran
2051 }
2052
2053 if (vlist_name) {
2054 free(vlist_name);
2055 }
2056 if (vlist_power) {
2057 free(vlist_power);
2058 }
2059 if (vlist_raise) {
2060 free(vlist_raise);
2061 }
2062 if (vlist_wraise) {
2063 free(vlist_wraise);
2064 }
2065 if (vlist_move) {
2066 free(vlist_move);
2067 }
2068
2069 return ret;
2070}
2071
2072/**********************************************************************/
2075static bool load_ruleset_units(struct section_file *file,
2076 struct rscompat_info *compat)
2077{
2078 int j, ival;
2079 size_t nval;
2080 struct section_list *sec, *csec;
2081 const char *sval, **slist;
2082 const char *filename = secfile_name(file);
2083 char msg[MAX_LEN_MSG];
2084 bool ok = TRUE;
2085
2086 if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg,
2087 sizeof(msg), compat)
2088 || game.veteran == NULL) {
2090 "Error loading the default veteran system: %s",
2091 msg);
2092 ok = FALSE;
2093 }
2094
2096 nval = (NULL != sec ? section_list_size(sec) : 0);
2097
2099 nval = (NULL != csec ? section_list_size(csec) : 0);
2100
2101 if (ok) {
2102 unit_class_iterate(uc) {
2103 int i = uclass_index(uc);
2104 const char *sec_name = section_name(section_list_get(csec, i));
2105
2106 if (secfile_lookup_int(file, &uc->min_speed, "%s.min_speed", sec_name)) {
2107 uc->min_speed *= SINGLE_MOVE;
2108 } else {
2109 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
2110 ok = FALSE;
2111 break;
2112 }
2113 if (!secfile_lookup_int(file, &uc->hp_loss_pct,
2114 "%s.hp_loss_pct", sec_name)) {
2115 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
2116 ok = FALSE;
2117 break;
2118 }
2119
2120 uc->non_native_def_pct = secfile_lookup_int_default(file, 100,
2121 "%s.non_native_def_pct",
2122 sec_name);
2123
2124 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
2125 const char *hut_str;
2126
2127 hut_str = secfile_lookup_str_default(file, "Normal",
2128 "%s.hut_behavior", sec_name);
2129 if (fc_strcasecmp(hut_str, "Normal") == 0) {
2130 uc->rscompat_cache_from_3_0.hut_behavior = HUT_NORMAL;
2131 } else if (fc_strcasecmp(hut_str, "Nothing") == 0) {
2132 uc->rscompat_cache_from_3_0.hut_behavior = HUT_NOTHING;
2133 } else if (fc_strcasecmp(hut_str, "Frighten") == 0) {
2134 uc->rscompat_cache_from_3_0.hut_behavior = HUT_FRIGHTEN;
2135 } else {
2137 "\"%s\" unit_class \"%s\":"
2138 " Illegal hut behavior \"%s\".",
2139 filename, uclass_rule_name(uc), hut_str);
2140 ok = FALSE;
2141 break;
2142 }
2143 }
2144
2145 BV_CLR_ALL(uc->flags);
2147 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
2148 for (j = 0; j < nval; j++) {
2149 sval = slist[j];
2150 if (strcmp(sval, "") == 0) {
2151 continue;
2152 }
2153 ival = unit_class_flag_id_by_name(sval, fc_strcasecmp);
2154 if (!unit_class_flag_id_is_valid(ival)) {
2155 ok = FALSE;
2156 ival = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, sval),
2158 if (unit_type_flag_id_is_valid(ival)) {
2160 "\"%s\" unit_class \"%s\": unit_type flag \"%s\"!",
2161 filename, uclass_rule_name(uc), sval);
2162 } else {
2164 "\"%s\" unit_class \"%s\": bad flag name \"%s\".",
2165 filename, uclass_rule_name(uc), sval);
2166 }
2167 break;
2168 } else {
2169 BV_SET(uc->flags, ival);
2170 }
2171 }
2172 free(slist);
2173
2174 uc->helptext = lookup_strvec(file, sec_name, "helptext");
2175
2176 if (!ok) {
2177 break;
2178 }
2180 }
2181
2182 if (ok) {
2183 /* Tech and Gov requirements; per unit veteran system */
2185 const int i = utype_index(u);
2186 const struct section *psection = section_list_get(sec, i);
2187 const char *sec_name = section_name(psection);
2188
2189 if (!lookup_tech(file, &u->require_advance, sec_name,
2190 "tech_req", filename,
2191 rule_name_get(&u->name))) {
2192 ok = FALSE;
2193 break;
2194 }
2195 if (u->require_advance == A_NEVER) {
2197 "%s lacks valid tech_req.",
2198 rule_name_get(&u->name));
2199 ok = FALSE;
2200 break;
2201 }
2202
2203 /* Read the government build requirement from the old ruleset format
2204 * and put it in unit_type's build_reqs requirement vector.
2205 * The build_reqs requirement vector isn't ready to be exposed in the
2206 * ruleset yet.
2207 * Barbarians can build certain units as long as anyone in the world
2208 * has the required tech. Regular players must have the required tech
2209 * them self to build the same unit. One way to solve this is to make
2210 * unit building an action enabler controlled action with a city (not
2211 * unit) actor.
2212 * Putting a requirement vector on unit types in the ruleset will
2213 * force ruleset authors to change all their unit type build
2214 * requirements to a requirement vector. Forcing them to convert their
2215 * unit type requirements again in the next version (should building be
2216 * switched to an action enabler with a city actor) is not good. */
2217 if (NULL != section_entry_by_name(psection, "gov_req")) {
2218 char tmp[200] = "\0";
2219 struct government *need_government;
2220
2221 fc_strlcat(tmp, section_name(psection), sizeof(tmp));
2222 fc_strlcat(tmp, ".gov_req", sizeof(tmp));
2223 need_government = lookup_government(file, tmp, filename, NULL);
2224 if (need_government == NULL) {
2225 ok = FALSE;
2226 break;
2227 }
2228 requirement_vector_append(&u->build_reqs, req_from_values(
2229 VUT_GOVERNMENT, REQ_RANGE_PLAYER,
2230 FALSE, TRUE, FALSE,
2231 government_number(need_government)));
2232 }
2233
2234 if (!load_ruleset_veteran(file, sec_name, &u->veteran,
2235 msg, sizeof(msg), compat)) {
2237 "Error loading the veteran system: %s",
2238 msg);
2239 ok = FALSE;
2240 break;
2241 }
2242
2243 if (!lookup_unit_type(file, sec_name, "obsolete_by",
2244 &u->obsoleted_by, filename,
2245 rule_name_get(&u->name))
2246 || !lookup_unit_type(file, sec_name, "convert_to",
2247 &u->converted_to, filename,
2248 rule_name_get(&u->name))) {
2249 ok = FALSE;
2250 break;
2251 }
2252 u->convert_time = 1; /* default */
2253 lookup_time(file, &u->convert_time, sec_name, "convert_time",
2254 filename, rule_name_get(&u->name), &ok);
2256 }
2257
2258 if (ok) {
2259 /* main stats: */
2261 const int i = utype_index(u);
2262 struct unit_class *pclass;
2263 const char *sec_name = section_name(section_list_get(sec, i));
2264 const char *str;
2265 struct impr_type *impr_req = NULL;
2266
2267 /* Read the building build requirement from the old ruleset format
2268 * and put it in unit_type's build_reqs requirement vector.
2269 * The build_reqs requirement vector isn't ready to be exposed in the
2270 * ruleset yet.
2271 * See the comment for gov_req above for why. */
2272 if (!lookup_building(file, sec_name, "impr_req",
2273 &impr_req, filename,
2274 rule_name_get(&u->name))) {
2275 ok = FALSE;
2276 break;
2277 }
2278 if (impr_req) {
2279 requirement_vector_append(&u->build_reqs, req_from_values(
2280 VUT_IMPROVEMENT, REQ_RANGE_CITY,
2281 FALSE, TRUE, FALSE,
2282 improvement_number(impr_req)));
2283 }
2284
2285 sval = secfile_lookup_str(file, "%s.class", sec_name);
2286 pclass = unit_class_by_rule_name(sval);
2287 if (!pclass) {
2289 "\"%s\" unit_type \"%s\": bad class \"%s\".",
2290 filename, utype_rule_name(u), sval);
2291 ok = FALSE;
2292 break;
2293 }
2294 u->uclass = pclass;
2295
2296 sz_strlcpy(u->sound_move,
2297 secfile_lookup_str_default(file, "-", "%s.sound_move",
2298 sec_name));
2299 sz_strlcpy(u->sound_move_alt,
2300 secfile_lookup_str_default(file, "-", "%s.sound_move_alt",
2301 sec_name));
2302 sz_strlcpy(u->sound_fight,
2303 secfile_lookup_str_default(file, "-", "%s.sound_fight",
2304 sec_name));
2305 sz_strlcpy(u->sound_fight_alt,
2306 secfile_lookup_str_default(file, "-", "%s.sound_fight_alt",
2307 sec_name));
2308
2309 if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) {
2310 sz_strlcpy(u->graphic_str, str);
2311 } else {
2312 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
2313 ok = FALSE;
2314 break;
2315 }
2316 sz_strlcpy(u->graphic_alt,
2317 secfile_lookup_str_default(file, "-", "%s.graphic_alt",
2318 sec_name));
2319
2320 if (!secfile_lookup_int(file, &u->build_cost,
2321 "%s.build_cost", sec_name)
2322 || !secfile_lookup_int(file, &u->pop_cost,
2323 "%s.pop_cost", sec_name)
2324 || !secfile_lookup_int(file, &u->attack_strength,
2325 "%s.attack", sec_name)
2326 || !secfile_lookup_int(file, &u->defense_strength,
2327 "%s.defense", sec_name)
2328 || !secfile_lookup_int(file, &u->move_rate,
2329 "%s.move_rate", sec_name)
2330 || !secfile_lookup_int(file, &u->vision_radius_sq,
2331 "%s.vision_radius_sq", sec_name)
2332 || !secfile_lookup_int(file, &u->transport_capacity,
2333 "%s.transport_cap", sec_name)
2334 || !secfile_lookup_int(file, &u->hp,
2335 "%s.hitpoints", sec_name)
2336 || !secfile_lookup_int(file, &u->firepower,
2337 "%s.firepower", sec_name)
2338 || !secfile_lookup_int(file, &u->fuel,
2339 "%s.fuel", sec_name)
2340 || !secfile_lookup_int(file, &u->happy_cost,
2341 "%s.uk_happy", sec_name)) {
2342 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
2343 ok = FALSE;
2344 break;
2345 }
2346 u->move_rate *= SINGLE_MOVE;
2347
2348 if (u->firepower <= 0) {
2350 "\"%s\" unit_type \"%s\":"
2351 " firepower is %d,"
2352 " but must be at least 1. "
2353 " If you want no attack ability,"
2354 " set the unit's attack strength to 0.",
2355 filename, utype_rule_name(u), u->firepower);
2356 ok = FALSE;
2357 break;
2358 }
2359
2360 lookup_cbonus_list(compat, u->bonuses, file, sec_name, "bonuses");
2361
2363 u->upkeep[o] = secfile_lookup_int_default(file, 0, "%s.uk_%s",
2364 sec_name,
2367
2368 slist = secfile_lookup_str_vec(file, &nval, "%s.cargo", sec_name);
2369
2370 BV_CLR_ALL(u->cargo);
2371 for (j = 0; j < nval; j++) {
2372 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2373
2374 if (!uclass) {
2376 "\"%s\" unit_type \"%s\":"
2377 "has unknown unit class %s as cargo.",
2378 filename, utype_rule_name(u), slist[j]);
2379 ok = FALSE;
2380 break;
2381 }
2382
2383 BV_SET(u->cargo, uclass_index(uclass));
2384 }
2385 free(slist);
2386
2387 if (!ok) {
2388 break;
2389 }
2390
2391 slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec_name);
2392 BV_CLR_ALL(u->targets);
2393 for (j = 0; j < nval; j++) {
2394 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2395
2396 if (!uclass) {
2398 "\"%s\" unit_type \"%s\":"
2399 "has unknown unit class %s as target.",
2400 filename, utype_rule_name(u), slist[j]);
2401 ok = FALSE;
2402 break;
2403 }
2404
2405 BV_SET(u->targets, uclass_index(uclass));
2406 }
2407 free(slist);
2408
2409 if (!ok) {
2410 break;
2411 }
2412
2413 slist = secfile_lookup_str_vec(file, &nval, "%s.embarks", sec_name);
2414 BV_CLR_ALL(u->embarks);
2415 for (j = 0; j < nval; j++) {
2416 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2417
2418 if (!uclass) {
2420 "\"%s\" unit_type \"%s\":"
2421 "has unknown unit class %s as embarkable.",
2422 filename, utype_rule_name(u), slist[j]);
2423 ok = FALSE;
2424 break;
2425 }
2426
2427 BV_SET(u->embarks, uclass_index(uclass));
2428 }
2429 free(slist);
2430
2431 if (!ok) {
2432 break;
2433 }
2434
2435 slist = secfile_lookup_str_vec(file, &nval, "%s.disembarks", sec_name);
2436 BV_CLR_ALL(u->disembarks);
2437 for (j = 0; j < nval; j++) {
2438 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
2439
2440 if (!uclass) {
2442 "\"%s\" unit_type \"%s\":"
2443 "has unknown unit class %s as disembarkable.",
2444 filename, utype_rule_name(u), slist[j]);
2445 ok = FALSE;
2446 break;
2447 }
2448
2449 BV_SET(u->disembarks, uclass_index(uclass));
2450 }
2451 free(slist);
2452
2453 if (!ok) {
2454 break;
2455 }
2456
2457 /* Set also all classes that are never unreachable as targets,
2458 * embarks, and disembarks. */
2459 unit_class_iterate(preachable) {
2460 if (!uclass_has_flag(preachable, UCF_UNREACHABLE)) {
2461 BV_SET(u->targets, uclass_index(preachable));
2462 BV_SET(u->embarks, uclass_index(preachable));
2463 BV_SET(u->disembarks, uclass_index(preachable));
2464 }
2466
2467 str = secfile_lookup_str_default(file, "Main", "%s.vision_layer",
2468 sec_name);
2469 u->vlayer = vision_layer_by_name(str, fc_strcasecmp);
2470 if (!vision_layer_is_valid(u->vlayer)) {
2472 "\"%s\" unit_type \"%s\":"
2473 "has unknown vision layer %s.",
2474 filename, utype_rule_name(u), str);
2475 ok = FALSE;
2476 break;
2477 }
2478
2479 u->helptext = lookup_strvec(file, sec_name, "helptext");
2480
2481 u->paratroopers_range = secfile_lookup_int_default(file,
2482 0, "%s.paratroopers_range", sec_name);
2483 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
2484 u->rscompat_cache.paratroopers_mr_req
2486 file, 0, "%s.paratroopers_mr_req", sec_name);
2487 u->rscompat_cache.paratroopers_mr_sub
2489 file, 0, "%s.paratroopers_mr_sub", sec_name);
2490 } else {
2491 u->rscompat_cache.paratroopers_mr_req = 0;
2492 u->rscompat_cache.paratroopers_mr_sub = 0;
2493 }
2494 u->bombard_rate = secfile_lookup_int_default(file, 0,
2495 "%s.bombard_rate", sec_name);
2496 u->city_slots = secfile_lookup_int_default(file, 0,
2497 "%s.city_slots", sec_name);
2498 u->city_size = secfile_lookup_int_default(file, 1,
2499 "%s.city_size", sec_name);
2500
2501 sval = secfile_lookup_str_default(file, transp_def_type_name(TDT_ALIGHT),
2502 "%s.tp_defense", sec_name);
2503 u->tp_defense = transp_def_type_by_name(sval, fc_strcasecmp);
2504 if (!transp_def_type_is_valid(u->tp_defense)) {
2506 "\"%s\" unit_type \"%s\":"
2507 " bad tp_defense \"%s\".",
2508 filename, utype_rule_name(u), sval);
2509 ok = FALSE;
2510 break;
2511 }
2513 }
2514
2515 if (ok) {
2516 /* flags */
2518 const int i = utype_index(u);
2519
2520 BV_CLR_ALL(u->flags);
2522
2523 slist = secfile_lookup_str_vec(file, &nval, "%s.flags",
2524 section_name(section_list_get(sec, i)));
2525 for (j = 0; j < nval; j++) {
2526 sval = slist[j];
2527 if (0 == strcmp(sval, "")) {
2528 continue;
2529 }
2530 if (compat->compat_mode && !fc_strcasecmp("Partial_Invis", sval)) {
2531 u->vlayer = V_INVIS;
2532 } else {
2533 ival = unit_type_flag_id_by_name(rscompat_utype_flag_name_3_1(compat, sval),
2535 if (!unit_type_flag_id_is_valid(ival)) {
2536 ok = FALSE;
2537 ival = unit_class_flag_id_by_name(sval, fc_strcasecmp);
2538 if (unit_class_flag_id_is_valid(ival)) {
2540 "\"%s\" unit_type \"%s\": unit_class flag!",
2541 filename, utype_rule_name(u));
2542 } else {
2544 "\"%s\" unit_type \"%s\": bad flag name \"%s\".",
2545 filename, utype_rule_name(u), sval);
2546 }
2547 break;
2548 } else {
2549 BV_SET(u->flags, ival);
2550 }
2551 fc_assert(utype_has_flag(u, ival));
2552 }
2553 }
2554 free(slist);
2555
2556 if (!ok) {
2557 break;
2558 }
2560 }
2561
2562 /* roles */
2563 if (ok) {
2565 const int i = utype_index(u);
2566
2567 BV_CLR_ALL(u->roles);
2568
2569 slist = secfile_lookup_str_vec(file, &nval, "%s.roles",
2570 section_name(section_list_get(sec, i)));
2571 for (j = 0; j < nval; j++) {
2572 sval = slist[j];
2573 if (strcmp(sval, "") == 0) {
2574 continue;
2575 }
2576 ival = unit_role_id_by_name(sval, fc_strcasecmp);
2577 if (!unit_role_id_is_valid(ival)) {
2579 "\"%s\" unit_type \"%s\": bad role name \"%s\".",
2580 filename, utype_rule_name(u), sval);
2581 ok = FALSE;
2582 break;
2583 } else {
2584 BV_SET(u->roles, ival - L_FIRST);
2585 }
2586 fc_assert(utype_has_role(u, ival));
2587 }
2588 free(slist);
2590 }
2591
2592 if (ok) {
2593 /* Some more consistency checking: */
2595 if (!valid_advance(u->require_advance)) {
2597 "\"%s\" unit_type \"%s\": depends on removed tech \"%s\".",
2598 filename, utype_rule_name(u),
2599 advance_rule_name(u->require_advance));
2600 u->require_advance = A_NEVER;
2601 ok = FALSE;
2602 break;
2603 }
2605 }
2606
2607 section_list_destroy(csec);
2608 section_list_destroy(sec);
2609
2610 if (ok) {
2612 }
2613
2614 return ok;
2615}
2616
2617/**********************************************************************/
2621static bool load_building_names(struct section_file *file,
2622 struct rscompat_info *compat)
2623{
2624 struct section_list *sec;
2625 int i, nval = 0;
2626 const char *filename = secfile_name(file);
2627 bool ok = TRUE;
2628
2629 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2630 return FALSE;
2631 }
2632
2633 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2634 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2635
2636 /* The names: */
2638 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2640 "\"%s\": No improvements?!?", filename);
2641 ok = FALSE;
2642 } else {
2643 log_verbose("%d improvement types (including possibly unused)", nval);
2644 if (nval > B_LAST) {
2646 "\"%s\": Too many improvements (%d, max %d)",
2647 filename, nval, B_LAST);
2648 ok = FALSE;
2649 }
2650 }
2651
2652 if (ok) {
2654
2655 for (i = 0; i < nval; i++) {
2656 struct impr_type *b = improvement_by_number(i);
2657
2658 if (!ruleset_load_names(&b->name, NULL, file, section_name(section_list_get(sec, i)))) {
2659 ok = FALSE;
2660 break;
2661 }
2662 }
2663 }
2664
2665 section_list_destroy(sec);
2666
2667 return ok;
2668}
2669
2670/**********************************************************************/
2673static bool load_ruleset_buildings(struct section_file *file,
2674 struct rscompat_info *compat)
2675{
2676 struct section_list *sec;
2677 const char *item;
2678 int i, nval;
2679 const char *filename = secfile_name(file);
2680 bool ok = TRUE;
2681
2683 nval = (NULL != sec ? section_list_size(sec) : 0);
2684
2685 for (i = 0; i < nval && ok; i++) {
2686 struct impr_type *b = improvement_by_number(i);
2687 const char *sec_name = section_name(section_list_get(sec, i));
2688 struct requirement_vector *reqs =
2689 lookup_req_list(file, compat, sec_name, "reqs",
2691
2692 if (reqs == NULL) {
2693 ok = FALSE;
2694 break;
2695 } else {
2696 const char *sval, **slist;
2697 int j, ival;
2698 size_t nflags;
2699
2700 item = secfile_lookup_str(file, "%s.genus", sec_name);
2701 b->genus = impr_genus_id_by_name(item, fc_strcasecmp);
2702 if (!impr_genus_id_is_valid(b->genus)) {
2704 "\"%s\" improvement \"%s\": couldn't match "
2705 "genus \"%s\".", filename,
2707 ok = FALSE;
2708 break;
2709 }
2710
2711 slist = secfile_lookup_str_vec(file, &nflags, "%s.flags", sec_name);
2712 BV_CLR_ALL(b->flags);
2713
2714 for (j = 0; j < nflags; j++) {
2715 sval = slist[j];
2716 if (strcmp(sval, "") == 0) {
2717 continue;
2718 }
2719 ival = impr_flag_id_by_name(sval, fc_strcasecmp);
2720 if (!impr_flag_id_is_valid(ival)) {
2722 "\"%s\" improvement \"%s\": bad flag name \"%s\".",
2723 filename, improvement_rule_name(b), sval);
2724 ok = FALSE;
2725 break;
2726 } else {
2727 BV_SET(b->flags, ival);
2728 }
2729 }
2730 free(slist);
2731
2732 if (!ok) {
2733 break;
2734 }
2735
2736 requirement_vector_copy(&b->reqs, reqs);
2737
2738 {
2739 struct requirement_vector *obs_reqs =
2740 lookup_req_list(file, compat, sec_name, "obsolete_by",
2742
2743 if (obs_reqs == NULL) {
2744 ok = FALSE;
2745 break;
2746 } else {
2747 requirement_vector_copy(&b->obsolete_by, obs_reqs);
2748 }
2749 }
2750
2751 if (!secfile_lookup_int(file, &b->build_cost,
2752 "%s.build_cost", sec_name)
2753 || !secfile_lookup_int(file, &b->upkeep,
2754 "%s.upkeep", sec_name)
2755 || !secfile_lookup_int(file, &b->sabotage,
2756 "%s.sabotage", sec_name)) {
2757 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
2758 ok = FALSE;
2759 break;
2760 }
2761
2764 "%s.graphic", sec_name));
2767 "%s.graphic_alt", sec_name));
2768
2771 "%s.sound", sec_name));
2774 "%s.sound_alt", sec_name));
2775 b->helptext = lookup_strvec(file, sec_name, "helptext");
2776 }
2777 }
2778
2779 section_list_destroy(sec);
2780 if (ok) {
2782 }
2783
2784 return ok;
2785}
2786
2787/**********************************************************************/
2791static bool load_terrain_names(struct section_file *file,
2792 struct rscompat_info *compat)
2793{
2794 int nval = 0;
2795 struct section_list *sec = NULL;
2796 const char *flag;
2797 int i;
2798 const char *filename = secfile_name(file);
2799 bool ok = TRUE;
2800
2801 if (!rscompat_check_cap_and_version(file, filename, compat)) {
2802 return FALSE;
2803 }
2804
2805 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
2806 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
2807
2808 /* User terrain flag names */
2809 for (i = 0; (flag = secfile_lookup_str_default(file, NULL, "control.flags%d.name", i)) ;
2810 i++) {
2811 const char *helptxt = secfile_lookup_str_default(file, NULL, "control.flags%d.helptxt",
2812 i);
2813
2814 if (terrain_flag_id_by_name(flag, fc_strcasecmp)
2815 != terrain_flag_id_invalid()) {
2817 "\"%s\": Duplicate terrain flag name '%s'",
2818 filename, flag);
2819 ok = FALSE;
2820 break;
2821 }
2822 if (i > MAX_NUM_USER_TER_FLAGS) {
2824 "\"%s\": Too many user terrain flags!",
2825 filename);
2826 ok = FALSE;
2827 break;
2828 }
2829
2830 set_user_terrain_flag_name(TER_USER_1 + i, flag, helptxt);
2831 }
2832
2833 if (ok) {
2834 /* Blank the remaining terrain user flag slots. */
2835 for (; i < MAX_NUM_USER_TER_FLAGS; i++) {
2836 set_user_terrain_flag_name(TER_USER_1 + i, NULL, NULL);
2837 }
2838 }
2839
2840 /* User extra flag names */
2841 for (i = 0;
2842 (flag = secfile_lookup_str_default(file, NULL,
2843 "control.extra_flags%d.name",
2844 i));
2845 i++) {
2846 const char *helptxt = secfile_lookup_str_default(file, NULL,
2847 "control.extra_flags%d.helptxt", i);
2848
2849 if (extra_flag_id_by_name(flag, fc_strcasecmp)
2850 != extra_flag_id_invalid()) {
2852 "\"%s\": Duplicate extra flag name '%s'",
2853 filename, flag);
2854 ok = FALSE;
2855 break;
2856 }
2857 if (i > MAX_NUM_USER_EXTRA_FLAGS) {
2859 "\"%s\": Too many user extra flags!",
2860 filename);
2861 ok = FALSE;
2862 break;
2863 }
2864
2865 set_user_extra_flag_name(EF_USER_FLAG_1 + i, flag, helptxt);
2866 }
2867
2868 if (ok) {
2869 /* Blank the remaining extra user flag slots. */
2870 for (; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
2871 set_user_extra_flag_name(EF_USER_FLAG_1 + i, NULL, NULL);
2872 }
2873
2874 /* terrain names */
2875
2877 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
2879 "\"%s\": ruleset doesn't have any terrains.",
2880 filename);
2881 ok = FALSE;
2882 } else {
2883 if (nval > MAX_NUM_TERRAINS) {
2885 "\"%s\": Too many terrains (%d, max %d)",
2886 filename, nval, MAX_NUM_TERRAINS);
2887 ok = FALSE;
2888 }
2889 }
2890 }
2891
2892 if (ok) {
2893 game.control.terrain_count = nval;
2894
2895 /* avoid re-reading files */
2896 if (terrain_sections) {
2897 free(terrain_sections);
2898 }
2900
2901 terrain_type_iterate(pterrain) {
2902 const int terri = terrain_index(pterrain);
2903 const char *sec_name = section_name(section_list_get(sec, terri));
2904
2905 if (!ruleset_load_names(&pterrain->name, NULL, file, sec_name)) {
2906 ok = FALSE;
2907 break;
2908 }
2909
2912 }
2913
2914 section_list_destroy(sec);
2915 sec = NULL;
2916
2917 /* extra names */
2918
2919 if (ok) {
2921 nval = (NULL != sec ? section_list_size(sec) : 0);
2922 if (nval > MAX_EXTRA_TYPES) {
2924 "\"%s\": Too many extra types (%d, max %d)",
2925 filename, nval, MAX_EXTRA_TYPES);
2926 ok = FALSE;
2927 }
2928 }
2929
2930 if (ok) {
2931 int idx;
2932
2934
2935 if (extra_sections) {
2936 free(extra_sections);
2937 }
2939
2940 if (ok) {
2941 for (idx = 0; idx < nval; idx++) {
2942 const char *sec_name = section_name(section_list_get(sec, idx));
2943 struct extra_type *pextra = extra_by_number(idx);
2944
2945 if (!ruleset_load_names(&pextra->name, NULL, file, sec_name)) {
2946 ok = FALSE;
2947 break;
2948 }
2950 }
2951 }
2952 }
2953
2954 section_list_destroy(sec);
2955 sec = NULL;
2956
2957 /* Base names */
2958
2959 if (ok) {
2961 nval = (NULL != sec ? section_list_size(sec) : 0);
2962 if (nval > MAX_EXTRA_TYPES) {
2964 "\"%s\": Too many base types (%d, max %d)",
2965 filename, nval, MAX_EXTRA_TYPES);
2966 ok = FALSE;
2967 }
2968
2970 }
2971
2972 if (ok) {
2973 int idx;
2974
2975 if (base_sections) {
2976 free(base_sections);
2977 }
2979
2980 /* Cannot use base_type_iterate() before bases are added to
2981 * EC_BASE caused_by list. Have to get them by extra_type_by_rule_name() */
2982 for (idx = 0; idx < nval; idx++) {
2983 const char *sec_name = section_name(section_list_get(sec, idx));
2984 const char *base_name = secfile_lookup_str(file, "%s.extra", sec_name);
2985
2986 if (base_name != NULL) {
2987 struct extra_type *pextra = extra_type_by_rule_name(base_name);
2988
2989 if (pextra != NULL) {
2990 base_type_init(pextra, idx);
2992 } else {
2994 "No extra definition matching base definition \"%s\"",
2995 base_name);
2996 ok = FALSE;
2997 }
2998 } else {
3000 "Base section \"%s\" does not associate base with any extra",
3001 sec_name);
3002 ok = FALSE;
3003 }
3004 }
3005 }
3006
3007 section_list_destroy(sec);
3008 sec = NULL;
3009
3010 /* Road names */
3011
3012 if (ok) {
3014 nval = (NULL != sec ? section_list_size(sec) : 0);
3015 if (nval > MAX_EXTRA_TYPES) {
3017 "\"%s\": Too many road types (%d, max %d)",
3018 filename, nval, MAX_EXTRA_TYPES);
3019 ok = FALSE;
3020 }
3021
3023 }
3024
3025 if (ok) {
3026 int idx;
3027
3028 if (road_sections) {
3029 free(road_sections);
3030 }
3032
3033 /* Cannot use extra_type_by_cause_iterate(EC_ROAD) before roads are added to
3034 * EC_ROAD caused_by list. Have to get them by extra_type_by_rule_name() */
3035 for (idx = 0; idx < nval; idx++) {
3036 const char *sec_name = section_name(section_list_get(sec, idx));
3037 const char *road_name = secfile_lookup_str(file, "%s.extra", sec_name);
3038
3039 if (road_name != NULL) {
3040 struct extra_type *pextra = extra_type_by_rule_name(road_name);
3041
3042 if (pextra != NULL) {
3043 road_type_init(pextra, idx);
3045 } else {
3047 "No extra definition matching road definition \"%s\"",
3048 road_name);
3049 ok = FALSE;
3050 }
3051 } else {
3053 "Road section \"%s\" does not associate road with any extra",
3054 sec_name);
3055 ok = FALSE;
3056 }
3057 }
3058 }
3059
3060 section_list_destroy(sec);
3061 sec = NULL;
3062
3063 /* resource names */
3064
3065 if (ok) {
3067 nval = (NULL != sec ? section_list_size(sec) : 0);
3068 if (nval > MAX_RESOURCE_TYPES) {
3070 "\"%s\": Too many resource types (%d, max %d)",
3071 filename, nval, MAX_RESOURCE_TYPES);
3072 ok = FALSE;
3073 }
3074
3076 }
3077
3078 if (ok) {
3079 int idx;
3080
3081 if (resource_sections) {
3082 free(resource_sections);
3083 }
3085
3086 /* Cannot use resource_type_iterate() before resource are added to
3087 * EC_RESOURCE caused_by list. Have to get them by extra_type_by_rule_name() */
3088 for (idx = 0; idx < nval; idx++) {
3089 const char *sec_name = section_name(section_list_get(sec, idx));
3090 const char *resource_name;
3091 struct extra_type *pextra = NULL;
3092
3093 resource_name = secfile_lookup_str_default(file, NULL, "%s.extra", sec_name);
3094
3095 if (resource_name != NULL) {
3096 pextra = extra_type_by_rule_name(resource_name);
3097
3098 if (pextra != NULL) {
3099 resource_type_init(pextra);
3101 } else {
3103 "No extra definition matching resource definition \"%s\"",
3104 resource_name);
3105 ok = FALSE;
3106 }
3107 } else {
3109 "Resource section %s does not list extra this resource belongs to.",
3110 sec_name);
3111 ok = FALSE;
3112 }
3113 }
3114 }
3115
3116 section_list_destroy(sec);
3117
3118 return ok;
3119}
3120
3121/**********************************************************************/
3124static bool load_ruleset_terrain(struct section_file *file,
3125 struct rscompat_info *compat)
3126{
3127 size_t nval;
3128 int j;
3129 bool compat_road = FALSE;
3130 bool compat_rail = FALSE;
3131 bool compat_river = FALSE;
3132 const char **res;
3133 const char *filename = secfile_name(file);
3134 const char *text;
3135 bool ok = TRUE;
3136
3137 /* parameters */
3138
3139 terrain_control.ocean_reclaim_requirement_pct
3140 = secfile_lookup_int_default(file, 101,
3141 "parameters.ocean_reclaim_requirement");
3142 terrain_control.land_channel_requirement_pct
3143 = secfile_lookup_int_default(file, 101,
3144 "parameters.land_channel_requirement");
3145 terrain_control.terrain_thaw_requirement_pct
3146 = secfile_lookup_int_default(file, 101,
3147 "parameters.thaw_requirement");
3148 terrain_control.terrain_freeze_requirement_pct
3149 = secfile_lookup_int_default(file, 101,
3150 "parameters.freeze_requirement");
3151 terrain_control.lake_max_size
3153 "parameters.lake_max_size");
3154 terrain_control.min_start_native_area
3156 "parameters.min_start_native_area");
3157 terrain_control.move_fragments
3159 "parameters.move_fragments");
3160 if (terrain_control.move_fragments < 1) {
3162 "\"%s\": move_fragments must be at least 1",
3163 filename);
3164 ok = FALSE;
3165 }
3167 terrain_control.igter_cost
3169 "parameters.igter_cost");
3170 if (terrain_control.igter_cost < 1) {
3172 "\"%s\": igter_cost must be at least 1",
3173 filename);
3174 ok = FALSE;
3175 }
3176 terrain_control.infrapoints = FALSE; /* This will be updated if we find
3177 * an placeable extra. */
3178
3179 terrain_control.pythagorean_diagonal
3181 "parameters.pythagorean_diagonal");
3182
3185 "parameters.ocean_resources");
3186
3187 text = secfile_lookup_str_default(file,
3188 N_("?gui_type:Build Type A Base"),
3189 "extraui.ui_name_base_fortress");
3190 sz_strlcpy(terrain_control.gui_type_base0, text);
3191
3192 text = secfile_lookup_str_default(file,
3193 N_("?gui_type:Build Type B Base"),
3194 "extraui.ui_name_base_airbase");
3195 sz_strlcpy(terrain_control.gui_type_base1, text);
3196
3197 if (ok) {
3198 /* terrain details */
3199
3200 terrain_type_iterate(pterrain) {
3201 const char **slist;
3202 const int i = terrain_index(pterrain);
3203 const char *tsection = &terrain_sections[i * MAX_SECTION_LABEL];
3204 const char *cstr;
3205
3206 sz_strlcpy(pterrain->graphic_str,
3207 secfile_lookup_str(file, "%s.graphic", tsection));
3208 sz_strlcpy(pterrain->graphic_alt,
3209 secfile_lookup_str(file, "%s.graphic_alt", tsection));
3210
3211 pterrain->identifier
3212 = secfile_lookup_str(file, "%s.identifier", tsection)[0];
3213 if ('\0' == pterrain->identifier) {
3215 "\"%s\" [%s] identifier missing value.",
3216 filename, tsection);
3217 ok = FALSE;
3218 break;
3219 }
3220 if (TERRAIN_UNKNOWN_IDENTIFIER == pterrain->identifier) {
3222 "\"%s\" [%s] cannot use '%c' as an identifier;"
3223 " it is reserved for unknown terrain.",
3224 filename, tsection, pterrain->identifier);
3225 ok = FALSE;
3226 break;
3227 }
3228 for (j = T_FIRST; j < i; j++) {
3229 if (pterrain->identifier == terrain_by_number(j)->identifier) {
3231 "\"%s\" [%s] has the same identifier as [%s].",
3232 filename, tsection,
3234 ok = FALSE;
3235 break;
3236 }
3237 }
3238
3239 if (!ok) {
3240 break;
3241 }
3242
3243 cstr = secfile_lookup_str(file, "%s.class", tsection);
3244 pterrain->tclass = terrain_class_by_name(cstr, fc_strcasecmp);
3245 if (!terrain_class_is_valid(pterrain->tclass)) {
3247 "\"%s\": [%s] unknown class \"%s\"",
3248 filename, tsection, cstr);
3249 ok = FALSE;
3250 break;
3251 }
3252
3253 if (!secfile_lookup_int(file, &pterrain->movement_cost,
3254 "%s.movement_cost", tsection)
3255 || !secfile_lookup_int(file, &pterrain->defense_bonus,
3256 "%s.defense_bonus", tsection)) {
3257 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
3258 ok = FALSE;
3259 break;
3260 }
3261
3263 pterrain->output[o]
3264 = secfile_lookup_int_default(file, 0, "%s.%s", tsection,
3267
3268 res = secfile_lookup_str_vec(file, &nval, "%s.resources", tsection);
3269 pterrain->resources = fc_calloc(nval + 1, sizeof(*pterrain->resources));
3270 for (j = 0; j < nval; j++) {
3271 pterrain->resources[j] = lookup_resource(filename, res[j], tsection);
3272 if (pterrain->resources[j] == NULL) {
3273 ok = FALSE;
3274 break;
3275 }
3276 }
3277 pterrain->resources[nval] = NULL;
3278 free(res);
3279 res = NULL;
3280
3281 if (!ok) {
3282 break;
3283 }
3284
3286 pterrain->road_output_incr_pct[o]
3287 = secfile_lookup_int_default(file, 0, "%s.road_%s_incr_pct",
3288 tsection, get_output_identifier(o));
3290
3291 if (!lookup_time(file, &pterrain->base_time, tsection, "base_time",
3292 filename, NULL, &ok)
3293 || !lookup_time(file, &pterrain->road_time, tsection, "road_time",
3294 filename, NULL, &ok)) {
3295 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
3296 ok = FALSE;
3297 break;
3298 }
3299
3300 if (!lookup_terrain(file, "cultivate_result", filename, pterrain,
3301 &pterrain->cultivate_result, FALSE)) {
3302 if (compat->compat_mode) {
3303 if (!lookup_terrain(file, "irrigation_result", filename, pterrain,
3304 &pterrain->cultivate_result, TRUE)) {
3305 ok = FALSE;
3306 break;
3307 }
3308 } else {
3309 ruleset_error(NULL, LOG_ERROR, "%s: No cultivate_result", tsection);
3310 ok = FALSE;
3311 break;
3312 }
3313 }
3314 if (!compat->compat_mode && pterrain->cultivate_result == pterrain) {
3316 "%s: Cultivating result in terrain itself.",
3317 tsection);
3318 ok = FALSE;
3319 break;
3320 }
3321 if (!secfile_lookup_int(file, &pterrain->irrigation_food_incr,
3322 "%s.irrigation_food_incr", tsection)
3323 || !lookup_time(file, &pterrain->irrigation_time,
3324 tsection, "irrigation_time", filename, NULL, &ok)) {
3325 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
3326 ok = FALSE;
3327 break;
3328 }
3329
3330 if (!lookup_terrain(file, "plant_result", filename, pterrain,
3331 &pterrain->plant_result, FALSE)) {
3332 if (compat->compat_mode) {
3333 if (!lookup_terrain(file, "mining_result", filename, pterrain,
3334 &pterrain->plant_result, TRUE)) {
3335 ok = FALSE;
3336 break;
3337 }
3338 } else {
3339 ruleset_error(NULL, LOG_ERROR, "%s: No plant_result", tsection);
3340 ok = FALSE;
3341 break;
3342 }
3343 }
3344 if (!compat->compat_mode && pterrain->plant_result == pterrain) {
3346 "%s: Planting result in terrain itself.",
3347 tsection);
3348 ok = FALSE;
3349 break;
3350 }
3351 if (!secfile_lookup_int(file, &pterrain->mining_shield_incr,
3352 "%s.mining_shield_incr", tsection)
3353 || !lookup_time(file, &pterrain->mining_time,
3354 tsection, "mining_time", filename, NULL, &ok)) {
3355 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
3356 ok = FALSE;
3357 break;
3358 }
3359
3360 if (!lookup_time(file, &pterrain->cultivate_time,
3361 tsection, "cultivate_time", filename, NULL, &ok)) {
3362 if (compat->compat_mode) {
3363 if (pterrain->cultivate_result != pterrain) {
3364 if (pterrain->cultivate_result == NULL && pterrain->irrigation_time != 0) {
3365 /* Make sure cultivate_time is zero when cultivate_result is "no".
3366 * In S3_0 it was legal to have any kind of _time value when _result was "no",
3367 * it was just ignored. We no longer accept that. */
3368 if (compat->log_cb != NULL) {
3369 char buf[512];
3370
3371 fc_snprintf(buf, sizeof(buf),
3372 "Changed %s cultivate_time to zero, as it inconsistently had "
3373 "irrigation_result \"no\" and nonzero irrigation_time.",
3374 tsection);
3375 compat->log_cb(buf);
3376 }
3377 pterrain->cultivate_time = 0;
3378 } else {
3379 pterrain->cultivate_time = pterrain->irrigation_time;
3380 }
3381 pterrain->irrigation_time = 0;
3382 } else {
3383 pterrain->cultivate_time = 0;
3384 pterrain->cultivate_result = NULL;
3385 }
3386 } else {
3388 "%s: Missing cultivate_time", tsection);
3389 ok = FALSE;
3390 break;
3391 }
3392 }
3393 if ((pterrain->cultivate_result != NULL
3394 && pterrain->cultivate_time <= 0)
3395 || (pterrain->cultivate_result == NULL
3396 && pterrain->cultivate_time > 0)) {
3398 "%s: cultivate_result and cultivate_time disagree "
3399 "whether cultivating is enabled", tsection);
3400 ok = FALSE;
3401 break;
3402 }
3403
3404 if (!lookup_time(file, &pterrain->plant_time,
3405 tsection, "plant_time", filename, NULL, &ok)) {
3406 if (compat->compat_mode) {
3407 if (pterrain->plant_result != pterrain) {
3408 if (pterrain->plant_result == NULL && pterrain->mining_time != 0) {
3409 /* Make sure plant_time is zero when plant_result is "no".
3410 * In S3_0 it was legal to have any kind of _time value when _result was "no",
3411 * it was just ignored. We no longer accept that. */
3412 if (compat->log_cb != NULL) {
3413 char buf[512];
3414
3415 fc_snprintf(buf, sizeof(buf),
3416 "Changed %s plant_time to zero, as it inconsistently had "
3417 "mining_result \"no\" and nonzero mining_time.",
3418 tsection);
3419 compat->log_cb(buf);
3420 }
3421 pterrain->plant_time = 0;
3422 } else {
3423 pterrain->plant_time = pterrain->mining_time;
3424 }
3425 pterrain->mining_time = 0;
3426 } else {
3427 pterrain->plant_time = 0;
3428 pterrain->plant_result = NULL;
3429 }
3430 } else {
3431 ruleset_error(NULL, LOG_ERROR, "%s: Missing plant_time", tsection);
3432 ok = FALSE;
3433 break;
3434 }
3435
3436 }
3437 if ((pterrain->plant_result != NULL
3438 && pterrain->plant_time <= 0)
3439 || (pterrain->plant_result == NULL
3440 && pterrain->plant_time > 0)) {
3442 "%s: plant_result and plant_time disagree "
3443 "whether planting is enabled", tsection);
3444 ok = FALSE;
3445 break;
3446 }
3447
3448 if (!lookup_unit_type(file, tsection, "animal",
3449 &pterrain->animal, filename,
3450 rule_name_get(&pterrain->name))) {
3451 ok = FALSE;
3452 break;
3453 }
3454
3455 if (!lookup_terrain(file, "transform_result", filename, pterrain,
3456 &pterrain->transform_result, TRUE)) {
3457 ok = FALSE;
3458 break;
3459 }
3460 if (!lookup_time(file, &pterrain->transform_time,
3461 tsection, "transform_time", filename, NULL, &ok)) {
3462 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
3463 ok = FALSE;
3464 break;
3465 }
3466 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
3467 if (pterrain->transform_time <= 0) {
3468 /* Transform time of zero was documented to disable the transform
3469 * regardless of given transform result in earlier versions, i.e.,
3470 * having them inconsistent was not an error. */
3471 pterrain->transform_result = NULL;
3472 } else if (pterrain->transform_result == NULL) {
3473 pterrain->transform_time = 0;
3474 }
3475 }
3476 if ((pterrain->transform_result != NULL
3477 && pterrain->transform_time <= 0)
3478 || (pterrain->transform_result == NULL
3479 && pterrain->transform_time > 0)) {
3481 "%s: transform_result and transform_time disagree "
3482 "whether transforming is enabled", tsection);
3483 ok = FALSE;
3484 break;
3485 }
3486
3487 pterrain->placing_time = 1; /* default */
3488 lookup_time(file, &pterrain->placing_time,
3489 tsection, "placing_time", filename, NULL, &ok);
3490
3491 pterrain->pillage_time = 1; /* default */
3492 lookup_time(file, &pterrain->pillage_time,
3493 tsection, "pillage_time", filename, NULL, &ok);
3494 pterrain->clean_pollution_time = 3; /* default */
3495 lookup_time(file, &pterrain->clean_pollution_time,
3496 tsection, "clean_pollution_time", filename, NULL, &ok);
3497 pterrain->clean_fallout_time = 3; /* default */
3498 lookup_time(file, &pterrain->clean_fallout_time,
3499 tsection, "clean_fallout_time", filename, NULL, &ok);
3500
3501 if (!lookup_terrain(file, "warmer_wetter_result", filename, pterrain,
3502 &pterrain->warmer_wetter_result, TRUE)
3503 || !lookup_terrain(file, "warmer_drier_result", filename, pterrain,
3504 &pterrain->warmer_drier_result, TRUE)
3505 || !lookup_terrain(file, "cooler_wetter_result", filename, pterrain,
3506 &pterrain->cooler_wetter_result, TRUE)
3507 || !lookup_terrain(file, "cooler_drier_result", filename, pterrain,
3508 &pterrain->cooler_drier_result, TRUE)) {
3509 ok = FALSE;
3510 break;
3511 }
3512
3513 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", tsection);
3514 BV_CLR_ALL(pterrain->flags);
3515 for (j = 0; j < nval; j++) {
3516 const char *sval = slist[j];
3517 enum terrain_flag_id flag
3518 = terrain_flag_id_by_name(sval, fc_strcasecmp);
3519
3520 if (!terrain_flag_id_is_valid(flag)) {
3522 "\"%s\" [%s] has unknown flag \"%s\".",
3523 filename, tsection, sval);
3524 ok = FALSE;
3525 break;
3526 } else {
3527 BV_SET(pterrain->flags, flag);
3528 }
3529 }
3530 free(slist);
3531
3532 if (!ok) {
3533 break;
3534 }
3535
3536 {
3537 enum mapgen_terrain_property mtp;
3538 for (mtp = mapgen_terrain_property_begin();
3539 mtp != mapgen_terrain_property_end();
3540 mtp = mapgen_terrain_property_next(mtp)) {
3541 pterrain->property[mtp]
3542 = secfile_lookup_int_default(file, 0, "%s.property_%s", tsection,
3543 mapgen_terrain_property_name(mtp));
3544 }
3545 }
3546
3547 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", tsection);
3548 BV_CLR_ALL(pterrain->native_to);
3549 for (j = 0; j < nval; j++) {
3550 struct unit_class *class = unit_class_by_rule_name(slist[j]);
3551
3552 if (!class) {
3554 "\"%s\" [%s] is native to unknown unit class \"%s\".",
3555 filename, tsection, slist[j]);
3556 ok = FALSE;
3557 break;
3558 } else {
3559 BV_SET(pterrain->native_to, uclass_index(class));
3560 }
3561 }
3562 free(slist);
3563
3564 if (!ok) {
3565 break;
3566 }
3567
3568 /* get terrain color */
3569 {
3570 fc_assert_ret_val(pterrain->rgb == NULL, FALSE);
3571 if (!rgbcolor_load(file, &pterrain->rgb, "%s.color", tsection)) {
3573 "Missing terrain color definition: %s",
3574 secfile_error());
3575 ok = FALSE;
3576 break;
3577 }
3578 }
3579
3580 pterrain->helptext = lookup_strvec(file, tsection, "helptext");
3582 }
3583
3584 if (ok) {
3585 /* extra details */
3586 extra_type_iterate(pextra) {
3587 BV_CLR_ALL(pextra->conflicts);
3589
3590 extra_type_iterate(pextra) {
3591 const char *section = &extra_sections[extra_index(pextra) * MAX_SECTION_LABEL];
3592 const char **slist;
3593 struct requirement_vector *reqs;
3594 const char *catname;
3595 int cj;
3596 enum extra_cause cause;
3597 enum extra_rmcause rmcause;
3598 const char *eus_name;
3599 const char *vis_req_name;
3600 const struct advance *vis_req;
3601
3602 catname = secfile_lookup_str(file, "%s.category", section);
3603 if (catname == NULL) {
3605 "\"%s\" extra \"%s\" has no category.",
3606 filename, extra_rule_name(pextra));
3607 ok = FALSE;
3608 break;
3609 }
3610 pextra->category = extra_category_by_name(catname, fc_strcasecmp);
3611 if (!extra_category_is_valid(pextra->category)) {
3613 "\"%s\" extra \"%s\" has invalid category \"%s\".",
3614 filename, extra_rule_name(pextra), catname);
3615 ok = FALSE;
3616 break;
3617 }
3618
3619 slist = secfile_lookup_str_vec(file, &nval, "%s.causes", section);
3620 pextra->causes = 0;
3621 for (cj = 0; cj < nval; cj++) {
3622 const char *sval = slist[cj];
3623
3624 cause = extra_cause_by_name(sval, fc_strcasecmp);
3625
3626 if (!extra_cause_is_valid(cause)) {
3628 "\"%s\" extra \"%s\": unknown cause \"%s\".",
3629 filename, extra_rule_name(pextra), sval);
3630 ok = FALSE;
3631 break;
3632 } else {
3633 pextra->causes |= (1 << cause);
3634 extra_to_caused_by_list(pextra, cause);
3635 }
3636 }
3637
3638 if (pextra->causes == 0) {
3639 /* Extras that do not have any causes added to EC_NONE list */
3641 }
3642
3643 if (!is_extra_caused_by(pextra, EC_BASE)
3644 && !is_extra_caused_by(pextra, EC_ROAD)
3645 && !is_extra_caused_by(pextra, EC_RESOURCE)) {
3646 /* Not a base, road, nor resource, so special */
3647 pextra->data.special_idx = extra_type_list_size(extra_type_list_by_cause(EC_SPECIAL));
3649 }
3650
3651 free(slist);
3652
3653 slist = secfile_lookup_str_vec(file, &nval, "%s.rmcauses", section);
3654 pextra->rmcauses = 0;
3655 for (j = 0; j < nval; j++) {
3656 const char *sval = slist[j];
3657
3658 rmcause = extra_rmcause_by_name(sval, fc_strcasecmp);
3659
3660 if (!extra_rmcause_is_valid(rmcause)) {
3662 "\"%s\" extra \"%s\": unknown rmcause \"%s\".",
3663 filename, extra_rule_name(pextra), sval);
3664 ok = FALSE;
3665 break;
3666 } else {
3667 pextra->rmcauses |= (1 << rmcause);
3668 extra_to_removed_by_list(pextra, rmcause);
3669 }
3670 }
3671
3672 free(slist);
3673
3674 sz_strlcpy(pextra->activity_gfx,
3676 "%s.activity_gfx", section));
3677 sz_strlcpy(pextra->act_gfx_alt,
3679 "%s.act_gfx_alt", section));
3680 sz_strlcpy(pextra->act_gfx_alt2,
3682 "%s.act_gfx_alt2", section));
3683 sz_strlcpy(pextra->rmact_gfx,
3685 "%s.rmact_gfx", section));
3686 sz_strlcpy(pextra->rmact_gfx_alt,
3688 "%s.rmact_gfx_alt", section));
3689 sz_strlcpy(pextra->graphic_str,
3690 secfile_lookup_str_default(file, "-", "%s.graphic", section));
3691 sz_strlcpy(pextra->graphic_alt,
3693 "%s.graphic_alt", section));
3694
3695 reqs = lookup_req_list(file, compat, section, "reqs", extra_rule_name(pextra));
3696 if (reqs == NULL) {
3697 ok = FALSE;
3698 break;
3699 }
3700 requirement_vector_copy(&pextra->reqs, reqs);
3701
3702 reqs = lookup_req_list(file, compat, section, "rmreqs", extra_rule_name(pextra));
3703 if (reqs == NULL) {
3704 ok = FALSE;
3705 break;
3706 }
3707 requirement_vector_copy(&pextra->rmreqs, reqs);
3708
3709 reqs = lookup_req_list(file, compat, section, "appearance_reqs", extra_rule_name(pextra));
3710 if (reqs == NULL) {
3711 ok = FALSE;
3712 break;
3713 }
3714 requirement_vector_copy(&pextra->appearance_reqs, reqs);
3715
3716 reqs = lookup_req_list(file, compat, section, "disappearance_reqs", extra_rule_name(pextra));
3717 if (reqs == NULL) {
3718 ok = FALSE;
3719 break;
3720 }
3721 requirement_vector_copy(&pextra->disappearance_reqs, reqs);
3722
3723 pextra->buildable = secfile_lookup_bool_default(file,
3725 "%s.buildable", section);
3726 pextra->generated = secfile_lookup_bool_default(file, TRUE,
3727 "%s.generated", section);
3728
3729 pextra->build_time = 0; /* default */
3730 lookup_time(file, &pextra->build_time, section, "build_time",
3731 filename, extra_rule_name(pextra), &ok);
3732 pextra->build_time_factor = secfile_lookup_int_default(file, 1,
3733 "%s.build_time_factor", section);
3734 pextra->removal_time = 0; /* default */
3735 lookup_time(file, &pextra->removal_time, section, "removal_time",
3736 filename, extra_rule_name(pextra), &ok);
3737 pextra->removal_time_factor = secfile_lookup_int_default(file, 1,
3738 "%s.removal_time_factor", section);
3739 pextra->infracost = secfile_lookup_int_default(file, 0,
3740 "%s.infracost", section);
3741 if (pextra->infracost > 0) {
3742 terrain_control.infrapoints = TRUE;
3743 }
3744
3745 pextra->defense_bonus = secfile_lookup_int_default(file, 0,
3746 "%s.defense_bonus",
3747 section);
3748 if (pextra->defense_bonus != 0) {
3749 if (extra_has_flag(pextra, EF_NATURAL_DEFENSE)) {
3751 } else {
3753 }
3754 }
3755
3756 eus_name = secfile_lookup_str_default(file, "Normal", "%s.unit_seen", section);
3757 pextra->eus = extra_unit_seen_type_by_name(eus_name, fc_strcasecmp);
3758 if (!extra_unit_seen_type_is_valid(pextra->eus)) {
3760 "\"%s\" extra \"%s\" has illegal unit_seen value \"%s\".",
3761 filename, extra_rule_name(pextra), eus_name);
3762 ok = FALSE;
3763 break;
3764 }
3765 if (pextra->eus == EUS_HIDDEN) {
3766 extra_type_list_append(extra_type_list_of_unit_hiders(), pextra);
3767 }
3768
3769 pextra->appearance_chance = secfile_lookup_int_default(file, RS_DEFAULT_EXTRA_APPEARANCE,
3770 "%s.appearance_chance",
3771 section);
3772 pextra->disappearance_chance = secfile_lookup_int_default(file,
3774 "%s.disappearance_chance",
3775 section);
3776
3777 slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", section);
3778 BV_CLR_ALL(pextra->native_to);
3779 for (j = 0; j < nval; j++) {
3780 struct unit_class *uclass = unit_class_by_rule_name(slist[j]);
3781
3782 if (uclass == NULL) {
3784 "\"%s\" extra \"%s\" is native to unknown unit class \"%s\".",
3785 filename, extra_rule_name(pextra), slist[j]);
3786 ok = FALSE;
3787 break;
3788 } else {
3789 BV_SET(pextra->native_to, uclass_index(uclass));
3790 }
3791 }
3792 free(slist);
3793
3794 if (!ok) {
3795 break;
3796 }
3797
3798 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
3799 BV_CLR_ALL(pextra->flags);
3800 for (j = 0; j < nval; j++) {
3801 const char *sval = slist[j];
3802 enum extra_flag_id flag = extra_flag_id_by_name(sval, fc_strcasecmp);
3803
3804 if (!extra_flag_id_is_valid(flag)) {
3806 "\"%s\" extra \"%s\": unknown flag \"%s\".",
3807 filename, extra_rule_name(pextra), sval);
3808 ok = FALSE;
3809 break;
3810 } else {
3811 BV_SET(pextra->flags, flag);
3812 }
3813 }
3814 free(slist);
3815
3816 if (extra_has_flag(pextra, EF_NOT_AGGRESSIVE)) {
3818 }
3819
3820 if (!ok) {
3821 break;
3822 }
3823
3824 slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
3825 for (j = 0; j < nval; j++) {
3826 const char *sval = slist[j];
3827 struct extra_type *pextra2 = extra_type_by_rule_name(sval);
3828
3829 if (pextra2 == NULL) {
3831 "\"%s\" extra \"%s\": unknown conflict extra \"%s\".",
3832 filename, extra_rule_name(pextra), sval);
3833 ok = FALSE;
3834 break;
3835 } else {
3836 BV_SET(pextra->conflicts, extra_index(pextra2));
3837 BV_SET(pextra2->conflicts, extra_index(pextra));
3838 }
3839 }
3840
3841 free(slist);
3842
3843 if (!ok) {
3844 break;
3845 }
3846
3847 slist = secfile_lookup_str_vec(file, &nval, "%s.hidden_by", section);
3848 BV_CLR_ALL(pextra->hidden_by);
3849 for (j = 0; j < nval; j++) {
3850 const char *sval = slist[j];
3851 const struct extra_type *top = extra_type_by_rule_name(sval);
3852
3853 if (top == NULL) {
3855 "\"%s\" extra \"%s\" hidden by unknown extra \"%s\".",
3856 filename, extra_rule_name(pextra), sval);
3857 ok = FALSE;
3858 break;
3859 } else {
3860 BV_SET(pextra->hidden_by, extra_index(top));
3861 }
3862 }
3863 free(slist);
3864
3865 if (!ok) {
3866 break;
3867 }
3868
3869 slist = secfile_lookup_str_vec(file, &nval, "%s.bridged_over", section);
3870 BV_CLR_ALL(pextra->bridged_over);
3871 for (j = 0; j < nval; j++) {
3872 const char *sval = slist[j];
3873 const struct extra_type *top = extra_type_by_rule_name(sval);
3874
3875 if (top == NULL) {
3877 "\"%s\" extra \"%s\" bridged over unknown extra \"%s\".",
3878 filename, extra_rule_name(pextra), sval);
3879 ok = FALSE;
3880 break;
3881 } else {
3882 BV_SET(pextra->bridged_over, extra_index(top));
3883 }
3884 }
3885 free(slist);
3886
3887 if (!ok) {
3888 break;
3889 }
3890
3891 vis_req_name = secfile_lookup_str_default(file, "None",
3892 "%s.visibility_req", section);
3893 vis_req = advance_by_rule_name(vis_req_name);
3894
3895 if (vis_req == NULL) {
3897 "\"%s\" %s: unknown visibility_req %s.",
3898 filename, section, vis_req_name);
3899 ok = FALSE;
3900 break;
3901 }
3902
3903 pextra->visibility_req = advance_number(vis_req);
3904
3905 pextra->helptext = lookup_strvec(file, section, "helptext");
3906
3909 }
3910
3911 if (ok) {
3912 int i = 0;
3913 /* resource details */
3914
3915 extra_type_by_cause_iterate(EC_RESOURCE, presource) {
3916 char identifier[MAX_LEN_NAME];
3917 const char *rsection = &resource_sections[i * MAX_SECTION_LABEL];
3918
3919 if (!presource->data.resource) {
3921 "\"%s\" extra \"%s\" has \"Resource\" cause but no "
3922 "corresponding [resource_*] section",
3923 filename, extra_rule_name(presource));
3924 ok = FALSE;
3925 break;
3926 }
3927
3929 presource->data.resource->output[o] =
3930 secfile_lookup_int_default(file, 0, "%s.%s", rsection,
3933
3934 sz_strlcpy(identifier,
3935 secfile_lookup_str(file, "%s.identifier", rsection));
3936 presource->data.resource->id_old_save = identifier[0];
3937 if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
3939 "\"%s\" [%s] identifier missing value.",
3940 filename, rsection);
3941 ok = FALSE;
3942 break;
3943 }
3944 if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
3946 "\"%s\" [%s] cannot use '%c' as an identifier;"
3947 " it is reserved.",
3948 filename, rsection, presource->data.resource->id_old_save);
3949 ok = FALSE;
3950 break;
3951 }
3952
3953 if (!ok) {
3954 break;
3955 }
3956
3957 i++;
3959
3960 for (j = 0; ok && j < game.control.num_resource_types; j++) {
3961 const char *section = &resource_sections[j * MAX_SECTION_LABEL];
3962 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
3963 struct extra_type *pextra = extra_type_by_rule_name(extra_name);
3964
3965 if (!is_extra_caused_by(pextra, EC_RESOURCE)) {
3967 "\"%s\" resource section [%s]: extra \"%s\" does not "
3968 "have \"Resource\" in its causes",
3969 filename, section, extra_name);
3970 ok = FALSE;
3971 }
3972 }
3973 }
3974
3975 if (ok) {
3976 /* This can't be part of previous loop as we don't want random data from previous
3977 * ruleset to play havoc on us when we have only some resource identifiers loaded
3978 * from the new ruleset. */
3979 extra_type_by_cause_iterate(EC_RESOURCE, pres) {
3980 extra_type_by_cause_iterate(EC_RESOURCE, pres2) {
3981 if (pres->data.resource->id_old_save == pres2->data.resource->id_old_save
3982 && pres != pres2) {
3984 "\"%s\" [%s] has the same identifier as [%s].",
3985 filename,
3986 extra_rule_name(pres),
3987 extra_rule_name(pres2));
3988 ok = FALSE;
3989 break;
3990 }
3992
3993 if (!ok) {
3994 break;
3995 }
3997 }
3998
3999 if (ok) {
4000 /* base details */
4001 extra_type_by_cause_iterate(EC_BASE, pextra) {
4002 struct base_type *pbase = extra_base_get(pextra);
4003 const char *section;
4004 const char *gui_str;
4005
4006 if (!pbase) {
4008 "\"%s\" extra \"%s\" has \"Base\" cause but no "
4009 "corresponding [base_*] section",
4010 filename, extra_rule_name(pextra));
4011 ok = FALSE;
4012 break;
4013 }
4015
4016 gui_str = secfile_lookup_str(file, "%s.gui_type", section);
4017 pbase->gui_type = base_gui_type_by_name(gui_str, fc_strcasecmp);
4018 if (!base_gui_type_is_valid(pbase->gui_type)) {
4020 "\"%s\" base \"%s\": unknown gui_type \"%s\".",
4021 filename, extra_rule_name(pextra), gui_str);
4022 ok = FALSE;
4023 break;
4024 }
4025
4026 pbase->border_sq = secfile_lookup_int_default(file, -1, "%s.border_sq",
4027 section);
4029 "%s.vision_main_sq",
4030 section);
4032 "%s.vision_invis_sq",
4033 section);
4035 "%s.vision_subs_sq",
4036 section);
4037
4038 if (compat->compat_mode) {
4039 int bj;
4040 const char **slist;
4041
4042 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4043 for (bj = 0; bj < nval; bj++) {
4044 const char *sval = slist[bj];
4045
4046 if (fc_strcasecmp("NoAggressive", sval)) {
4048 "\"%s\" base \"%s\": unknown flag \"%s\".",
4049 filename, extra_rule_name(pextra), sval);
4050 ok = FALSE;
4051 break;
4052 } else {
4053 if (!BV_ISSET(pextra->flags, EF_NOT_AGGRESSIVE)) {
4054 /* We would not be adding extra to caused_by_list second time. */
4055 BV_SET(pextra->flags, EF_NOT_AGGRESSIVE);
4057 }
4058 }
4059 }
4060
4061 free(slist);
4062 }
4063
4064 if (!ok) {
4065 break;
4066 }
4067
4068 if (territory_claiming_base(pbase)) {
4069 extra_type_list_append(extra_type_list_of_terr_claimers(), pextra);
4070
4071 extra_type_by_cause_iterate(EC_BASE, pextra2) {
4072 struct base_type *pbase2;
4073
4074 if (pextra == pextra2) {
4075 /* End of the fully initialized bases iteration. */
4076 break;
4077 }
4078
4079 pbase2 = extra_base_get(pextra2);
4080 if (territory_claiming_base(pbase2)) {
4081 BV_SET(pextra->conflicts, extra_index(pextra2));
4082 BV_SET(pextra2->conflicts, extra_index(pextra));
4083 }
4085 }
4087
4088 for (j = 0; ok && j < game.control.num_base_types; j++) {
4089 const char *section = &base_sections[j * MAX_SECTION_LABEL];
4090 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4091 struct extra_type *pextra = extra_type_by_rule_name(extra_name);
4092
4093 if (!is_extra_caused_by(pextra, EC_BASE)) {
4095 "\"%s\" base section [%s]: extra \"%s\" does not have "
4096 "\"Base\" in its causes",
4097 filename, section, extra_name);
4098 ok = FALSE;
4099 }
4100 }
4101 }
4102
4103 if (ok) {
4104 bv_extras compat_bridged;
4105
4106 if (compat->compat_mode) {
4107 BV_CLR_ALL(compat_bridged);
4108 extra_type_by_cause_iterate(EC_ROAD, pextra) {
4109 struct road_type *proad = extra_road_get(pextra);
4110 const char *section = &road_sections[road_number(proad) * MAX_SECTION_LABEL];
4111 const char **slist;
4112
4113 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4114
4115 for (j = 0; j < nval; j++) {
4116 if (!fc_strcasecmp("PreventsOtherRoads", slist[j])) {
4117 BV_SET(compat_bridged, pextra->id);
4118 }
4119 }
4121 }
4122 extra_type_by_cause_iterate(EC_ROAD, pextra) {
4123 struct road_type *proad = extra_road_get(pextra);
4124 const char *section;
4125 const char **slist;
4126 const char *special;
4127 const char *modestr;
4128 struct requirement_vector *reqs;
4129 const char *gui_str;
4130
4131 if (!proad) {
4133 "\"%s\" extra \"%s\" has \"Road\" cause but no "
4134 "corresponding [road_*] section",
4135 filename, extra_rule_name(pextra));
4136 ok = FALSE;
4137 break;
4138 }
4140
4141 reqs = lookup_req_list(file, compat, section, "first_reqs", extra_rule_name(pextra));
4142 if (reqs == NULL) {
4143 ok = FALSE;
4144 break;
4145 }
4146 requirement_vector_copy(&proad->first_reqs, reqs);
4147
4148 if (!secfile_lookup_int(file, &proad->move_cost,
4149 "%s.move_cost", section)) {
4150 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4151 ok = FALSE;
4152 break;
4153 }
4154
4155 modestr = secfile_lookup_str_default(file, "FastAlways", "%s.move_mode",
4156 section);
4157 proad->move_mode = road_move_mode_by_name(modestr, fc_strcasecmp);
4158 if (!road_move_mode_is_valid(proad->move_mode)) {
4160 "Illegal move_mode \"%s\" for road \"%s\"",
4161 modestr, extra_rule_name(pextra));
4162 ok = FALSE;
4163 break;
4164 }
4165
4167 proad->tile_incr_const[o] =
4168 secfile_lookup_int_default(file, 0, "%s.%s_incr_const",
4170 proad->tile_incr[o] =
4171 secfile_lookup_int_default(file, 0, "%s.%s_incr",
4173 proad->tile_bonus[o] =
4174 secfile_lookup_int_default(file, 0, "%s.%s_bonus",
4177
4178 special = secfile_lookup_str_default(file, "None", "%s.compat_special", section);
4179 if (!fc_strcasecmp(special, "Road")) {
4180 if (compat_road) {
4182 "Multiple roads marked as compatibility \"Road\"");
4183 ok = FALSE;
4184 }
4185 compat_road = TRUE;
4186 proad->compat = ROCO_ROAD;
4187 } else if (!fc_strcasecmp(special, "Railroad")) {
4188 if (compat_rail) {
4190 "Multiple roads marked as compatibility \"Railroad\"");
4191 ok = FALSE;
4192 }
4193 compat_rail = TRUE;
4194 proad->compat = ROCO_RAILROAD;
4195 } else if (!fc_strcasecmp(special, "River")) {
4196 if (compat_river) {
4198 "Multiple roads marked as compatibility \"River\"");
4199 ok = FALSE;
4200 }
4201 compat_river = TRUE;
4202 proad->compat = ROCO_RIVER;
4203 } else if (!fc_strcasecmp(special, "None")) {
4204 proad->compat = ROCO_NONE;
4205 } else {
4207 "Illegal compatibility special \"%s\" for road %s",
4208 special, extra_rule_name(pextra));
4209 ok = FALSE;
4210 }
4211
4212 if (!ok) {
4213 break;
4214 }
4215
4216 gui_str = secfile_lookup_str_default(file, NULL, "%s.gui_type", section);
4217 if (gui_str == NULL) {
4218 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
4219 proad->gui_type = rscompat_road_gui_type_3_1(proad);
4220 } else {
4222 "\"%s\" road \"%s\": no gui_type.",
4223 filename, extra_rule_name(pextra));
4224 ok = FALSE;
4225 break;
4226 }
4227 } else {
4228 proad->gui_type = road_gui_type_by_name(gui_str, fc_strcasecmp);
4229 if (!road_gui_type_is_valid(proad->gui_type)) {
4231 "\"%s\" road \"%s\": unknown gui_type \"%s\".",
4232 filename, extra_rule_name(pextra), gui_str);
4233 ok = FALSE;
4234 break;
4235 }
4236 }
4237
4238 slist = secfile_lookup_str_vec(file, &nval, "%s.integrates", section);
4239 BV_CLR_ALL(proad->integrates);
4240 for (j = 0; j < nval; j++) {
4241 const char *sval = slist[j];
4242 struct extra_type *textra = extra_type_by_rule_name(sval);
4243 struct road_type *top = NULL;
4244
4245 if (textra != NULL) {
4246 top = extra_road_get(textra);
4247 }
4248
4249 if (top == NULL) {
4251 "\"%s\" road \"%s\" integrates with unknown road \"%s\".",
4252 filename, extra_rule_name(pextra), sval);
4253 ok = FALSE;
4254 break;
4255 } else {
4256 BV_SET(proad->integrates, road_number(top));
4257 }
4258 }
4259 free(slist);
4260
4261 if (!ok) {
4262 break;
4263 }
4264
4265 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
4266 BV_CLR_ALL(proad->flags);
4267 for (j = 0; j < nval; j++) {
4268 const char *sval = slist[j];
4269
4270 if (compat->compat_mode && !fc_strcasecmp("PreventsOtherRoads", sval)) {
4271 /* Nothing to do here */
4272 } else if (compat->compat_mode && !fc_strcasecmp("RequiresBridge", sval)) {
4273 extra_type_iterate(pbridged) {
4274 if (BV_ISSET(compat_bridged, pbridged->id)) {
4275 BV_SET(pextra->bridged_over, pbridged->id);
4276 }
4278 } else {
4279 enum road_flag_id flag = road_flag_id_by_name(sval, fc_strcasecmp);
4280
4281 if (!road_flag_id_is_valid(flag)) {
4283 "\"%s\" road \"%s\": unknown flag \"%s\".",
4284 filename, extra_rule_name(pextra), sval);
4285 ok = FALSE;
4286 break;
4287 } else {
4288 BV_SET(proad->flags, flag);
4289 }
4290 }
4291 }
4292 free(slist);
4293
4294 if (!ok) {
4295 break;
4296 }
4298
4299 for (j = 0; ok && j < game.control.num_road_types; j++) {
4300 const char *section = &road_sections[j * MAX_SECTION_LABEL];
4301 const char *extra_name = secfile_lookup_str(file, "%s.extra", section);
4302 struct extra_type *pextra = extra_type_by_rule_name(extra_name);
4303
4304 if (!is_extra_caused_by(pextra, EC_ROAD)) {
4306 "\"%s\" road section [%s]: extra \"%s\" does not have "
4307 "\"Road\" in its causes",
4308 filename, section, extra_name);
4309 ok = FALSE;
4310 }
4311 }
4312 }
4313
4314 if (ok) {
4315 extra_type_iterate(pextra) {
4316 pextra->bridged = extra_type_list_new();
4317 extra_type_iterate(pbridged) {
4318 if (BV_ISSET(pextra->bridged_over, pbridged->id)) {
4319 extra_type_list_append(pextra->bridged, pbridged);
4320 }
4323 }
4324
4325 if (ok) {
4327 }
4328
4329 return ok;
4330}
4331
4332/**********************************************************************/
4336static bool load_government_names(struct section_file *file,
4337 struct rscompat_info *compat)
4338{
4339 int nval = 0;
4340 struct section_list *sec;
4341 const char *filename = secfile_name(file);
4342 bool ok = TRUE;
4343
4344 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4345 return FALSE;
4346 }
4347
4348 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4349 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4350
4352 if (NULL == sec || 0 == (nval = section_list_size(sec))) {
4353 ruleset_error(NULL, LOG_ERROR, "\"%s\": No governments?!?", filename);
4354 ok = FALSE;
4355 } else if (nval > G_LAST) {
4357 "\"%s\": Too many governments (%d, max %d)",
4358 filename, nval, G_LAST);
4359 ok = FALSE;
4360 }
4361
4362 if (ok) {
4363 governments_alloc(nval);
4364
4365 /* Government names are needed early so that get_government_by_name will
4366 * work. */
4367 governments_iterate(gov) {
4368 const char *sec_name =
4369 section_name(section_list_get(sec, government_index(gov)));
4370
4371 if (!ruleset_load_names(&gov->name, NULL, file, sec_name)) {
4372 ok = FALSE;
4373 break;
4374 }
4376 }
4377
4378 section_list_destroy(sec);
4379
4380 if (ok) {
4382 nval = (NULL != sec ? section_list_size(sec) : 0);
4383
4384 if (nval > MAX_NUM_MULTIPLIERS) {
4386 "\"%s\": Too many multipliers (%d, max %d)",
4387 filename, nval, MAX_NUM_MULTIPLIERS);
4388
4389 ok = FALSE;
4390 } else {
4392 }
4393
4394 if (ok) {
4395 multipliers_iterate(pmul) {
4396 const char *sec_name =
4397 section_name(section_list_get(sec, multiplier_index(pmul)));
4398
4399 if (!ruleset_load_names(&pmul->name, NULL, file, sec_name)) {
4401 "\"%s\": Cannot load multiplier names",
4402 filename);
4403 ok = FALSE;
4404 break;
4405 }
4407 }
4408 }
4409
4410 section_list_destroy(sec);
4411
4412 return ok;
4413}
4414
4415/**********************************************************************/
4419 struct rscompat_info *compat)
4420{
4421 struct section_list *sec;
4422 const char *filename = secfile_name(file);
4423 bool ok = TRUE;
4424
4426
4428 = lookup_government(file, "governments.during_revolution", filename, NULL);
4429 if (game.government_during_revolution == NULL) {
4430 ok = FALSE;
4431 }
4432
4433 if (ok) {
4436
4437 /* easy ones: */
4439 const int i = government_index(g);
4440 const char *sec_name = section_name(section_list_get(sec, i));
4441 struct requirement_vector *reqs =
4442 lookup_req_list(file, compat, sec_name, "reqs", government_rule_name(g));
4443
4444 if (reqs == NULL) {
4445 ok = FALSE;
4446 break;
4447 }
4448
4449 if (NULL != secfile_entry_lookup(file, "%s.ai_better", sec_name)) {
4450 char entry[100];
4451
4452 fc_snprintf(entry, sizeof(entry), "%s.ai_better", sec_name);
4453 g->ai.better = lookup_government(file, entry, filename, NULL);
4454 if (g->ai.better == NULL) {
4455 ok = FALSE;
4456 break;
4457 }
4458 } else {
4459 g->ai.better = NULL;
4460 }
4461 requirement_vector_copy(&g->reqs, reqs);
4462
4463 sz_strlcpy(g->graphic_str,
4464 secfile_lookup_str(file, "%s.graphic", sec_name));
4465 sz_strlcpy(g->graphic_alt,
4466 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
4467
4468 g->helptext = lookup_strvec(file, sec_name, "helptext");
4470 }
4471
4472
4473 if (ok) {
4474 /* titles */
4476 const char *sec_name =
4477 section_name(section_list_get(sec, government_index(g)));
4478 const char *male, *female;
4479
4480 if (!(male = secfile_lookup_str(file, "%s.ruler_male_title", sec_name))
4481 || !(female = secfile_lookup_str(file, "%s.ruler_female_title",
4482 sec_name))) {
4484 "Lack of default ruler titles for "
4485 "government \"%s\" (nb %d): %s",
4487 secfile_error());
4488 ok = FALSE;
4489 break;
4490 } else if (NULL == government_ruler_title_new(g, NULL, male, female)) {
4492 "Lack of default ruler titles for "
4493 "government \"%s\" (nb %d).",
4495 ok = FALSE;
4496 break;
4497 }
4499 }
4500
4501 section_list_destroy(sec);
4502
4503 if (ok) {
4505 multipliers_iterate(pmul) {
4506 int id = multiplier_index(pmul);
4507 const char *sec_name = section_name(section_list_get(sec, id));
4508 struct requirement_vector *reqs;
4509
4510 if (!secfile_lookup_int(file, &pmul->start, "%s.start", sec_name)) {
4511 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4512 ok = FALSE;
4513 break;
4514 }
4515 if (!secfile_lookup_int(file, &pmul->stop, "%s.stop", sec_name)) {
4516 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4517 ok = FALSE;
4518 break;
4519 }
4520 if (pmul->stop <= pmul->start) {
4522 "Multiplier \"%s\" stop (%d) must be greater "
4523 "than start (%d)", multiplier_rule_name(pmul),
4524 pmul->stop, pmul->start);
4525 ok = FALSE;
4526 break;
4527 }
4528 if (!secfile_lookup_int(file, &pmul->step, "%s.step", sec_name)) {
4529 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4530 ok = FALSE;
4531 break;
4532 }
4533 if (((pmul->stop - pmul->start) % pmul->step) != 0) {
4535 "Multiplier \"%s\" step (%d) does not fit "
4536 "exactly into interval start-stop (%d to %d)",
4537 multiplier_rule_name(pmul), pmul->step,
4538 pmul->start, pmul->stop);
4539 ok = FALSE;
4540 break;
4541 }
4542 if (!secfile_lookup_int(file, &pmul->def, "%s.default", sec_name)) {
4543 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4544 ok = FALSE;
4545 break;
4546 }
4547 if (pmul->def < pmul->start || pmul->def > pmul->stop) {
4549 "Multiplier \"%s\" default (%d) not within "
4550 "legal range (%d to %d)", multiplier_rule_name(pmul),
4551 pmul->def, pmul->start, pmul->stop);
4552 ok = FALSE;
4553 break;
4554 }
4555 if (((pmul->def - pmul->start) % pmul->step) != 0) {
4557 "Multiplier \"%s\" default (%d) not legal "
4558 "with respect to step size %d",
4559 multiplier_rule_name(pmul), pmul->def, pmul->step);
4560 ok = FALSE;
4561 break;
4562 }
4563 pmul->offset = secfile_lookup_int_default(file, 0,
4564 "%s.offset", sec_name);
4565 pmul->factor = secfile_lookup_int_default(file, 100,
4566 "%s.factor", sec_name);
4567 if (pmul->factor == 0) {
4569 "Multiplier \"%s\" scaling factor must "
4570 "not be zero", multiplier_rule_name(pmul));
4571 ok = FALSE;
4572 break;
4573 }
4574
4575 pmul->minimum_turns = secfile_lookup_int_default(file, 0,
4576 "%s.minimum_turns",
4577 sec_name);
4578
4579 reqs = lookup_req_list(file, compat, sec_name, "reqs",
4580 multiplier_rule_name(pmul));
4581 if (reqs == NULL) {
4582 ok = FALSE;
4583 break;
4584 }
4585 requirement_vector_copy(&pmul->reqs, reqs);
4586
4587 pmul->helptext = lookup_strvec(file, sec_name, "helptext");
4589 section_list_destroy(sec);
4590 }
4591
4592 if (ok) {
4594 }
4595
4596 return ok;
4597}
4598
4599/**********************************************************************/
4610static void send_ruleset_control(struct conn_list *dest)
4611{
4612 int desc_left = game.control.desc_length32;
4613 int idx = 0;
4614
4617
4618 if (game.ruleset_summary != NULL) {
4619 struct packet_ruleset_summary summary;
4620
4622
4623 lsend_packet_ruleset_summary(dest, &summary);
4624 }
4625
4626 while (desc_left > 0) {
4628 int this_len = desc_left;
4629
4630 if (this_len > MAX_LEN_CONTENT - 21) {
4631 this_len = MAX_LEN_CONTENT - 1;
4632 }
4633
4634 part.text[this_len] = '\0';
4635
4636 strncpy(part.text, &game.ruleset_description[idx], this_len);
4637 idx += this_len;
4638 desc_left -= this_len;
4639
4641 }
4642}
4643
4644/**********************************************************************/
4649static const char *check_leader_names(struct nation_type *pnation)
4650{
4651 nation_leader_list_iterate(nation_leaders(pnation), pleader) {
4652 const char *name = nation_leader_name(pleader);
4653
4654 nation_leader_list_iterate(nation_leaders(pnation), prev_leader) {
4655 if (prev_leader == pleader) {
4656 break;
4657 } else if (0 == fc_strcasecmp(name, nation_leader_name(prev_leader))) {
4658 return name;
4659 }
4662 return NULL;
4663}
4664
4665/**********************************************************************/
4669static bool load_nation_names(struct section_file *file,
4670 struct rscompat_info *compat)
4671{
4672 struct section_list *sec;
4673 int j;
4674 bool ok = TRUE;
4675 const char *filename = secfile_name(file);
4676
4677 if (!rscompat_check_cap_and_version(file, filename, compat)) {
4678 return FALSE;
4679 }
4680
4681 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
4682 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
4683
4685 if (NULL == sec) {
4687 "No available nations in this ruleset!");
4688 ok = FALSE;
4689 } else if (section_list_size(sec) > MAX_NUM_NATIONS) {
4691 "Too many nations (max %d, we have %d)!",
4692 MAX_NUM_NATIONS, section_list_size(sec));
4693 ok = FALSE;
4694 } else {
4695 game.control.nation_count = section_list_size(sec);
4697
4698 nations_iterate(pl) {
4699 const int i = nation_index(pl);
4700 const char *sec_name = section_name(section_list_get(sec, i));
4701 const char *domain = secfile_lookup_str_default(file, NULL,
4702 "%s.translation_domain", sec_name);
4703 const char *noun_plural = secfile_lookup_str(file,
4704 "%s.plural", sec_name);
4705
4706
4707 if (domain == NULL) {
4708 domain = "freeciv-nations";
4709 }
4710
4711 if (!strcmp("freeciv-core", domain)) {
4712 pl->translation_domain = NULL;
4713 } else if (compat->compat_mode && compat->version < RSFORMAT_3_1
4714 && !strcmp("freeciv", domain)) {
4715 pl->translation_domain = NULL;
4716 } else if (!strcmp("freeciv-nations", domain)) {
4717 pl->translation_domain = fc_strdup(domain);
4718 } else {
4720 "Unsupported translation domain \"%s\" for %s",
4721 domain, sec_name);
4722 ok = FALSE;
4723 break;
4724 }
4725
4726 if (!ruleset_load_names(&pl->adjective, pl->translation_domain, file, sec_name)) {
4727 ok = FALSE;
4728 break;
4729 }
4730 name_set(&pl->noun_plural, pl->translation_domain, noun_plural);
4731
4732 /* Check if nation name is already defined. */
4733 for (j = 0; j < i && ok; j++) {
4734 struct nation_type *n2 = nation_by_number(j);
4735
4736 /* Compare strings after stripping off qualifiers -- we don't want
4737 * two nations to end up with identical adjectives displayed to users.
4738 * (This check only catches English, not localisations, of course.) */
4739 if (0 == strcmp(Qn_(untranslated_name(&n2->adjective)),
4740 Qn_(untranslated_name(&pl->adjective)))) {
4742 "Two nations defined with the same adjective \"%s\": "
4743 "in section \'%s\' and section \'%s\'",
4744 Qn_(untranslated_name(&pl->adjective)),
4745 section_name(section_list_get(sec, j)), sec_name);
4746 ok = FALSE;
4747 } else if (!strcmp(rule_name_get(&n2->adjective),
4748 rule_name_get(&pl->adjective))) {
4749 /* We cannot have the same rule name, as the game needs them to be
4750 * distinct. */
4752 "Two nations defined with the same rule_name \"%s\": "
4753 "in section \'%s\' and section \'%s\'",
4754 rule_name_get(&pl->adjective),
4755 section_name(section_list_get(sec, j)), sec_name);
4756 ok = FALSE;
4757 } else if (0 == strcmp(Qn_(untranslated_name(&n2->noun_plural)),
4758 Qn_(untranslated_name(&pl->noun_plural)))) {
4759 /* We don't want identical English plural names either. */
4761 "Two nations defined with the same plural name \"%s\": "
4762 "in section \'%s\' and section \'%s\'",
4763 Qn_(untranslated_name(&pl->noun_plural)),
4764 section_name(section_list_get(sec, j)), sec_name);
4765 ok = FALSE;
4766 }
4767 }
4768 if (!ok) {
4769 break;
4770 }
4772 }
4773
4774 section_list_destroy(sec);
4775
4776 if (ok) {
4778 if (sec != NULL) {
4779 game.control.num_nation_groups = section_list_size(sec);
4780
4781 section_list_iterate(sec, psection) {
4782 struct nation_group *pgroup;
4783 const char *name;
4784
4785 name = secfile_lookup_str(file, "%s.name", section_name(psection));
4786 if (NULL == name) {
4787 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
4788 ok = FALSE;
4789 break;
4790 }
4791 pgroup = nation_group_new(name);
4792 if (pgroup == NULL) {
4793 ok = FALSE;
4794 break;
4795 }
4797 section_list_destroy(sec);
4798 sec = NULL;
4799 }
4800 }
4801
4802 return ok;
4803}
4804
4805/**********************************************************************/
4808static bool is_on_allowed_list(const char *name, const char **list, size_t len)
4809{
4810 int i;
4811
4812 for (i = 0; i < len; i++) {
4813 if (!fc_strcasecmp(name, list[i])) {
4814 return TRUE;
4815 }
4816 }
4817 return FALSE;
4818}
4819
4820/**********************************************************************/
4824static bool load_city_name_list(struct section_file *file,
4825 struct nation_type *pnation,
4826 const char *secfile_str1,
4827 const char *secfile_str2,
4828 const char **allowed_terrains,
4829 size_t atcount)
4830{
4831 size_t dim, j;
4832 bool ok = TRUE;
4833 const char **cities = secfile_lookup_str_vec(file, &dim, "%s.%s",
4834 secfile_str1, secfile_str2);
4835
4836 /* Each string will be of the form "<cityname> (<label>, <label>, ...)".
4837 * The cityname is just the name for this city, while each "label" matches
4838 * a terrain type for the city (or "river"), with a preceding ! to negate
4839 * it. The parentheses are optional (but necessary to have the settings,
4840 * of course). Our job is now to parse it. */
4841 for (j = 0; j < dim; j++) {
4842 size_t len = strlen(cities[j]);
4843 char city_name[len + 1], *p, *next, *end;
4844 struct nation_city *pncity;
4845
4846 sz_strlcpy(city_name, cities[j]);
4847
4848 /* Now we wish to determine values for all of the city labels. A value
4849 * of NCP_NONE means no preference (which is necessary so that the use
4850 * of this is optional); NCP_DISLIKE means the label is negated and
4851 * NCP_LIKE means it's labelled. Mostly the parsing just involves
4852 * a lot of ugly string handling... */
4853 if ((p = strchr(city_name, '('))) {
4854 *p++ = '\0';
4855
4856 if (!(end = strchr(p, ')'))) {
4858 "\"%s\" [%s] %s: city name \"%s\" "
4859 "unmatched parenthesis.", secfile_name(file),
4860 secfile_str1, secfile_str2, cities[j]);
4861 ok = FALSE;
4862 } else {
4863 for (*end++ = '\0'; '\0' != *end; end++) {
4864 if (!fc_isspace(*end)) {
4866 "\"%s\" [%s] %s: city name \"%s\" "
4867 "contains characters after last parenthesis.",
4868 secfile_name(file), secfile_str1, secfile_str2,
4869 cities[j]);
4870 ok = FALSE;
4871 break;
4872 }
4873 }
4874 }
4875 }
4876
4877 /* Build the nation_city. */
4879 if (check_cityname(city_name)) {
4880 /* The ruleset contains a name that is too long. This shouldn't
4881 * happen - if it does, the author should get immediate feedback. */
4883 "\"%s\" [%s] %s: city name \"%s\" is too long.",
4884 secfile_name(file),
4885 secfile_str1, secfile_str2, city_name);
4886 ok = FALSE;
4887 city_name[MAX_LEN_CITYNAME - 1] = '\0';
4888 }
4889 pncity = nation_city_new(pnation, city_name);
4890
4891 if (NULL != p) {
4892 /* Handle the labels one at a time. */
4893 do {
4894 enum nation_city_preference prefer;
4895
4896 if ((next = strchr(p, ','))) {
4897 *next = '\0';
4898 }
4900
4901 /* The ! is used to mark a negative, which is recorded with
4902 * NCP_DISLIKE. Otherwise we use a NCP_LIKE.
4903 */
4904 if (*p == '!') {
4905 p++;
4906 prefer = NCP_DISLIKE;
4907 } else {
4908 prefer = NCP_LIKE;
4909 }
4910
4911 if (0 == fc_strcasecmp(p, "river")) {
4913 && !is_on_allowed_list(p,
4914 game.server.ruledit.allowed_terrains, atcount)) {
4916 "\"%s\" [%s] %s: city \"%s\" "
4917 "has terrain hint \"%s\" not in allowed_terrains.",
4918 secfile_name(file), secfile_str1, secfile_str2,
4919 city_name, p);
4920 ok = FALSE;
4921 } else {
4922 nation_city_set_river_preference(pncity, prefer);
4923 }
4924 } else {
4925 const struct terrain *pterrain = terrain_by_rule_name(p);
4926
4927 if (NULL == pterrain) {
4928 /* Try with removing frequent trailing 's'. */
4929 size_t l = strlen(p);
4930
4931 if (0 < l && 's' == fc_tolower(p[l - 1])) {
4932 char saved = p[l - 1];
4933
4934 p[l - 1] = '\0';
4935 pterrain = terrain_by_rule_name(p);
4936 if (pterrain == NULL) {
4937 /* Didn't help, restore for later allowed_terrains check */
4938 p[l - 1] = saved;
4939 }
4940 }
4941 }
4942
4943 /* Nationset may have been devised with a specific set of terrains
4944 * in mind which don't quite match this ruleset, in which case we
4945 * (a) quietly ignore any hints mentioned that don't happen to be in
4946 * the current ruleset, (b) enforce that terrains mentioned by nations
4947 * must be on the list */
4948 if (pterrain != NULL && game.server.ruledit.allowed_terrains != NULL) {
4949 if (!is_on_allowed_list(p,
4950 game.server.ruledit.allowed_terrains, atcount)) {
4951 /* Terrain exists, but not intended for these nations */
4953 "\"%s\" [%s] %s: city \"%s\" "
4954 "has terrain hint \"%s\" not in allowed_terrains.",
4955 secfile_name(file), secfile_str1, secfile_str2,
4956 city_name, p);
4957 ok = FALSE;
4958 break;
4959 }
4960 } else if (!pterrain) {
4961 /* Terrain doesn't exist; only complain if it's not on any list */
4963 || !is_on_allowed_list(p,
4964 game.server.ruledit.allowed_terrains, atcount)) {
4966 "\"%s\" [%s] %s: city \"%s\" "
4967 "has unknown terrain hint \"%s\".",
4968 secfile_name(file), secfile_str1, secfile_str2,
4969 city_name, p);
4970 ok = FALSE;
4971 break;
4972 }
4973 }
4974 if (NULL != pterrain) {
4975 nation_city_set_terrain_preference(pncity, pterrain, prefer);
4976 }
4977 }
4978
4979 p = next ? next + 1 : NULL;
4980 } while (NULL != p && '\0' != *p);
4981 }
4982 }
4983
4984 if (NULL != cities) {
4985 free(cities);
4986 }
4987
4988 return ok;
4989}
4990
4991/**********************************************************************/
4994static bool load_ruleset_nations(struct section_file *file,
4995 struct rscompat_info *compat)
4996{
4997 struct government *gov;
4998 int j;
4999 size_t dim;
5000 char temp_name[MAX_LEN_NAME];
5001 const char **vec;
5002 const char *name, *bad_leader;
5003 const char *sval;
5004 int default_set;
5005 const char *filename = secfile_name(file);
5006 struct section_list *sec = NULL;
5007 enum trait tr;
5008 bool ok = TRUE;
5009
5010 name = secfile_lookup_str_default(file, NULL, "ruledit.nationlist");
5011 if (name != NULL) {
5013 }
5015 "ruledit.embedded_nations");
5016
5017 if (vec != NULL) {
5018 /* Copy to persistent vector */
5021
5022 for (j = 0; j < game.server.ruledit.embedded_nations_count; j++) {
5024 }
5025
5026 free(vec);
5027 }
5028
5029 game.default_government = NULL;
5030
5031 ruleset_load_traits(game.server.default_traits, file, "default_traits", "");
5032 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5033 if (game.server.default_traits[tr].min < 0) {
5035 }
5036 if (game.server.default_traits[tr].max < 0) {
5038 }
5039 if (game.server.default_traits[tr].fixed < 0) {
5041
5042 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5044 }
5047 "Default values for trait %s not sane.",
5048 trait_name(tr));
5049 ok = FALSE;
5050 break;
5051 }
5052 }
5053
5054 if (ok) {
5056 "compatibility.allowed_govs");
5057 if (vec != NULL) {
5058 /* Copy to persistent vector */
5060 = fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
5062 (const char **)game.server.ruledit.nc_agovs;
5063
5064 for (j = 0; j < game.server.ruledit.ag_count; j++) {
5066 }
5067
5068 free(vec);
5069 }
5070
5072 "compatibility.allowed_terrains");
5073 if (vec != NULL) {
5074 /* Copy to persistent vector */
5076 = fc_malloc(game.server.ruledit.at_count * sizeof(char *));
5078 (const char **)game.server.ruledit.nc_aterrs;
5079
5080 for (j = 0; j < game.server.ruledit.at_count; j++) {
5082 }
5083
5084 free(vec);
5085 }
5086
5088 "compatibility.allowed_styles");
5089 if (vec != NULL) {
5090 /* Copy to persistent vector */
5092 = fc_malloc(game.server.ruledit.as_count * sizeof(char *));
5094 (const char **)game.server.ruledit.nc_astyles;
5095
5096 for (j = 0; j < game.server.ruledit.as_count; j++) {
5098 }
5099
5100 free(vec);
5101 }
5102
5103 sval = secfile_lookup_str_default(file, NULL,
5104 "compatibility.default_government");
5105 /* We deliberately don't check this against allowed_govs. It's only
5106 * specified once so not vulnerable to typos, and may usefully be set in
5107 * a specific ruleset to a gov not explicitly known by the nation set. */
5108 if (sval != NULL) {
5110 if (game.default_government == NULL) {
5112 "Tried to set unknown government type \"%s\" as default_government!",
5113 sval);
5114 ok = FALSE;
5115 } else {
5118 }
5119 }
5120 }
5121
5122 if (ok) {
5124 if (sec != NULL) {
5125 game.control.num_nation_sets = section_list_size(sec);
5126
5127 section_list_iterate(sec, psection) {
5128 const char *set_name, *set_rule_name, *set_description;
5129
5130 set_name = secfile_lookup_str(file, "%s.name", section_name(psection));
5131 set_rule_name =
5132 secfile_lookup_str(file, "%s.rule_name", section_name(psection));
5133 set_description = secfile_lookup_str_default(file, "", "%s.description",
5134 section_name(psection));
5135 if (NULL == set_name || NULL == set_rule_name) {
5136 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5137 ok = FALSE;
5138 break;
5139 }
5140 if (nation_set_new(set_name, set_rule_name, set_description) == NULL) {
5141 ok = FALSE;
5142 break;
5143 }
5145 section_list_destroy(sec);
5146 sec = NULL;
5147 } else {
5149 "At least one nation set [" NATION_SET_SECTION_PREFIX "_*] "
5150 "must be defined.");
5151 ok = FALSE;
5152 }
5153 }
5154
5155 if (ok) {
5156 /* Default set that every nation is a member of. */
5157 sval = secfile_lookup_str_default(file, NULL,
5158 "compatibility.default_nationset");
5159 if (sval != NULL) {
5160 const struct nation_set *pset = nation_set_by_rule_name(sval);
5161 if (pset != NULL) {
5162 default_set = nation_set_number(pset);
5163 } else {
5165 "Unknown default_nationset \"%s\".", sval);
5166 ok = FALSE;
5167 }
5168 } else if (nation_set_count() == 1) {
5169 /* If there's only one set defined, every nation is implicitly a
5170 * member of that set. */
5171 default_set = 0;
5172 } else {
5173 /* No default nation set; every nation must explicitly specify at
5174 * least one set to be a member of. */
5175 default_set = -1;
5176 }
5177 }
5178
5179 if (ok) {
5181 if (sec) {
5182 section_list_iterate(sec, psection) {
5183 struct nation_group *pgroup;
5184 bool hidden;
5185
5186 name = secfile_lookup_str(file, "%s.name", section_name(psection));
5188 if (pgroup == NULL) {
5189 ok = FALSE;
5190 break;
5191 }
5192
5193 hidden = secfile_lookup_bool_default(file, FALSE, "%s.hidden",
5194 section_name(psection));
5196
5197 if (!secfile_lookup_int(file, &j, "%s.match", section_name(psection))) {
5198 ruleset_error(NULL, LOG_ERROR, "Error: %s", secfile_error());
5199 ok = FALSE;
5200 break;
5201 }
5202 nation_group_set_match(pgroup, j);
5204 section_list_destroy(sec);
5205 sec = NULL;
5206 }
5207 }
5208
5209 if (ok) {
5211 nations_iterate(pnation) {
5212 struct nation_type *pconflict;
5213 const int i = nation_index(pnation);
5214 char tmp[200] = "\0";
5215 const char *barb_type;
5216 const char *sec_name = section_name(section_list_get(sec, i));
5217 const char *legend;
5218
5219 /* Nation sets and groups. */
5220 if (default_set >= 0) {
5221 nation_set_list_append(pnation->sets,
5222 nation_set_by_number(default_set));
5223 }
5224 vec = secfile_lookup_str_vec(file, &dim, "%s.groups", sec_name);
5225 for (j = 0; j < dim; j++) {
5226 struct nation_set *pset = nation_set_by_rule_name(vec[j]);
5227 struct nation_group *pgroup = nation_group_by_rule_name(vec[j]);
5228
5229 fc_assert(pset == NULL || pgroup == NULL);
5230
5231 if (NULL != pset) {
5232 nation_set_list_append(pnation->sets, pset);
5233 } else if (NULL != pgroup) {
5234 nation_group_list_append(pnation->groups, pgroup);
5235 } else {
5236 /* For nation authors, this would probably be considered an error.
5237 * But it can happen normally. The civ1 compatibility ruleset only
5238 * uses the nations that were in civ1, so not all of the links will
5239 * exist. */
5240 log_verbose("Nation %s: Unknown set/group \"%s\".",
5241 nation_rule_name(pnation), vec[j]);
5242 }
5243 }
5244 if (NULL != vec) {
5245 free(vec);
5246 }
5247 if (nation_set_list_size(pnation->sets) < 1) {
5249 "Nation %s is not a member of any nation set",
5250 nation_rule_name(pnation));
5251 ok = FALSE;
5252 break;
5253 }
5254
5255 /* Nation conflicts. */
5256 vec = secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec_name);
5257 for (j = 0; j < dim; j++) {
5258 pconflict = nation_by_rule_name(vec[j]);
5259
5260 if (pnation == pconflict) {
5262 "Nation %s conflicts with itself",
5263 nation_rule_name(pnation));
5264 ok = FALSE;
5265 break;
5266 } else if (NULL != pconflict) {
5267 nation_list_append(pnation->server.conflicts_with, pconflict);
5268 } else {
5269 /* For nation authors, this would probably be considered an error.
5270 * But it can happen normally. The civ1 compatibility ruleset only
5271 * uses the nations that were in civ1, so not all of the links will
5272 * exist. */
5273 log_verbose("Nation %s: conflicts_with nation \"%s\" is unknown.",
5274 nation_rule_name(pnation), vec[j]);
5275 }
5276 }
5277 if (NULL != vec) {
5278 free(vec);
5279 }
5280 if (!ok) {
5281 break;
5282 }
5283
5284 /* Nation leaders. */
5285 for (j = 0; j < MAX_NUM_LEADERS; j++) {
5286 const char *sex;
5287 bool is_male = FALSE;
5288
5289 name = secfile_lookup_str(file, "%s.leaders%d.name", sec_name, j);
5290 if (NULL == name) {
5291 /* No more to read. */
5292 break;
5293 }
5294
5295 if (check_name(name)) {
5296 /* The ruleset contains a name that is too long. This shouldn't
5297 * happen - if it does, the author should get immediate feedback */
5298 sz_strlcpy(temp_name, name);
5300 "Nation %s: leader name \"%s\" is too long.",
5301 nation_rule_name(pnation), name);
5302 ok = FALSE;
5303 break;
5304 }
5305
5306 sex = secfile_lookup_str(file, "%s.leaders%d.sex", sec_name, j);
5307 if (NULL == sex) {
5308 ruleset_error(NULL, LOG_ERROR, "Nation %s: leader \"%s\": %s.",
5309 nation_rule_name(pnation), name, secfile_error());
5310 ok = FALSE;
5311 break;
5312 } else if (0 == fc_strcasecmp("Male", sex)) {
5313 is_male = TRUE;
5314 } else if (0 != fc_strcasecmp("Female", sex)) {
5316 "Nation %s: leader \"%s\" has unsupported "
5317 "sex variant \"%s\".",
5318 nation_rule_name(pnation), name, sex);
5319 ok = FALSE;
5320 break;
5321 }
5322 (void) nation_leader_new(pnation, name, is_male);
5323 }
5324 if (!ok) {
5325 break;
5326 }
5327
5328 /* Check the number of leaders. */
5329 if (MAX_NUM_LEADERS == j) {
5330 /* Too much leaders, get the real number defined in the ruleset. */
5331 while (NULL != secfile_entry_lookup(file, "%s.leaders%d.name",
5332 sec_name, j)) {
5333 j++;
5334 }
5336 "Nation %s: Too many leaders; max is %d",
5338 ok = FALSE;
5339 break;
5340 } else if (0 == j) {
5342 "Nation %s: no leaders; at least one is required.",
5343 nation_rule_name(pnation));
5344 ok = FALSE;
5345 break;
5346 }
5347
5348 /* Check if leader name is not already defined in this nation. */
5349 if ((bad_leader = check_leader_names(pnation))) {
5351 "Nation %s: leader \"%s\" defined more than once.",
5352 nation_rule_name(pnation), bad_leader);
5353 ok = FALSE;
5354 break;
5355 }
5356
5357 /* Nation player color preference, if any */
5358 fc_assert_ret_val(pnation->server.rgb == NULL, FALSE);
5359 (void) rgbcolor_load(file, &pnation->server.rgb, "%s.color", sec_name);
5360
5361 /* Load nation traits */
5362 ruleset_load_traits(pnation->server.traits, file, sec_name, "trait_");
5363 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
5364 bool server_traits_used = TRUE;
5365
5366 if (pnation->server.traits[tr].min < 0) {
5367 pnation->server.traits[tr].min = game.server.default_traits[tr].min;
5368 } else {
5369 server_traits_used = FALSE;
5370 }
5371 if (pnation->server.traits[tr].max < 0) {
5372 pnation->server.traits[tr].max = game.server.default_traits[tr].max;
5373 } else {
5374 server_traits_used = FALSE;
5375 }
5376 if (pnation->server.traits[tr].fixed < 0) {
5377 if (server_traits_used) {
5378 pnation->server.traits[tr].fixed = game.server.default_traits[tr].fixed;
5379 } else {
5380 int diff = pnation->server.traits[tr].max - pnation->server.traits[tr].min;
5381
5382 /* TODO: Should sometimes round the a / 2 = x.5 results up */
5383 pnation->server.traits[tr].fixed = diff / 2 + pnation->server.traits[tr].min;
5384 }
5385 }
5386 if (pnation->server.traits[tr].max < pnation->server.traits[tr].min) {
5388 "%s values for trait %s not sane.",
5389 nation_rule_name(pnation), trait_name(tr));
5390 ok = FALSE;
5391 break;
5392 }
5393 }
5394
5395 if (!ok) {
5396 break;
5397 }
5398
5399 pnation->is_playable =
5400 secfile_lookup_bool_default(file, TRUE, "%s.is_playable", sec_name);
5401
5402 /* Check barbarian type. Default is "None" meaning not a barbarian */
5403 barb_type = secfile_lookup_str_default(file, "None",
5404 "%s.barbarian_type", sec_name);
5405 pnation->barb_type = barbarian_type_by_name(barb_type, fc_strcasecmp);
5406 if (!barbarian_type_is_valid(pnation->barb_type)) {
5408 "Nation %s, barbarian_type is invalid (\"%s\")",
5409 nation_rule_name(pnation), barb_type);
5410 ok = FALSE;
5411 break;
5412 }
5413
5414 if (pnation->barb_type != NOT_A_BARBARIAN
5415 && pnation->is_playable) {
5416 /* We can't allow players to use barbarian nations, barbarians
5417 * may run out of nations */
5419 "Nation %s marked both barbarian and playable.",
5420 nation_rule_name(pnation));
5421 ok = FALSE;
5422 break;
5423 }
5424
5425 /* Flags */
5426 sz_strlcpy(pnation->flag_graphic_str,
5427 secfile_lookup_str_default(file, "-", "%s.flag", sec_name));
5428 sz_strlcpy(pnation->flag_graphic_alt,
5430 "%s.flag_alt", sec_name));
5431
5432 /* Ruler titles */
5433 for (j = 0;; j++) {
5434 const char *male, *female;
5435
5436 name = secfile_lookup_str_default(file, NULL,
5437 "%s.ruler_titles%d.government",
5438 sec_name, j);
5439 if (NULL == name) {
5440 /* End of the list of ruler titles. */
5441 break;
5442 }
5443
5444 /* NB: even if the government doesn't exist, we load the entries for
5445 * the ruler titles to avoid warnings about unused entries. */
5446 male = secfile_lookup_str(file, "%s.ruler_titles%d.male_title",
5447 sec_name, j);
5448 female = secfile_lookup_str(file, "%s.ruler_titles%d.female_title",
5449 sec_name, j);
5451
5452 /* Nationset may have been devised with a specific set of govs in
5453 * mind which don't quite match this ruleset, in which case we
5454 * (a) quietly ignore any govs mentioned that don't happen to be in
5455 * the current ruleset, (b) enforce that govs mentioned by nations
5456 * must be on the list */
5457 if (gov != NULL && game.server.ruledit.allowed_govs != NULL) {
5461 /* Gov exists, but not intended for these nations */
5462 gov = NULL;
5464 "Nation %s: government \"%s\" not in allowed_govs.",
5465 nation_rule_name(pnation), name);
5466 ok = FALSE;
5467 break;
5468 }
5469 } else if (!gov) {
5470 /* Gov doesn't exist; only complain if it's not on any list */
5471 if (game.server.ruledit.allowed_govs == NULL
5476 "Nation %s: government \"%s\" not found.",
5477 nation_rule_name(pnation), name);
5478 ok = FALSE;
5479 break;
5480 }
5481 }
5482 if (NULL != male && NULL != female) {
5483 if (gov) {
5484 (void) government_ruler_title_new(gov, pnation, male, female);
5485 }
5486 } else {
5487 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
5488 ok = FALSE;
5489 break;
5490 }
5491 }
5492 if (!ok) {
5493 break;
5494 }
5495
5496 /* City styles */
5497 name = secfile_lookup_str(file, "%s.style", sec_name);
5498 if (!name) {
5499 ruleset_error(NULL, LOG_ERROR, "%s", secfile_error());
5500 ok = FALSE;
5501 break;
5502 }
5503 pnation->style = style_by_rule_name(name);
5504 if (pnation->style == NULL) {
5505 if (game.server.ruledit.allowed_styles == NULL
5510 "Nation %s: Illegal style \"%s\"",
5511 nation_rule_name(pnation), name);
5512 ok = FALSE;
5513 break;
5514 } else {
5515 log_verbose("Nation %s: style \"%s\" not supported in this "
5516 "ruleset; using default.",
5517 nation_rule_name(pnation), name);
5518 pnation->style = style_by_number(0);
5519 }
5520 }
5521
5522 /* Civilwar nations */
5523 vec = secfile_lookup_str_vec(file, &dim,
5524 "%s.civilwar_nations", sec_name);
5525 for (j = 0; j < dim; j++) {
5526 pconflict = nation_by_rule_name(vec[j]);
5527
5528 /* No test for duplicate nations is performed. If there is a duplicate
5529 * entry it will just cause that nation to have an increased
5530 * probability of being chosen. */
5531 if (pconflict == pnation) {
5533 "Nation %s is its own civil war nation",
5534 nation_rule_name(pnation));
5535 ok = FALSE;
5536 break;
5537 } else if (NULL != pconflict) {
5538 nation_list_append(pnation->server.civilwar_nations, pconflict);
5539 nation_list_append(pconflict->server.parent_nations, pnation);
5540 } else {
5541 /* For nation authors, this would probably be considered an error.
5542 * But it can happen normally. The civ1 compatibility ruleset only
5543 * uses the nations that were in civ1, so not all of the links will
5544 * exist. */
5545 log_verbose("Nation %s: civil war nation \"%s\" is unknown.",
5546 nation_rule_name(pnation), vec[j]);
5547 }
5548 }
5549 if (NULL != vec) {
5550 free(vec);
5551 }
5552 if (!ok) {
5553 break;
5554 }
5555
5556 /* Load nation specific initial items */
5557 if (!lookup_tech_list(file, sec_name, "init_techs",
5558 pnation->init_techs, filename)) {
5559 ok = FALSE;
5560 break;
5561 }
5562 if (!lookup_building_list(file, sec_name, "init_buildings",
5563 pnation->init_buildings, filename)) {
5564 ok = FALSE;
5565 break;
5566 }
5567 if (!lookup_unit_list(file, sec_name, "init_units",
5568 pnation->init_units, filename)) {
5569 ok = FALSE;
5570 break;
5571 }
5572 fc_strlcat(tmp, sec_name, 200);
5573 fc_strlcat(tmp, ".init_government", 200);
5574 if (secfile_entry_by_path(file, tmp)) {
5575 pnation->init_government = lookup_government(file, tmp, filename,
5576 NULL);
5577 /* If specified, init_government has to be in this specific ruleset,
5578 * not just allowed_govs */
5579 if (pnation->init_government == NULL) {
5580 ok = FALSE;
5581 break;
5582 }
5583 /* ...but if a list of govs has been specified, enforce that this
5584 * nation's init_government is on the list. */
5585 if (game.server.ruledit.allowed_govs != NULL
5586 && !is_on_allowed_list(government_rule_name(pnation->init_government),
5590 "Nation %s: init_government \"%s\" not allowed.",
5591 nation_rule_name(pnation),
5592 government_rule_name(pnation->init_government));
5593 ok = FALSE;
5594 break;
5595 }
5596 }
5597
5598 /* Read default city names. */
5599 if (!load_city_name_list(file, pnation, sec_name, "cities",
5602 ok = FALSE;
5603 break;
5604 }
5605
5606 legend = secfile_lookup_str_default(file, "", "%s.legend", sec_name);
5607 pnation->legend = fc_strdup(legend);
5608 if (check_strlen(pnation->legend, MAX_LEN_MSG, NULL)) {
5610 "Nation %s: legend \"%s\" is too long.",
5611 nation_rule_name(pnation),
5612 pnation->legend);
5613 ok = FALSE;
5614 break;
5615 }
5616
5617 pnation->player = NULL;
5619 section_list_destroy(sec);
5620 sec = NULL;
5621 }
5622
5623 /* Clean up on aborted load */
5624 if (sec != NULL) {
5625 fc_assert(!ok);
5626 section_list_destroy(sec);
5627 }
5628
5629 if (ok) {
5631 }
5632
5633 if (ok) {
5634 /* Update cached number of playable nations in the current set */
5636
5637 /* Sanity checks on all sets */
5638 nation_sets_iterate(pset) {
5639 int num_playable = 0, barb_land_count = 0, barb_sea_count = 0, barb_both_count = 0;
5640
5641 nations_iterate(pnation) {
5642 if (nation_is_in_set(pnation, pset)) {
5643 switch (nation_barbarian_type(pnation)) {
5644 case NOT_A_BARBARIAN:
5645 if (is_nation_playable(pnation)) {
5646 num_playable++;
5647 }
5648 break;
5649 case LAND_BARBARIAN:
5650 barb_land_count++;
5651 break;
5652 case SEA_BARBARIAN:
5653 barb_sea_count++;
5654 break;
5655 case ANIMAL_BARBARIAN:
5656 /* Animals are optional */
5657 break;
5658 case LAND_AND_SEA_BARBARIAN:
5659 barb_both_count++;
5660 break;
5661 default:
5663 }
5664 }
5666 if (num_playable < 1) {
5668 "Nation set \"%s\" has no playable nations. "
5669 "At least one required!", nation_set_rule_name(pset));
5670 ok = FALSE;
5671 break;
5672 }
5673 if (barb_land_count == 0 && barb_both_count == 0) {
5675 "No land barbarian nation defined in set \"%s\". "
5676 "At least one required!", nation_set_rule_name(pset));
5677 ok = FALSE;
5678 break;
5679 }
5680 if (barb_sea_count == 0 && barb_both_count == 0) {
5682 "No sea barbarian nation defined in set \"%s\". "
5683 "At least one required!", nation_set_rule_name(pset));
5684 ok = FALSE;
5685 break;
5686 }
5688 }
5689
5690 return ok;
5691}
5692
5693/**********************************************************************/
5697static bool load_style_names(struct section_file *file,
5698 struct rscompat_info *compat)
5699{
5700 bool ok = TRUE;
5701 struct section_list *sec;
5702 const char *filename = secfile_name(file);
5703
5704 if (!rscompat_check_cap_and_version(file, filename, compat)) {
5705 return FALSE;
5706 }
5707
5708 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
5709 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
5710
5712 if (NULL == sec) {
5714 "No available nation styles in this ruleset!");
5715 ok = FALSE;
5716 } else {
5717 game.control.num_styles = section_list_size(sec);
5718
5720
5721 styles_iterate(ps) {
5722 const int i = style_index(ps);
5723 const char *sec_name = section_name(section_list_get(sec, i));
5724
5725 ruleset_load_names(&ps->name, NULL, file, sec_name);
5727 }
5728
5729 section_list_destroy(sec);
5730
5731 if (ok) {
5732 /* The citystyle sections: */
5733 int i = 0;
5734
5736 if (NULL != sec) {
5737 city_styles_alloc(section_list_size(sec));
5738 section_list_iterate(sec, style) {
5739 if (!ruleset_load_names(&city_styles[i].name, NULL, file, section_name(style))) {
5740 ok = FALSE;
5741 break;
5742 }
5743 i++;
5745
5746 section_list_destroy(sec);
5747 } else {
5749 }
5750 }
5751
5752 return ok;
5753}
5754
5755/**********************************************************************/
5758static bool load_ruleset_styles(struct section_file *file,
5759 struct rscompat_info *compat)
5760{
5761 struct section_list *sec;
5762 int i;
5763 bool ok = TRUE;
5764
5765 /* City Styles ... */
5766
5768
5769 /* Get rest: */
5770 for (i = 0; i < game.control.styles_count; i++) {
5771 struct requirement_vector *reqs;
5772 const char *sec_name = section_name(section_list_get(sec, i));
5773
5774 sz_strlcpy(city_styles[i].graphic,
5775 secfile_lookup_str(file, "%s.graphic", sec_name));
5776 sz_strlcpy(city_styles[i].graphic_alt,
5777 secfile_lookup_str(file, "%s.graphic_alt", sec_name));
5778 sz_strlcpy(city_styles[i].citizens_graphic,
5780 "%s.citizens_graphic", sec_name));
5781
5782 reqs = lookup_req_list(file, compat, sec_name, "reqs", city_style_rule_name(i));
5783 if (reqs == NULL) {
5784 ok = FALSE;
5785 break;
5786 }
5787 requirement_vector_copy(&city_styles[i].reqs, reqs);
5788 }
5789
5790 section_list_destroy(sec);
5791
5792 if (ok) {
5794
5795 if (sec != NULL) {
5796 int musi;
5797
5798 game.control.num_music_styles = section_list_size(sec);
5800 musi = 0;
5801
5802 section_list_iterate(sec, psection) {
5803 struct requirement_vector *reqs;
5804 struct music_style *pmus = music_style_by_number(musi);
5805 const char *sec_name = section_name(psection);
5806
5809 "%s.music_peaceful", sec_name));
5812 "%s.music_combat", sec_name));
5813
5814 reqs = lookup_req_list(file, compat, sec_name, "reqs", "Music Style");
5815 if (reqs == NULL) {
5816 ok = FALSE;
5817 break;
5818 }
5819 requirement_vector_copy(&pmus->reqs, reqs);
5820
5821 musi++;
5823 }
5824
5825 section_list_destroy(sec);
5826 }
5827
5828 return ok;
5829}
5830
5831/**********************************************************************/
5837 struct action_auto_perf *auto_perf,
5838 const char *uflags_path,
5839 const char *filename)
5840{
5841 /* Add each listed protected unit type flag as a !present
5842 * requirement. */
5843 if (secfile_entry_lookup(file, "%s", uflags_path)) {
5844 enum unit_type_flag_id *protecor_flag;
5845 size_t psize;
5846 int i;
5847
5848 protecor_flag =
5849 secfile_lookup_enum_vec(file, &psize, unit_type_flag_id,
5850 "%s", uflags_path);
5851
5852 if (!protecor_flag) {
5853 /* Entity exists but couldn't read it. */
5855 "\"%s\": %s: bad unit type flag list.",
5856 filename, uflags_path);
5857
5858 return FALSE;
5859 }
5860
5861 for (i = 0; i < psize; i++) {
5862 requirement_vector_append(&auto_perf->reqs,
5863 req_from_values(VUT_UTFLAG,
5864 REQ_RANGE_LOCAL,
5865 FALSE, FALSE, TRUE,
5866 protecor_flag[i]));
5867 }
5868
5869 free(protecor_flag);
5870 }
5871
5872 return TRUE;
5873}
5874
5875/**********************************************************************/
5880 struct action_auto_perf *auto_perf,
5881 const char *actions_path,
5882 const char *filename)
5883{
5884 /* Read the alternative actions. */
5885 if (secfile_entry_lookup(file, "%s", actions_path)) {
5886 enum gen_action *unit_acts;
5887 size_t asize;
5888 int i;
5889
5890 unit_acts = secfile_lookup_enum_vec(file, &asize, gen_action,
5891 "%s", actions_path);
5892
5893 if (!unit_acts) {
5894 /* Entity exists but couldn't read it. */
5896 "\"%s\": %s: bad action list",
5897 filename, actions_path);
5898
5899 return FALSE;
5900 }
5901
5902 for (i = 0; i < asize; i++) {
5903 auto_perf->alternatives[i] = unit_acts[i];
5904 }
5905
5906 free(unit_acts);
5907 }
5908
5909 return TRUE;
5910}
5911
5912/**********************************************************************/
5916 struct action_auto_perf *auto_perf,
5917 const char *item,
5918 const char *filename)
5919{
5920 char uflags_path[100];
5921 char action_path[100];
5922
5923 fc_snprintf(uflags_path, sizeof(uflags_path),
5924 "missing_unit_upkeep.%s_protected", item);
5925 fc_snprintf(action_path, sizeof(action_path),
5926 "missing_unit_upkeep.%s_unit_act", item);
5927
5928 return (load_action_auto_uflag_block(file, auto_perf, uflags_path,
5929 filename)
5930 && load_action_auto_actions(file, auto_perf, action_path,
5931 filename));
5932}
5933
5934/**********************************************************************/
5937static bool load_ruleset_cities(struct section_file *file,
5938 struct rscompat_info *compat)
5939{
5940 const char *filename = secfile_name(file);
5941 const char *item;
5942 struct section_list *sec;
5943 bool ok = TRUE;
5944
5945 if (!rscompat_check_cap_and_version(file, filename, compat)) {
5946 return FALSE;
5947 }
5948
5949 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
5950 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
5951
5952 /* Specialist options */
5954 if (!sec) {
5955 ruleset_error(NULL, LOG_ERROR, "\"%s\": No specialists.", filename);
5956 ok = FALSE;
5957 } else if (section_list_size(sec) >= SP_MAX) {
5959 "\"%s\": Too many specialists (%d, max %d).",
5960 filename, section_list_size(sec), SP_MAX);
5961 ok = FALSE;
5962 }
5963
5964 if (ok) {
5965 int i = 0;
5966 const char *tag;
5967
5968 game.control.num_specialist_types = section_list_size(sec);
5969
5970 section_list_iterate(sec, psection) {
5971 struct specialist *s = specialist_by_number(i);
5972 struct requirement_vector *reqs;
5973 const char *sec_name = section_name(psection);
5974
5975 if (!ruleset_load_names(&s->name, NULL, file, sec_name)) {
5976 ok = FALSE;
5977 break;
5978 }
5979
5981 "%s.short_name", sec_name);
5982 name_set(&s->abbreviation, NULL, item);
5983
5984 tag = secfile_lookup_str(file, "%s.graphic", sec_name);
5985 if (tag == NULL) {
5987 "\"%s\": No graphic tag for specialist at %s.",
5988 filename, sec_name);
5989 ok = FALSE;
5990 break;
5991 }
5992 sz_strlcpy(s->graphic_str, tag);
5995 "%s.graphic_alt", sec_name));
5996
5997 reqs = lookup_req_list(file, compat, sec_name, "reqs", specialist_rule_name(s));
5998 if (reqs == NULL) {
5999 ok = FALSE;
6000 break;
6001 }
6002 requirement_vector_copy(&s->reqs, reqs);
6003
6004 s->helptext = lookup_strvec(file, sec_name, "helptext");
6005
6006 if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
6008 }
6009 i++;
6011 }
6012
6013 if (ok && DEFAULT_SPECIALIST == -1) {
6015 "\"%s\": must have zero reqs for at least one "
6016 "specialist type.", filename);
6017 ok = FALSE;
6018 }
6019 section_list_destroy(sec);
6020 sec = NULL;
6021
6022 if (ok) {
6023 /* City Parameters */
6024
6027 "parameters.celebrate_size_limit");
6029 secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
6032 "parameters.angry_citizens");
6033
6035 secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
6037 secfile_lookup_int_default(file, 0, "parameters.forced_science");
6039 secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
6041 secfile_lookup_int_default(file, 0, "parameters.forced_gold");
6043 + game.info.forced_gold != 100) {
6045 "\"%s\": Forced taxes do not add up in ruleset!",
6046 filename);
6047 ok = FALSE;
6048 }
6049 }
6050
6051 if (ok) {
6052 /* civ1 & 2 didn't reveal tiles */
6055 "parameters.vision_reveal_tiles");
6056
6058 secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
6059
6060 /* Citizens configuration. */
6063 "citizen.nationality");
6066 "citizen.convert_speed");
6068 secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
6070 secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
6071 }
6072
6073 if (ok) {
6074 /* Missing unit upkeep. */
6075 struct action_auto_perf *auto_perf;
6076
6077 /* Can't pay food upkeep! */
6079 auto_perf->cause = AAPC_UNIT_UPKEEP;
6080
6081 /* This is about food upkeep. */
6082 requirement_vector_append(&auto_perf->reqs,
6083 req_from_str("OutputType", "Local",
6084 FALSE, TRUE, TRUE,
6085 "Food"));
6086
6087 /* Internally represented as an action auto performer rule. */
6088 if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
6089 ok = FALSE;
6090 }
6091
6094 "missing_unit_upkeep.food_wipe");
6095
6096 /* Can't pay gold upkeep! */
6098 auto_perf->cause = AAPC_UNIT_UPKEEP;
6099
6100 /* This is about gold upkeep. */
6101 requirement_vector_append(&auto_perf->reqs,
6102 req_from_str("OutputType", "Local",
6103 FALSE, TRUE, TRUE,
6104 "Gold"));
6105
6106 /* Internally represented as an action auto performer rule. */
6107 if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
6108 ok = FALSE;
6109 }
6110
6113 "missing_unit_upkeep.gold_wipe");
6114
6115 /* Can't pay shield upkeep! */
6117 auto_perf->cause = AAPC_UNIT_UPKEEP;
6118
6119 /* This is about shield upkeep. */
6120 requirement_vector_append(&auto_perf->reqs,
6121 req_from_str("OutputType", "Local",
6122 FALSE, TRUE, TRUE,
6123 "Shield"));
6124
6125 /* Internally represented as an action auto performer rule. */
6126 if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
6127 ok = FALSE;
6128 }
6129
6132 "missing_unit_upkeep.shield_wipe");
6133 }
6134
6135 if (ok) {
6137 }
6138
6139 return ok;
6140}
6141
6142/**********************************************************************/
6145static bool load_ruleset_effects(struct section_file *file,
6146 struct rscompat_info *compat)
6147{
6148 struct section_list *sec;
6149 const char *type;
6150 const char *filename;
6151 bool ok = TRUE;
6152
6153 filename = secfile_name(file);
6154
6155 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6156 return FALSE;
6157 }
6158
6159 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6160 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6161
6162 /* Parse effects and add them to the effects ruleset cache. */
6164 section_list_iterate(sec, psection) {
6165 enum effect_type eff;
6166 int value;
6167 struct multiplier *pmul;
6168 struct effect *peffect;
6169 const char *sec_name = section_name(psection);
6170 struct requirement_vector *reqs;
6171
6172 type = secfile_lookup_str(file, "%s.type", sec_name);
6173
6174 if (type == NULL) {
6176 "\"%s\" [%s] missing effect type.", filename, sec_name);
6177 ok = FALSE;
6178 break;
6179 }
6180
6181 if (compat->compat_mode && rscompat_old_effect_3_1(type, file, sec_name, compat)) {
6182 continue;
6183 }
6184
6185 eff = effect_type_by_name(type, fc_strcasecmp);
6186 if (!effect_type_is_valid(eff)) {
6188 "\"%s\" [%s] lists unknown effect type \"%s\".",
6189 filename, sec_name, type);
6190 ok = FALSE;
6191 break;
6192 }
6193
6194 value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
6195
6196 {
6197 const char *multiplier_name
6198 = secfile_lookup_str(file, "%s.multiplier", sec_name);
6199
6200 if (multiplier_name) {
6201 pmul = multiplier_by_rule_name(multiplier_name);
6202 if (!pmul) {
6204 "\"%s\" [%s] has unknown multiplier \"%s\".",
6205 filename, sec_name, multiplier_name);
6206 ok = FALSE;
6207 break;
6208 }
6209 } else {
6210 pmul = NULL;
6211 }
6212 }
6213
6214 peffect = effect_new(eff, value, pmul);
6215
6216 reqs = lookup_req_list(file, compat, sec_name, "reqs", type);
6217 if (reqs == NULL) {
6218 ok = FALSE;
6219 break;
6220 }
6221
6223 effect_req_append(peffect, *preq);
6225
6227 section_list_destroy(sec);
6228
6229 if (ok) {
6231 }
6232
6233 return ok;
6234}
6235
6236/**********************************************************************/
6239static int secfile_lookup_int_default_min_max(struct section_file *file,
6240 int def, int min, int max,
6241 const char *path, ...)
6242 fc__attribute((__format__ (__printf__, 5, 6)));
6244 int def, int min, int max,
6245 const char *path, ...)
6246{
6247 char fullpath[256];
6248 int ival;
6249 va_list args;
6250
6251 va_start(args, path);
6252 fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
6253 va_end(args);
6254
6255 if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
6256 ival = def;
6257 }
6258
6259 if (ival < min) {
6261 "\"%s\" should be in the interval [%d, %d] "
6262 "but is %d; using the minimal value.",
6263 fullpath, min, max, ival);
6264 ival = min;
6265 }
6266
6267 if (ival > max) {
6269 "\"%s\" should be in the interval [%d, %d] "
6270 "but is %d; using the maximal value.",
6271 fullpath, min, max, ival);
6272 ival = max;
6273 }
6274
6275 return ival;
6276}
6277
6278/**********************************************************************/
6281static bool load_action_ui_name(struct section_file *file, int act,
6282 const char *entry_name,
6283 const char *compat_name)
6284{
6285 const char *text;
6286 const char *def = action_ui_name_default(act);
6287
6288 if (compat_name != NULL) {
6289 def = secfile_lookup_str_default(file, def,
6290 "actions.%s", compat_name);
6291 }
6292
6293 text = secfile_lookup_str_default(file, def,
6294 "actions.%s", entry_name);
6295 sz_strlcpy(action_by_number(act)->ui_name, text);
6296
6297 return TRUE;
6298}
6299
6300/**********************************************************************/
6304 struct section_file *file, action_id act)
6305{
6306 struct action *paction = action_by_number(act);
6307 const char *vname = action_max_range_ruleset_var_name(act);
6308
6309 if (vname != NULL) {
6310 struct entry *pentry;
6311 int max_range;
6312
6313 pentry = secfile_entry_lookup(file, "actions.%s", vname);
6314
6315 if (pentry == NULL) {
6316 const char *compat_name = rscompat_action_max_range_name_S3_1(compat, act);
6317
6318 if (compat_name != NULL) {
6319 pentry = secfile_entry_lookup(file, "actions.%s",
6320 compat_name);
6321 }
6322 }
6323
6324 if (pentry == NULL) {
6325 max_range = action_max_range_default(paction->result);
6326 } else {
6327 const char *custom;
6328
6329 if (entry_type_get(pentry) == ENTRY_INT
6330 && entry_int_get(pentry, &max_range)) {
6331 /* max_range already assigned */
6332 } else if (entry_type_get(pentry) == ENTRY_STR
6333 && entry_str_get(pentry, &custom)
6335 max_range = ACTION_DISTANCE_UNLIMITED;
6336 } else {
6337 ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
6340
6341 return FALSE;
6342 }
6343 }
6344
6345 action_by_number(act)->max_distance = max_range;
6346 }
6347
6348 return TRUE;
6349}
6350
6351/**********************************************************************/
6355 struct section_file *file, action_id act)
6356{
6357 struct action *paction = action_by_number(act);
6358 const char *vname;
6359
6360 if (!load_action_range_max(compat, file, act)) {
6361 return FALSE;
6362 }
6363
6365 if (vname != NULL) {
6366 /* Min range can be loaded from the ruleset. */
6370 "actions.%s",
6371 vname);
6372 }
6373
6374 return TRUE;
6375}
6376
6377/**********************************************************************/
6380static bool load_action_kind(struct section_file *file, action_id act)
6381{
6382 struct action *paction = action_by_number(act);
6383 const char *var_name = action_target_kind_ruleset_var_name(act);
6384
6385 if (var_name != NULL) {
6389 paction->result),
6390 action_target_kind,
6391 "actions.%s", var_name);
6392 } else {
6395 }
6396
6397 return TRUE;
6398}
6399
6400/**********************************************************************/
6404 action_id act)
6405{
6407 /* Actor consumption can be loaded from the ruleset. */
6410 file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
6412 }
6413
6414 return TRUE;
6415}
6416
6417/**********************************************************************/
6421 const char *filename,
6422 struct action *paction)
6423{
6424 if (action_blocked_by_ruleset_var_name(paction) != NULL) {
6425 /* Action blocking can be loaded from the ruleset. */
6426
6427 char fullpath[1024];
6428
6429 fc_snprintf(fullpath, sizeof(fullpath), "actions.%s",
6431
6432 if (secfile_entry_by_path(file, fullpath)) {
6433 enum gen_action *blocking_actions;
6434 size_t asize;
6435 int j;
6436
6437 blocking_actions =
6438 secfile_lookup_enum_vec(file, &asize, gen_action, "%s", fullpath);
6439
6440 if (!blocking_actions) {
6441 /* Entity exists but couldn't read it. */
6443 "\"%s\": %s: bad action list",
6444 filename, fullpath);
6445
6446 return FALSE;
6447 }
6448
6449 for (j = 0; j < asize; j++) {
6450 BV_SET(paction->blocked_by, blocking_actions[j]);
6451 }
6452
6453 free(blocking_actions);
6454 }
6455 }
6456
6457 return TRUE;
6458}
6459
6460/**********************************************************************/
6465 const char *filename,
6466 int performer_slot,
6467 struct action *paction)
6468{
6469 struct action_auto_perf *auto_perf;
6470 char action_list_path[100];
6471
6472 if (action_post_success_forced_ruleset_var_name(paction) == NULL) {
6473 /* Not relevant. */
6474 return TRUE;
6475 }
6476
6477 auto_perf = action_auto_perf_slot_number(performer_slot);
6478 auto_perf->cause = AAPC_POST_ACTION;
6479
6480 /* Limit auto performer to this action. */
6481 requirement_vector_append(&auto_perf->reqs,
6482 req_from_values(VUT_ACTION, REQ_RANGE_LOCAL,
6483 FALSE, TRUE, TRUE,
6484 paction->id));
6485
6486 /* Load the list of actions. */
6487 fc_snprintf(action_list_path, sizeof(action_list_path),
6488 "actions.%s",
6490 if (!load_action_auto_actions(file, auto_perf,
6491 action_list_path, filename)) {
6492 return FALSE;
6493 }
6494
6495 return TRUE;
6496}
6497
6498/**********************************************************************/
6501static bool lookup_bv_actions(struct section_file *file,
6502 const char *filename,
6503 bv_actions *target,
6504 const char *path)
6505{
6506 if (secfile_entry_by_path(file, path)) {
6507 enum gen_action *listed_actions;
6508 size_t asize;
6509 int j;
6510
6511 listed_actions = secfile_lookup_enum_vec(file, &asize, gen_action,
6512 "%s", path);
6513
6514 if (!listed_actions) {
6515 /* Entity exists but couldn't read it. */
6516 ruleset_error(NULL, LOG_ERROR, "\"%s\": %s: bad action list",
6517 filename, path);
6518
6519 return FALSE;
6520 }
6521
6522 for (j = 0; j < asize; j++) {
6523 BV_SET(*target, listed_actions[j]);
6524 }
6525
6526 free(listed_actions);
6527 }
6528
6529 return TRUE;
6530}
6531
6532/**********************************************************************/
6535static bool load_ruleset_game(struct section_file *file, bool act,
6536 struct rscompat_info *compat)
6537{
6538 const char *sval, **svec;
6539 const char *filename;
6540 int *food_ini;
6541 int i;
6542 size_t teams;
6543 const char *pref_text;
6544 size_t gni_tmp;
6545 struct section_list *sec;
6546 size_t nval;
6547 const char *name;
6548 bool ok = TRUE;
6549
6550 if (file == NULL) {
6551 return FALSE;
6552 }
6553 filename = secfile_name(file);
6554
6555 name = secfile_lookup_str_default(file, NULL, "ruledit.description_file");
6556 if (name != NULL) {
6558 }
6559
6560 /* section: tileset */
6561 pref_text = secfile_lookup_str_default(file, "", "tileset.prefered");
6562 if (pref_text[0] != '\0') {
6563 log_deprecation("Entry tileset.prefered in game.ruleset."
6564 " Use correct spelling tileset.preferred instead");
6565 }
6566 pref_text = secfile_lookup_str_default(file, pref_text, "tileset.preferred");
6567 if (pref_text[0] != '\0') {
6568 /* There was tileset suggestion */
6570 } else {
6571 /* No tileset suggestions */
6572 game.control.preferred_tileset[0] = '\0';
6573 }
6574
6575 /* section: soundset */
6576 pref_text = secfile_lookup_str_default(file, "", "soundset.prefered");
6577 if (pref_text[0] != '\0') {
6578 log_deprecation("Entry soundset.prefered in game.ruleset."
6579 " Use correct spelling soundset.preferred instead");
6580 }
6581 pref_text = secfile_lookup_str_default(file, pref_text, "soundset.preferred");
6582 if (pref_text[0] != '\0') {
6583 /* There was soundset suggestion */
6585 } else {
6586 /* No soundset suggestions */
6588 }
6589
6590 /* section: musicset */
6591 pref_text = secfile_lookup_str_default(file, "", "musicset.prefered");
6592 if (pref_text[0] != '\0') {
6593 log_deprecation("Entry musicset.prefered in game.ruleset."
6594 " Use correct spelling musicset.preferred instead");
6595 }
6596 pref_text = secfile_lookup_str_default(file, pref_text, "musicset.preferred");
6597 if (pref_text[0] != '\0') {
6598 /* There was musicset suggestion */
6600 } else {
6601 /* No musicset suggestions */
6603 }
6604
6605 /* section: about */
6606 pref_text = secfile_lookup_str(file, "about.name");
6607 /* Ruleset/modpack name found */
6608 sz_strlcpy(game.control.name, pref_text);
6609
6610 pref_text = secfile_lookup_str_default(file, "", "about.version");
6611 if (pref_text[0] != '\0') {
6612 /* Ruleset/modpack version found */
6613 sz_strlcpy(game.control.version, pref_text);
6614 } else {
6615 /* No version information */
6616 game.control.version[0] = '\0';
6617 }
6618
6619 pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
6620 if (pref_text[0] != '\0') {
6621 /* Alt directory definition found. */
6622 sz_strlcpy(game.control.alt_dir, pref_text);
6623 } else {
6624 /* No alt directory information */
6625 game.control.alt_dir[0] = '\0';
6626 }
6627
6628 pref_text = secfile_lookup_str_default(file, "", "about.summary");
6629 if (pref_text[0] != '\0') {
6630 int len;
6631
6632 /* Ruleset/modpack summary found */
6633 len = strlen(pref_text);
6635 fc_strlcpy(game.ruleset_summary, pref_text, len + 1);
6636 } else {
6637 /* No summary */
6638 if (game.ruleset_summary != NULL) {
6639 free(game.ruleset_summary);
6640 game.ruleset_summary = NULL;
6641 }
6642 }
6643
6644 pref_text = secfile_lookup_str_default(file, "", "about.description");
6645 if (pref_text[0] != '\0') {
6646 int len;
6647
6648 /* Ruleset/modpack description found */
6649 len = strlen(pref_text);
6651 fc_strlcpy(game.ruleset_description, pref_text, len + 1);
6653 } else {
6654 /* No description */
6655 if (game.ruleset_description != NULL) {
6658 }
6660 }
6661
6662 pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
6663 if (pref_text[0] != '\0') {
6664 int len = strlen(pref_text);
6665
6667 fc_strlcpy(game.ruleset_capabilities, pref_text, len +1);
6668 } else {
6670 game.ruleset_capabilities[0] = '\0';
6671 }
6672
6673 /* section: options */
6674 if (!lookup_tech_list(file, "options", "global_init_techs",
6675 game.rgame.global_init_techs, filename)) {
6676 ok = FALSE;
6677 }
6678
6679 if (ok) {
6680 if (!lookup_building_list(file, "options", "global_init_buildings",
6681 game.rgame.global_init_buildings, filename)) {
6682 ok = FALSE;
6683 }
6684 }
6685
6686 if (ok) {
6687 const char **slist;
6688 int j;
6689
6691 "options.popup_tech_help");
6692
6693 /* section: civstyle */
6696 "civstyle.base_pollution");
6697
6698 game.info.gameloss_style = GAMELOSS_STYLE_CLASSICAL;
6699
6700 slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
6701 for (j = 0; j < nval; j++) {
6702 enum gameloss_style style;
6703
6704 sval = slist[j];
6705 if (strcmp(sval, "") == 0) {
6706 continue;
6707 }
6708 style = gameloss_style_by_name(sval, fc_strcasecmp);
6709 if (!gameloss_style_is_valid(style)) {
6711 "\"%s\": bad value \"%s\" for gameloss_style.",
6712 filename, sval);
6713 ok = FALSE;
6714 break;
6715 } else {
6716 game.info.gameloss_style |= style;
6717 }
6718 }
6719 free(slist);
6720 }
6721
6722 if (ok) {
6728 "civstyle.happy_cost");
6734 "civstyle.food_cost");
6736 = secfile_lookup_bool_default(file, TRUE, "civstyle.civil_war_enabled");
6737
6740 "civstyle.civil_war_bonus_celebrating");
6741
6744 "civstyle.civil_war_bonus_unhappy");
6745
6751 "civstyle.base_bribe_cost");
6757 "civstyle.ransom_gold");
6760 "civstyle.pillage_select");
6761
6764 "civstyle.tech_steal_allow_holes");
6767 "civstyle.tech_trade_allow_holes");
6770 "civstyle.tech_trade_loss_allow_holes");
6773 "civstyle.tech_parasite_allow_holes");
6776 "civstyle.tech_loss_allow_holes");
6777
6783 "civstyle.upgrade_veteran_loss");
6789 "civstyle.autoupgrade_veteran_loss");
6790
6796 "research.base_tech_cost");
6797
6798 food_ini = secfile_lookup_int_vec(file, &gni_tmp,
6799 "civstyle.granary_food_ini");
6800 game.info.granary_num_inis = (int) gni_tmp;
6801
6804 "Too many granary_food_ini entries (%d, max %d)",
6806 ok = FALSE;
6807 } else if (game.info.granary_num_inis == 0) {
6808 log_error("No values for granary_food_ini. Using default "
6809 "value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
6812 } else {
6813 int gi;
6814
6815 /* check for <= 0 entries */
6816 for (gi = 0; gi < game.info.granary_num_inis; gi++) {
6817 if (food_ini[gi] <= 0) {
6818 if (gi == 0) {
6819 food_ini[gi] = RS_DEFAULT_GRANARY_FOOD_INI;
6820 } else {
6821 food_ini[gi] = food_ini[gi - 1];
6822 }
6823 log_error("Bad value for granary_food_ini[%i]. Using %i.",
6824 gi, food_ini[gi]);
6825 }
6826 game.info.granary_food_ini[gi] = food_ini[gi];
6827 }
6828 }
6829 free(food_ini);
6830 }
6831
6832 if (ok) {
6838 "civstyle.granary_food_inc");
6839
6846 "civstyle.min_city_center_%s",
6849 }
6850
6851 if (ok) {
6852 const char *tus_text;
6853
6859 "civstyle.init_vis_radius_sq");
6860
6866 "civstyle.init_city_radius_sq");
6867
6869 "civstyle.gold_upkeep_style");
6870 game.info.gold_upkeep_style = gold_upkeep_style_by_name(tus_text,
6872 if (!gold_upkeep_style_is_valid(game.info.gold_upkeep_style)) {
6874 "Unknown gold upkeep style \"%s\"",
6875 tus_text);
6876 ok = FALSE;
6877 }
6878
6880 "civstyle.output_granularity");
6881
6883 = secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
6884
6886 = secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
6887
6888 /* section: wonder_visibility */
6889 if (ok) {
6890 const char *text;
6891
6892 text = secfile_lookup_str_default(file,
6894 "wonder_visibility.small_wonders");
6895
6896 game.info.small_wonder_visibility = wonder_visib_type_by_name(text,
6898 if (!wonder_visib_type_is_valid(game.info.small_wonder_visibility)) {
6900 "Unknown wonder visibility type \"%s\"",
6901 text);
6902 ok = FALSE;
6903 }
6904 }
6905
6906 /* section: illness */
6909 "illness.illness_on");
6915 "illness.illness_base_factor");
6921 "illness.illness_min_size");
6927 "illness.illness_trade_infection");
6933 "illness.illness_pollution_factor");
6934
6935 /* section: incite_cost */
6941 "incite_cost.base_incite_cost");
6947 "incite_cost.improvement_factor");
6953 "incite_cost.unit_factor");
6959 "incite_cost.total_factor");
6960
6961 if (ok) {
6962 /* Auto attack. */
6963 struct action_auto_perf *auto_perf;
6964
6965 /* Action auto performers aren't ready to be exposed in the ruleset
6966 * yet. The behavior when two action auto performers for the same
6967 * cause can fire isn't set in stone yet. How is one of them chosen?
6968 * What if all the actions of the chosen action auto performer turned
6969 * out to be illegal but one of the other action auto performers that
6970 * fired has legal actions? These issues can decide what other action
6971 * rules action auto performers can represent in the future. Deciding
6972 * should therefore wait until a rule needs action auto performers to
6973 * work a certain way. */
6974 /* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
6975 * by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
6976 * requirement vector to the ruleset. */
6977 struct requirement_vector *reqs;
6978
6979 /* A unit moved next to this unit and the autoattack server setting
6980 * is enabled. */
6982 auto_perf->cause = AAPC_UNIT_MOVED_ADJ;
6983
6984 reqs = lookup_req_list(file, compat,
6985 "auto_attack", "if_attacker",
6986 "auto_attack");
6987 if (reqs == NULL) {
6988 ok = FALSE;
6989 } else {
6990 requirement_vector_copy(&auto_perf->reqs, reqs);
6991
6992 if (!load_action_auto_actions(file, auto_perf,
6993 "auto_attack.attack_actions",
6994 filename)) {
6995 /* Failed to load auto attack actions */
6997 "\"%s\": %s: failed load %s.",
6998 filename, "auto_attack", "attack_actions");
6999 ok = FALSE;
7000 }
7001
7002 if (ok && compat->compat_mode) {
7003 enum unit_type_flag_id *protecor_flag;
7004 size_t psize;
7005
7006 if (secfile_entry_lookup(file, "%s", "auto_attack.will_never")) {
7007 protecor_flag =
7008 secfile_lookup_enum_vec(file, &psize, unit_type_flag_id,
7009 "%s", "auto_attack.will_never");
7010
7011 if (!protecor_flag) {
7012 /* Entity exists but couldn't read it. */
7014 "\"%s\": %s: bad unit type flag list.",
7015 filename, "auto_attack.will_never");
7016
7017 ok = FALSE;
7018 }
7019 } else {
7020 psize = 0;
7021 protecor_flag = NULL;
7022 }
7023
7024 if (ok && !rscompat_auto_attack_3_1(compat, auto_perf,
7025 psize, protecor_flag)) {
7026 /* Upgrade failed */
7028 "\"%s\": %s: failed to upgrade.",
7029 filename, "auto_attack");
7030 ok = FALSE;
7031 }
7032
7033 if (psize) {
7034 FC_FREE(protecor_flag);
7035 }
7036 }
7037 }
7038 }
7039
7040 /* Section: actions */
7041 if (ok) {
7042 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7043 int force_capture_units, force_bombard, force_explode_nuclear;
7044
7046 "actions.force_trade_route")) {
7047 /* Forbid entering the marketplace when a trade route can be
7048 * established. */
7049 BV_SET(action_by_number(ACTION_MARKETPLACE)->blocked_by,
7050 ACTION_TRADE_ROUTE);
7051 }
7052
7053 /* Forbid bombarding, exploading nuclear or attacking when it is
7054 * legal to capture units. */
7055 force_capture_units
7057 "actions.force_capture_units");
7058
7059 if (force_capture_units) {
7060 BV_SET(action_by_number(ACTION_BOMBARD)->blocked_by,
7061 ACTION_CAPTURE_UNITS);
7062 BV_SET(action_by_number(ACTION_BOMBARD2)->blocked_by,
7063 ACTION_CAPTURE_UNITS);
7064 BV_SET(action_by_number(ACTION_BOMBARD3)->blocked_by,
7065 ACTION_CAPTURE_UNITS);
7066 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7067 ACTION_CAPTURE_UNITS);
7068 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7069 ACTION_CAPTURE_UNITS);
7070 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7071 ACTION_CAPTURE_UNITS);
7072 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7073 ACTION_CAPTURE_UNITS);
7074 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7075 ACTION_CAPTURE_UNITS);
7076 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7077 ACTION_CAPTURE_UNITS);
7078 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7079 ACTION_CAPTURE_UNITS);
7080 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7081 ACTION_CAPTURE_UNITS);
7082 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7083 ACTION_CAPTURE_UNITS);
7084 }
7085
7086 /* Forbid exploding nuclear or attacking when it is legal to
7087 * bombard. */
7088 force_bombard
7090 "actions.force_bombard");
7091
7092 if (force_bombard) {
7093 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7094 ACTION_BOMBARD);
7095 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7096 ACTION_BOMBARD);
7097 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7098 ACTION_BOMBARD);
7099 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7100 ACTION_BOMBARD);
7101 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7102 ACTION_BOMBARD);
7103 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7104 ACTION_BOMBARD);
7105 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7106 ACTION_BOMBARD);
7107 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7108 ACTION_BOMBARD);
7109 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7110 ACTION_BOMBARD);
7111 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7112 ACTION_BOMBARD2);
7113 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7114 ACTION_BOMBARD2);
7115 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7116 ACTION_BOMBARD2);
7117 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7118 ACTION_BOMBARD2);
7119 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7120 ACTION_BOMBARD2);
7121 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7122 ACTION_BOMBARD2);
7123 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7124 ACTION_BOMBARD2);
7125 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7126 ACTION_BOMBARD2);
7127 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7128 ACTION_BOMBARD2);
7129 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7130 ACTION_BOMBARD3);
7131 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7132 ACTION_BOMBARD3);
7133 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7134 ACTION_BOMBARD3);
7135 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7136 ACTION_BOMBARD3);
7137 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7138 ACTION_BOMBARD3);
7139 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7140 ACTION_BOMBARD3);
7141 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7142 ACTION_BOMBARD3);
7143 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7144 ACTION_BOMBARD3);
7145 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7146 ACTION_BOMBARD3);
7147 }
7148
7149 /* Forbid attacking when it is legal to do explode nuclear. */
7150 force_explode_nuclear
7152 "actions.force_explode_nuclear");
7153
7154 if (force_explode_nuclear) {
7155 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7156 ACTION_NUKE);
7157 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7158 ACTION_NUKE);
7159 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7160 ACTION_NUKE);
7161 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7162 ACTION_NUKE);
7163 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7164 ACTION_NUKE);
7165 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7166 ACTION_NUKE);
7167 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7168 ACTION_NUKE_CITY);
7169 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7170 ACTION_NUKE_CITY);
7171 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7172 ACTION_NUKE_CITY);
7173 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7174 ACTION_NUKE_CITY);
7175 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7176 ACTION_NUKE_CITY);
7177 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7178 ACTION_NUKE_CITY);
7179 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7180 ACTION_NUKE_UNITS);
7181 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7182 ACTION_NUKE_UNITS);
7183 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7184 ACTION_NUKE_UNITS);
7185 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7186 ACTION_NUKE_UNITS);
7187 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7188 ACTION_NUKE_UNITS);
7189 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7190 ACTION_NUKE_UNITS);
7191 }
7192 }
7193
7194 action_iterate(act_id) {
7195 struct action *paction = action_by_number(act_id);
7196
7197 if (!load_action_blocked_by_list(file, filename, paction)) {
7198 ok = FALSE;
7199 break;
7200 }
7202
7203 if (ok && !lookup_bv_actions(file, filename,
7205 "actions.diplchance_initial_odds")) {
7206 ok = FALSE;
7207 }
7208
7209 if (ok) {
7210 /* If the "Poison City" action or the "Poison City Escape" action
7211 * should empty the granary. */
7212 /* TODO: empty granary and reduce population should become separate
7213 * action effect flags when actions are generalized. */
7217 "actions.poison_empties_food_stock");
7218
7219 /* If the "Steal Maps" action or the "Steal Maps Escape" action always
7220 * will reveal all cities when successful. */
7224 "actions.steal_maps_reveals_all_cities");
7225
7226 /* Allow setting certain properties for some actions before
7227 * generalized actions. */
7228 action_iterate(act_id) {
7229 if (!load_action_range(compat, file, act_id)) {
7230 ok = FALSE;
7231 } else if (!load_action_kind(file, act_id)) {
7232 ok = FALSE;
7233 } else if (!load_action_actor_consuming_always(file, act_id)) {
7234 ok = FALSE;
7235 } else {
7236 load_action_ui_name(file, act_id,
7239 }
7240
7241 if (!ok) {
7242 break;
7243 }
7245
7246 /* The quiet (don't auto generate help for) property of all actions
7247 * live in a single enum vector. This avoids generic action
7248 * expectations. */
7249 if (ok && secfile_entry_by_path(file, "actions.quiet_actions")) {
7250 enum gen_action *quiet_actions;
7251 size_t asize;
7252 int j;
7253
7254 quiet_actions =
7255 secfile_lookup_enum_vec(file, &asize, gen_action,
7256 "actions.quiet_actions");
7257
7258 if (!quiet_actions) {
7259 /* Entity exists but couldn't read it. */
7261 "\"%s\": actions.quiet_actions: bad action list",
7262 filename);
7263
7264 ok = FALSE;
7265 } else {
7266 for (j = 0; j < asize; j++) {
7267 /* Don't auto generate help text for this action. */
7268 action_by_number(quiet_actions[j])->quiet = TRUE;
7269 }
7270
7271 free(quiet_actions);
7272 }
7273 }
7274
7275 if (ok) {
7276 /* Hard code action sub results for now. */
7277
7278 /* Unit Enter Hut */
7279 action_by_result_iterate(paction, ACTRES_HUT_ENTER) {
7280 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
7282 BV_SET(action_by_number(ACTION_PARADROP_ENTER)->sub_results,
7283 ACT_SUB_RES_HUT_ENTER);
7284 BV_SET(action_by_number(ACTION_PARADROP_ENTER_CONQUER)->sub_results,
7285 ACT_SUB_RES_HUT_ENTER);
7286
7287 /* Unit Frighten Hut */
7288 action_by_result_iterate(paction, ACTRES_HUT_FRIGHTEN) {
7289 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN);
7291 BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN)->sub_results,
7292 ACT_SUB_RES_HUT_FRIGHTEN);
7293 BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN_CONQUER)->sub_results,
7294 ACT_SUB_RES_HUT_FRIGHTEN);
7295
7296 /* Unit May Embark */
7297 action_iterate(act_id) {
7298 struct action *paction = action_by_number(act_id);
7299
7301 "civstyle.paradrop_to_transport")
7302 && (action_has_result(paction, ACTRES_PARADROP)
7303 || action_has_result(paction, ACTRES_PARADROP_CONQUER))) {
7304 BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
7305 }
7306
7307 /* Embark actions will always embark, not maybe embark. */
7309 }
7310 }
7311 }
7312
7313 if (ok) {
7314 /* Forced actions after another action was successfully performed. */
7315
7316 /* "Bribe Unit" */
7317 if (!load_action_post_success_force(file, filename,
7320 ACTION_SPY_BRIBE_UNIT))) {
7321 ok = FALSE;
7322 } else if (!load_action_post_success_force(file, filename,
7325 ACTION_ATTACK))) {
7326 ok = FALSE;
7327 }
7328 }
7329
7330 if (ok) {
7331 struct action_auto_perf *auto_perf;
7332
7333 /* The city that made the unit's current tile native is gone.
7334 * Evaluated against an adjacent tile. */
7336 auto_perf->cause = AAPC_CITY_GONE;
7337
7338 /* I have no objections to moving this out of game's actions to
7339 * cities.ruleset, units.ruleset or an other location in game.ruleset
7340 * you find more suitable. -- Sveinung */
7341 if (!load_action_auto_actions(file, auto_perf,
7342 "actions.escape_city", filename)) {
7343 ok = FALSE;
7344 }
7345 }
7346
7347 if (ok) {
7348 struct action_auto_perf *auto_perf;
7349
7350 /* The unit's stack has been defeated and is scheduled for execution
7351 * but the unit has the CanEscape unit type flag.
7352 * Evaluated against an adjacent tile. */
7354 auto_perf->cause = AAPC_UNIT_STACK_DEATH;
7355
7356 /* I have no objections to moving this out of game's actions to
7357 * cities.ruleset, units.ruleset or an other location in game.ruleset
7358 * you find more suitable. -- Sveinung */
7359 if (!load_action_auto_actions(file, auto_perf,
7360 "actions.unit_stack_death", filename)) {
7361 ok = FALSE;
7362 }
7363 }
7364
7365 if (ok) {
7368
7369 if (sec) {
7370 section_list_iterate(sec, psection) {
7371 struct action_enabler *enabler;
7372 const char *sec_name = section_name(psection);
7373 struct action *paction;
7374 struct requirement_vector *actor_reqs;
7375 struct requirement_vector *target_reqs;
7376 const char *action_text;
7377
7378 enabler = action_enabler_new();
7379
7380 action_text = secfile_lookup_str(file, "%s.action", sec_name);
7381
7382 if (action_text == NULL) {
7384 "\"%s\" [%s] missing action to enable.",
7385 filename, sec_name);
7386 ok = FALSE;
7387 break;
7388 }
7389
7390 paction = action_by_rule_name(action_text);
7391 if (!paction) {
7393 "\"%s\" [%s] lists unknown action type \"%s\".",
7394 filename, sec_name, action_text);
7395 ok = FALSE;
7396 break;
7397 }
7398
7399 enabler->action = paction->id;
7400
7401 actor_reqs = lookup_req_list(file, compat, sec_name, "actor_reqs", action_text);
7402 if (actor_reqs == NULL) {
7403 ok = FALSE;
7404 break;
7405 }
7406
7407 requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
7408
7409 target_reqs = lookup_req_list(file, compat, sec_name, "target_reqs", action_text);
7410 if (target_reqs == NULL) {
7411 ok = FALSE;
7412 break;
7413 }
7414
7415 requirement_vector_copy(&enabler->target_reqs, target_reqs);
7416
7417 action_enabler_add(enabler);
7419
7420 section_list_destroy(sec);
7421 }
7422 }
7423 }
7424
7425 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7426 bool slow_invasions
7428 "global_unit_options.slow_invasions");
7429
7430 if (!rscompat_old_slow_invasions_3_1(compat, slow_invasions)) {
7431 ok = FALSE;
7432 }
7433 }
7434
7435 if (ok) {
7436 const char *tus_text;
7437 bool default_drbr = RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE;
7438
7439 /* section: combat_rules */
7442 "combat_rules.tired_attack");
7443
7446 "combat_rules.only_killing_makes_veteran");
7447
7450 "combat_rules.only_real_fight_makes_veteran");
7451
7454 "combat_rules.combat_odds_scaled_veterancy");
7455
7456 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7457 /* Old hardcoded behavior was not to have bombard rate reduced for damage. */
7458 default_drbr = FALSE;
7459 }
7461 = secfile_lookup_bool_default(file, default_drbr,
7462 "combat_rules.damage_reduces_bombard_rate");
7463
7466 "combat_rules.low_firepower_badwallattacker");
7469 "combat_rules.low_firepower_pearl_harbour");
7472 "combat_rules.low_firepower_combat_bonus");
7475 "combat_rules.low_firepower_nonnat_bombard");
7476
7481 "combat_rules.nuke_pop_loss_pct");
7482
7487 "combat_rules.nuke_defender_survival_chance_pct");
7488
7489 /* section: borders */
7495 "borders.radius_sq_city");
7501 "borders.size_effect");
7502
7508 "borders.radius_sq_city_permanent");
7509
7510 /* section: research */
7512 "research.tech_cost_style");
7513 game.info.tech_cost_style = tech_cost_style_by_name(tus_text,
7515 if (!tech_cost_style_is_valid(game.info.tech_cost_style)) {
7517 "Unknown tech cost style \"%s\"",
7518 tus_text);
7519 ok = FALSE;
7520 }
7521
7523 "research.tech_leakage");
7524 game.info.tech_leakage = tech_leakage_style_by_name(tus_text,
7526 if (!tech_leakage_style_is_valid(game.info.tech_leakage)) {
7528 "Unknown tech leakage \"%s\"",
7529 tus_text);
7530 ok = FALSE;
7531 }
7532 if (game.info.tech_cost_style == TECH_COST_CIV1CIV2
7533 && game.info.tech_leakage != TECH_LEAKAGE_NONE) {
7534 log_error("Only tech_leakage \"%s\" supported with "
7535 "tech_cost_style \"%s\". ",
7536 tech_leakage_style_name(TECH_LEAKAGE_NONE),
7537 tech_cost_style_name(TECH_COST_CIV1CIV2));
7538 log_error("Switching to tech_leakage \"%s\".",
7539 tech_leakage_style_name(TECH_LEAKAGE_NONE));
7540 game.info.tech_leakage = TECH_LEAKAGE_NONE;
7541 }
7547 "research.base_tech_cost");
7548
7550 "research.tech_upkeep_style");
7551
7552 game.info.tech_upkeep_style = tech_upkeep_style_by_name(tus_text, fc_strcasecmp);
7553
7554 if (!tech_upkeep_style_is_valid(game.info.tech_upkeep_style)) {
7556 "Unknown tech upkeep style \"%s\"",
7557 tus_text);
7558 ok = FALSE;
7559 }
7560 }
7561
7562 if (ok) {
7568 "research.tech_upkeep_divider");
7569
7570 sval = secfile_lookup_str_default(file, NULL, "research.free_tech_method");
7571 if (sval == NULL) {
7573 "No free_tech_method given");
7574 ok = FALSE;
7575 } else {
7576 game.info.free_tech_method = free_tech_method_by_name(sval, fc_strcasecmp);
7577 if (!free_tech_method_is_valid(game.info.free_tech_method)) {
7579 "Bad value %s for free_tech_method.", sval);
7580 ok = FALSE;
7581 }
7582 }
7583 }
7584
7585 if (ok) {
7586 int cf;
7587
7588 /* section: culture */
7591 "culture.victory_min_points");
7594 "culture.victory_lead_pct");
7597 "culture.migration_pml");
7600 "culture.history_interest_pml");
7601
7602 /* section: calendar */
7605 "calendar.skip_year_0");
7608 "calendar.start_year");
7610 = secfile_lookup_int_default(file, 0, "calendar.fragments");
7611
7614 "Too many calendar fragments. Max is %d",
7616 ok = FALSE;
7618 }
7622 "calendar.positive_label"));
7626 "calendar.negative_label"));
7627
7628 for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
7629 const char *fname;
7630
7631 fname = secfile_lookup_str_default(file, NULL, "calendar.fragment_name%d", cf);
7632 if (fname != NULL) {
7633 strncpy(game.calendar.calendar_fragment_name[cf], fname,
7635 }
7636 }
7637 }
7638
7639 if (ok) {
7640 /* section playercolors */
7641 struct rgbcolor *prgbcolor = NULL;
7642 bool color_read = TRUE;
7643
7644 /* Check if the player list is defined and empty. */
7645 if (playercolor_count() != 0) {
7646 ok = FALSE;
7647 } else {
7648 i = 0;
7649
7650 while (color_read) {
7651 prgbcolor = NULL;
7652
7653 color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
7654 if (color_read) {
7655 playercolor_add(prgbcolor);
7656 }
7657
7658 i++;
7659 }
7660
7661 if (playercolor_count() == 0) {
7662 ruleset_error(NULL, LOG_ERROR, "No player colors defined!");
7663 ok = FALSE;
7664 }
7665
7666 if (ok) {
7667 fc_assert(game.plr_bg_color == NULL);
7668 if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
7670 "No background player color defined! (%s)",
7671 secfile_error());
7672 ok = FALSE;
7673 }
7674 }
7675 }
7676 }
7677
7678 if (ok) {
7679 /* section: teams */
7680 svec = secfile_lookup_str_vec(file, &teams, "teams.names");
7681 if (team_slot_count() < teams) {
7682 teams = team_slot_count();
7683 }
7685 for (i = 0; i < teams; i++) {
7687 }
7688 free(svec);
7689
7691 nval = (NULL != sec ? section_list_size(sec) : 0);
7692 if (nval > MAX_DISASTER_TYPES) {
7693 int num = nval; /* No "size_t" to printf */
7694
7696 "\"%s\": Too many disaster types (%d, max %d)",
7697 filename, num, MAX_DISASTER_TYPES);
7698 section_list_destroy(sec);
7699 ok = FALSE;
7700 } else {
7702 }
7703 }
7704
7705 if (ok) {
7706 disaster_type_iterate(pdis) {
7707 int id = disaster_index(pdis);
7708 int j;
7709 size_t eff_count;
7710 struct requirement_vector *reqs;
7711 const char *sec_name = section_name(section_list_get(sec, id));
7712
7713 if (!ruleset_load_names(&pdis->name, NULL, file, sec_name)) {
7715 "\"%s\": Cannot load disaster names",
7716 filename);
7717 ok = FALSE;
7718 break;
7719 }
7720
7721 reqs = lookup_req_list(file, compat, sec_name, "reqs", disaster_rule_name(pdis));
7722 if (reqs == NULL) {
7723 ok = FALSE;
7724 break;
7725 }
7726 requirement_vector_copy(&pdis->reqs, reqs);
7727
7729 "%s.frequency", sec_name);
7730
7731 svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
7732
7733 BV_CLR_ALL(pdis->effects);
7734 for (j = 0; j < eff_count; j++) {
7735 const char *dsval = svec[j];
7736 enum disaster_effect_id effect;
7737
7738 effect = disaster_effect_id_by_name(dsval, fc_strcasecmp);
7739
7740 if (!disaster_effect_id_is_valid(effect)) {
7742 "\"%s\" disaster \"%s\": unknown effect \"%s\".",
7743 filename, disaster_rule_name(pdis), dsval);
7744 ok = FALSE;
7745 break;
7746 } else {
7747 BV_SET(pdis->effects, effect);
7748 }
7749 }
7750
7751 free(svec);
7752
7753 if (!ok) {
7754 break;
7755 }
7757 section_list_destroy(sec);
7758 }
7759
7760 if (ok) {
7762
7763 achievements_iterate(pach) {
7764 int id = achievement_index(pach);
7765 const char *sec_name = section_name(section_list_get(sec, id));
7766 const char *typename;
7767 const char *msg;
7768
7769 typename = secfile_lookup_str_default(file, NULL, "%s.type", sec_name);
7770
7771 pach->type = achievement_type_by_name(typename, fc_strcasecmp);
7772 if (!achievement_type_is_valid(pach->type)) {
7774 "Achievement has unknown type \"%s\".",
7775 typename != NULL ? typename : "(NULL)");
7776 ok = FALSE;
7777 }
7778
7779 if (ok) {
7781 "%s.unique", sec_name);
7782
7784 "%s.value", sec_name);
7785 pach->culture = secfile_lookup_int_default(file, 0,
7786 "%s.culture", sec_name);
7787
7788 msg = secfile_lookup_str_default(file, NULL, "%s.first_msg", sec_name);
7789 if (msg == NULL) {
7791 "Achievement %s has no first msg!", sec_name);
7792 ok = FALSE;
7793 } else {
7794 pach->first_msg = fc_strdup(msg);
7795 }
7796 }
7797
7798 if (ok) {
7799 msg = secfile_lookup_str_default(file, NULL, "%s.cons_msg", sec_name);
7800 if (msg == NULL) {
7801 if (!pach->unique) {
7803 "Achievement %s has no msg for consecutive gainers!",
7804 sec_name);
7805 ok = FALSE;
7806 }
7807 } else {
7808 pach->cons_msg = fc_strdup(msg);
7809 }
7810 }
7811
7812 if (!ok) {
7813 break;
7814 }
7816 section_list_destroy(sec);
7817 }
7818
7819 if (ok) {
7820 for (i = 0; (name = secfile_lookup_str_default(file, NULL,
7821 "trade.settings%d.type",
7822 i)); i++) {
7824
7825 if (type == TRT_LAST) {
7827 "\"%s\" unknown trade route type \"%s\".",
7828 filename, name);
7829 ok = FALSE;
7830 } else {
7832 const char *cancelling;
7833 const char *bonus;
7834
7835 set->trade_pct = secfile_lookup_int_default(file, 100,
7836 "trade.settings%d.pct", i);
7837 cancelling = secfile_lookup_str_default(file, "Active",
7838 "trade.settings%d.cancelling", i);
7840 if (set->cancelling == TRI_LAST) {
7842 "\"%s\" unknown trade route cancelling type \"%s\".",
7843 filename, cancelling);
7844 ok = FALSE;
7845 }
7846
7847 bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
7848
7849 set->bonus_type = trade_route_bonus_type_by_name(bonus, fc_strcasecmp);
7850
7851 if (!trade_route_bonus_type_is_valid(set->bonus_type)) {
7853 "\"%s\" unknown trade route bonus type \"%s\".",
7854 filename, bonus);
7855 ok = FALSE;
7856 }
7857 }
7858 }
7859 }
7860
7861 if (ok) {
7862 const char *str;
7863
7865 = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
7866
7868 goods_selection_method_name(RS_DEFAULT_GOODS_SELECTION),
7869 "trade.goods_selection");
7870
7871 game.info.goods_selection = goods_selection_method_by_name(str, fc_strcasecmp);
7872
7873 if (!goods_selection_method_is_valid(game.info.goods_selection)) {
7875 "\"%s\" goods selection method \"%s\" unknown.",
7876 filename, str);
7877 ok = FALSE;
7878 }
7879 }
7880
7881 if (ok) {
7883
7884 goods_type_iterate(pgood) {
7885 int id = goods_index(pgood);
7886 const char *sec_name = section_name(section_list_get(sec, id));
7887 struct requirement_vector *reqs;
7888 const char **slist;
7889 int j;
7890
7891 reqs = lookup_req_list(file, compat, sec_name, "reqs", goods_rule_name(pgood));
7892 if (reqs == NULL) {
7893 ok = FALSE;
7894 break;
7895 }
7896 requirement_vector_copy(&pgood->reqs, reqs);
7897
7898 pgood->from_pct = secfile_lookup_int_default(file, 100,
7899 "%s.from_pct", sec_name);
7900 pgood->to_pct = secfile_lookup_int_default(file, 100,
7901 "%s.to_pct", sec_name);
7902 pgood->onetime_pct = secfile_lookup_int_default(file, 100,
7903 "%s.onetime_pct", sec_name);
7904
7905 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
7906 BV_CLR_ALL(pgood->flags);
7907 for (j = 0; j < nval; j++) {
7908 enum goods_flag_id flag;
7909
7910 sval = slist[j];
7911 flag = goods_flag_id_by_name(sval, fc_strcasecmp);
7912 if (!goods_flag_id_is_valid(flag)) {
7913 ruleset_error(NULL, LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
7914 filename, goods_rule_name(pgood), sval);
7915 ok = FALSE;
7916 break;
7917 } else {
7918 BV_SET(pgood->flags, flag);
7919 }
7920 }
7921 free(slist);
7922
7923 pgood->helptext = lookup_strvec(file, sec_name, "helptext");
7925 section_list_destroy(sec);
7926 }
7927
7928 if (ok) {
7930
7931 if (sec != NULL) {
7932 int num = section_list_size(sec);
7933
7934 for (i = 0; i < num; i++) {
7935 const char *sec_name = section_name(section_list_get(sec, i));
7936 const char *clause_name = secfile_lookup_str_default(file, NULL,
7937 "%s.type", sec_name);
7938 enum clause_type type = clause_type_by_name(clause_name, fc_strcasecmp);
7939 struct clause_info *info;
7940 struct requirement_vector *reqs;
7941
7942 if (!clause_type_is_valid(type)) {
7944 "\"%s\" unknown clause type \"%s\".",
7945 filename, clause_name);
7946 ok = FALSE;
7947 break;
7948 }
7949
7950 info = clause_info_get(type);
7951
7952 if (info->enabled) {
7954 "\"%s\" duplicate clause type \"%s\" definition.",
7955 filename, clause_name);
7956 ok = FALSE;
7957 break;
7958 }
7959
7960 reqs = lookup_req_list(file, compat, sec_name, "giver_reqs", clause_name);
7961 if (reqs == NULL) {
7962 ok = FALSE;
7963 break;
7964 }
7965 requirement_vector_copy(&info->giver_reqs, reqs);
7966
7967 reqs = lookup_req_list(file, compat, sec_name, "receiver_reqs", clause_name);
7968 if (reqs == NULL) {
7969 ok = FALSE;
7970 break;
7971 }
7972 requirement_vector_copy(&info->receiver_reqs, reqs);
7973
7974 info->enabled = TRUE;
7975 }
7976 }
7977 section_list_destroy(sec);
7978 }
7979
7980 /* secfile_check_unused() is not here, but only after also settings section
7981 * has been loaded. */
7982
7983 return ok;
7984}
7985
7986/**********************************************************************/
7990static void send_ruleset_unit_classes(struct conn_list *dest)
7991{
7992 struct packet_ruleset_unit_class packet;
7993 struct packet_ruleset_unit_class_flag fpacket;
7994 int i;
7995
7996 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
7997 const char *flagname;
7998 const char *helptxt;
7999
8000 fpacket.id = i + UCF_USER_FLAG_1;
8001
8002 flagname = unit_class_flag_id_name(i + UCF_USER_FLAG_1);
8003 if (flagname == NULL) {
8004 fpacket.name[0] = '\0';
8005 } else {
8006 sz_strlcpy(fpacket.name, flagname);
8007 }
8008
8009 helptxt = unit_class_flag_helptxt(i + UCF_USER_FLAG_1);
8010 if (helptxt == NULL) {
8011 fpacket.helptxt[0] = '\0';
8012 } else {
8013 sz_strlcpy(fpacket.helptxt, helptxt);
8014 }
8015
8017 }
8018
8020 packet.id = uclass_number(c);
8021 sz_strlcpy(packet.name, untranslated_name(&c->name));
8022 sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
8023 packet.min_speed = c->min_speed;
8024 packet.hp_loss_pct = c->hp_loss_pct;
8025 packet.non_native_def_pct = c->non_native_def_pct;
8026 packet.flags = c->flags;
8027
8028 PACKET_STRVEC_COMPUTE(packet.helptext, c->helptext);
8029
8030 lsend_packet_ruleset_unit_class(dest, &packet);
8032}
8033
8034/**********************************************************************/
8038static void send_ruleset_units(struct conn_list *dest)
8039{
8040 struct packet_ruleset_unit packet;
8041#ifdef FREECIV_WEB
8042 struct packet_web_ruleset_unit_addition web_packet;
8043#endif /* FREECIV_WEB */
8044 struct packet_ruleset_unit_flag fpacket;
8045 int i;
8046
8047 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
8048 const char *flagname;
8049 const char *helptxt;
8050
8051 fpacket.id = i + UTYF_USER_FLAG_1;
8052
8053 flagname = unit_type_flag_id_name(i + UTYF_USER_FLAG_1);
8054 if (flagname == NULL) {
8055 fpacket.name[0] = '\0';
8056 } else {
8057 sz_strlcpy(fpacket.name, flagname);
8058 }
8059
8060 helptxt = unit_type_flag_helptxt(i + UTYF_USER_FLAG_1);
8061 if (helptxt == NULL) {
8062 fpacket.helptxt[0] = '\0';
8063 } else {
8064 sz_strlcpy(fpacket.helptxt, helptxt);
8065 }
8066
8067 lsend_packet_ruleset_unit_flag(dest, &fpacket);
8068 }
8069
8071 packet.id = utype_number(u);
8072 sz_strlcpy(packet.name, untranslated_name(&u->name));
8073 sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
8074 sz_strlcpy(packet.sound_move, u->sound_move);
8075 sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
8076 sz_strlcpy(packet.sound_fight, u->sound_fight);
8077 sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
8078 sz_strlcpy(packet.graphic_str, u->graphic_str);
8079 sz_strlcpy(packet.graphic_alt, u->graphic_alt);
8081 packet.build_cost = u->build_cost;
8082 packet.pop_cost = u->pop_cost;
8083 packet.attack_strength = u->attack_strength;
8084 packet.defense_strength = u->defense_strength;
8085 packet.move_rate = u->move_rate;
8086 packet.tech_requirement = u->require_advance
8087 ? advance_number(u->require_advance)
8088 : advance_count();
8089
8090 i = 0;
8091 requirement_vector_iterate(&u->build_reqs, req) {
8092 packet.build_reqs[i++] = *req;
8094 packet.build_reqs_count = i;
8095
8096 packet.vision_radius_sq = u->vision_radius_sq;
8097 packet.transport_capacity = u->transport_capacity;
8098 packet.hp = u->hp;
8099 packet.firepower = u->firepower;
8100 packet.obsoleted_by = u->obsoleted_by
8101 ? utype_number(u->obsoleted_by)
8102 : utype_count();
8103 packet.converted_to = u->converted_to
8104 ? utype_number(u->converted_to)
8105 : utype_count();
8106 packet.convert_time = u->convert_time;
8107 packet.fuel = u->fuel;
8108 packet.flags = u->flags;
8109 packet.roles = u->roles;
8110 packet.happy_cost = u->happy_cost;
8112 packet.upkeep[o] = u->upkeep[o];
8114 packet.paratroopers_range = u->paratroopers_range;
8115 packet.bombard_rate = u->bombard_rate;
8116 packet.city_size = u->city_size;
8117 packet.city_slots = u->city_slots;
8118 packet.tp_defense = u->tp_defense;
8119 packet.cargo = u->cargo;
8120 packet.targets = u->targets;
8121 packet.embarks = u->embarks;
8122 packet.disembarks = u->disembarks;
8123 packet.vlayer = u->vlayer;
8124
8125 if (u->veteran == NULL) {
8126 /* Use the default veteran system. */
8127 packet.veteran_levels = 0;
8128 } else {
8129 /* Per unit veteran system definition. */
8131
8132 for (i = 0; i < packet.veteran_levels; i++) {
8133 const struct veteran_level *vlevel = utype_veteran_level(u, i);
8134
8135 sz_strlcpy(packet.veteran_name[i], untranslated_name(&vlevel->name));
8136 packet.power_fact[i] = vlevel->power_fact;
8137 packet.move_bonus[i] = vlevel->move_bonus;
8138 packet.base_raise_chance[i] = vlevel->base_raise_chance;
8139 packet.work_raise_chance[i] = vlevel->work_raise_chance;
8140 }
8141 }
8142 PACKET_STRVEC_COMPUTE(packet.helptext, u->helptext);
8143
8144 packet.worker = u->adv.worker;
8145
8146#ifdef FREECIV_WEB
8147 web_packet.id = utype_number(u);
8148
8149 BV_CLR_ALL(web_packet.utype_actions);
8150
8151 action_iterate(act) {
8152 if (utype_can_do_action(u, act)) {
8153 BV_SET(web_packet.utype_actions, act);
8154 }
8156#endif /* FREECIV_WEB */
8157
8158 lsend_packet_ruleset_unit(dest, &packet);
8159 web_lsend_packet(ruleset_unit_addition, dest, &web_packet);
8160
8161 combat_bonus_list_iterate(u->bonuses, pbonus) {
8162 struct packet_ruleset_unit_bonus bonuspacket;
8163
8164 bonuspacket.unit = packet.id;
8165 bonuspacket.flag = pbonus->flag;
8166 bonuspacket.type = pbonus->type;
8167 bonuspacket.value = pbonus->value;
8168 bonuspacket.quiet = pbonus->quiet;
8169
8170 lsend_packet_ruleset_unit_bonus(dest, &bonuspacket);
8173}
8174
8175/**********************************************************************/
8179static void send_ruleset_specialists(struct conn_list *dest)
8180{
8181 struct packet_ruleset_specialist packet;
8182
8183 specialist_type_iterate(spec_id) {
8184 struct specialist *s = specialist_by_number(spec_id);
8185 int j;
8186
8187 packet.id = spec_id;
8189 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
8193 j = 0;
8194 requirement_vector_iterate(&s->reqs, preq) {
8195 packet.reqs[j++] = *preq;
8197 packet.reqs_count = j;
8198
8200
8201 lsend_packet_ruleset_specialist(dest, &packet);
8203}
8204/**********************************************************************/
8207static void send_ruleset_tech_classes(struct conn_list *dest)
8208{
8209 struct packet_ruleset_tech_class packet;
8210
8211 tech_class_iterate(ptclass) {
8212 packet.id = ptclass->idx;
8213 sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
8214 sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
8215 packet.cost_pct = ptclass->cost_pct;
8216
8217 lsend_packet_ruleset_tech_class(dest, &packet);
8219}
8220
8221/**********************************************************************/
8225static void send_ruleset_techs(struct conn_list *dest)
8226{
8227 struct packet_ruleset_tech packet;
8228 struct packet_ruleset_tech_flag fpacket;
8229 int i;
8230
8231 for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
8232 const char *flagname;
8233 const char *helptxt;
8234
8235 fpacket.id = i + TECH_USER_1;
8236
8237 flagname = tech_flag_id_name_cb(i + TECH_USER_1);
8238 if (flagname == NULL) {
8239 fpacket.name[0] = '\0';
8240 } else {
8241 sz_strlcpy(fpacket.name, flagname);
8242 }
8243
8244 helptxt = tech_flag_helptxt(i + TECH_USER_1);
8245 if (helptxt == NULL) {
8246 fpacket.helptxt[0] = '\0';
8247 } else {
8248 sz_strlcpy(fpacket.helptxt, helptxt);
8249 }
8250
8251 lsend_packet_ruleset_tech_flag(dest, &fpacket);
8252 }
8253
8255 packet.id = advance_number(a);
8256 packet.removed = !valid_advance(a);
8257 if (a->tclass == NULL) {
8258 packet.tclass = 0;
8259 } else {
8260 packet.tclass = a->tclass->idx;
8261 }
8262 sz_strlcpy(packet.name, untranslated_name(&a->name));
8263 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8264 sz_strlcpy(packet.graphic_str, a->graphic_str);
8265 sz_strlcpy(packet.graphic_alt, a->graphic_alt);
8266
8267 /* Current size of the packet's research_reqs requirement vector. */
8268 i = 0;
8269
8270 /* The requirements req1 and req2 are needed to research a tech. Send
8271 * them in the research_reqs requirement vector. Range is set to player
8272 * since pooled research is configurable. */
8273
8274 if ((a->require[AR_ONE] != A_NEVER)
8275 && advance_number(a->require[AR_ONE]) > A_NONE) {
8276 packet.research_reqs[i++]
8277 = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
8278 FALSE, TRUE, FALSE,
8279 advance_number(a->require[AR_ONE]));
8280 }
8281
8282 if ((a->require[AR_TWO] != A_NEVER)
8283 && advance_number(a->require[AR_TWO]) > A_NONE) {
8284 packet.research_reqs[i++]
8285 = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
8286 FALSE, TRUE, FALSE,
8287 advance_number(a->require[AR_TWO]));;
8288 }
8289
8290 /* The requirements of the tech's research_reqs also goes in the
8291 * packet's research_reqs requirement vector. */
8292 requirement_vector_iterate(&a->research_reqs, req) {
8293 packet.research_reqs[i++] = *req;
8295
8296 /* The packet's research_reqs should contain req1, req2 and the
8297 * requirements of the tech's research_reqs. */
8298 packet.research_reqs_count = i;
8299
8300 packet.root_req = a->require[AR_ROOT]
8301 ? advance_number(a->require[AR_ROOT])
8302 : advance_count();
8303
8304 packet.flags = a->flags;
8305 packet.cost = a->cost;
8306 packet.num_reqs = a->num_reqs;
8307 PACKET_STRVEC_COMPUTE(packet.helptext, a->helptext);
8308
8309 lsend_packet_ruleset_tech(dest, &packet);
8311}
8312
8313/**********************************************************************/
8317static void send_ruleset_buildings(struct conn_list *dest)
8318{
8320 struct packet_ruleset_building packet;
8321 int j;
8322
8323 packet.id = improvement_number(b);
8324 packet.genus = b->genus;
8325 sz_strlcpy(packet.name, untranslated_name(&b->name));
8326 sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
8327 sz_strlcpy(packet.graphic_str, b->graphic_str);
8328 sz_strlcpy(packet.graphic_alt, b->graphic_alt);
8329 j = 0;
8330 requirement_vector_iterate(&b->reqs, preq) {
8331 packet.reqs[j++] = *preq;
8333 packet.reqs_count = j;
8334 j = 0;
8335 requirement_vector_iterate(&b->obsolete_by, pobs) {
8336 packet.obs_reqs[j++] = *pobs;
8338 packet.obs_count = j;
8339 packet.build_cost = b->build_cost;
8340 packet.upkeep = b->upkeep;
8341 packet.sabotage = b->sabotage;
8342 packet.flags = b->flags;
8343 sz_strlcpy(packet.soundtag, b->soundtag);
8344 sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
8345 PACKET_STRVEC_COMPUTE(packet.helptext, b->helptext);
8346
8347 lsend_packet_ruleset_building(dest, &packet);
8349}
8350
8351/**********************************************************************/
8355static void send_ruleset_terrain(struct conn_list *dest)
8356{
8357 struct packet_ruleset_terrain packet;
8358 struct packet_ruleset_terrain_flag fpacket;
8359 int i;
8360
8362
8363 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
8364 const char *flagname;
8365 const char *helptxt;
8366
8367 fpacket.id = i + TER_USER_1;
8368
8369 flagname = terrain_flag_id_name_cb(i + TER_USER_1);
8370 if (flagname == NULL) {
8371 fpacket.name[0] = '\0';
8372 } else {
8373 sz_strlcpy(fpacket.name, flagname);
8374 }
8375
8376 helptxt = terrain_flag_helptxt(i + TER_USER_1);
8377 if (helptxt == NULL) {
8378 fpacket.helptxt[0] = '\0';
8379 } else {
8380 sz_strlcpy(fpacket.helptxt, helptxt);
8381 }
8382
8383 lsend_packet_ruleset_terrain_flag(dest, &fpacket);
8384 }
8385
8386 terrain_type_iterate(pterrain) {
8387 struct extra_type **r;
8388
8389 packet.id = terrain_number(pterrain);
8390 packet.tclass = pterrain->tclass;
8391 packet.native_to = pterrain->native_to;
8392
8393 sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
8394 sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
8395 sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
8396 sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
8397
8398 packet.movement_cost = pterrain->movement_cost;
8399 packet.defense_bonus = pterrain->defense_bonus;
8400
8402 packet.output[o] = pterrain->output[o];
8404
8405 packet.num_resources = 0;
8406 for (r = pterrain->resources; *r; r++) {
8407 packet.resources[packet.num_resources++] = extra_number(*r);
8408 }
8409
8411 packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
8413
8414 packet.base_time = pterrain->base_time;
8415 packet.road_time = pterrain->road_time;
8416
8417 packet.cultivate_result = (pterrain->cultivate_result
8418 ? terrain_number(pterrain->cultivate_result)
8419 : terrain_count());
8420 packet.cultivate_time = pterrain->cultivate_time;
8421
8422 packet.plant_result = (pterrain->plant_result
8423 ? terrain_number(pterrain->plant_result)
8424 : terrain_count());
8425 packet.plant_time = pterrain->plant_time;
8426
8427 packet.irrigation_food_incr = pterrain->irrigation_food_incr;
8428 packet.irrigation_time = pterrain->irrigation_time;
8429
8430 packet.mining_shield_incr = pterrain->mining_shield_incr;
8431 packet.mining_time = pterrain->mining_time;
8432
8433 packet.animal = (pterrain->animal == NULL ? -1 : utype_number(pterrain->animal));
8434 packet.transform_result = (pterrain->transform_result
8435 ? terrain_number(pterrain->transform_result)
8436 : terrain_count());
8437 packet.placing_time = pterrain->placing_time;
8438 packet.pillage_time = pterrain->pillage_time;
8439 packet.transform_time = pterrain->transform_time;
8440 packet.clean_pollution_time = pterrain->clean_pollution_time;
8441 packet.clean_fallout_time = pterrain->clean_fallout_time;
8442
8443 packet.flags = pterrain->flags;
8444
8445 packet.color_red = pterrain->rgb->r;
8446 packet.color_green = pterrain->rgb->g;
8447 packet.color_blue = pterrain->rgb->b;
8448
8449 PACKET_STRVEC_COMPUTE(packet.helptext, pterrain->helptext);
8450
8451 lsend_packet_ruleset_terrain(dest, &packet);
8453}
8454
8455/**********************************************************************/
8458static void send_ruleset_resources(struct conn_list *dest)
8459{
8460 struct packet_ruleset_resource packet;
8461
8462 extra_type_by_cause_iterate(EC_RESOURCE, presource) {
8463 packet.id = extra_index(presource);
8464
8466 packet.output[o] = presource->data.resource->output[o];
8468
8469 lsend_packet_ruleset_resource(dest, &packet);
8471}
8472
8473/**********************************************************************/
8477static void send_ruleset_extras(struct conn_list *dest)
8478{
8479 struct packet_ruleset_extra packet;
8480 struct packet_ruleset_extra_flag fpacket;
8481 int i;
8482
8483 for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
8484 const char *flagname;
8485 const char *helptxt;
8486
8487 fpacket.id = i + EF_USER_FLAG_1;
8488
8489 flagname = extra_flag_id_name(i + EF_USER_FLAG_1);
8490 if (flagname == NULL) {
8491 fpacket.name[0] = '\0';
8492 } else {
8493 sz_strlcpy(fpacket.name, flagname);
8494 }
8495
8496 helptxt = extra_flag_helptxt(i + EF_USER_FLAG_1);
8497 if (helptxt == NULL) {
8498 fpacket.helptxt[0] = '\0';
8499 } else {
8500 sz_strlcpy(fpacket.helptxt, helptxt);
8501 }
8502
8503 lsend_packet_ruleset_extra_flag(dest, &fpacket);
8504 }
8505
8507 int j;
8508
8509 packet.id = extra_number(e);
8510 sz_strlcpy(packet.name, untranslated_name(&e->name));
8511 sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
8512
8513 packet.category = e->category;
8514
8515 BV_CLR_ALL(packet.causes);
8516 for (j = 0; j < EC_COUNT; j++) {
8517 if (is_extra_caused_by(e, j)) {
8518 BV_SET(packet.causes, j);
8519 }
8520 }
8521
8522 BV_CLR_ALL(packet.rmcauses);
8523 for (j = 0; j < ERM_COUNT; j++) {
8524 if (is_extra_removed_by(e, j)) {
8525 BV_SET(packet.rmcauses, j);
8526 }
8527 }
8528
8529 sz_strlcpy(packet.activity_gfx, e->activity_gfx);
8530 sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
8531 sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
8532 sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
8533 sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
8534 sz_strlcpy(packet.graphic_str, e->graphic_str);
8535 sz_strlcpy(packet.graphic_alt, e->graphic_alt);
8536
8537 j = 0;
8538 requirement_vector_iterate(&e->reqs, preq) {
8539 packet.reqs[j++] = *preq;
8541 packet.reqs_count = j;
8542
8543 j = 0;
8544 requirement_vector_iterate(&e->rmreqs, preq) {
8545 packet.rmreqs[j++] = *preq;
8547 packet.rmreqs_count = j;
8548
8549 packet.appearance_chance = e->appearance_chance;
8550 j = 0;
8551 requirement_vector_iterate(&e->appearance_reqs, preq) {
8552 packet.appearance_reqs[j++] = *preq;
8554 packet.appearance_reqs_count = j;
8555
8556 packet.disappearance_chance = e->disappearance_chance;
8557 j = 0;
8558 requirement_vector_iterate(&e->disappearance_reqs, preq) {
8559 packet.disappearance_reqs[j++] = *preq;
8561 packet.disappearance_reqs_count = j;
8562
8563 packet.visibility_req = e->visibility_req;
8564 packet.buildable = e->buildable;
8565 packet.generated = e->generated;
8566 packet.build_time = e->build_time;
8567 packet.build_time_factor = e->build_time_factor;
8568 packet.removal_time = e->removal_time;
8569 packet.removal_time_factor = e->removal_time_factor;
8570 packet.infracost = e->infracost;
8571 packet.defense_bonus = e->defense_bonus;
8572 packet.eus = e->eus;
8573
8574 packet.native_to = e->native_to;
8575
8576 packet.flags = e->flags;
8577 packet.hidden_by = e->hidden_by;
8578 packet.bridged_over = e->bridged_over;
8579 packet.conflicts = e->conflicts;
8580
8581 PACKET_STRVEC_COMPUTE(packet.helptext, e->helptext);
8582
8583 lsend_packet_ruleset_extra(dest, &packet);
8585}
8586
8587/**********************************************************************/
8591static void send_ruleset_bases(struct conn_list *dest)
8592{
8593 extra_type_by_cause_iterate(EC_BASE, pextra) {
8594 struct base_type *b = extra_base_get(pextra);
8595 struct packet_ruleset_base packet;
8596
8597 packet.id = base_number(b);
8598
8599 packet.gui_type = b->gui_type;
8600 packet.border_sq = b->border_sq;
8601 packet.vision_main_sq = b->vision_main_sq;
8602 packet.vision_invis_sq = b->vision_invis_sq;
8603 packet.vision_subs_sq = b->vision_subs_sq;
8604
8605 lsend_packet_ruleset_base(dest, &packet);
8607}
8608
8609/**********************************************************************/
8613static void send_ruleset_roads(struct conn_list *dest)
8614{
8615 struct packet_ruleset_road packet;
8616
8617 extra_type_by_cause_iterate(EC_ROAD, pextra) {
8618 struct road_type *r = extra_road_get(pextra);
8619 int j;
8620
8621 packet.id = road_number(r);
8622
8623 packet.gui_type = r->gui_type;
8624
8625 j = 0;
8627 packet.first_reqs[j++] = *preq;
8629 packet.first_reqs_count = j;
8630
8631 packet.move_cost = r->move_cost;
8632 packet.move_mode = r->move_mode;
8633
8635 packet.tile_incr_const[o] = r->tile_incr_const[o];
8636 packet.tile_incr[o] = r->tile_incr[o];
8637 packet.tile_bonus[o] = r->tile_bonus[o];
8639
8640 packet.compat = r->compat;
8641
8642 packet.integrates = r->integrates;
8643 packet.flags = r->flags;
8644
8645 lsend_packet_ruleset_road(dest, &packet);
8647}
8648
8649/**********************************************************************/
8653static void send_ruleset_goods(struct conn_list *dest)
8654{
8655 struct packet_ruleset_goods packet;
8656
8658 int j;
8659
8660 packet.id = goods_number(g);
8661 sz_strlcpy(packet.name, untranslated_name(&g->name));
8662 sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
8663
8664 j = 0;
8665 requirement_vector_iterate(&g->reqs, preq) {
8666 packet.reqs[j++] = *preq;
8668 packet.reqs_count = j;
8669
8670 packet.from_pct = g->from_pct;
8671 packet.to_pct = g->to_pct;
8672 packet.onetime_pct = g->onetime_pct;
8673 packet.flags = g->flags;
8674
8675 PACKET_STRVEC_COMPUTE(packet.helptext, g->helptext);
8676
8677 lsend_packet_ruleset_goods(dest, &packet);
8679}
8680
8681/**********************************************************************/
8685static void send_ruleset_disasters(struct conn_list *dest)
8686{
8687 struct packet_ruleset_disaster packet;
8688
8690 int j;
8691
8692 packet.id = disaster_number(d);
8693
8694 sz_strlcpy(packet.name, untranslated_name(&d->name));
8695 sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
8696
8697 j = 0;
8698 requirement_vector_iterate(&d->reqs, preq) {
8699 packet.reqs[j++] = *preq;
8701 packet.reqs_count = j;
8702
8703 packet.frequency = d->frequency;
8704
8705 packet.effects = d->effects;
8706
8707 lsend_packet_ruleset_disaster(dest, &packet);
8709}
8710
8711/**********************************************************************/
8715static void send_ruleset_achievements(struct conn_list *dest)
8716{
8717 struct packet_ruleset_achievement packet;
8718
8720 packet.id = achievement_number(a);
8721
8722 sz_strlcpy(packet.name, untranslated_name(&a->name));
8723 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8724
8725 packet.type = a->type;
8726 packet.unique = a->unique;
8727 packet.value = a->value;
8728
8729 lsend_packet_ruleset_achievement(dest, &packet);
8731}
8732
8733/**********************************************************************/
8736static void send_ruleset_actions(struct conn_list *dest)
8737{
8738 struct packet_ruleset_action packet;
8739
8740 action_iterate(act) {
8741 struct action *paction = action_by_number(act);
8742
8743 packet.id = act;
8745 packet.quiet = action_by_number(act)->quiet;
8746
8747 packet.result = paction->result;
8748 packet.sub_results = paction->sub_results;
8750
8751 packet.act_kind = action_by_number(act)->actor_kind;
8752 packet.tgt_kind = action_by_number(act)->target_kind;
8754
8757 packet.blocked_by = action_by_number(act)->blocked_by;
8758
8759 lsend_packet_ruleset_action(dest, &packet);
8761}
8762
8763/**********************************************************************/
8766static void send_ruleset_action_enablers(struct conn_list *dest)
8767{
8768 int counter;
8769 struct packet_ruleset_action_enabler packet;
8770
8771 action_enablers_iterate(enabler) {
8772 packet.enabled_action = enabler->action;
8773
8774 counter = 0;
8775 requirement_vector_iterate(&enabler->actor_reqs, req) {
8776 packet.actor_reqs[counter++] = *req;
8778 packet.actor_reqs_count = counter;
8779
8780 counter = 0;
8781 requirement_vector_iterate(&enabler->target_reqs, req) {
8782 packet.target_reqs[counter++] = *req;
8784 packet.target_reqs_count = counter;
8785
8788}
8789
8790/**********************************************************************/
8794static void send_ruleset_action_auto_performers(struct conn_list *dest)
8795{
8796 int counter;
8797 int id;
8798 struct packet_ruleset_action_auto packet;
8799
8800 id = 0;
8802 packet.id = id++;
8803
8804 packet.cause = aperf->cause;
8805
8806 counter = 0;
8807 requirement_vector_iterate(&aperf->reqs, req) {
8808 packet.reqs[counter++] = *req;
8810 packet.reqs_count = counter;
8811
8812 for (counter = 0;
8813 /* Can't list more actions than all actions. */
8814 counter < NUM_ACTIONS
8815 /* ACTION_NONE terminates the list. */
8816 && aperf->alternatives[counter] != ACTION_NONE;
8817 counter++) {
8818 packet.alternatives[counter] = aperf->alternatives[counter];
8819 }
8820 packet.alternatives_count = counter;
8821
8822 lsend_packet_ruleset_action_auto(dest, &packet);
8824}
8825
8826/**********************************************************************/
8830static void send_ruleset_trade_routes(struct conn_list *dest)
8831{
8832 struct packet_ruleset_trade packet;
8834
8835 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
8837
8838 packet.id = type;
8839 packet.trade_pct = set->trade_pct;
8840 packet.cancelling = set->cancelling;
8841 packet.bonus_type = set->bonus_type;
8842
8843 lsend_packet_ruleset_trade(dest, &packet);
8844 }
8845}
8846
8847/**********************************************************************/
8851static void send_ruleset_governments(struct conn_list *dest)
8852{
8853 struct packet_ruleset_government gov;
8855 int j;
8856
8858 /* send one packet_government */
8859 gov.id = government_number(g);
8860
8861 j = 0;
8862 requirement_vector_iterate(&g->reqs, preq) {
8863 gov.reqs[j++] = *preq;
8865 gov.reqs_count = j;
8866
8867 sz_strlcpy(gov.name, untranslated_name(&g->name));
8868 sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
8869 sz_strlcpy(gov.graphic_str, g->graphic_str);
8870 sz_strlcpy(gov.graphic_alt, g->graphic_alt);
8871 PACKET_STRVEC_COMPUTE(gov.helptext, g->helptext);
8872
8874
8875 /* Send one packet_government_ruler_title per ruler title. */
8877 const struct nation_type *pnation = ruler_title_nation(pruler_title);
8878
8879 title.gov = government_number(g);
8880 title.nation = pnation ? nation_number(pnation) : nation_count();
8881 sz_strlcpy(title.male_title,
8883 sz_strlcpy(title.female_title,
8888}
8889
8890/**********************************************************************/
8894static void send_ruleset_nations(struct conn_list *dest)
8895{
8896 struct packet_ruleset_nation_sets sets_packet;
8897 struct packet_ruleset_nation_groups groups_packet;
8898 struct packet_ruleset_nation packet;
8899 int i;
8900
8901 sets_packet.nsets = nation_set_count();
8902 i = 0;
8903 nation_sets_iterate(pset) {
8904 sz_strlcpy(sets_packet.names[i], nation_set_untranslated_name(pset));
8905 sz_strlcpy(sets_packet.rule_names[i], nation_set_rule_name(pset));
8906 sz_strlcpy(sets_packet.descriptions[i], nation_set_description(pset));
8907 i++;
8909 lsend_packet_ruleset_nation_sets(dest, &sets_packet);
8910
8911 groups_packet.ngroups = nation_group_count();
8912 i = 0;
8913 nation_groups_iterate(pgroup) {
8914 sz_strlcpy(groups_packet.groups[i],
8916 groups_packet.hidden[i] = pgroup->hidden;
8917 i++;
8919 lsend_packet_ruleset_nation_groups(dest, &groups_packet);
8920
8922 packet.id = nation_number(n);
8923 if (n->translation_domain == NULL) {
8924 packet.translation_domain[0] = '\0';
8925 } else {
8926 sz_strlcpy(packet.translation_domain, n->translation_domain);
8927 }
8928 sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
8929 sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
8930 sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
8931 sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
8932 sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
8933
8934 i = 0;
8936 sz_strlcpy(packet.leader_name[i], nation_leader_name(pleader));
8937 packet.leader_is_male[i] = nation_leader_is_male(pleader);
8938 i++;
8940 packet.leader_count = i;
8941
8942 packet.style = style_number(n->style);
8943 packet.is_playable = n->is_playable;
8944 packet.barbarian_type = n->barb_type;
8945
8946 sz_strlcpy(packet.legend, n->legend);
8947
8948 i = 0;
8949 nation_set_list_iterate(n->sets, pset) {
8950 packet.sets[i++] = nation_set_number(pset);
8952 packet.nsets = i;
8953
8954 i = 0;
8955 nation_group_list_iterate(n->groups, pgroup) {
8956 packet.groups[i++] = nation_group_number(pgroup);
8958 packet.ngroups = i;
8959
8960 packet.init_government_id = n->init_government
8961 ? government_number(n->init_government) : government_count();
8962 fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
8963 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
8964 if (n->init_techs[i] != A_LAST) {
8965 packet.init_techs[i] = n->init_techs[i];
8966 } else {
8967 break;
8968 }
8969 }
8970 packet.init_techs_count = i;
8971 fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
8972 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
8973 const struct unit_type *t = n->init_units[i];
8974 if (t) {
8975 packet.init_units[i] = utype_number(t);
8976 } else {
8977 break;
8978 }
8979 }
8980 packet.init_units_count = i;
8982 == ARRAY_SIZE(n->init_buildings));
8983 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
8984 if (n->init_buildings[i] != B_LAST) {
8985 /* Impr_type_id to int */
8986 packet.init_buildings[i] = n->init_buildings[i];
8987 } else {
8988 break;
8989 }
8990 }
8991 packet.init_buildings_count = i;
8992
8993 lsend_packet_ruleset_nation(dest, &packet);
8995
8996 /* Send initial values of is_pickable */
8998}
8999
9000/**********************************************************************/
9004static void send_ruleset_styles(struct conn_list *dest)
9005{
9006 struct packet_ruleset_style packet;
9007
9008 styles_iterate(s) {
9009 packet.id = style_index(s);
9010 sz_strlcpy(packet.name, untranslated_name(&s->name));
9011 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
9012
9013 lsend_packet_ruleset_style(dest, &packet);
9015}
9016
9017/**********************************************************************/
9020static void send_ruleset_clauses(struct conn_list *dest)
9021{
9022 struct packet_ruleset_clause packet;
9023 int i;
9024
9025 for (i = 0; i < CLAUSE_COUNT; i++) {
9026 struct clause_info *info = clause_info_get(i);
9027 int j;
9028
9029 packet.type = i;
9030 packet.enabled = info->enabled;
9031
9032 j = 0;
9034 packet.giver_reqs[j++] = *preq;
9036 packet.giver_reqs_count = j;
9037
9038 j = 0;
9040 packet.receiver_reqs[j++] = *preq;
9042 packet.receiver_reqs_count = j;
9043
9044 lsend_packet_ruleset_clause(dest, &packet);
9045 }
9046}
9047
9048/**********************************************************************/
9052static void send_ruleset_multipliers(struct conn_list *dest)
9053{
9054 multipliers_iterate(pmul) {
9055 int j;
9056 struct packet_ruleset_multiplier packet;
9057
9058 packet.id = multiplier_number(pmul);
9059 packet.start = pmul->start;
9060 packet.stop = pmul->stop;
9061 packet.step = pmul->step;
9062 packet.def = pmul->def;
9063 packet.offset = pmul->offset;
9064 packet.factor = pmul->factor;
9065 packet.minimum_turns = pmul->minimum_turns;
9066
9067 sz_strlcpy(packet.name, untranslated_name(&pmul->name));
9068 sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
9069
9070 j = 0;
9071 requirement_vector_iterate(&pmul->reqs, preq) {
9072 packet.reqs[j++] = *preq;
9074 packet.reqs_count = j;
9075
9076 PACKET_STRVEC_COMPUTE(packet.helptext, pmul->helptext);
9077
9078 lsend_packet_ruleset_multiplier(dest, &packet);
9080}
9081
9082/**********************************************************************/
9086static void send_ruleset_cities(struct conn_list *dest)
9087{
9088 struct packet_ruleset_city city_p;
9089 int k, j;
9090
9091 for (k = 0; k < game.control.styles_count; k++) {
9092 city_p.style_id = k;
9093
9094 j = 0;
9096 city_p.reqs[j++] = *preq;
9098 city_p.reqs_count = j;
9099
9105
9106 lsend_packet_ruleset_city(dest, &city_p);
9107 }
9108}
9109
9110/**********************************************************************/
9114static void send_ruleset_musics(struct conn_list *dest)
9115{
9116 struct packet_ruleset_music packet;
9117
9118 music_styles_iterate(pmus) {
9119 int j;
9120
9121 packet.id = pmus->id;
9122
9123 sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
9124 sz_strlcpy(packet.music_combat, pmus->music_combat);
9125
9126 j = 0;
9127 requirement_vector_iterate(&(pmus->reqs), preq) {
9128 packet.reqs[j++] = *preq;
9130 packet.reqs_count = j;
9131
9132 lsend_packet_ruleset_music(dest, &packet);
9134}
9135
9136/**********************************************************************/
9140static void send_ruleset_game(struct conn_list *dest)
9141{
9142 struct packet_ruleset_game misc_p;
9143 int i;
9144
9145 fc_assert_ret(game.veteran != NULL);
9146
9147 /* Per unit veteran system definition. */
9149
9150 for (i = 0; i < misc_p.veteran_levels; i++) {
9151 const struct veteran_level *vlevel = game.veteran->definitions + i;
9152
9153 sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
9154 misc_p.power_fact[i] = vlevel->power_fact;
9155 misc_p.move_bonus[i] = vlevel->move_bonus;
9156 misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
9157 misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
9158 }
9159
9160 fc_assert(sizeof(misc_p.global_init_techs)
9161 == sizeof(game.rgame.global_init_techs));
9164 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9165 if (game.rgame.global_init_techs[i] != A_LAST) {
9167 } else {
9168 break;
9169 }
9170 }
9171 misc_p.global_init_techs_count = i;
9172
9175 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9177 /* Impr_type_id to int */
9178 misc_p.global_init_buildings[i] =
9180 } else {
9181 break;
9182 }
9183 }
9184 misc_p.global_init_buildings_count = i;
9185
9187
9189
9193
9194 lsend_packet_ruleset_game(dest, &misc_p);
9195}
9196
9197/**********************************************************************/
9201static void send_ruleset_team_names(struct conn_list *dest)
9202{
9203 struct packet_team_name_info team_name_info_p;
9204
9205 team_slots_iterate(tslot) {
9206 const char *name = team_slot_defined_name(tslot);
9207
9208 if (NULL == name) {
9209 /* End of defined names. */
9210 break;
9211 }
9212
9213 team_name_info_p.team_id = team_slot_index(tslot);
9214 sz_strlcpy(team_name_info_p.team_name, name);
9215
9216 lsend_packet_team_name_info(dest, &team_name_info_p);
9218}
9219
9220/**********************************************************************/
9223static void notify_ruleset_fallback(const char *msg)
9224{
9225 notify_conn(NULL, NULL, E_LOG_FATAL, ftc_warning, "%s", msg);
9226}
9227
9228/**********************************************************************/
9231bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
9232 rs_conversion_logger logger,
9233 bool act, bool buffer_script, bool load_luadata)
9234{
9235 set_ruleset_compat_mode(compat_mode);
9236
9237 if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
9238 act, buffer_script, load_luadata)) {
9240 return TRUE;
9241 }
9242
9243 if (alt != NULL) {
9244 if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
9245 load_luadata)) {
9247
9249 return TRUE;
9250 }
9251 }
9252
9253 /* Fallback to previous one. */
9254 if (restore != NULL) {
9255 if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
9256 sz_strlcpy(game.server.rulesetdir, restore);
9257
9258 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
9259
9261
9263
9264 /* We're in sane state as restoring previous ruleset succeeded,
9265 * but return failure to indicate that this is not what caller
9266 * wanted. */
9267 return FALSE;
9268 }
9269 }
9270
9272
9274
9275 /* Fallback to default one, but not if that's what we tried already */
9277 && (restore == NULL || strcmp(GAME_DEFAULT_RULESETDIR, restore))) {
9278 if (load_rulesetdir(GAME_DEFAULT_RULESETDIR, FALSE, NULL, act, buffer_script, TRUE)) {
9279 /* We're in sane state as fallback ruleset loading succeeded,
9280 * but return failure to indicate that this is not what caller
9281 * wanted. */
9283
9284 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
9285
9286 return FALSE;
9287 }
9288 }
9289
9290#ifdef FREECIV_WEB
9291 log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
9292 "https://github.com/freeciv/freeciv-web"));
9293#endif /* FREECIV_WEB */
9294
9295 /* Cannot load even default ruleset, we're in completely unusable state */
9296 exit(EXIT_FAILURE);
9297
9299}
9300
9301/**********************************************************************/
9305{
9306 if (file != NULL) {
9307 secfile_destroy(file);
9308 }
9309}
9310
9311/**********************************************************************/
9316{
9318 requirement_vector_free(&reqs_list);
9319}
9320
9321/**********************************************************************/
9325static bool load_rulesetdir(const char *rsdir, bool compat_mode,
9326 rs_conversion_logger logger,
9327 bool act, bool buffer_script, bool load_luadata)
9328{
9329 struct section_file *techfile, *unitfile, *buildfile, *govfile, *terrfile;
9330 struct section_file *stylefile, *cityfile, *nationfile, *effectfile, *gamefile;
9331 bool ok = TRUE;
9332 struct rscompat_info compat_info;
9333
9334 log_normal(_("Loading rulesets."));
9335
9336 rscompat_init_info(&compat_info);
9337 compat_info.compat_mode = compat_mode;
9338 compat_info.log_cb = logger;
9339
9341 /* Reset the list of available player colors. */
9345
9346 if (script_buffer != NULL) {
9348 script_buffer = NULL;
9349 }
9350 if (parser_buffer != NULL) {
9352 parser_buffer = NULL;
9353 }
9354
9355 server.playable_nations = 0;
9356
9357 techfile = openload_ruleset_file("techs", rsdir);
9358 buildfile = openload_ruleset_file("buildings", rsdir);
9359 govfile = openload_ruleset_file("governments", rsdir);
9360 unitfile = openload_ruleset_file("units", rsdir);
9361 terrfile = openload_ruleset_file("terrain", rsdir);
9362 stylefile = openload_ruleset_file("styles", rsdir);
9363 cityfile = openload_ruleset_file("cities", rsdir);
9364 nationfile = openload_ruleset_file("nations", rsdir);
9365 effectfile = openload_ruleset_file("effects", rsdir);
9366 gamefile = openload_ruleset_file("game", rsdir);
9367 if (load_luadata) {
9369 } else {
9370 game.server.luadata = NULL;
9371 }
9372
9373 if (techfile == NULL
9374 || buildfile == NULL
9375 || govfile == NULL
9376 || unitfile == NULL
9377 || terrfile == NULL
9378 || stylefile == NULL
9379 || cityfile == NULL
9380 || nationfile == NULL
9381 || effectfile == NULL
9382 || gamefile == NULL) {
9383 ok = FALSE;
9384 }
9385
9386 if (ok) {
9387 /* Note: Keep load_game_names first so that compat_info.version is
9388 * correctly initialized. */
9389 ok = load_game_names(gamefile, &compat_info)
9390 && load_tech_names(techfile, &compat_info)
9391 && load_building_names(buildfile, &compat_info)
9392 && load_government_names(govfile, &compat_info)
9393 && load_unit_names(unitfile, &compat_info)
9394 && load_terrain_names(terrfile, &compat_info)
9395 && load_style_names(stylefile, &compat_info)
9396 && load_nation_names(nationfile, &compat_info);
9397 }
9398
9399 if (ok) {
9400 ok = rscompat_names(&compat_info);
9401 }
9402
9403 if (ok) {
9404 ok = load_ruleset_techs(techfile, &compat_info);
9405 }
9406 if (ok) {
9407 ok = load_ruleset_styles(stylefile, &compat_info);
9408 }
9409 if (ok) {
9410 ok = load_ruleset_cities(cityfile, &compat_info);
9411 }
9412 if (ok) {
9413 ok = load_ruleset_governments(govfile, &compat_info);
9414 }
9415 if (ok) {
9416 /* terrain must precede nations and units */
9417 ok = load_ruleset_terrain(terrfile, &compat_info);
9418 }
9419 if (ok) {
9420 ok = load_ruleset_units(unitfile, &compat_info);
9421 }
9422 if (ok) {
9423 ok = load_ruleset_buildings(buildfile, &compat_info);
9424 }
9425 if (ok) {
9426 ok = load_ruleset_nations(nationfile, &compat_info);
9427 }
9428 if (ok) {
9429 ok = load_ruleset_effects(effectfile, &compat_info);
9430 }
9431 if (ok) {
9432 ok = load_ruleset_game(gamefile, act, &compat_info);
9433 }
9434
9435 if (ok) {
9436 rscompat_adjust_pre_sanity(&compat_info);
9437
9438 /* Init nations we just loaded. */
9440
9441 /* Needed by role_unit_precalcs(). */
9443
9444 /* Prepare caches we want to sanity check. */
9448
9450 && sanity_check_ruleset_data(&compat_info);
9451 }
9452
9453 if (ok) {
9454 /* Only load settings for a sane ruleset */
9455 ok = settings_ruleset(gamefile, "settings", act);
9456
9457 if (ok) {
9458 secfile_check_unused(gamefile);
9459 }
9460 }
9461
9462 nullcheck_secfile_destroy(techfile);
9463 nullcheck_secfile_destroy(stylefile);
9464 nullcheck_secfile_destroy(cityfile);
9466 nullcheck_secfile_destroy(terrfile);
9467 nullcheck_secfile_destroy(unitfile);
9468 nullcheck_secfile_destroy(buildfile);
9469 nullcheck_secfile_destroy(nationfile);
9470 nullcheck_secfile_destroy(effectfile);
9471 nullcheck_secfile_destroy(gamefile);
9472
9473 if (extra_sections) {
9474 free(extra_sections);
9475 extra_sections = NULL;
9476 }
9477 if (base_sections) {
9478 free(base_sections);
9479 base_sections = NULL;
9480 }
9481 if (road_sections) {
9482 free(road_sections);
9483 road_sections = NULL;
9484 }
9485 if (resource_sections) {
9486 free(resource_sections);
9487 resource_sections = NULL;
9488 }
9489 if (terrain_sections) {
9490 free(terrain_sections);
9491 terrain_sections = NULL;
9492 }
9493
9494 if (ok) {
9495 rscompat_postprocess(&compat_info);
9496 }
9497
9498 if (ok) {
9499 char **buffer = buffer_script ? &script_buffer : NULL;
9500
9502
9504
9505 ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
9506 }
9507
9508 if (ok) {
9509 enum fc_tristate pret;
9510 char **buffer = buffer_script ? &parser_buffer : NULL;
9511
9512 pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
9513
9514 if (pret == TRI_MAYBE && buffer_script) {
9516 "-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
9517 }
9518
9519 ok = (pret != TRI_NO);
9520 }
9521
9522 if (ok && !buffer_script) {
9523 ok = (openload_script_file("default", rsdir, NULL, FALSE) == TRI_YES);
9524 }
9525
9526 if (ok && act) {
9527 /* Populate remaining caches. */
9530 unit_class_iterate(pclass) {
9531 set_unit_class_caches(pclass);
9533 unit_type_iterate(ptype) {
9534 ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
9535 set_unit_type_caches(ptype);
9538
9539 /* Build advisors unit class cache corresponding to loaded rulesets */
9541 CALL_FUNC_EACH_AI(units_ruleset_init);
9542
9543 /* We may need to adjust the number of AI players
9544 * if the number of available nations changed. */
9545 (void) aifill(game.info.aifill);
9546 }
9547
9548 return ok;
9549}
9550
9551/**********************************************************************/
9555{
9556 struct section_file *file;
9557 bool ok = TRUE;
9558
9560 if (file == NULL) {
9562 "Could not load game.ruleset:\n%s",
9563 secfile_error());
9564 ok = FALSE;
9565 }
9566 if (ok) {
9567 settings_ruleset(file, "settings", TRUE);
9568 secfile_destroy(file);
9569 }
9570
9571 return ok;
9572}
9573
9574/**********************************************************************/
9577void send_rulesets(struct conn_list *dest)
9578{
9580
9581 /* ruleset_control also indicates to client that ruleset sending starts. */
9583
9584 /* Currently containing control-kind of data of nation sets and groups,
9585 * this too must be sent before any requirement vector may depend on
9586 * that data. */
9588
9589 send_ruleset_game(dest);
9598 send_ruleset_techs(dest);
9601 send_ruleset_units(dest);
9603 send_ruleset_extras(dest);
9604 send_ruleset_bases(dest);
9605 send_ruleset_roads(dest);
9608 send_ruleset_goods(dest);
9610 send_ruleset_styles(dest);
9612 send_ruleset_cities(dest);
9614 send_ruleset_musics(dest);
9615 send_ruleset_cache(dest);
9616
9617 /* Indicate client that all rulesets have now been sent. */
9619
9620 /* changed game settings will be send in
9621 * connecthand.c:establish_new_connection() */
9622
9624}
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:7349
void actions_rs_pre_san_gen(void)
Definition actions.c:1520
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:7962
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:9030
bool action_is_in_use(struct action *paction)
Definition actions.c:7326
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:9172
struct action * action_by_rule_name(const char *name)
Definition actions.c:1708
const char * action_rule_name(const struct action *action)
Definition actions.c:1876
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:8895
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:8173
enum action_target_kind action_target_kind_default(enum action_result result)
Definition actions.c:8524
int action_min_range_default(enum action_result result)
Definition actions.c:8091
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:8394
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:2442
const char * action_ui_name_default(int act)
Definition actions.c:7660
struct action_enabler * action_enabler_new(void)
Definition actions.c:2396
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:7270
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2475
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:7434
int action_max_range_default(enum action_result result)
Definition actions.c:8308
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:490
#define action_auto_perf_iterate_end
Definition actions.h:595
#define action_enablers_iterate_end
Definition actions.h:528
#define ACTION_AUTO_MOVED_ADJ
Definition actions.h:619
#define action_id_get_sub_target_kind(act_id)
Definition actions.h:661
#define ACTION_AUTO_UPKEEP_GOLD
Definition actions.h:617
static struct action * action_by_number(action_id act_id)
Definition actions.h:640
#define NUM_ACTIONS
Definition actions.h:299
#define ACTION_AUTO_ESCAPE_STACK
Definition actions.h:623
#define action_has_result(_act_, _res_)
Definition actions.h:450
#define ACTION_AUTO_ESCAPE_CITY
Definition actions.h:622
#define action_enabler_list_iterate_end
Definition actions.h:459
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:354
#define action_by_result_iterate_end
Definition actions.h:494
#define ACTION_AUTO_UPKEEP_SHIELD
Definition actions.h:618
#define ACTION_AUTO_POST_BRIBE
Definition actions.h:620
#define action_iterate_end
Definition actions.h:474
#define action_enablers_iterate(_enabler_)
Definition actions.h:522
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:457
#define action_iterate(_act_)
Definition actions.h:469
#define action_auto_perf_iterate(_act_perf_)
Definition actions.h:583
#define ACTION_AUTO_UPKEEP_FOOD
Definition actions.h:616
#define ACTION_AUTO_POST_ATTACK
Definition actions.h:621
#define ACTION_NONE
Definition actions.h:295
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
struct citystyle * city_styles
Definition city.c:79
void city_styles_alloc(int num)
Definition city.c:3309
void city_production_caravan_shields_init(void)
Definition city.c:1751
const char * city_style_rule_name(const int style)
Definition city.c:1738
const char * get_output_identifier(Output_type_id output)
Definition city.c:614
#define output_type_iterate(output)
Definition city.h:821
#define output_type_iterate_end
Definition city.h:827
static struct fc_sockaddr_list * list
Definition clinet.c:102
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:729
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:717
#define MAX_LEN_CONTENT
Definition connection.h:59
#define log_deprecation(message,...)
struct clause_info * clause_info_get(enum clause_type type)
Definition diptreaty.c:273
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:553
struct effect * effect_new(enum effect_type type, int value, struct multiplier *pmul)
Definition effects.c:179
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:136
void effect_req_append(struct effect *peffect, struct requirement req)
Definition effects.c:229
#define effect_list_iterate_end
Definition effects.h:375
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:373
struct extra_type * extra_type_by_rule_name(const char *name)
Definition extras.c:204
const char * extra_flag_helptxt(enum extra_flag_id id)
Definition extras.c:923
void set_user_extra_flag_name(enum extra_flag_id id, const char *name, const char *helptxt)
Definition extras.c:882
bool is_extra_caused_by_worker_action(const struct extra_type *pextra)
Definition extras.c:981
int extra_number(const struct extra_type *pextra)
Definition extras.c:153
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:810
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:241
void extra_to_caused_by_list(struct extra_type *pextra, enum extra_cause cause)
Definition extras.c:296
struct extra_type * extra_by_number(int id)
Definition extras.c:175
void extra_to_removed_by_list(struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:316
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:259
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:327
struct extra_type_list * extra_type_list_of_unit_hiders(void)
Definition extras.c:251
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
#define is_extra_caused_by(e, c)
Definition extras.h:196
#define extra_index(_e_)
Definition extras.h:177
#define extra_base_get(_e_)
Definition extras.h:184
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define MAX_NUM_USER_EXTRA_FLAGS
Definition extras.h:80
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
#define MAX_DISASTER_TYPES
Definition fc_types.h:52
#define MAX_VET_LEVELS
Definition fc_types.h:49
@ ROCO_RAILROAD
Definition fc_types.h:1105
@ ROCO_NONE
Definition fc_types.h:1105
@ ROCO_RIVER
Definition fc_types.h:1105
@ ROCO_ROAD
Definition fc_types.h:1105
#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:380
#define MAX_GOODS_TYPES
Definition fc_types.h:51
#define EC_NATURAL_DEFENSIVE
Definition fc_types.h:970
#define EC_SPECIAL
Definition fc_types.h:968
int action_id
Definition fc_types.h:359
#define SP_MAX
Definition fc_types.h:379
#define EC_NONE
Definition fc_types.h:967
#define EC_NOT_AGGRESSIVE
Definition fc_types.h:971
#define EC_DEFENSIVE
Definition fc_types.h:969
#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
#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 UCL_LAST
Definition fc_types.h:387
#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:57
void game_ruleset_init(void)
Definition game.c:499
void game_ruleset_free(void)
Definition game.c:544
struct world wld
Definition game.c:58
#define RS_DEFAULT_RANSOM_GOLD
Definition game.h:840
#define RS_DEFAULT_GRANARY_FOOD_INI
Definition game.h:789
#define RS_DEFAULT_CIVIL_WAR_UNHAPPY
Definition game.h:826
#define RS_DEFAULT_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:832
#define RS_MIN_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:770
#define RS_MAX_TECH_UPKEEP_DIVIDER
Definition game.h:852
#define RS_MIN_ILLNESS_POLLUTION_PCT
Definition game.h:756
#define RS_DEFAULT_NUKE_POP_LOSS_PCT
Definition game.h:829
#define RS_MAX_BORDER_RADIUS_SQ_CITY
Definition game.h:763
#define RS_DEFAULT_BASE_POLLUTION
Definition game.h:812
#define RS_MIN_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:752
#define RS_MAX_ILLNESS_BASE_FACTOR
Definition game.h:745
#define RS_DEFAULT_INCITE_TOTAL_FCT
Definition game.h:785
#define RS_DEFAULT_ILLNESS_BASE_FACTOR
Definition game.h:743
#define RS_DEFAULT_NEG_YEAR_LABEL
Definition game.h:739
#define RS_MIN_NUKE_POP_LOSS_PCT
Definition game.h:830
#define RS_MIN_INCITE_IMPROVEMENT_FCT
Definition game.h:778
#define RS_MIN_FOOD_COST
Definition game.h:822
#define RS_MIN_BASE_BRIBE_COST
Definition game.h:837
#define RS_MAX_NUKE_POP_LOSS_PCT
Definition game.h:831
#define RS_DEFAULT_INCITE_IMPROVEMENT_FCT
Definition game.h:777
#define RS_MAX_INCITE_IMPROVEMENT_FCT
Definition game.h:779
#define RS_MIN_RANSOM_GOLD
Definition game.h:841
#define RS_ACTION_NO_MAX_DISTANCE
Definition game.h:866
#define RS_DEFAULT_BASE_BRIBE_COST
Definition game.h:836
#define RS_MAX_INCITE_BASE_COST
Definition game.h:775
#define RS_DEFAULT_TECH_UPKEEP_DIVIDER
Definition game.h:850
#define RS_DEFAULT_HAPPY_COST
Definition game.h:817
#define RS_MIN_UPGRADE_VETERAN_LOSS
Definition game.h:847
#define RS_MIN_ILLNESS_MIN_SIZE
Definition game.h:748
#define RS_DEFAULT_POISON_EMPTIES_FOOD_STOCK
Definition game.h:858
#define RS_DEFAULT_GRANARY_FOOD_INC
Definition game.h:791
#define RS_DEFAULT_ILLNESS_ON
Definition game.h:741
#define RS_MAX_FOOD_COST
Definition game.h:823
#define RS_MAX_HAPPY_COST
Definition game.h:819
#define GAME_DEFAULT_CELEBRATESIZE
Definition game.h:480
#define RS_MIN_ILLNESS_BASE_FACTOR
Definition game.h:744
#define RS_DEFAULT_STEAL_MAP_REVEALS_CITIES
Definition game.h:859
#define RS_MIN_TECH_UPKEEP_DIVIDER
Definition game.h:851
#define RS_MAX_RANSOM_GOLD
Definition game.h:842
#define RS_MIN_HAPPY_COST
Definition game.h:818
#define RS_MIN_BORDER_RADIUS_SQ_CITY
Definition game.h:762
#define GAME_DEFAULT_RULESETDIR
Definition game.h:654
#define RS_DEFAULT_CIVIL_WAR_CELEB
Definition game.h:825
#define RS_MAX_BASE_TECH_COST
Definition game.h:856
#define RS_DEFAULT_BASE_TECH_COST
Definition game.h:854
#define RS_MIN_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:833
#define RS_MAX_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:771
#define RS_DEFAULT_UPGRADE_VETERAN_LOSS
Definition game.h:846
#define RS_MAX_NUKE_DEFENDER_SURVIVAL_CHANCE_PCT
Definition game.h:834
#define RS_MAX_INCITE_UNIT_FCT
Definition game.h:783
#define RS_MIN_VIS_RADIUS_SQ
Definition game.h:809
#define RS_DEFAULT_CALENDAR_SKIP_0
Definition game.h:759
#define RS_MAX_ILLNESS_MIN_SIZE
Definition game.h:749
#define RS_DEFAULT_CITY_RADIUS_SQ
Definition game.h:804
#define GAME_DEFAULT_START_YEAR
Definition game.h:715
#define RS_MAX_BORDER_SIZE_EFFECT
Definition game.h:767
#define RS_DEFAULT_BORDER_SIZE_EFFECT
Definition game.h:765
#define RS_MAX_BASE_BRIBE_COST
Definition game.h:838
#define RS_MIN_INCITE_BASE_COST
Definition game.h:774
#define RS_DEFAULT_PILLAGE_SELECT
Definition game.h:844
#define RS_MIN_CITY_RADIUS_SQ
Definition game.h:805
#define RS_MIN_CITY_CENTER_OUTPUT
Definition game.h:796
#define RS_MAX_GRANARY_FOOD_INC
Definition game.h:793
#define RS_MAX_CITY_CENTER_OUTPUT
Definition game.h:797
#define RS_MAX_CITY_RADIUS_SQ
Definition game.h:806
#define RS_DEFAULT_POS_YEAR_LABEL
Definition game.h:737
#define RS_MIN_INCITE_UNIT_FCT
Definition game.h:782
#define RS_MIN_BORDER_SIZE_EFFECT
Definition game.h:766
#define RS_DEFAULT_VIS_RADIUS_SQ
Definition game.h:808
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY_PERMANENT
Definition game.h:769
#define RS_DEFAULT_TIRED_ATTACK
Definition game.h:828
#define RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS
Definition game.h:860
#define RS_MAX_ILLNESS_POLLUTION_PCT
Definition game.h:757
#define RS_DEFAULT_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:751
#define RS_DEFAULT_FOOD_COST
Definition game.h:821
#define RS_DEFAULT_INCITE_UNIT_FCT
Definition game.h:781
#define RS_MAX_INCITE_TOTAL_FCT
Definition game.h:787
#define RS_DEFAULT_INCITE_BASE_COST
Definition game.h:773
#define GAME_DEFAULT_ANGRYCITIZEN
Definition game.h:371
#define RS_DEFAULT_CITY_CENTER_OUTPUT
Definition game.h:795
#define RS_MIN_INCITE_TOTAL_FCT
Definition game.h:786
#define RS_DEFAULT_ILLNESS_POLLUTION_PCT
Definition game.h:755
#define RS_MAX_UPGRADE_VETERAN_LOSS
Definition game.h:848
static void set_ruleset_compat_mode(bool active)
Definition game.h:332
#define RS_MAX_VIS_RADIUS_SQ
Definition game.h:810
#define RS_MIN_GRANARY_FOOD_INC
Definition game.h:792
#define RS_MAX_ILLNESS_TRADE_INFECTION_PCT
Definition game.h:753
#define RS_DEFAULT_ILLNESS_MIN_SIZE
Definition game.h:747
#define RS_MIN_BASE_TECH_COST
Definition game.h:855
#define RS_DEFAULT_BORDER_RADIUS_SQ_CITY
Definition game.h:761
const struct nation_type * ruler_title_nation(const struct ruler_title *pruler_title)
Definition government.c:364
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:324
const char * ruler_title_female_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:382
Government_type_id government_count(void)
Definition government.c:70
const char * ruler_title_male_untranslated_name(const struct ruler_title *pruler_title)
Definition government.c:373
void governments_alloc(int num)
Definition government.c:528
Government_type_id government_number(const struct government *pgovern)
Definition government.c:90
const struct ruler_title_hash * government_ruler_titles(const struct government *pgovern)
Definition government.c:313
Government_type_id government_index(const struct government *pgovern)
Definition government.c:81
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
struct government * government_by_rule_name(const char *name)
Definition government.c:54
#define governments_iterate(NAME_pgov)
Definition government.h:121
#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:124
const char * title
Definition repodlgs.c:1313
GType type
Definition repodlgs.c:1312
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:90
struct impr_type * improvement_by_rule_name(const char *name)
#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:917
#define SINGLE_MOVE
Definition movement.h:24
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:1046
const char * nation_group_untranslated_name(const struct nation_group *pgroup)
Definition nation.c:1068
struct nation_group * nation_group_by_rule_name(const char *name)
Definition nation.c:1020
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
Nation_type_id nation_count(void)
Definition nation.c:506
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:485
struct nation_group * nation_group_new(const char *name)
Definition nation.c:959
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:289
struct nation_set * nation_set_new(const char *set_name, const char *set_rule_name, const char *set_description)
Definition nation.c:715
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
struct nation_city * nation_city_new(struct nation_type *pnation, const char *name)
Definition nation.c:341
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:229
const char * nation_set_untranslated_name(const struct nation_set *pset)
Definition nation.c:796
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
int nation_set_number(const struct nation_set *pset)
Definition nation.c:707
void nation_city_set_terrain_preference(struct nation_city *pncity, const struct terrain *pterrain, enum nation_city_preference prefer)
Definition nation.c:389
void nation_city_set_river_preference(struct nation_city *pncity, enum nation_city_preference prefer)
Definition nation.c:401
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:836
const char * nation_set_description(const struct nation_set *pset)
Definition nation.c:827
int nation_set_count(void)
Definition nation.c:690
struct nation_set * nation_set_by_number(int id)
Definition nation.c:761
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:120
struct nation_set * nation_set_by_rule_name(const char *name)
Definition nation.c:778
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:497
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:280
int nation_group_count(void)
Definition nation.c:934
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:806
struct nation_leader * nation_leader_new(struct nation_type *pnation, const char *name, bool is_male)
Definition nation.c:238
void nation_group_set_hidden(struct nation_group *pgroup, bool hidden)
Definition nation.c:1036
void nations_alloc(int num)
Definition nation.c:621
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
int nation_group_number(const struct nation_group *pgroup)
Definition nation.c:951
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:56
#define nation_sets_iterate_end
Definition nation.h:304
#define nation_set_list_iterate_end
Definition nation.h:67
#define nation_group_list_iterate(grouplist, pgroup)
Definition nation.h:74
#define nation_sets_iterate(NAME_pset)
Definition nation.h:300
#define nations_iterate_end
Definition nation.h:335
nation_city_preference
Definition nation.h:38
@ NCP_DISLIKE
Definition nation.h:39
@ NCP_LIKE
Definition nation.h:41
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define nation_leader_list_iterate_end
Definition nation.h:58
#define nation_group_list_iterate_end
Definition nation.h:76
#define nation_set_list_iterate(setlist, pset)
Definition nation.h:65
#define nation_groups_iterate(NAME_pgroup)
Definition nation.h:310
#define nation_groups_iterate_end
Definition nation.h:314
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
#define MAX_LEN_MSG
Definition packets.h:43
#define web_lsend_packet(packetname,...)
Definition packets.h:53
#define PACKET_STRVEC_COMPUTE(str, strvec)
Definition packets.h:205
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_rulesets_ready(struct conn_list *dest)
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:117
int len
Definition packhand.c:125
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2472
void playercolor_free(void)
Definition plrhand.c:3172
void playercolor_init(void)
Definition plrhand.c:3163
int playercolor_count(void)
Definition plrhand.c:3211
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3191
void count_playable_nations(void)
Definition plrhand.c:2429
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_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_action_ui_name_S3_1(struct rscompat_info *compat, int act_id)
Definition rscompat.c:2240
void rscompat_adjust_pre_sanity(struct rscompat_info *info)
Definition rscompat.c:839
enum road_gui_type rscompat_road_gui_type_3_1(struct road_type *proad)
Definition rscompat.c:2222
void rscompat_extra_adjust_3_1(struct rscompat_info *compat, struct extra_type *pextra)
Definition rscompat.c:2206
void rscompat_uclass_flags_3_1(struct rscompat_info *compat, struct unit_class *pclass)
Definition rscompat.c:2194
const char * rscompat_req_name_3_1(const char *type, const char *old_name)
Definition rscompat.c:2061
bool rscompat_auto_attack_3_1(struct rscompat_info *compat, struct action_auto_perf *auto_perf, size_t psize, enum unit_type_flag_id *protecor_flag)
Definition rscompat.c:1751
bool rscompat_old_effect_3_1(const char *type, struct section_file *file, const char *sec_name, struct rscompat_info *compat)
Definition rscompat.c:806
bool rscompat_names(struct rscompat_info *info)
Definition rscompat.c:386
const char * rscompat_utype_flag_name_3_1(struct rscompat_info *compat, const char *old_type)
Definition rscompat.c:2167
void rscompat_req_vec_adjust_3_1(struct rscompat_info *compat, struct requirement_vector *preqs, int *reqs_count, const char *filename, const char *sec, const char *sub, const char *rfor)
Definition rscompat.c:2081
bool rscompat_old_slow_invasions_3_1(struct rscompat_info *compat, bool slow_invasions)
Definition rscompat.c:1910
void rscompat_postprocess(struct rscompat_info *info)
Definition rscompat.c:859
int rscompat_check_capabilities(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:65
void rscompat_enablers_add_obligatory_hard_reqs(void)
Definition rscompat.c:285
const char * rscompat_action_max_range_name_S3_1(struct rscompat_info *compat, int act_id)
Definition rscompat.c:2255
void rscompat_init_info(struct rscompat_info *info)
Definition rscompat.c:56
bool rscompat_check_cap_and_version(struct section_file *file, const char *filename, const struct rscompat_info *info)
Definition rscompat.c:131
const char * rscompat_combat_bonus_name_3_1(struct rscompat_info *compat, const char *old_type)
Definition rscompat.c:2179
const char * rscompat_req_type_name_3_1(const char *old_type)
Definition rscompat.c:2045
bool sanity_check_ruleset_data(struct rscompat_info *compat)
Definition rssanity.c:861
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1542
#define check_cityname(name)
Definition ruleset.c:112
static int ruleset_purge_redundant_reqs_enablers(void)
Definition ruleset.c:414
static void ruleset_load_traits(struct trait_limits *out, struct section_file *file, const char *secname, const char *field_prefix)
Definition ruleset.c:1324
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:9325
#define STYLE_SECTION_PREFIX
Definition ruleset.c:95
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:1225
static bool load_terrain_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2791
static bool load_style_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5697
int ruleset_purge_unused_entities(void)
Definition ruleset.c:304
#define MUSICSTYLE_SECTION_PREFIX
Definition ruleset.c:89
static char * road_sections
Definition ruleset.c:123
static bool load_ruleset_governments(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4418
#define MULTIPLIER_SECTION_PREFIX
Definition ruleset.c:109
static struct requirement_vector reqs_list
Definition ruleset.c:125
static void send_ruleset_techs(struct conn_list *dest)
Definition ruleset.c:8225
#define section_strlcpy(dst, src)
Definition ruleset.c:117
#define check_name(name)
Definition ruleset.c:111
static void send_ruleset_units(struct conn_list *dest)
Definition ruleset.c:8038
static void send_ruleset_governments(struct conn_list *dest)
Definition ruleset.c:8851
static struct extra_type * lookup_resource(const char *filename, const char *name, const char *jsection)
Definition ruleset.c:1204
static struct section_file * openload_luadata_file(const char *rsdir)
Definition ruleset.c:617
static bool load_ruleset_techs(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1573
static bool purge_unused_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:318
void rulesets_deinit(void)
Definition ruleset.c:9315
static bool load_action_ui_name(struct section_file *file, int act, const char *entry_name, const char *compat_name)
Definition ruleset.c:6281
static void send_ruleset_resources(struct conn_list *dest)
Definition ruleset.c:8458
static bool load_ruleset_buildings(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2673
static char * terrain_sections
Definition ruleset.c:120
static bool lookup_building_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleset.c:1056
static void nullcheck_secfile_destroy(struct section_file *file)
Definition ruleset.c:9304
static void send_ruleset_clauses(struct conn_list *dest)
Definition ruleset.c:9020
static void send_ruleset_game(struct conn_list *dest)
Definition ruleset.c:9140
char * parser_buffer
Definition ruleset.c:200
#define NATION_SECTION_PREFIX
Definition ruleset.c:94
static bool load_ruleset_effects(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:6145
static void send_ruleset_nations(struct conn_list *dest)
Definition ruleset.c:8894
static void send_ruleset_roads(struct conn_list *dest)
Definition ruleset.c:8613
static int ruleset_purge_unused_enablers(void)
Definition ruleset.c:235
static bool is_on_allowed_list(const char *name, const char **list, size_t len)
Definition ruleset.c:4808
static void send_ruleset_tech_classes(struct conn_list *dest)
Definition ruleset.c:8207
static void send_ruleset_action_enablers(struct conn_list *dest)
Definition ruleset.c:8766
static void send_ruleset_control(struct conn_list *dest)
Definition ruleset.c:4610
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:9231
#define GOODS_SECTION_PREFIX
Definition ruleset.c:101
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:206
#define TERRAIN_SECTION_PREFIX
Definition ruleset.c:103
static struct section_file * openload_ruleset_file(const char *whichset, const char *rsdir)
Definition ruleset.c:562
static void send_ruleset_musics(struct conn_list *dest)
Definition ruleset.c:9114
int ruleset_purge_redundant_reqs(void)
Definition ruleset.c:481
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:6243
static char * base_sections
Definition ruleset.c:122
#define DISASTER_SECTION_PREFIX
Definition ruleset.c:106
static void send_ruleset_goods(struct conn_list *dest)
Definition ruleset.c:8653
static const char name_too_long[]
Definition ruleset.c:115
bool reload_rulesets_settings(void)
Definition ruleset.c:9554
static struct strvec * lookup_strvec(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleset.c:1184
#define CITYSTYLE_SECTION_PREFIX
Definition ruleset.c:88
static bool load_action_range(struct rscompat_info *compat, struct section_file *file, action_id act)
Definition ruleset.c:6354
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:867
static bool load_game_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1363
static void send_ruleset_specialists(struct conn_list *dest)
Definition ruleset.c:8179
static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, size_t err_len, struct rscompat_info *compat)
Definition ruleset.c:1943
#define ADVANCE_SECTION_PREFIX
Definition ruleset.c:85
#define EFFECT_SECTION_PREFIX
Definition ruleset.c:90
static void send_ruleset_action_auto_performers(struct conn_list *dest)
Definition ruleset.c:8794
static bool load_government_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4336
static void send_ruleset_team_names(struct conn_list *dest)
Definition ruleset.c:9201
static void send_ruleset_cities(struct conn_list *dest)
Definition ruleset.c:9086
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:899
static bool purge_redundant_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:403
static char * lookup_string(struct section_file *file, const char *prefix, const char *suffix)
Definition ruleset.c:1164
static const char * check_leader_names(struct nation_type *pnation)
Definition ruleset.c:4649
#define ACTION_ENABLER_SECTION_PREFIX
Definition ruleset.c:108
#define BASE_SECTION_PREFIX
Definition ruleset.c:98
static int ruleset_purge_redundant_reqs_effects(void)
Definition ruleset.c:452
static enum fc_tristate openload_script_file(const char *whichset, const char *rsdir, char **buffer, bool optional)
Definition ruleset.c:590
char * get_parser_buffer(void)
Definition ruleset.c:553
static bool load_building_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2621
#define EXTRA_SECTION_PREFIX
Definition ruleset.c:97
static bool load_action_range_max(struct rscompat_info *compat, struct section_file *file, action_id act)
Definition ruleset.c:6303
void send_rulesets(struct conn_list *dest)
Definition ruleset.c:9577
#define CLAUSE_SECTION_PREFIX
Definition ruleset.c:96
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:932
static char * resource_sections
Definition ruleset.c:119
#define UNIT_SECTION_PREFIX
Definition ruleset.c:105
#define ACHIEVEMENT_SECTION_PREFIX
Definition ruleset.c:107
static bool load_ruleset_cities(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5937
static bool load_ruleset_styles(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:5758
static struct government * lookup_government(struct section_file *file, const char *entry, const char *filename, struct government *fallback)
Definition ruleset.c:1139
static bool load_ruleset_units(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:2075
char * script_buffer
Definition ruleset.c:199
static bool lookup_time(const struct section_file *secfile, int *turns, const char *sec_name, const char *property_name, const char *filename, const char *item_name, bool *ok)
Definition ruleset.c:1275
static bool load_action_blocked_by_list(struct section_file *file, const char *filename, struct action *paction)
Definition ruleset.c:6420
static void send_ruleset_styles(struct conn_list *dest)
Definition ruleset.c:9004
#define NATION_GROUP_SECTION_PREFIX
Definition ruleset.c:93
static char * extra_sections
Definition ruleset.c:121
#define RULES_SUFFIX
Definition ruleset.c:82
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:645
static void send_ruleset_disasters(struct conn_list *dest)
Definition ruleset.c:8685
static bool purge_duplicate_req_vec(const struct requirement_vector *reqs, const char *msg)
Definition ruleset.c:358
static bool lookup_tech_list(struct section_file *file, const char *prefix, const char *entry, int *output, const char *filename)
Definition ruleset.c:992
#define MAX_SECTION_LABEL
Definition ruleset.c:116
#define BUILDING_SECTION_PREFIX
Definition ruleset.c:87
static bool load_ruleset_game(struct section_file *file, bool act, struct rscompat_info *compat)
Definition ruleset.c:6535
static bool load_nation_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4669
static void send_ruleset_achievements(struct conn_list *dest)
Definition ruleset.c:8715
#define SCRIPT_SUFFIX
Definition ruleset.c:83
static void send_ruleset_bases(struct conn_list *dest)
Definition ruleset.c:8591
static bool load_ruleset_terrain(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:3124
static int ruleset_purge_unused_effects(void)
Definition ruleset.c:281
static bool load_action_actor_consuming_always(struct section_file *file, action_id act)
Definition ruleset.c:6403
static bool load_action_post_success_force(struct section_file *file, const char *filename, int performer_slot, struct action *paction)
Definition ruleset.c:6464
static bool load_tech_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1456
#define SPECIALIST_SECTION_PREFIX
Definition ruleset.c:102
static bool lookup_cbonus_list(struct rscompat_info *compat, struct combat_bonus_list *list, struct section_file *file, const char *sec, const char *sub)
Definition ruleset.c:805
static bool load_action_kind(struct section_file *file, action_id act)
Definition ruleset.c:6380
static void send_ruleset_multipliers(struct conn_list *dest)
Definition ruleset.c:9052
char * get_script_buffer(void)
Definition ruleset.c:545
static void send_ruleset_actions(struct conn_list *dest)
Definition ruleset.c:8736
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:4824
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:5836
static bool load_ruleset_nations(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:4994
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:5879
static void send_ruleset_unit_classes(struct conn_list *dest)
Definition ruleset.c:7990
#define TECH_CLASS_SECTION_PREFIX
Definition ruleset.c:86
#define RESOURCE_SECTION_PREFIX
Definition ruleset.c:100
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:1108
static void send_ruleset_extras(struct conn_list *dest)
Definition ruleset.c:8477
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action)
static void send_ruleset_terrain(struct conn_list *dest)
Definition ruleset.c:8355
#define GOVERNMENT_SECTION_PREFIX
Definition ruleset.c:91
static bool load_unit_names(struct section_file *file, struct rscompat_info *compat)
Definition ruleset.c:1784
static void send_ruleset_trade_routes(struct conn_list *dest)
Definition ruleset.c:8830
static void notify_ruleset_fallback(const char *msg)
Definition ruleset.c:9223
static bool lookup_bv_actions(struct section_file *file, const char *filename, bv_actions *target, const char *path)
Definition ruleset.c:6501
static void send_ruleset_buildings(struct conn_list *dest)
Definition ruleset.c:8317
#define UNIT_CLASS_SECTION_PREFIX
Definition ruleset.c:104
static bool ruleset_load_names(struct name_translation *pname, const char *domain, struct section_file *file, const char *sec_name)
Definition ruleset.c:1301
#define ROAD_SECTION_PREFIX
Definition ruleset.c:99
static const char * valid_ruleset_filename(const char *subdir, const char *name, const char *extension, bool optional)
Definition ruleset.c:500
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:5915
#define NATION_SET_SECTION_PREFIX
Definition ruleset.c:92
#define RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE
Definition ruleset.h:107
#define RS_DEFAULT_TECH_TRADE_LOSS_HOLES
Definition ruleset.h:84
#define RS_DEFAULT_TECH_COST_STYLE
Definition ruleset.h:90
#define RS_DEFAULT_EXTRA_APPEARANCE
Definition ruleset.h:101
#define RS_DEFAULT_TECH_PARASITE_HOLES
Definition ruleset.h:85
#define GAME_DEFAULT_ACH_VALUE
Definition ruleset.h:78
#define RS_DEFAULT_TECH_TRADE_HOLES
Definition ruleset.h:83
#define RS_DEFAULT_CULTURE_VIC_POINTS
Definition ruleset.h:94
#define RS_DEFAULT_CULTURE_MIGRATION_PML
Definition ruleset.h:96
void(* rs_conversion_logger)(const char *msg)
Definition ruleset.h:40
#define RS_DEFAULT_SMALL_WONDER_VISIBILITY
Definition ruleset.h:109
#define ruleset_error(logger, level, format,...)
Definition ruleset.h:57
#define RS_DEFAULT_ONLY_KILLING_VETERAN
Definition ruleset.h:104
#define RS_DEFAULT_TECH_LOSS_HOLES
Definition ruleset.h:86
#define RS_DEFAULT_HISTORY_INTEREST_PML
Definition ruleset.h:97
#define RS_DEFAULT_TECH_UPKEEP_STYLE
Definition ruleset.h:92
#define RS_DEFAULT_GOODS_SELECTION
Definition ruleset.h:99
#define RS_DEFAULT_PYTHAGOREAN_DIAGONAL
Definition ruleset.h:87
#define RS_DEFAULT_TECH_STEAL_HOLES
Definition ruleset.h:82
#define GAME_DEFAULT_ACH_UNIQUE
Definition ruleset.h:77
#define RS_DEFAULT_COMBAT_ODDS_SCALED_VETERANCY
Definition ruleset.h:106
#define RS_DEFAULT_MUUK_FOOD_WIPE
Definition ruleset.h:79
#define RS_DEFAULT_MUUK_GOLD_WIPE
Definition ruleset.h:80
#define GAME_DEFAULT_CHANGABLE_TAX
Definition ruleset.h:72
#define RS_DEFAULT_MUUK_SHIELD_WIPE
Definition ruleset.h:81
#define RS_DEFAULT_GOLD_UPKEEP_STYLE
Definition ruleset.h:89
#define GAME_DEFAULT_NATIONALITY
Definition ruleset.h:74
#define GAME_DEFAULT_ADDTOSIZE
Definition ruleset.h:71
#define RS_DEFAULT_ONLY_REAL_FIGHT_VETERAN
Definition ruleset.h:105
#define RS_DEFAULT_EXTRA_DISAPPEARANCE
Definition ruleset.h:102
#define GAME_DEFAULT_VISION_REVEAL_TILES
Definition ruleset.h:73
#define RS_DEFAULT_CULTURE_VIC_LEAD
Definition ruleset.h:95
#define RS_DEFAULT_TECH_LEAKAGE
Definition ruleset.h:91
#define RSFORMAT_3_1
Definition ruleset.h:36
#define GAME_DEFAULT_DISASTER_FREQ
Definition ruleset.h:76
#define GAME_DEFAULT_CONVERT_SPEED
Definition ruleset.h:75
static struct compatibility compat[]
Definition savecompat.c:101
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)
bool settings_ruleset(struct section_file *file, const char *section, bool act)
Definition settings.c:4178
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
bool check_strlen(const char *str, size_t len, const char *errmsg)
Definition shared.c:492
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
void remove_leading_trailing_spaces(char *s)
Definition shared.c:443
const struct strvec * get_data_dirs(void)
Definition shared.c:886
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
#define DIR_SEPARATOR
Definition shared.h:127
#define ARRAY_SIZE(x)
Definition shared.h:85
struct specialist * specialist_by_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:2395
void update_nations_with_startpos(void)
Definition srv_main.c:2200
void strvec_store(struct strvec *psv, const char *const *vec, size_t size)
struct strvec * strvec_new(void)
struct requirement_vector reqs
Definition actions.h:576
enum action_auto_perf_cause cause
Definition actions.h:572
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:580
action_id action
Definition actions.h:441
struct requirement_vector actor_reqs
Definition actions.h:442
struct requirement_vector target_reqs
Definition actions.h:443
action_id id
Definition actions.h:382
bool actor_consuming_always
Definition actions.h:414
int max_distance
Definition actions.h:397
bool quiet
Definition actions.h:404
enum action_result result
Definition actions.h:384
char ui_name[MAX_LEN_NAME]
Definition actions.h:400
bv_action_sub_results sub_results
Definition actions.h:385
enum action_actor_kind actor_kind
Definition actions.h:387
bv_actions blocked_by
Definition actions.h:408
enum action_target_kind target_kind
Definition actions.h:388
int min_distance
Definition actions.h:397
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 citizens_graphic[MAX_LEN_NAME]
Definition city.h:475
char graphic_alt[MAX_LEN_NAME]
Definition city.h:474
char graphic[MAX_LEN_NAME]
Definition city.h:473
struct civ_game::@29 rgame
char * nationlist
Definition game.h:274
int named_teams
Definition game.h:286
size_t as_count
Definition game.h:285
const char ** allowed_govs
Definition game.h:277
int upgrade_veteran_loss
Definition game.h:198
struct rgbcolor * plr_bg_color
Definition game.h:102
int incite_total_factor
Definition game.h:149
int init_vis_radius_sq
Definition game.h:151
struct civ_game::@30::@34 server
bool vision_reveal_tiles
Definition game.h:199
char * description_file
Definition game.h:273
struct packet_ruleset_control control
Definition game.h:83
char * ruleset_summary
Definition game.h:84
char ** nc_agovs
Definition game.h:278
int base_incite_cost
Definition game.h:133
int global_init_techs[MAX_NUM_TECH_LIST]
Definition game.h:107
struct packet_game_info info
Definition game.h:89
int autoupgrade_veteran_loss
Definition game.h:131
char rulesetdir[MAX_LEN_NAME]
Definition game.h:236
int start_year
Definition game.h:190
int incite_improvement_factor
Definition game.h:148
struct section_file * luadata
Definition game.h:244
char ** embedded_nations
Definition game.h:275
int global_init_buildings[MAX_NUM_BUILDING_LIST]
Definition game.h:108
struct civ_game::@30::@34::@39 ruledit
struct trait_limits default_traits[TRAIT_COUNT]
Definition game.h:270
char ** nc_astyles
Definition game.h:284
const char ** allowed_terrains
Definition game.h:280
char * ruleset_description
Definition game.h:85
size_t ag_count
Definition game.h:279
const char ** allowed_styles
Definition game.h:283
char ** nc_aterrs
Definition game.h:281
size_t embedded_nations_count
Definition game.h:276
int incite_unit_factor
Definition game.h:150
char * ruleset_capabilities
Definition game.h:86
int ransom_gold
Definition game.h:174
size_t at_count
Definition game.h:282
struct veteran_system * veteran
Definition game.h:100
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::@41::@43 server
bool ocean_resources
Definition map_types.h:105
struct requirement_vector receiver_reqs
Definition diptreaty.h:57
struct requirement_vector giver_reqs
Definition diptreaty.h:56
bool enabled
Definition diptreaty.h:55
enum unit_type_flag_id flag
Definition unittype.h:448
enum combat_bonus_type type
Definition unittype.h:449
bv_extras conflicts
Definition extras.h:129
struct name_translation name
Definition extras.h:87
int build_cost
Definition improvement.h:77
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:73
enum impr_genus_id genus
Definition improvement.h:80
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:74
struct requirement_vector obsolete_by
Definition improvement.h:76
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:84
struct requirement_vector reqs
Definition improvement.h:75
struct strvec * helptext
Definition improvement.h:82
struct name_translation name
Definition improvement.h:70
bv_impr_flags flags
Definition improvement.h:81
char soundtag[MAX_LEN_NAME]
Definition improvement.h:83
Definition climisc.h:82
struct requirement_vector reqs
Definition style.h:33
char music_peaceful[MAX_LEN_NAME]
Definition style.h:31
char music_combat[MAX_LEN_NAME]
Definition style.h:32
bool hidden
Definition nation.h:168
struct name_translation noun_plural
Definition nation.h:101
struct nation_list * parent_nations
Definition nation.h:135
struct name_translation adjective
Definition nation.h:100
char * legend
Definition nation.h:106
enum barbarian_type barb_type
Definition nation.h:109
struct nation_type::@50::@52 server
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
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 rule_name[MAX_LEN_NAME]
char graphic_str[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char citizens_graphic[MAX_LEN_NAME]
char name[MAX_LEN_NAME]
char rule_name[MAX_LEN_NAME]
char graphic_alt[MAX_LEN_NAME]
char graphic[MAX_LEN_NAME]
struct requirement reqs[MAX_NUM_REQS]
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]
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]
char name[MAX_LEN_NAME]
bv_unit_classes native_to
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]
int work_raise_chance[MAX_VET_LEVELS]
int base_raise_chance[MAX_VET_LEVELS]
int global_init_techs[MAX_NUM_TECH_LIST]
int move_bonus[MAX_VET_LEVELS]
char veteran_name[MAX_VET_LEVELS][MAX_LEN_NAME]
Impr_type_id global_init_buildings[MAX_NUM_BUILDING_LIST]
int power_fact[MAX_VET_LEVELS]
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 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]
char groups[MAX_NUM_NATION_GROUPS][MAX_LEN_NAME]
bool hidden[MAX_NUM_NATION_GROUPS]
char rule_names[MAX_NUM_NATION_SETS][MAX_LEN_NAME]
char names[MAX_NUM_NATION_SETS][MAX_LEN_NAME]
char descriptions[MAX_NUM_NATION_SETS][MAX_LEN_MSG]
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 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 name[MAX_LEN_NAME]
char helptxt[MAX_LEN_PACKET]
Terrain_type_id transform_result
char helptext[MAX_LEN_PACKET]
bv_terrain_flags flags
Resource_type_id resources[MAX_RESOURCE_TYPES]
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 rule_name[MAX_LEN_NAME]
enum trade_route_illegal_cancelling cancelling
enum trade_route_bonus_type bonus_type
enum combat_bonus_type type
enum unit_type_flag_id flag
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 name[MAX_LEN_NAME]
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_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]
char team_name[MAX_LEN_NAME]
Definition goto.c:52
enum req_vec_change_operation operation
struct requirement req
struct req_vec_change * suggested_solutions
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:84
struct requirement_vector first_reqs
Definition road.h:86
enum road_move_mode move_mode
Definition road.h:79
int tile_bonus[O_LAST]
Definition road.h:82
int tile_incr_const[O_LAST]
Definition road.h:80
int tile_incr[O_LAST]
Definition road.h:81
bv_road_flags flags
Definition road.h:89
int move_cost
Definition road.h:78
enum road_compat compat
Definition road.h:83
bv_max_extras integrates
Definition road.h:88
bool compat_mode
Definition rscompat.h:30
rs_conversion_logger log_cb
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:758
int base_raise_chance
Definition unittype.h:471
struct name_translation name
Definition unittype.h:468
int work_raise_chance
Definition unittype.h:472
struct veteran_level * definitions
Definition unittype.h:478
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:969
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:787
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
bool fc_isspace(char c)
Definition support.c:1249
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:832
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:896
char fc_tolower(char c)
Definition support.c:1282
#define sz_strlcpy(dest, src)
Definition support.h:167
#define RETURN_VALUE_AFTER_EXIT(_val_)
Definition support.h:121
#define fc__attribute(x)
Definition support.h:89
#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:75
#define team_slots_iterate(_tslot)
Definition team.h:70
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
@ AR_TWO
Definition tech.h:112
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
#define advance_iterate(_start, _p)
Definition tech.h:264
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 tech_class_iterate(_p)
Definition tech.h:198
#define advance_iterate_end
Definition tech.h:270
#define A_LAST
Definition tech.h:45
struct terrain * terrain_by_rule_name(const char *name)
Definition terrain.c:174
Terrain_type_id terrain_count(void)
Definition terrain.c:106
const char * terrain_flag_id_name_cb(enum terrain_flag_id flag)
Definition terrain.c:805
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:126
struct terrain * terrain_by_number(const Terrain_type_id type)
Definition terrain.c:144
const char * terrain_flag_helptxt(enum terrain_flag_id id)
Definition terrain.c:817
struct resource_type * resource_type_init(struct extra_type *pextra)
Definition terrain.c:260
void set_user_terrain_flag_name(enum terrain_flag_id id, const char *name, const char *helptxt)
Definition terrain.c:776
Terrain_type_id terrain_number(const struct terrain *pterrain)
Definition terrain.c:135
#define terrain_type_iterate(_p)
Definition terrain.h:358
#define MAX_RESOURCE_TYPES
Definition terrain.h:67
#define T_NONE
Definition terrain.h:56
#define TERRAIN_UNKNOWN_IDENTIFIER
Definition terrain.h:188
#define terrain_type_iterate_end
Definition terrain.h:364
#define RESOURCE_NONE_IDENTIFIER
Definition terrain.h:47
#define RESOURCE_NULL_IDENTIFIER
Definition terrain.h:46
#define MAX_NUM_TERRAINS
Definition terrain.h:64
#define T_FIRST
Definition terrain.h:60
#define MAX_NUM_USER_TER_FLAGS
Definition terrain.h:146
#define ACTIVITY_FACTOR
Definition tile.h:168
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:2772
const char * unit_class_flag_helptxt(enum unit_class_flag_id id)
Definition unittype.c:1906
struct unit_type * unit_type_by_rule_name(const char *name)
Definition unittype.c:1819
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:193
void unit_type_action_cache_init(void)
Definition unittype.c:983
void set_unit_type_caches(struct unit_type *ptype)
Definition unittype.c:2831
void role_unit_precalcs(void)
Definition unittype.c:2223
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:2733
Unit_type_id utype_count(void)
Definition unittype.c:80
int utype_veteran_levels(const struct unit_type *punittype)
Definition unittype.c:2673
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2645
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693
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:1836
const char * unit_type_flag_helptxt(enum unit_type_flag_id id)
Definition unittype.c:1969
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:1864
struct veteran_system * veteran_system_new(int count)
Definition unittype.c:2702
Unit_Class_id uclass_number(const struct unit_class *pclass)
Definition unittype.c:2516
bool utype_can_do_action(const struct unit_type *putype, const action_id act_id)
Definition unittype.c:443
void set_user_unit_type_flag_name(enum unit_type_flag_id id, const char *name, const char *helptxt)
Definition unittype.c:1928
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
#define utype_class(_t_)
Definition unittype.h:736
#define combat_bonus_list_iterate_end
Definition unittype.h:463
#define L_FIRST
Definition unittype.h:333
#define combat_bonus_list_iterate(bonuslist, pbonus)
Definition unittype.h:461
@ HUT_FRIGHTEN
Definition unittype.h:129
@ HUT_NOTHING
Definition unittype.h:129
@ HUT_NORMAL
Definition unittype.h:129
#define unit_class_iterate(_p)
Definition unittype.h:879
#define MAX_NUM_USER_UNIT_FLAGS
Definition unittype.h:316
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
#define UTYF_LAST_USER_FLAG
Definition unittype.h:315
#define unit_type_iterate(_p)
Definition unittype.h:841
#define U_LAST
Definition unittype.h:40
#define uclass_index(_c_)
Definition unittype.h:729
#define unit_class_iterate_end
Definition unittype.h:886
#define unit_type_iterate_end
Definition unittype.h:848
#define MAX_NUM_USER_UCLASS_FLAGS
Definition unittype.h:113