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 (section_list_size(sec) >= SP_MAX) {
5956 "\"%s\": Too many specialists (%d, max %d).",
5957 filename, section_list_size(sec), SP_MAX);
5958 ok = FALSE;
5959 }
5960
5961 if (ok) {
5962 int i = 0;
5963 const char *tag;
5964
5965 game.control.num_specialist_types = section_list_size(sec);
5966
5967 section_list_iterate(sec, psection) {
5968 struct specialist *s = specialist_by_number(i);
5969 struct requirement_vector *reqs;
5970 const char *sec_name = section_name(psection);
5971
5972 if (!ruleset_load_names(&s->name, NULL, file, sec_name)) {
5973 ok = FALSE;
5974 break;
5975 }
5976
5978 "%s.short_name", sec_name);
5979 name_set(&s->abbreviation, NULL, item);
5980
5981 tag = secfile_lookup_str(file, "%s.graphic", sec_name);
5982 if (tag == NULL) {
5984 "\"%s\": No graphic tag for specialist at %s.",
5985 filename, sec_name);
5986 ok = FALSE;
5987 break;
5988 }
5989 sz_strlcpy(s->graphic_str, tag);
5992 "%s.graphic_alt", sec_name));
5993
5994 reqs = lookup_req_list(file, compat, sec_name, "reqs", specialist_rule_name(s));
5995 if (reqs == NULL) {
5996 ok = FALSE;
5997 break;
5998 }
5999 requirement_vector_copy(&s->reqs, reqs);
6000
6001 s->helptext = lookup_strvec(file, sec_name, "helptext");
6002
6003 if (requirement_vector_size(&s->reqs) == 0 && DEFAULT_SPECIALIST == -1) {
6005 }
6006 i++;
6008 }
6009
6010 if (ok && DEFAULT_SPECIALIST == -1) {
6012 "\"%s\": must give a min_size of 0 for at least one "
6013 "specialist type.", filename);
6014 ok = FALSE;
6015 }
6016 section_list_destroy(sec);
6017 sec = NULL;
6018
6019 if (ok) {
6020 /* City Parameters */
6021
6024 "parameters.celebrate_size_limit");
6026 secfile_lookup_int_default(file, GAME_DEFAULT_ADDTOSIZE, "parameters.add_to_size_limit");
6029 "parameters.angry_citizens");
6030
6032 secfile_lookup_bool_default(file, GAME_DEFAULT_CHANGABLE_TAX, "parameters.changable_tax");
6034 secfile_lookup_int_default(file, 0, "parameters.forced_science");
6036 secfile_lookup_int_default(file, 100, "parameters.forced_luxury");
6038 secfile_lookup_int_default(file, 0, "parameters.forced_gold");
6040 + game.info.forced_gold != 100) {
6042 "\"%s\": Forced taxes do not add up in ruleset!",
6043 filename);
6044 ok = FALSE;
6045 }
6046 }
6047
6048 if (ok) {
6049 /* civ1 & 2 didn't reveal tiles */
6052 "parameters.vision_reveal_tiles");
6053
6055 secfile_lookup_int_default(file, 1, "parameters.pop_report_zeroes");
6056
6057 /* Citizens configuration. */
6060 "citizen.nationality");
6063 "citizen.convert_speed");
6065 secfile_lookup_int_default(file, 0, "citizen.partisans_pct");
6067 secfile_lookup_int_default(file, 0, "citizen.conquest_convert_pct");
6068 }
6069
6070 if (ok) {
6071 /* Missing unit upkeep. */
6072 struct action_auto_perf *auto_perf;
6073
6074 /* Can't pay food upkeep! */
6076 auto_perf->cause = AAPC_UNIT_UPKEEP;
6077
6078 /* This is about food upkeep. */
6079 requirement_vector_append(&auto_perf->reqs,
6080 req_from_str("OutputType", "Local",
6081 FALSE, TRUE, TRUE,
6082 "Food"));
6083
6084 /* Internally represented as an action auto performer rule. */
6085 if (!load_muuk_as_action_auto(file, auto_perf, "food", filename)) {
6086 ok = FALSE;
6087 }
6088
6091 "missing_unit_upkeep.food_wipe");
6092
6093 /* Can't pay gold upkeep! */
6095 auto_perf->cause = AAPC_UNIT_UPKEEP;
6096
6097 /* This is about gold upkeep. */
6098 requirement_vector_append(&auto_perf->reqs,
6099 req_from_str("OutputType", "Local",
6100 FALSE, TRUE, TRUE,
6101 "Gold"));
6102
6103 /* Internally represented as an action auto performer rule. */
6104 if (!load_muuk_as_action_auto(file, auto_perf, "gold", filename)) {
6105 ok = FALSE;
6106 }
6107
6110 "missing_unit_upkeep.gold_wipe");
6111
6112 /* Can't pay shield upkeep! */
6114 auto_perf->cause = AAPC_UNIT_UPKEEP;
6115
6116 /* This is about shield upkeep. */
6117 requirement_vector_append(&auto_perf->reqs,
6118 req_from_str("OutputType", "Local",
6119 FALSE, TRUE, TRUE,
6120 "Shield"));
6121
6122 /* Internally represented as an action auto performer rule. */
6123 if (!load_muuk_as_action_auto(file, auto_perf, "shield", filename)) {
6124 ok = FALSE;
6125 }
6126
6129 "missing_unit_upkeep.shield_wipe");
6130 }
6131
6132 if (ok) {
6134 }
6135
6136 return ok;
6137}
6138
6139/**********************************************************************/
6142static bool load_ruleset_effects(struct section_file *file,
6143 struct rscompat_info *compat)
6144{
6145 struct section_list *sec;
6146 const char *type;
6147 const char *filename;
6148 bool ok = TRUE;
6149
6150 filename = secfile_name(file);
6151
6152 if (!rscompat_check_cap_and_version(file, filename, compat)) {
6153 return FALSE;
6154 }
6155
6156 (void) secfile_entry_by_path(file, "datafile.description"); /* unused */
6157 (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */
6158
6159 /* Parse effects and add them to the effects ruleset cache. */
6161 section_list_iterate(sec, psection) {
6162 enum effect_type eff;
6163 int value;
6164 struct multiplier *pmul;
6165 struct effect *peffect;
6166 const char *sec_name = section_name(psection);
6167 struct requirement_vector *reqs;
6168
6169 type = secfile_lookup_str(file, "%s.type", sec_name);
6170
6171 if (type == NULL) {
6173 "\"%s\" [%s] missing effect type.", filename, sec_name);
6174 ok = FALSE;
6175 break;
6176 }
6177
6178 if (compat->compat_mode && rscompat_old_effect_3_1(type, file, sec_name, compat)) {
6179 continue;
6180 }
6181
6182 eff = effect_type_by_name(type, fc_strcasecmp);
6183 if (!effect_type_is_valid(eff)) {
6185 "\"%s\" [%s] lists unknown effect type \"%s\".",
6186 filename, sec_name, type);
6187 ok = FALSE;
6188 break;
6189 }
6190
6191 value = secfile_lookup_int_default(file, 1, "%s.value", sec_name);
6192
6193 {
6194 const char *multiplier_name
6195 = secfile_lookup_str(file, "%s.multiplier", sec_name);
6196
6197 if (multiplier_name) {
6198 pmul = multiplier_by_rule_name(multiplier_name);
6199 if (!pmul) {
6201 "\"%s\" [%s] has unknown multiplier \"%s\".",
6202 filename, sec_name, multiplier_name);
6203 ok = FALSE;
6204 break;
6205 }
6206 } else {
6207 pmul = NULL;
6208 }
6209 }
6210
6211 peffect = effect_new(eff, value, pmul);
6212
6213 reqs = lookup_req_list(file, compat, sec_name, "reqs", type);
6214 if (reqs == NULL) {
6215 ok = FALSE;
6216 break;
6217 }
6218
6220 effect_req_append(peffect, *preq);
6222
6224 section_list_destroy(sec);
6225
6226 if (ok) {
6228 }
6229
6230 return ok;
6231}
6232
6233/**********************************************************************/
6236static int secfile_lookup_int_default_min_max(struct section_file *file,
6237 int def, int min, int max,
6238 const char *path, ...)
6239 fc__attribute((__format__ (__printf__, 5, 6)));
6241 int def, int min, int max,
6242 const char *path, ...)
6243{
6244 char fullpath[256];
6245 int ival;
6246 va_list args;
6247
6248 va_start(args, path);
6249 fc_vsnprintf(fullpath, sizeof(fullpath), path, args);
6250 va_end(args);
6251
6252 if (!secfile_lookup_int(file, &ival, "%s", fullpath)) {
6253 ival = def;
6254 }
6255
6256 if (ival < min) {
6258 "\"%s\" should be in the interval [%d, %d] "
6259 "but is %d; using the minimal value.",
6260 fullpath, min, max, ival);
6261 ival = min;
6262 }
6263
6264 if (ival > max) {
6266 "\"%s\" should be in the interval [%d, %d] "
6267 "but is %d; using the maximal value.",
6268 fullpath, min, max, ival);
6269 ival = max;
6270 }
6271
6272 return ival;
6273}
6274
6275/**********************************************************************/
6278static bool load_action_ui_name(struct section_file *file, int act,
6279 const char *entry_name,
6280 const char *compat_name)
6281{
6282 const char *text;
6283 const char *def = action_ui_name_default(act);
6284
6285 if (compat_name != NULL) {
6286 def = secfile_lookup_str_default(file, def,
6287 "actions.%s", compat_name);
6288 }
6289
6290 text = secfile_lookup_str_default(file, def,
6291 "actions.%s", entry_name);
6292 sz_strlcpy(action_by_number(act)->ui_name, text);
6293
6294 return TRUE;
6295}
6296
6297/**********************************************************************/
6301 struct section_file *file, action_id act)
6302{
6303 struct action *paction = action_by_number(act);
6304 const char *vname = action_max_range_ruleset_var_name(act);
6305
6306 if (vname != NULL) {
6307 struct entry *pentry;
6308 int max_range;
6309
6310 pentry = secfile_entry_lookup(file, "actions.%s", vname);
6311
6312 if (pentry == NULL) {
6313 const char *compat_name = rscompat_action_max_range_name_S3_1(compat, act);
6314
6315 if (compat_name != NULL) {
6316 pentry = secfile_entry_lookup(file, "actions.%s",
6317 compat_name);
6318 }
6319 }
6320
6321 if (pentry == NULL) {
6322 max_range = action_max_range_default(paction->result);
6323 } else {
6324 const char *custom;
6325
6326 if (entry_type_get(pentry) == ENTRY_INT
6327 && entry_int_get(pentry, &max_range)) {
6328 /* max_range already assigned */
6329 } else if (entry_type_get(pentry) == ENTRY_STR
6330 && entry_str_get(pentry, &custom)
6332 max_range = ACTION_DISTANCE_UNLIMITED;
6333 } else {
6334 ruleset_error(NULL, LOG_ERROR, "Bad actions.%s",
6337
6338 return FALSE;
6339 }
6340 }
6341
6342 action_by_number(act)->max_distance = max_range;
6343 }
6344
6345 return TRUE;
6346}
6347
6348/**********************************************************************/
6352 struct section_file *file, action_id act)
6353{
6354 struct action *paction = action_by_number(act);
6355 const char *vname;
6356
6357 if (!load_action_range_max(compat, file, act)) {
6358 return FALSE;
6359 }
6360
6362 if (vname != NULL) {
6363 /* Min range can be loaded from the ruleset. */
6367 "actions.%s",
6368 vname);
6369 }
6370
6371 return TRUE;
6372}
6373
6374/**********************************************************************/
6377static bool load_action_kind(struct section_file *file, action_id act)
6378{
6379 struct action *paction = action_by_number(act);
6380
6381 if (action_target_kind_ruleset_var_name(act) == NULL) {
6382 /* Target kind can't be loaded from the ruleset. */
6383 }
6384
6388 paction->result),
6389 action_target_kind,
6390 "actions.%s",
6392
6393 return TRUE;
6394}
6395
6396/**********************************************************************/
6400 action_id act)
6401{
6403 /* Actor consumption can be loaded from the ruleset. */
6406 file, RS_DEFAULT_ACTION_ACTOR_CONSUMING_ALWAYS, "actions.%s",
6408 }
6409
6410 return TRUE;
6411}
6412
6413/**********************************************************************/
6417 const char *filename,
6418 struct action *paction)
6419{
6420 if (action_blocked_by_ruleset_var_name(paction) != NULL) {
6421 /* Action blocking can be loaded from the ruleset. */
6422
6423 char fullpath[1024];
6424
6425 fc_snprintf(fullpath, sizeof(fullpath), "actions.%s",
6427
6428 if (secfile_entry_by_path(file, fullpath)) {
6429 enum gen_action *blocking_actions;
6430 size_t asize;
6431 int j;
6432
6433 blocking_actions =
6434 secfile_lookup_enum_vec(file, &asize, gen_action, "%s", fullpath);
6435
6436 if (!blocking_actions) {
6437 /* Entity exists but couldn't read it. */
6439 "\"%s\": %s: bad action list",
6440 filename, fullpath);
6441
6442 return FALSE;
6443 }
6444
6445 for (j = 0; j < asize; j++) {
6446 BV_SET(paction->blocked_by, blocking_actions[j]);
6447 }
6448
6449 free(blocking_actions);
6450 }
6451 }
6452
6453 return TRUE;
6454}
6455
6456/**********************************************************************/
6461 const char *filename,
6462 int performer_slot,
6463 struct action *paction)
6464{
6465 struct action_auto_perf *auto_perf;
6466 char action_list_path[100];
6467
6468 if (action_post_success_forced_ruleset_var_name(paction) == NULL) {
6469 /* Not relevant. */
6470 return TRUE;
6471 }
6472
6473 auto_perf = action_auto_perf_slot_number(performer_slot);
6474 auto_perf->cause = AAPC_POST_ACTION;
6475
6476 /* Limit auto performer to this action. */
6477 requirement_vector_append(&auto_perf->reqs,
6478 req_from_values(VUT_ACTION, REQ_RANGE_LOCAL,
6479 FALSE, TRUE, TRUE,
6480 paction->id));
6481
6482 /* Load the list of actions. */
6483 fc_snprintf(action_list_path, sizeof(action_list_path),
6484 "actions.%s",
6486 if (!load_action_auto_actions(file, auto_perf,
6487 action_list_path, filename)) {
6488 return FALSE;
6489 }
6490
6491 return TRUE;
6492}
6493
6494/**********************************************************************/
6497static bool lookup_bv_actions(struct section_file *file,
6498 const char *filename,
6499 bv_actions *target,
6500 const char *path)
6501{
6502 if (secfile_entry_by_path(file, path)) {
6503 enum gen_action *listed_actions;
6504 size_t asize;
6505 int j;
6506
6507 listed_actions = secfile_lookup_enum_vec(file, &asize, gen_action,
6508 "%s", path);
6509
6510 if (!listed_actions) {
6511 /* Entity exists but couldn't read it. */
6512 ruleset_error(NULL, LOG_ERROR, "\"%s\": %s: bad action list",
6513 filename, path);
6514
6515 return FALSE;
6516 }
6517
6518 for (j = 0; j < asize; j++) {
6519 BV_SET(*target, listed_actions[j]);
6520 }
6521
6522 free(listed_actions);
6523 }
6524
6525 return TRUE;
6526}
6527
6528/**********************************************************************/
6531static bool load_ruleset_game(struct section_file *file, bool act,
6532 struct rscompat_info *compat)
6533{
6534 const char *sval, **svec;
6535 const char *filename;
6536 int *food_ini;
6537 int i;
6538 size_t teams;
6539 const char *pref_text;
6540 size_t gni_tmp;
6541 struct section_list *sec;
6542 size_t nval;
6543 const char *name;
6544 bool ok = TRUE;
6545
6546 if (file == NULL) {
6547 return FALSE;
6548 }
6549 filename = secfile_name(file);
6550
6551 name = secfile_lookup_str_default(file, NULL, "ruledit.description_file");
6552 if (name != NULL) {
6554 }
6555
6556 /* section: tileset */
6557 pref_text = secfile_lookup_str_default(file, "", "tileset.prefered");
6558 if (pref_text[0] != '\0') {
6559 log_deprecation("Entry tileset.prefered in game.ruleset."
6560 " Use correct spelling tileset.preferred instead");
6561 }
6562 pref_text = secfile_lookup_str_default(file, pref_text, "tileset.preferred");
6563 if (pref_text[0] != '\0') {
6564 /* There was tileset suggestion */
6566 } else {
6567 /* No tileset suggestions */
6568 game.control.preferred_tileset[0] = '\0';
6569 }
6570
6571 /* section: soundset */
6572 pref_text = secfile_lookup_str_default(file, "", "soundset.prefered");
6573 if (pref_text[0] != '\0') {
6574 log_deprecation("Entry soundset.prefered in game.ruleset."
6575 " Use correct spelling soundset.preferred instead");
6576 }
6577 pref_text = secfile_lookup_str_default(file, pref_text, "soundset.preferred");
6578 if (pref_text[0] != '\0') {
6579 /* There was soundset suggestion */
6581 } else {
6582 /* No soundset suggestions */
6584 }
6585
6586 /* section: musicset */
6587 pref_text = secfile_lookup_str_default(file, "", "musicset.prefered");
6588 if (pref_text[0] != '\0') {
6589 log_deprecation("Entry musicset.prefered in game.ruleset."
6590 " Use correct spelling musicset.preferred instead");
6591 }
6592 pref_text = secfile_lookup_str_default(file, pref_text, "musicset.preferred");
6593 if (pref_text[0] != '\0') {
6594 /* There was musicset suggestion */
6596 } else {
6597 /* No musicset suggestions */
6599 }
6600
6601 /* section: about */
6602 pref_text = secfile_lookup_str(file, "about.name");
6603 /* Ruleset/modpack name found */
6604 sz_strlcpy(game.control.name, pref_text);
6605
6606 pref_text = secfile_lookup_str_default(file, "", "about.version");
6607 if (pref_text[0] != '\0') {
6608 /* Ruleset/modpack version found */
6609 sz_strlcpy(game.control.version, pref_text);
6610 } else {
6611 /* No version information */
6612 game.control.version[0] = '\0';
6613 }
6614
6615 pref_text = secfile_lookup_str_default(file, "", "about.alt_dir");
6616 if (pref_text[0] != '\0') {
6617 /* Alt directory definition found. */
6618 sz_strlcpy(game.control.alt_dir, pref_text);
6619 } else {
6620 /* No alt directory information */
6621 game.control.alt_dir[0] = '\0';
6622 }
6623
6624 pref_text = secfile_lookup_str_default(file, "", "about.summary");
6625 if (pref_text[0] != '\0') {
6626 int len;
6627
6628 /* Ruleset/modpack summary found */
6629 len = strlen(pref_text);
6631 fc_strlcpy(game.ruleset_summary, pref_text, len + 1);
6632 } else {
6633 /* No summary */
6634 if (game.ruleset_summary != NULL) {
6635 free(game.ruleset_summary);
6636 game.ruleset_summary = NULL;
6637 }
6638 }
6639
6640 pref_text = secfile_lookup_str_default(file, "", "about.description");
6641 if (pref_text[0] != '\0') {
6642 int len;
6643
6644 /* Ruleset/modpack description found */
6645 len = strlen(pref_text);
6647 fc_strlcpy(game.ruleset_description, pref_text, len + 1);
6649 } else {
6650 /* No description */
6651 if (game.ruleset_description != NULL) {
6654 }
6656 }
6657
6658 pref_text = secfile_lookup_str_default(file, "", "about.capabilities");
6659 if (pref_text[0] != '\0') {
6660 int len = strlen(pref_text);
6661
6663 fc_strlcpy(game.ruleset_capabilities, pref_text, len +1);
6664 } else {
6666 game.ruleset_capabilities[0] = '\0';
6667 }
6668
6669 /* section: options */
6670 if (!lookup_tech_list(file, "options", "global_init_techs",
6671 game.rgame.global_init_techs, filename)) {
6672 ok = FALSE;
6673 }
6674
6675 if (ok) {
6676 if (!lookup_building_list(file, "options", "global_init_buildings",
6677 game.rgame.global_init_buildings, filename)) {
6678 ok = FALSE;
6679 }
6680 }
6681
6682 if (ok) {
6683 const char **slist;
6684 int j;
6685
6687 "options.popup_tech_help");
6688
6689 /* section: civstyle */
6692 "civstyle.base_pollution");
6693
6694 game.info.gameloss_style = GAMELOSS_STYLE_CLASSICAL;
6695
6696 slist = secfile_lookup_str_vec(file, &nval, "civstyle.gameloss_style");
6697 for (j = 0; j < nval; j++) {
6698 enum gameloss_style style;
6699
6700 sval = slist[j];
6701 if (strcmp(sval, "") == 0) {
6702 continue;
6703 }
6704 style = gameloss_style_by_name(sval, fc_strcasecmp);
6705 if (!gameloss_style_is_valid(style)) {
6707 "\"%s\": bad value \"%s\" for gameloss_style.",
6708 filename, sval);
6709 ok = FALSE;
6710 break;
6711 } else {
6712 game.info.gameloss_style |= style;
6713 }
6714 }
6715 free(slist);
6716 }
6717
6718 if (ok) {
6724 "civstyle.happy_cost");
6730 "civstyle.food_cost");
6732 = secfile_lookup_bool_default(file, TRUE, "civstyle.civil_war_enabled");
6733
6736 "civstyle.civil_war_bonus_celebrating");
6737
6740 "civstyle.civil_war_bonus_unhappy");
6741
6747 "civstyle.base_bribe_cost");
6753 "civstyle.ransom_gold");
6756 "civstyle.pillage_select");
6757
6760 "civstyle.tech_steal_allow_holes");
6763 "civstyle.tech_trade_allow_holes");
6766 "civstyle.tech_trade_loss_allow_holes");
6769 "civstyle.tech_parasite_allow_holes");
6772 "civstyle.tech_loss_allow_holes");
6773
6779 "civstyle.upgrade_veteran_loss");
6785 "civstyle.autoupgrade_veteran_loss");
6786
6792 "research.base_tech_cost");
6793
6794 food_ini = secfile_lookup_int_vec(file, &gni_tmp,
6795 "civstyle.granary_food_ini");
6796 game.info.granary_num_inis = (int) gni_tmp;
6797
6800 "Too many granary_food_ini entries (%d, max %d)",
6802 ok = FALSE;
6803 } else if (game.info.granary_num_inis == 0) {
6804 log_error("No values for granary_food_ini. Using default "
6805 "value %d.", RS_DEFAULT_GRANARY_FOOD_INI);
6808 } else {
6809 int gi;
6810
6811 /* check for <= 0 entries */
6812 for (gi = 0; gi < game.info.granary_num_inis; gi++) {
6813 if (food_ini[gi] <= 0) {
6814 if (gi == 0) {
6815 food_ini[gi] = RS_DEFAULT_GRANARY_FOOD_INI;
6816 } else {
6817 food_ini[gi] = food_ini[gi - 1];
6818 }
6819 log_error("Bad value for granary_food_ini[%i]. Using %i.",
6820 gi, food_ini[gi]);
6821 }
6822 game.info.granary_food_ini[gi] = food_ini[gi];
6823 }
6824 }
6825 free(food_ini);
6826 }
6827
6828 if (ok) {
6834 "civstyle.granary_food_inc");
6835
6842 "civstyle.min_city_center_%s",
6845 }
6846
6847 if (ok) {
6848 const char *tus_text;
6849
6855 "civstyle.init_vis_radius_sq");
6856
6862 "civstyle.init_city_radius_sq");
6863
6865 "civstyle.gold_upkeep_style");
6866 game.info.gold_upkeep_style = gold_upkeep_style_by_name(tus_text,
6868 if (!gold_upkeep_style_is_valid(game.info.gold_upkeep_style)) {
6870 "Unknown gold upkeep style \"%s\"",
6871 tus_text);
6872 ok = FALSE;
6873 }
6874
6876 "civstyle.output_granularity");
6877
6879 = secfile_lookup_bool_default(file, FALSE, "civstyle.airlift_from_always_enabled");
6880
6882 = secfile_lookup_bool_default(file, TRUE, "civstyle.airlift_to_always_enabled");
6883
6884 /* section: wonder_visibility */
6885 if (ok) {
6886 const char *text;
6887
6888 text = secfile_lookup_str_default(file,
6890 "wonder_visibility.small_wonders");
6891
6892 game.info.small_wonder_visibility = wonder_visib_type_by_name(text,
6894 if (!wonder_visib_type_is_valid(game.info.small_wonder_visibility)) {
6896 "Unknown wonder visibility type \"%s\"",
6897 text);
6898 ok = FALSE;
6899 }
6900 }
6901
6902 /* section: illness */
6905 "illness.illness_on");
6911 "illness.illness_base_factor");
6917 "illness.illness_min_size");
6923 "illness.illness_trade_infection");
6929 "illness.illness_pollution_factor");
6930
6931 /* section: incite_cost */
6937 "incite_cost.base_incite_cost");
6943 "incite_cost.improvement_factor");
6949 "incite_cost.unit_factor");
6955 "incite_cost.total_factor");
6956
6957 if (ok) {
6958 /* Auto attack. */
6959 struct action_auto_perf *auto_perf;
6960
6961 /* Action auto performers aren't ready to be exposed in the ruleset
6962 * yet. The behavior when two action auto performers for the same
6963 * cause can fire isn't set in stone yet. How is one of them chosen?
6964 * What if all the actions of the chosen action auto performer turned
6965 * out to be illegal but one of the other action auto performers that
6966 * fired has legal actions? These issues can decide what other action
6967 * rules action auto performers can represent in the future. Deciding
6968 * should therefore wait until a rule needs action auto performers to
6969 * work a certain way. */
6970 /* Only one action auto performer, ACTION_AUTO_MOVED_ADJ, is caused
6971 * by AAPC_UNIT_MOVED_ADJ. It is therefore safe to expose the full
6972 * requirement vector to the ruleset. */
6973 struct requirement_vector *reqs;
6974
6975 /* A unit moved next to this unit and the autoattack server setting
6976 * is enabled. */
6978 auto_perf->cause = AAPC_UNIT_MOVED_ADJ;
6979
6980 reqs = lookup_req_list(file, compat,
6981 "auto_attack", "if_attacker",
6982 "auto_attack");
6983 if (reqs == NULL) {
6984 ok = FALSE;
6985 } else {
6986 requirement_vector_copy(&auto_perf->reqs, reqs);
6987
6988 if (!load_action_auto_actions(file, auto_perf,
6989 "auto_attack.attack_actions",
6990 filename)) {
6991 /* Failed to load auto attack actions */
6993 "\"%s\": %s: failed load %s.",
6994 filename, "auto_attack", "attack_actions");
6995 ok = FALSE;
6996 }
6997
6998 if (ok && compat->compat_mode) {
6999 enum unit_type_flag_id *protecor_flag;
7000 size_t psize;
7001
7002 if (secfile_entry_lookup(file, "%s", "auto_attack.will_never")) {
7003 protecor_flag =
7004 secfile_lookup_enum_vec(file, &psize, unit_type_flag_id,
7005 "%s", "auto_attack.will_never");
7006
7007 if (!protecor_flag) {
7008 /* Entity exists but couldn't read it. */
7010 "\"%s\": %s: bad unit type flag list.",
7011 filename, "auto_attack.will_never");
7012
7013 ok = FALSE;
7014 }
7015 } else {
7016 psize = 0;
7017 protecor_flag = NULL;
7018 }
7019
7020 if (ok && !rscompat_auto_attack_3_1(compat, auto_perf,
7021 psize, protecor_flag)) {
7022 /* Upgrade failed */
7024 "\"%s\": %s: failed to upgrade.",
7025 filename, "auto_attack");
7026 ok = FALSE;
7027 }
7028
7029 if (psize) {
7030 FC_FREE(protecor_flag);
7031 }
7032 }
7033 }
7034 }
7035
7036 /* Section: actions */
7037 if (ok) {
7038 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7039 int force_capture_units, force_bombard, force_explode_nuclear;
7040
7042 "actions.force_trade_route")) {
7043 /* Forbid entering the marketplace when a trade route can be
7044 * established. */
7045 BV_SET(action_by_number(ACTION_MARKETPLACE)->blocked_by,
7046 ACTION_TRADE_ROUTE);
7047 }
7048
7049 /* Forbid bombarding, exploading nuclear or attacking when it is
7050 * legal to capture units. */
7051 force_capture_units
7053 "actions.force_capture_units");
7054
7055 if (force_capture_units) {
7056 BV_SET(action_by_number(ACTION_BOMBARD)->blocked_by,
7057 ACTION_CAPTURE_UNITS);
7058 BV_SET(action_by_number(ACTION_BOMBARD2)->blocked_by,
7059 ACTION_CAPTURE_UNITS);
7060 BV_SET(action_by_number(ACTION_BOMBARD3)->blocked_by,
7061 ACTION_CAPTURE_UNITS);
7062 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7063 ACTION_CAPTURE_UNITS);
7064 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7065 ACTION_CAPTURE_UNITS);
7066 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7067 ACTION_CAPTURE_UNITS);
7068 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7069 ACTION_CAPTURE_UNITS);
7070 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7071 ACTION_CAPTURE_UNITS);
7072 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7073 ACTION_CAPTURE_UNITS);
7074 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7075 ACTION_CAPTURE_UNITS);
7076 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7077 ACTION_CAPTURE_UNITS);
7078 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7079 ACTION_CAPTURE_UNITS);
7080 }
7081
7082 /* Forbid exploding nuclear or attacking when it is legal to
7083 * bombard. */
7084 force_bombard
7086 "actions.force_bombard");
7087
7088 if (force_bombard) {
7089 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7090 ACTION_BOMBARD);
7091 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7092 ACTION_BOMBARD);
7093 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7094 ACTION_BOMBARD);
7095 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7096 ACTION_BOMBARD);
7097 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7098 ACTION_BOMBARD);
7099 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7100 ACTION_BOMBARD);
7101 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7102 ACTION_BOMBARD);
7103 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7104 ACTION_BOMBARD);
7105 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7106 ACTION_BOMBARD);
7107 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7108 ACTION_BOMBARD2);
7109 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7110 ACTION_BOMBARD2);
7111 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7112 ACTION_BOMBARD2);
7113 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7114 ACTION_BOMBARD2);
7115 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7116 ACTION_BOMBARD2);
7117 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7118 ACTION_BOMBARD2);
7119 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7120 ACTION_BOMBARD2);
7121 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7122 ACTION_BOMBARD2);
7123 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7124 ACTION_BOMBARD2);
7125 BV_SET(action_by_number(ACTION_NUKE)->blocked_by,
7126 ACTION_BOMBARD3);
7127 BV_SET(action_by_number(ACTION_NUKE_CITY)->blocked_by,
7128 ACTION_BOMBARD3);
7129 BV_SET(action_by_number(ACTION_NUKE_UNITS)->blocked_by,
7130 ACTION_BOMBARD3);
7131 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7132 ACTION_BOMBARD3);
7133 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7134 ACTION_BOMBARD3);
7135 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7136 ACTION_BOMBARD3);
7137 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7138 ACTION_BOMBARD3);
7139 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7140 ACTION_BOMBARD3);
7141 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7142 ACTION_BOMBARD3);
7143 }
7144
7145 /* Forbid attacking when it is legal to do explode nuclear. */
7146 force_explode_nuclear
7148 "actions.force_explode_nuclear");
7149
7150 if (force_explode_nuclear) {
7151 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7152 ACTION_NUKE);
7153 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7154 ACTION_NUKE);
7155 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7156 ACTION_NUKE);
7157 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7158 ACTION_NUKE);
7159 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7160 ACTION_NUKE);
7161 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7162 ACTION_NUKE);
7163 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7164 ACTION_NUKE_CITY);
7165 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7166 ACTION_NUKE_CITY);
7167 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7168 ACTION_NUKE_CITY);
7169 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7170 ACTION_NUKE_CITY);
7171 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7172 ACTION_NUKE_CITY);
7173 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7174 ACTION_NUKE_CITY);
7175 BV_SET(action_by_number(ACTION_SUICIDE_ATTACK)->blocked_by,
7176 ACTION_NUKE_UNITS);
7177 BV_SET(action_by_number(ACTION_ATTACK)->blocked_by,
7178 ACTION_NUKE_UNITS);
7179 BV_SET(action_by_number(ACTION_CONQUER_CITY)->blocked_by,
7180 ACTION_NUKE_UNITS);
7181 BV_SET(action_by_number(ACTION_CONQUER_CITY2)->blocked_by,
7182 ACTION_NUKE_UNITS);
7183 BV_SET(action_by_number(ACTION_CONQUER_CITY3)->blocked_by,
7184 ACTION_NUKE_UNITS);
7185 BV_SET(action_by_number(ACTION_CONQUER_CITY4)->blocked_by,
7186 ACTION_NUKE_UNITS);
7187 }
7188 }
7189
7190 action_iterate(act_id) {
7191 struct action *paction = action_by_number(act_id);
7192
7193 if (!load_action_blocked_by_list(file, filename, paction)) {
7194 ok = FALSE;
7195 break;
7196 }
7198
7199 if (ok && !lookup_bv_actions(file, filename,
7201 "actions.diplchance_initial_odds")) {
7202 ok = FALSE;
7203 }
7204
7205 if (ok) {
7206 /* If the "Poison City" action or the "Poison City Escape" action
7207 * should empty the granary. */
7208 /* TODO: empty granary and reduce population should become separate
7209 * action effect flags when actions are generalized. */
7213 "actions.poison_empties_food_stock");
7214
7215 /* If the "Steal Maps" action or the "Steal Maps Escape" action always
7216 * will reveal all cities when successful. */
7220 "actions.steal_maps_reveals_all_cities");
7221
7222 /* Allow setting certain properties for some actions before
7223 * generalized actions. */
7224 action_iterate(act_id) {
7225 if (!load_action_range(compat, file, act_id)) {
7226 ok = FALSE;
7227 } else if (!load_action_kind(file, act_id)) {
7228 ok = FALSE;
7229 } else if (!load_action_actor_consuming_always(file, act_id)) {
7230 ok = FALSE;
7231 } else {
7232 load_action_ui_name(file, act_id,
7235 }
7236
7237 if (!ok) {
7238 break;
7239 }
7241
7242 /* The quiet (don't auto generate help for) property of all actions
7243 * live in a single enum vector. This avoids generic action
7244 * expectations. */
7245 if (ok && secfile_entry_by_path(file, "actions.quiet_actions")) {
7246 enum gen_action *quiet_actions;
7247 size_t asize;
7248 int j;
7249
7250 quiet_actions =
7251 secfile_lookup_enum_vec(file, &asize, gen_action,
7252 "actions.quiet_actions");
7253
7254 if (!quiet_actions) {
7255 /* Entity exists but couldn't read it. */
7257 "\"%s\": actions.quiet_actions: bad action list",
7258 filename);
7259
7260 ok = FALSE;
7261 } else {
7262 for (j = 0; j < asize; j++) {
7263 /* Don't auto generate help text for this action. */
7264 action_by_number(quiet_actions[j])->quiet = TRUE;
7265 }
7266
7267 free(quiet_actions);
7268 }
7269 }
7270
7271 if (ok) {
7272 /* Hard code action sub results for now. */
7273
7274 /* Unit Enter Hut */
7275 action_by_result_iterate(paction, ACTRES_HUT_ENTER) {
7276 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_ENTER);
7278 BV_SET(action_by_number(ACTION_PARADROP_ENTER)->sub_results,
7279 ACT_SUB_RES_HUT_ENTER);
7280 BV_SET(action_by_number(ACTION_PARADROP_ENTER_CONQUER)->sub_results,
7281 ACT_SUB_RES_HUT_ENTER);
7282
7283 /* Unit Frighten Hut */
7284 action_by_result_iterate(paction, ACTRES_HUT_FRIGHTEN) {
7285 BV_SET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN);
7287 BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN)->sub_results,
7288 ACT_SUB_RES_HUT_FRIGHTEN);
7289 BV_SET(action_by_number(ACTION_PARADROP_FRIGHTEN_CONQUER)->sub_results,
7290 ACT_SUB_RES_HUT_FRIGHTEN);
7291
7292 /* Unit May Embark */
7293 action_iterate(act_id) {
7294 struct action *paction = action_by_number(act_id);
7295
7297 "civstyle.paradrop_to_transport")
7298 && (action_has_result(paction, ACTRES_PARADROP)
7299 || action_has_result(paction, ACTRES_PARADROP_CONQUER))) {
7300 BV_SET(paction->sub_results, ACT_SUB_RES_MAY_EMBARK);
7301 }
7302
7303 /* Embark actions will always embark, not maybe embark. */
7305 }
7306 }
7307 }
7308
7309 if (ok) {
7310 /* Forced actions after another action was successfully performed. */
7311
7312 /* "Bribe Unit" */
7313 if (!load_action_post_success_force(file, filename,
7316 ACTION_SPY_BRIBE_UNIT))) {
7317 ok = FALSE;
7318 } else if (!load_action_post_success_force(file, filename,
7321 ACTION_ATTACK))) {
7322 ok = FALSE;
7323 }
7324 }
7325
7326 if (ok) {
7327 struct action_auto_perf *auto_perf;
7328
7329 /* The city that made the unit's current tile native is gone.
7330 * Evaluated against an adjacent tile. */
7332 auto_perf->cause = AAPC_CITY_GONE;
7333
7334 /* I have no objections to moving this out of game's actions to
7335 * cities.ruleset, units.ruleset or an other location in game.ruleset
7336 * you find more suitable. -- Sveinung */
7337 if (!load_action_auto_actions(file, auto_perf,
7338 "actions.escape_city", filename)) {
7339 ok = FALSE;
7340 }
7341 }
7342
7343 if (ok) {
7344 struct action_auto_perf *auto_perf;
7345
7346 /* The unit's stack has been defeated and is scheduled for execution
7347 * but the unit has the CanEscape unit type flag.
7348 * Evaluated against an adjacent tile. */
7350 auto_perf->cause = AAPC_UNIT_STACK_DEATH;
7351
7352 /* I have no objections to moving this out of game's actions to
7353 * cities.ruleset, units.ruleset or an other location in game.ruleset
7354 * you find more suitable. -- Sveinung */
7355 if (!load_action_auto_actions(file, auto_perf,
7356 "actions.unit_stack_death", filename)) {
7357 ok = FALSE;
7358 }
7359 }
7360
7361 if (ok) {
7364
7365 if (sec) {
7366 section_list_iterate(sec, psection) {
7367 struct action_enabler *enabler;
7368 const char *sec_name = section_name(psection);
7369 struct action *paction;
7370 struct requirement_vector *actor_reqs;
7371 struct requirement_vector *target_reqs;
7372 const char *action_text;
7373
7374 enabler = action_enabler_new();
7375
7376 action_text = secfile_lookup_str(file, "%s.action", sec_name);
7377
7378 if (action_text == NULL) {
7380 "\"%s\" [%s] missing action to enable.",
7381 filename, sec_name);
7382 ok = FALSE;
7383 break;
7384 }
7385
7386 paction = action_by_rule_name(action_text);
7387 if (!paction) {
7389 "\"%s\" [%s] lists unknown action type \"%s\".",
7390 filename, sec_name, action_text);
7391 ok = FALSE;
7392 break;
7393 }
7394
7395 enabler->action = paction->id;
7396
7397 actor_reqs = lookup_req_list(file, compat, sec_name, "actor_reqs", action_text);
7398 if (actor_reqs == NULL) {
7399 ok = FALSE;
7400 break;
7401 }
7402
7403 requirement_vector_copy(&enabler->actor_reqs, actor_reqs);
7404
7405 target_reqs = lookup_req_list(file, compat, sec_name, "target_reqs", action_text);
7406 if (target_reqs == NULL) {
7407 ok = FALSE;
7408 break;
7409 }
7410
7411 requirement_vector_copy(&enabler->target_reqs, target_reqs);
7412
7413 action_enabler_add(enabler);
7415
7416 section_list_destroy(sec);
7417 }
7418 }
7419 }
7420
7421 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7422 bool slow_invasions
7424 "global_unit_options.slow_invasions");
7425
7426 if (!rscompat_old_slow_invasions_3_1(compat, slow_invasions)) {
7427 ok = FALSE;
7428 }
7429 }
7430
7431 if (ok) {
7432 const char *tus_text;
7433 bool default_drbr = RS_DEFAULT_DAMAGE_REDUCES_BOMBARD_RATE;
7434
7435 /* section: combat_rules */
7438 "combat_rules.tired_attack");
7439
7442 "combat_rules.only_killing_makes_veteran");
7443
7446 "combat_rules.only_real_fight_makes_veteran");
7447
7450 "combat_rules.combat_odds_scaled_veterancy");
7451
7452 if (compat->compat_mode && compat->version < RSFORMAT_3_1) {
7453 /* Old hardcoded behavior was not to have bombard rate reduced for damage. */
7454 default_drbr = FALSE;
7455 }
7457 = secfile_lookup_bool_default(file, default_drbr,
7458 "combat_rules.damage_reduces_bombard_rate");
7459
7462 "combat_rules.low_firepower_badwallattacker");
7465 "combat_rules.low_firepower_pearl_harbour");
7468 "combat_rules.low_firepower_combat_bonus");
7471 "combat_rules.low_firepower_nonnat_bombard");
7472
7477 "combat_rules.nuke_pop_loss_pct");
7478
7483 "combat_rules.nuke_defender_survival_chance_pct");
7484
7485 /* section: borders */
7491 "borders.radius_sq_city");
7497 "borders.size_effect");
7498
7504 "borders.radius_sq_city_permanent");
7505
7506 /* section: research */
7508 "research.tech_cost_style");
7509 game.info.tech_cost_style = tech_cost_style_by_name(tus_text,
7511 if (!tech_cost_style_is_valid(game.info.tech_cost_style)) {
7513 "Unknown tech cost style \"%s\"",
7514 tus_text);
7515 ok = FALSE;
7516 }
7517
7519 "research.tech_leakage");
7520 game.info.tech_leakage = tech_leakage_style_by_name(tus_text,
7522 if (!tech_leakage_style_is_valid(game.info.tech_leakage)) {
7524 "Unknown tech leakage \"%s\"",
7525 tus_text);
7526 ok = FALSE;
7527 }
7528 if (game.info.tech_cost_style == TECH_COST_CIV1CIV2
7529 && game.info.tech_leakage != TECH_LEAKAGE_NONE) {
7530 log_error("Only tech_leakage \"%s\" supported with "
7531 "tech_cost_style \"%s\". ",
7532 tech_leakage_style_name(TECH_LEAKAGE_NONE),
7533 tech_cost_style_name(TECH_COST_CIV1CIV2));
7534 log_error("Switching to tech_leakage \"%s\".",
7535 tech_leakage_style_name(TECH_LEAKAGE_NONE));
7536 game.info.tech_leakage = TECH_LEAKAGE_NONE;
7537 }
7543 "research.base_tech_cost");
7544
7546 "research.tech_upkeep_style");
7547
7548 game.info.tech_upkeep_style = tech_upkeep_style_by_name(tus_text, fc_strcasecmp);
7549
7550 if (!tech_upkeep_style_is_valid(game.info.tech_upkeep_style)) {
7552 "Unknown tech upkeep style \"%s\"",
7553 tus_text);
7554 ok = FALSE;
7555 }
7556 }
7557
7558 if (ok) {
7564 "research.tech_upkeep_divider");
7565
7566 sval = secfile_lookup_str_default(file, NULL, "research.free_tech_method");
7567 if (sval == NULL) {
7569 "No free_tech_method given");
7570 ok = FALSE;
7571 } else {
7572 game.info.free_tech_method = free_tech_method_by_name(sval, fc_strcasecmp);
7573 if (!free_tech_method_is_valid(game.info.free_tech_method)) {
7575 "Bad value %s for free_tech_method.", sval);
7576 ok = FALSE;
7577 }
7578 }
7579 }
7580
7581 if (ok) {
7582 int cf;
7583
7584 /* section: culture */
7587 "culture.victory_min_points");
7590 "culture.victory_lead_pct");
7593 "culture.migration_pml");
7596 "culture.history_interest_pml");
7597
7598 /* section: calendar */
7601 "calendar.skip_year_0");
7604 "calendar.start_year");
7606 = secfile_lookup_int_default(file, 0, "calendar.fragments");
7607
7610 "Too many calendar fragments. Max is %d",
7612 ok = FALSE;
7614 }
7618 "calendar.positive_label"));
7622 "calendar.negative_label"));
7623
7624 for (cf = 0; cf < game.calendar.calendar_fragments; cf++) {
7625 const char *fname;
7626
7627 fname = secfile_lookup_str_default(file, NULL, "calendar.fragment_name%d", cf);
7628 if (fname != NULL) {
7629 strncpy(game.calendar.calendar_fragment_name[cf], fname,
7631 }
7632 }
7633 }
7634
7635 if (ok) {
7636 /* section playercolors */
7637 struct rgbcolor *prgbcolor = NULL;
7638 bool color_read = TRUE;
7639
7640 /* Check if the player list is defined and empty. */
7641 if (playercolor_count() != 0) {
7642 ok = FALSE;
7643 } else {
7644 i = 0;
7645
7646 while (color_read) {
7647 prgbcolor = NULL;
7648
7649 color_read = rgbcolor_load(file, &prgbcolor, "playercolors.colorlist%d", i);
7650 if (color_read) {
7651 playercolor_add(prgbcolor);
7652 }
7653
7654 i++;
7655 }
7656
7657 if (playercolor_count() == 0) {
7658 ruleset_error(NULL, LOG_ERROR, "No player colors defined!");
7659 ok = FALSE;
7660 }
7661
7662 if (ok) {
7663 fc_assert(game.plr_bg_color == NULL);
7664 if (!rgbcolor_load(file, &game.plr_bg_color, "playercolors.background")) {
7666 "No background player color defined! (%s)",
7667 secfile_error());
7668 ok = FALSE;
7669 }
7670 }
7671 }
7672 }
7673
7674 if (ok) {
7675 /* section: teams */
7676 svec = secfile_lookup_str_vec(file, &teams, "teams.names");
7677 if (team_slot_count() < teams) {
7678 teams = team_slot_count();
7679 }
7681 for (i = 0; i < teams; i++) {
7683 }
7684 free(svec);
7685
7687 nval = (NULL != sec ? section_list_size(sec) : 0);
7688 if (nval > MAX_DISASTER_TYPES) {
7689 int num = nval; /* No "size_t" to printf */
7690
7692 "\"%s\": Too many disaster types (%d, max %d)",
7693 filename, num, MAX_DISASTER_TYPES);
7694 section_list_destroy(sec);
7695 ok = FALSE;
7696 } else {
7698 }
7699 }
7700
7701 if (ok) {
7702 disaster_type_iterate(pdis) {
7703 int id = disaster_index(pdis);
7704 int j;
7705 size_t eff_count;
7706 struct requirement_vector *reqs;
7707 const char *sec_name = section_name(section_list_get(sec, id));
7708
7709 if (!ruleset_load_names(&pdis->name, NULL, file, sec_name)) {
7711 "\"%s\": Cannot load disaster names",
7712 filename);
7713 ok = FALSE;
7714 break;
7715 }
7716
7717 reqs = lookup_req_list(file, compat, sec_name, "reqs", disaster_rule_name(pdis));
7718 if (reqs == NULL) {
7719 ok = FALSE;
7720 break;
7721 }
7722 requirement_vector_copy(&pdis->reqs, reqs);
7723
7725 "%s.frequency", sec_name);
7726
7727 svec = secfile_lookup_str_vec(file, &eff_count, "%s.effects", sec_name);
7728
7729 BV_CLR_ALL(pdis->effects);
7730 for (j = 0; j < eff_count; j++) {
7731 const char *dsval = svec[j];
7732 enum disaster_effect_id effect;
7733
7734 effect = disaster_effect_id_by_name(dsval, fc_strcasecmp);
7735
7736 if (!disaster_effect_id_is_valid(effect)) {
7738 "\"%s\" disaster \"%s\": unknown effect \"%s\".",
7739 filename, disaster_rule_name(pdis), dsval);
7740 ok = FALSE;
7741 break;
7742 } else {
7743 BV_SET(pdis->effects, effect);
7744 }
7745 }
7746
7747 free(svec);
7748
7749 if (!ok) {
7750 break;
7751 }
7753 section_list_destroy(sec);
7754 }
7755
7756 if (ok) {
7758
7759 achievements_iterate(pach) {
7760 int id = achievement_index(pach);
7761 const char *sec_name = section_name(section_list_get(sec, id));
7762 const char *typename;
7763 const char *msg;
7764
7765 typename = secfile_lookup_str_default(file, NULL, "%s.type", sec_name);
7766
7767 pach->type = achievement_type_by_name(typename, fc_strcasecmp);
7768 if (!achievement_type_is_valid(pach->type)) {
7770 "Achievement has unknown type \"%s\".",
7771 typename != NULL ? typename : "(NULL)");
7772 ok = FALSE;
7773 }
7774
7775 if (ok) {
7777 "%s.unique", sec_name);
7778
7780 "%s.value", sec_name);
7781 pach->culture = secfile_lookup_int_default(file, 0,
7782 "%s.culture", sec_name);
7783
7784 msg = secfile_lookup_str_default(file, NULL, "%s.first_msg", sec_name);
7785 if (msg == NULL) {
7787 "Achievement %s has no first msg!", sec_name);
7788 ok = FALSE;
7789 } else {
7790 pach->first_msg = fc_strdup(msg);
7791 }
7792 }
7793
7794 if (ok) {
7795 msg = secfile_lookup_str_default(file, NULL, "%s.cons_msg", sec_name);
7796 if (msg == NULL) {
7797 if (!pach->unique) {
7799 "Achievement %s has no msg for consecutive gainers!",
7800 sec_name);
7801 ok = FALSE;
7802 }
7803 } else {
7804 pach->cons_msg = fc_strdup(msg);
7805 }
7806 }
7807
7808 if (!ok) {
7809 break;
7810 }
7812 section_list_destroy(sec);
7813 }
7814
7815 if (ok) {
7816 for (i = 0; (name = secfile_lookup_str_default(file, NULL,
7817 "trade.settings%d.type",
7818 i)); i++) {
7820
7821 if (type == TRT_LAST) {
7823 "\"%s\" unknown trade route type \"%s\".",
7824 filename, name);
7825 ok = FALSE;
7826 } else {
7828 const char *cancelling;
7829 const char *bonus;
7830
7831 set->trade_pct = secfile_lookup_int_default(file, 100,
7832 "trade.settings%d.pct", i);
7833 cancelling = secfile_lookup_str_default(file, "Active",
7834 "trade.settings%d.cancelling", i);
7836 if (set->cancelling == TRI_LAST) {
7838 "\"%s\" unknown trade route cancelling type \"%s\".",
7839 filename, cancelling);
7840 ok = FALSE;
7841 }
7842
7843 bonus = secfile_lookup_str_default(file, "None", "trade.settings%d.bonus", i);
7844
7845 set->bonus_type = trade_route_bonus_type_by_name(bonus, fc_strcasecmp);
7846
7847 if (!trade_route_bonus_type_is_valid(set->bonus_type)) {
7849 "\"%s\" unknown trade route bonus type \"%s\".",
7850 filename, bonus);
7851 ok = FALSE;
7852 }
7853 }
7854 }
7855 }
7856
7857 if (ok) {
7858 const char *str;
7859
7861 = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val");
7862
7864 goods_selection_method_name(RS_DEFAULT_GOODS_SELECTION),
7865 "trade.goods_selection");
7866
7867 game.info.goods_selection = goods_selection_method_by_name(str, fc_strcasecmp);
7868
7869 if (!goods_selection_method_is_valid(game.info.goods_selection)) {
7871 "\"%s\" goods selection method \"%s\" unknown.",
7872 filename, str);
7873 ok = FALSE;
7874 }
7875 }
7876
7877 if (ok) {
7879
7880 goods_type_iterate(pgood) {
7881 int id = goods_index(pgood);
7882 const char *sec_name = section_name(section_list_get(sec, id));
7883 struct requirement_vector *reqs;
7884 const char **slist;
7885 int j;
7886
7887 reqs = lookup_req_list(file, compat, sec_name, "reqs", goods_rule_name(pgood));
7888 if (reqs == NULL) {
7889 ok = FALSE;
7890 break;
7891 }
7892 requirement_vector_copy(&pgood->reqs, reqs);
7893
7894 pgood->from_pct = secfile_lookup_int_default(file, 100,
7895 "%s.from_pct", sec_name);
7896 pgood->to_pct = secfile_lookup_int_default(file, 100,
7897 "%s.to_pct", sec_name);
7898 pgood->onetime_pct = secfile_lookup_int_default(file, 100,
7899 "%s.onetime_pct", sec_name);
7900
7901 slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
7902 BV_CLR_ALL(pgood->flags);
7903 for (j = 0; j < nval; j++) {
7904 enum goods_flag_id flag;
7905
7906 sval = slist[j];
7907 flag = goods_flag_id_by_name(sval, fc_strcasecmp);
7908 if (!goods_flag_id_is_valid(flag)) {
7909 ruleset_error(NULL, LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
7910 filename, goods_rule_name(pgood), sval);
7911 ok = FALSE;
7912 break;
7913 } else {
7914 BV_SET(pgood->flags, flag);
7915 }
7916 }
7917 free(slist);
7918
7919 pgood->helptext = lookup_strvec(file, sec_name, "helptext");
7921 section_list_destroy(sec);
7922 }
7923
7924 if (ok) {
7926
7927 if (sec != NULL) {
7928 int num = section_list_size(sec);
7929
7930 for (i = 0; i < num; i++) {
7931 const char *sec_name = section_name(section_list_get(sec, i));
7932 const char *clause_name = secfile_lookup_str_default(file, NULL,
7933 "%s.type", sec_name);
7934 enum clause_type type = clause_type_by_name(clause_name, fc_strcasecmp);
7935 struct clause_info *info;
7936 struct requirement_vector *reqs;
7937
7938 if (!clause_type_is_valid(type)) {
7940 "\"%s\" unknown clause type \"%s\".",
7941 filename, clause_name);
7942 ok = FALSE;
7943 break;
7944 }
7945
7946 info = clause_info_get(type);
7947
7948 if (info->enabled) {
7950 "\"%s\" duplicate clause type \"%s\" definition.",
7951 filename, clause_name);
7952 ok = FALSE;
7953 break;
7954 }
7955
7956 reqs = lookup_req_list(file, compat, sec_name, "giver_reqs", clause_name);
7957 if (reqs == NULL) {
7958 ok = FALSE;
7959 break;
7960 }
7961 requirement_vector_copy(&info->giver_reqs, reqs);
7962
7963 reqs = lookup_req_list(file, compat, sec_name, "receiver_reqs", clause_name);
7964 if (reqs == NULL) {
7965 ok = FALSE;
7966 break;
7967 }
7968 requirement_vector_copy(&info->receiver_reqs, reqs);
7969
7970 info->enabled = TRUE;
7971 }
7972 }
7973 section_list_destroy(sec);
7974 }
7975
7976 /* secfile_check_unused() is not here, but only after also settings section
7977 * has been loaded. */
7978
7979 return ok;
7980}
7981
7982/**********************************************************************/
7986static void send_ruleset_unit_classes(struct conn_list *dest)
7987{
7988 struct packet_ruleset_unit_class packet;
7989 struct packet_ruleset_unit_class_flag fpacket;
7990 int i;
7991
7992 for (i = 0; i < MAX_NUM_USER_UCLASS_FLAGS; i++) {
7993 const char *flagname;
7994 const char *helptxt;
7995
7996 fpacket.id = i + UCF_USER_FLAG_1;
7997
7998 flagname = unit_class_flag_id_name(i + UCF_USER_FLAG_1);
7999 if (flagname == NULL) {
8000 fpacket.name[0] = '\0';
8001 } else {
8002 sz_strlcpy(fpacket.name, flagname);
8003 }
8004
8005 helptxt = unit_class_flag_helptxt(i + UCF_USER_FLAG_1);
8006 if (helptxt == NULL) {
8007 fpacket.helptxt[0] = '\0';
8008 } else {
8009 sz_strlcpy(fpacket.helptxt, helptxt);
8010 }
8011
8013 }
8014
8016 packet.id = uclass_number(c);
8017 sz_strlcpy(packet.name, untranslated_name(&c->name));
8018 sz_strlcpy(packet.rule_name, rule_name_get(&c->name));
8019 packet.min_speed = c->min_speed;
8020 packet.hp_loss_pct = c->hp_loss_pct;
8021 packet.non_native_def_pct = c->non_native_def_pct;
8022 packet.flags = c->flags;
8023
8024 PACKET_STRVEC_COMPUTE(packet.helptext, c->helptext);
8025
8026 lsend_packet_ruleset_unit_class(dest, &packet);
8028}
8029
8030/**********************************************************************/
8034static void send_ruleset_units(struct conn_list *dest)
8035{
8036 struct packet_ruleset_unit packet;
8037#ifdef FREECIV_WEB
8038 struct packet_web_ruleset_unit_addition web_packet;
8039#endif /* FREECIV_WEB */
8040 struct packet_ruleset_unit_flag fpacket;
8041 int i;
8042
8043 for (i = 0; i < MAX_NUM_USER_UNIT_FLAGS; i++) {
8044 const char *flagname;
8045 const char *helptxt;
8046
8047 fpacket.id = i + UTYF_USER_FLAG_1;
8048
8049 flagname = unit_type_flag_id_name(i + UTYF_USER_FLAG_1);
8050 if (flagname == NULL) {
8051 fpacket.name[0] = '\0';
8052 } else {
8053 sz_strlcpy(fpacket.name, flagname);
8054 }
8055
8056 helptxt = unit_type_flag_helptxt(i + UTYF_USER_FLAG_1);
8057 if (helptxt == NULL) {
8058 fpacket.helptxt[0] = '\0';
8059 } else {
8060 sz_strlcpy(fpacket.helptxt, helptxt);
8061 }
8062
8063 lsend_packet_ruleset_unit_flag(dest, &fpacket);
8064 }
8065
8067 packet.id = utype_number(u);
8068 sz_strlcpy(packet.name, untranslated_name(&u->name));
8069 sz_strlcpy(packet.rule_name, rule_name_get(&u->name));
8070 sz_strlcpy(packet.sound_move, u->sound_move);
8071 sz_strlcpy(packet.sound_move_alt, u->sound_move_alt);
8072 sz_strlcpy(packet.sound_fight, u->sound_fight);
8073 sz_strlcpy(packet.sound_fight_alt, u->sound_fight_alt);
8074 sz_strlcpy(packet.graphic_str, u->graphic_str);
8075 sz_strlcpy(packet.graphic_alt, u->graphic_alt);
8077 packet.build_cost = u->build_cost;
8078 packet.pop_cost = u->pop_cost;
8079 packet.attack_strength = u->attack_strength;
8080 packet.defense_strength = u->defense_strength;
8081 packet.move_rate = u->move_rate;
8082 packet.tech_requirement = u->require_advance
8083 ? advance_number(u->require_advance)
8084 : advance_count();
8085
8086 i = 0;
8087 requirement_vector_iterate(&u->build_reqs, req) {
8088 packet.build_reqs[i++] = *req;
8090 packet.build_reqs_count = i;
8091
8092 packet.vision_radius_sq = u->vision_radius_sq;
8093 packet.transport_capacity = u->transport_capacity;
8094 packet.hp = u->hp;
8095 packet.firepower = u->firepower;
8096 packet.obsoleted_by = u->obsoleted_by
8097 ? utype_number(u->obsoleted_by)
8098 : utype_count();
8099 packet.converted_to = u->converted_to
8100 ? utype_number(u->converted_to)
8101 : utype_count();
8102 packet.convert_time = u->convert_time;
8103 packet.fuel = u->fuel;
8104 packet.flags = u->flags;
8105 packet.roles = u->roles;
8106 packet.happy_cost = u->happy_cost;
8108 packet.upkeep[o] = u->upkeep[o];
8110 packet.paratroopers_range = u->paratroopers_range;
8111 packet.bombard_rate = u->bombard_rate;
8112 packet.city_size = u->city_size;
8113 packet.city_slots = u->city_slots;
8114 packet.tp_defense = u->tp_defense;
8115 packet.cargo = u->cargo;
8116 packet.targets = u->targets;
8117 packet.embarks = u->embarks;
8118 packet.disembarks = u->disembarks;
8119 packet.vlayer = u->vlayer;
8120
8121 if (u->veteran == NULL) {
8122 /* Use the default veteran system. */
8123 packet.veteran_levels = 0;
8124 } else {
8125 /* Per unit veteran system definition. */
8127
8128 for (i = 0; i < packet.veteran_levels; i++) {
8129 const struct veteran_level *vlevel = utype_veteran_level(u, i);
8130
8131 sz_strlcpy(packet.veteran_name[i], untranslated_name(&vlevel->name));
8132 packet.power_fact[i] = vlevel->power_fact;
8133 packet.move_bonus[i] = vlevel->move_bonus;
8134 packet.base_raise_chance[i] = vlevel->base_raise_chance;
8135 packet.work_raise_chance[i] = vlevel->work_raise_chance;
8136 }
8137 }
8138 PACKET_STRVEC_COMPUTE(packet.helptext, u->helptext);
8139
8140 packet.worker = u->adv.worker;
8141
8142#ifdef FREECIV_WEB
8143 web_packet.id = utype_number(u);
8144
8145 BV_CLR_ALL(web_packet.utype_actions);
8146
8147 action_iterate(act) {
8148 if (utype_can_do_action(u, act)) {
8149 BV_SET(web_packet.utype_actions, act);
8150 }
8152#endif /* FREECIV_WEB */
8153
8154 lsend_packet_ruleset_unit(dest, &packet);
8155 web_lsend_packet(ruleset_unit_addition, dest, &web_packet);
8156
8157 combat_bonus_list_iterate(u->bonuses, pbonus) {
8158 struct packet_ruleset_unit_bonus bonuspacket;
8159
8160 bonuspacket.unit = packet.id;
8161 bonuspacket.flag = pbonus->flag;
8162 bonuspacket.type = pbonus->type;
8163 bonuspacket.value = pbonus->value;
8164 bonuspacket.quiet = pbonus->quiet;
8165
8166 lsend_packet_ruleset_unit_bonus(dest, &bonuspacket);
8169}
8170
8171/**********************************************************************/
8175static void send_ruleset_specialists(struct conn_list *dest)
8176{
8177 struct packet_ruleset_specialist packet;
8178
8179 specialist_type_iterate(spec_id) {
8180 struct specialist *s = specialist_by_number(spec_id);
8181 int j;
8182
8183 packet.id = spec_id;
8185 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
8189 j = 0;
8190 requirement_vector_iterate(&s->reqs, preq) {
8191 packet.reqs[j++] = *preq;
8193 packet.reqs_count = j;
8194
8196
8197 lsend_packet_ruleset_specialist(dest, &packet);
8199}
8200/**********************************************************************/
8203static void send_ruleset_tech_classes(struct conn_list *dest)
8204{
8205 struct packet_ruleset_tech_class packet;
8206
8207 tech_class_iterate(ptclass) {
8208 packet.id = ptclass->idx;
8209 sz_strlcpy(packet.name, untranslated_name(&ptclass->name));
8210 sz_strlcpy(packet.rule_name, rule_name_get(&ptclass->name));
8211 packet.cost_pct = ptclass->cost_pct;
8212
8213 lsend_packet_ruleset_tech_class(dest, &packet);
8215}
8216
8217/**********************************************************************/
8221static void send_ruleset_techs(struct conn_list *dest)
8222{
8223 struct packet_ruleset_tech packet;
8224 struct packet_ruleset_tech_flag fpacket;
8225 int i;
8226
8227 for (i = 0; i < MAX_NUM_USER_TECH_FLAGS; i++) {
8228 const char *flagname;
8229 const char *helptxt;
8230
8231 fpacket.id = i + TECH_USER_1;
8232
8233 flagname = tech_flag_id_name_cb(i + TECH_USER_1);
8234 if (flagname == NULL) {
8235 fpacket.name[0] = '\0';
8236 } else {
8237 sz_strlcpy(fpacket.name, flagname);
8238 }
8239
8240 helptxt = tech_flag_helptxt(i + TECH_USER_1);
8241 if (helptxt == NULL) {
8242 fpacket.helptxt[0] = '\0';
8243 } else {
8244 sz_strlcpy(fpacket.helptxt, helptxt);
8245 }
8246
8247 lsend_packet_ruleset_tech_flag(dest, &fpacket);
8248 }
8249
8251 packet.id = advance_number(a);
8252 packet.removed = !valid_advance(a);
8253 if (a->tclass == NULL) {
8254 packet.tclass = 0;
8255 } else {
8256 packet.tclass = a->tclass->idx;
8257 }
8258 sz_strlcpy(packet.name, untranslated_name(&a->name));
8259 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8260 sz_strlcpy(packet.graphic_str, a->graphic_str);
8261 sz_strlcpy(packet.graphic_alt, a->graphic_alt);
8262
8263 /* Current size of the packet's research_reqs requirement vector. */
8264 i = 0;
8265
8266 /* The requirements req1 and req2 are needed to research a tech. Send
8267 * them in the research_reqs requirement vector. Range is set to player
8268 * since pooled research is configurable. */
8269
8270 if ((a->require[AR_ONE] != A_NEVER)
8271 && advance_number(a->require[AR_ONE]) > A_NONE) {
8272 packet.research_reqs[i++]
8273 = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
8274 FALSE, TRUE, FALSE,
8275 advance_number(a->require[AR_ONE]));
8276 }
8277
8278 if ((a->require[AR_TWO] != A_NEVER)
8279 && advance_number(a->require[AR_TWO]) > A_NONE) {
8280 packet.research_reqs[i++]
8281 = req_from_values(VUT_ADVANCE, REQ_RANGE_PLAYER,
8282 FALSE, TRUE, FALSE,
8283 advance_number(a->require[AR_TWO]));;
8284 }
8285
8286 /* The requirements of the tech's research_reqs also goes in the
8287 * packet's research_reqs requirement vector. */
8288 requirement_vector_iterate(&a->research_reqs, req) {
8289 packet.research_reqs[i++] = *req;
8291
8292 /* The packet's research_reqs should contain req1, req2 and the
8293 * requirements of the tech's research_reqs. */
8294 packet.research_reqs_count = i;
8295
8296 packet.root_req = a->require[AR_ROOT]
8297 ? advance_number(a->require[AR_ROOT])
8298 : advance_count();
8299
8300 packet.flags = a->flags;
8301 packet.cost = a->cost;
8302 packet.num_reqs = a->num_reqs;
8303 PACKET_STRVEC_COMPUTE(packet.helptext, a->helptext);
8304
8305 lsend_packet_ruleset_tech(dest, &packet);
8307}
8308
8309/**********************************************************************/
8313static void send_ruleset_buildings(struct conn_list *dest)
8314{
8316 struct packet_ruleset_building packet;
8317 int j;
8318
8319 packet.id = improvement_number(b);
8320 packet.genus = b->genus;
8321 sz_strlcpy(packet.name, untranslated_name(&b->name));
8322 sz_strlcpy(packet.rule_name, rule_name_get(&b->name));
8323 sz_strlcpy(packet.graphic_str, b->graphic_str);
8324 sz_strlcpy(packet.graphic_alt, b->graphic_alt);
8325 j = 0;
8326 requirement_vector_iterate(&b->reqs, preq) {
8327 packet.reqs[j++] = *preq;
8329 packet.reqs_count = j;
8330 j = 0;
8331 requirement_vector_iterate(&b->obsolete_by, pobs) {
8332 packet.obs_reqs[j++] = *pobs;
8334 packet.obs_count = j;
8335 packet.build_cost = b->build_cost;
8336 packet.upkeep = b->upkeep;
8337 packet.sabotage = b->sabotage;
8338 packet.flags = b->flags;
8339 sz_strlcpy(packet.soundtag, b->soundtag);
8340 sz_strlcpy(packet.soundtag_alt, b->soundtag_alt);
8341 PACKET_STRVEC_COMPUTE(packet.helptext, b->helptext);
8342
8343 lsend_packet_ruleset_building(dest, &packet);
8345}
8346
8347/**********************************************************************/
8351static void send_ruleset_terrain(struct conn_list *dest)
8352{
8353 struct packet_ruleset_terrain packet;
8354 struct packet_ruleset_terrain_flag fpacket;
8355 int i;
8356
8358
8359 for (i = 0; i < MAX_NUM_USER_TER_FLAGS; i++) {
8360 const char *flagname;
8361 const char *helptxt;
8362
8363 fpacket.id = i + TER_USER_1;
8364
8365 flagname = terrain_flag_id_name_cb(i + TER_USER_1);
8366 if (flagname == NULL) {
8367 fpacket.name[0] = '\0';
8368 } else {
8369 sz_strlcpy(fpacket.name, flagname);
8370 }
8371
8372 helptxt = terrain_flag_helptxt(i + TER_USER_1);
8373 if (helptxt == NULL) {
8374 fpacket.helptxt[0] = '\0';
8375 } else {
8376 sz_strlcpy(fpacket.helptxt, helptxt);
8377 }
8378
8379 lsend_packet_ruleset_terrain_flag(dest, &fpacket);
8380 }
8381
8382 terrain_type_iterate(pterrain) {
8383 struct extra_type **r;
8384
8385 packet.id = terrain_number(pterrain);
8386 packet.tclass = pterrain->tclass;
8387 packet.native_to = pterrain->native_to;
8388
8389 sz_strlcpy(packet.name, untranslated_name(&pterrain->name));
8390 sz_strlcpy(packet.rule_name, rule_name_get(&pterrain->name));
8391 sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
8392 sz_strlcpy(packet.graphic_alt, pterrain->graphic_alt);
8393
8394 packet.movement_cost = pterrain->movement_cost;
8395 packet.defense_bonus = pterrain->defense_bonus;
8396
8398 packet.output[o] = pterrain->output[o];
8400
8401 packet.num_resources = 0;
8402 for (r = pterrain->resources; *r; r++) {
8403 packet.resources[packet.num_resources++] = extra_number(*r);
8404 }
8405
8407 packet.road_output_incr_pct[o] = pterrain->road_output_incr_pct[o];
8409
8410 packet.base_time = pterrain->base_time;
8411 packet.road_time = pterrain->road_time;
8412
8413 packet.cultivate_result = (pterrain->cultivate_result
8414 ? terrain_number(pterrain->cultivate_result)
8415 : terrain_count());
8416 packet.cultivate_time = pterrain->cultivate_time;
8417
8418 packet.plant_result = (pterrain->plant_result
8419 ? terrain_number(pterrain->plant_result)
8420 : terrain_count());
8421 packet.plant_time = pterrain->plant_time;
8422
8423 packet.irrigation_food_incr = pterrain->irrigation_food_incr;
8424 packet.irrigation_time = pterrain->irrigation_time;
8425
8426 packet.mining_shield_incr = pterrain->mining_shield_incr;
8427 packet.mining_time = pterrain->mining_time;
8428
8429 packet.animal = (pterrain->animal == NULL ? -1 : utype_number(pterrain->animal));
8430 packet.transform_result = (pterrain->transform_result
8431 ? terrain_number(pterrain->transform_result)
8432 : terrain_count());
8433 packet.placing_time = pterrain->placing_time;
8434 packet.pillage_time = pterrain->pillage_time;
8435 packet.transform_time = pterrain->transform_time;
8436 packet.clean_pollution_time = pterrain->clean_pollution_time;
8437 packet.clean_fallout_time = pterrain->clean_fallout_time;
8438
8439 packet.flags = pterrain->flags;
8440
8441 packet.color_red = pterrain->rgb->r;
8442 packet.color_green = pterrain->rgb->g;
8443 packet.color_blue = pterrain->rgb->b;
8444
8445 PACKET_STRVEC_COMPUTE(packet.helptext, pterrain->helptext);
8446
8447 lsend_packet_ruleset_terrain(dest, &packet);
8449}
8450
8451/**********************************************************************/
8454static void send_ruleset_resources(struct conn_list *dest)
8455{
8456 struct packet_ruleset_resource packet;
8457
8458 extra_type_by_cause_iterate(EC_RESOURCE, presource) {
8459 packet.id = extra_index(presource);
8460
8462 packet.output[o] = presource->data.resource->output[o];
8464
8465 lsend_packet_ruleset_resource(dest, &packet);
8467}
8468
8469/**********************************************************************/
8473static void send_ruleset_extras(struct conn_list *dest)
8474{
8475 struct packet_ruleset_extra packet;
8476 struct packet_ruleset_extra_flag fpacket;
8477 int i;
8478
8479 for (i = 0; i < MAX_NUM_USER_EXTRA_FLAGS; i++) {
8480 const char *flagname;
8481 const char *helptxt;
8482
8483 fpacket.id = i + EF_USER_FLAG_1;
8484
8485 flagname = extra_flag_id_name(i + EF_USER_FLAG_1);
8486 if (flagname == NULL) {
8487 fpacket.name[0] = '\0';
8488 } else {
8489 sz_strlcpy(fpacket.name, flagname);
8490 }
8491
8492 helptxt = extra_flag_helptxt(i + EF_USER_FLAG_1);
8493 if (helptxt == NULL) {
8494 fpacket.helptxt[0] = '\0';
8495 } else {
8496 sz_strlcpy(fpacket.helptxt, helptxt);
8497 }
8498
8499 lsend_packet_ruleset_extra_flag(dest, &fpacket);
8500 }
8501
8503 int j;
8504
8505 packet.id = extra_number(e);
8506 sz_strlcpy(packet.name, untranslated_name(&e->name));
8507 sz_strlcpy(packet.rule_name, rule_name_get(&e->name));
8508
8509 packet.category = e->category;
8510
8511 BV_CLR_ALL(packet.causes);
8512 for (j = 0; j < EC_COUNT; j++) {
8513 if (is_extra_caused_by(e, j)) {
8514 BV_SET(packet.causes, j);
8515 }
8516 }
8517
8518 BV_CLR_ALL(packet.rmcauses);
8519 for (j = 0; j < ERM_COUNT; j++) {
8520 if (is_extra_removed_by(e, j)) {
8521 BV_SET(packet.rmcauses, j);
8522 }
8523 }
8524
8525 sz_strlcpy(packet.activity_gfx, e->activity_gfx);
8526 sz_strlcpy(packet.act_gfx_alt, e->act_gfx_alt);
8527 sz_strlcpy(packet.act_gfx_alt2, e->act_gfx_alt2);
8528 sz_strlcpy(packet.rmact_gfx, e->rmact_gfx);
8529 sz_strlcpy(packet.rmact_gfx_alt, e->rmact_gfx_alt);
8530 sz_strlcpy(packet.graphic_str, e->graphic_str);
8531 sz_strlcpy(packet.graphic_alt, e->graphic_alt);
8532
8533 j = 0;
8534 requirement_vector_iterate(&e->reqs, preq) {
8535 packet.reqs[j++] = *preq;
8537 packet.reqs_count = j;
8538
8539 j = 0;
8540 requirement_vector_iterate(&e->rmreqs, preq) {
8541 packet.rmreqs[j++] = *preq;
8543 packet.rmreqs_count = j;
8544
8545 packet.appearance_chance = e->appearance_chance;
8546 j = 0;
8547 requirement_vector_iterate(&e->appearance_reqs, preq) {
8548 packet.appearance_reqs[j++] = *preq;
8550 packet.appearance_reqs_count = j;
8551
8552 packet.disappearance_chance = e->disappearance_chance;
8553 j = 0;
8554 requirement_vector_iterate(&e->disappearance_reqs, preq) {
8555 packet.disappearance_reqs[j++] = *preq;
8557 packet.disappearance_reqs_count = j;
8558
8559 packet.visibility_req = e->visibility_req;
8560 packet.buildable = e->buildable;
8561 packet.generated = e->generated;
8562 packet.build_time = e->build_time;
8563 packet.build_time_factor = e->build_time_factor;
8564 packet.removal_time = e->removal_time;
8565 packet.removal_time_factor = e->removal_time_factor;
8566 packet.infracost = e->infracost;
8567 packet.defense_bonus = e->defense_bonus;
8568 packet.eus = e->eus;
8569
8570 packet.native_to = e->native_to;
8571
8572 packet.flags = e->flags;
8573 packet.hidden_by = e->hidden_by;
8574 packet.bridged_over = e->bridged_over;
8575 packet.conflicts = e->conflicts;
8576
8577 PACKET_STRVEC_COMPUTE(packet.helptext, e->helptext);
8578
8579 lsend_packet_ruleset_extra(dest, &packet);
8581}
8582
8583/**********************************************************************/
8587static void send_ruleset_bases(struct conn_list *dest)
8588{
8589 extra_type_by_cause_iterate(EC_BASE, pextra) {
8590 struct base_type *b = extra_base_get(pextra);
8591 struct packet_ruleset_base packet;
8592
8593 packet.id = base_number(b);
8594
8595 packet.gui_type = b->gui_type;
8596 packet.border_sq = b->border_sq;
8597 packet.vision_main_sq = b->vision_main_sq;
8598 packet.vision_invis_sq = b->vision_invis_sq;
8599 packet.vision_subs_sq = b->vision_subs_sq;
8600
8601 lsend_packet_ruleset_base(dest, &packet);
8603}
8604
8605/**********************************************************************/
8609static void send_ruleset_roads(struct conn_list *dest)
8610{
8611 struct packet_ruleset_road packet;
8612
8613 extra_type_by_cause_iterate(EC_ROAD, pextra) {
8614 struct road_type *r = extra_road_get(pextra);
8615 int j;
8616
8617 packet.id = road_number(r);
8618
8619 packet.gui_type = r->gui_type;
8620
8621 j = 0;
8623 packet.first_reqs[j++] = *preq;
8625 packet.first_reqs_count = j;
8626
8627 packet.move_cost = r->move_cost;
8628 packet.move_mode = r->move_mode;
8629
8631 packet.tile_incr_const[o] = r->tile_incr_const[o];
8632 packet.tile_incr[o] = r->tile_incr[o];
8633 packet.tile_bonus[o] = r->tile_bonus[o];
8635
8636 packet.compat = r->compat;
8637
8638 packet.integrates = r->integrates;
8639 packet.flags = r->flags;
8640
8641 lsend_packet_ruleset_road(dest, &packet);
8643}
8644
8645/**********************************************************************/
8649static void send_ruleset_goods(struct conn_list *dest)
8650{
8651 struct packet_ruleset_goods packet;
8652
8654 int j;
8655
8656 packet.id = goods_number(g);
8657 sz_strlcpy(packet.name, untranslated_name(&g->name));
8658 sz_strlcpy(packet.rule_name, rule_name_get(&g->name));
8659
8660 j = 0;
8661 requirement_vector_iterate(&g->reqs, preq) {
8662 packet.reqs[j++] = *preq;
8664 packet.reqs_count = j;
8665
8666 packet.from_pct = g->from_pct;
8667 packet.to_pct = g->to_pct;
8668 packet.onetime_pct = g->onetime_pct;
8669 packet.flags = g->flags;
8670
8671 PACKET_STRVEC_COMPUTE(packet.helptext, g->helptext);
8672
8673 lsend_packet_ruleset_goods(dest, &packet);
8675}
8676
8677/**********************************************************************/
8681static void send_ruleset_disasters(struct conn_list *dest)
8682{
8683 struct packet_ruleset_disaster packet;
8684
8686 int j;
8687
8688 packet.id = disaster_number(d);
8689
8690 sz_strlcpy(packet.name, untranslated_name(&d->name));
8691 sz_strlcpy(packet.rule_name, rule_name_get(&d->name));
8692
8693 j = 0;
8694 requirement_vector_iterate(&d->reqs, preq) {
8695 packet.reqs[j++] = *preq;
8697 packet.reqs_count = j;
8698
8699 packet.frequency = d->frequency;
8700
8701 packet.effects = d->effects;
8702
8703 lsend_packet_ruleset_disaster(dest, &packet);
8705}
8706
8707/**********************************************************************/
8711static void send_ruleset_achievements(struct conn_list *dest)
8712{
8713 struct packet_ruleset_achievement packet;
8714
8716 packet.id = achievement_number(a);
8717
8718 sz_strlcpy(packet.name, untranslated_name(&a->name));
8719 sz_strlcpy(packet.rule_name, rule_name_get(&a->name));
8720
8721 packet.type = a->type;
8722 packet.unique = a->unique;
8723 packet.value = a->value;
8724
8725 lsend_packet_ruleset_achievement(dest, &packet);
8727}
8728
8729/**********************************************************************/
8732static void send_ruleset_actions(struct conn_list *dest)
8733{
8734 struct packet_ruleset_action packet;
8735
8736 action_iterate(act) {
8737 struct action *paction = action_by_number(act);
8738
8739 packet.id = act;
8741 packet.quiet = action_by_number(act)->quiet;
8742
8743 packet.result = paction->result;
8744 packet.sub_results = paction->sub_results;
8746
8747 packet.act_kind = action_by_number(act)->actor_kind;
8748 packet.tgt_kind = action_by_number(act)->target_kind;
8750
8753 packet.blocked_by = action_by_number(act)->blocked_by;
8754
8755 lsend_packet_ruleset_action(dest, &packet);
8757}
8758
8759/**********************************************************************/
8762static void send_ruleset_action_enablers(struct conn_list *dest)
8763{
8764 int counter;
8765 struct packet_ruleset_action_enabler packet;
8766
8767 action_enablers_iterate(enabler) {
8768 packet.enabled_action = enabler->action;
8769
8770 counter = 0;
8771 requirement_vector_iterate(&enabler->actor_reqs, req) {
8772 packet.actor_reqs[counter++] = *req;
8774 packet.actor_reqs_count = counter;
8775
8776 counter = 0;
8777 requirement_vector_iterate(&enabler->target_reqs, req) {
8778 packet.target_reqs[counter++] = *req;
8780 packet.target_reqs_count = counter;
8781
8784}
8785
8786/**********************************************************************/
8790static void send_ruleset_action_auto_performers(struct conn_list *dest)
8791{
8792 int counter;
8793 int id;
8794 struct packet_ruleset_action_auto packet;
8795
8796 id = 0;
8798 packet.id = id++;
8799
8800 packet.cause = aperf->cause;
8801
8802 counter = 0;
8803 requirement_vector_iterate(&aperf->reqs, req) {
8804 packet.reqs[counter++] = *req;
8806 packet.reqs_count = counter;
8807
8808 for (counter = 0;
8809 /* Can't list more actions than all actions. */
8810 counter < NUM_ACTIONS
8811 /* ACTION_NONE terminates the list. */
8812 && aperf->alternatives[counter] != ACTION_NONE;
8813 counter++) {
8814 packet.alternatives[counter] = aperf->alternatives[counter];
8815 }
8816 packet.alternatives_count = counter;
8817
8818 lsend_packet_ruleset_action_auto(dest, &packet);
8820}
8821
8822/**********************************************************************/
8826static void send_ruleset_trade_routes(struct conn_list *dest)
8827{
8828 struct packet_ruleset_trade packet;
8830
8831 for (type = TRT_NATIONAL; type < TRT_LAST; type++) {
8833
8834 packet.id = type;
8835 packet.trade_pct = set->trade_pct;
8836 packet.cancelling = set->cancelling;
8837 packet.bonus_type = set->bonus_type;
8838
8839 lsend_packet_ruleset_trade(dest, &packet);
8840 }
8841}
8842
8843/**********************************************************************/
8847static void send_ruleset_governments(struct conn_list *dest)
8848{
8849 struct packet_ruleset_government gov;
8851 int j;
8852
8854 /* send one packet_government */
8855 gov.id = government_number(g);
8856
8857 j = 0;
8858 requirement_vector_iterate(&g->reqs, preq) {
8859 gov.reqs[j++] = *preq;
8861 gov.reqs_count = j;
8862
8863 sz_strlcpy(gov.name, untranslated_name(&g->name));
8864 sz_strlcpy(gov.rule_name, rule_name_get(&g->name));
8865 sz_strlcpy(gov.graphic_str, g->graphic_str);
8866 sz_strlcpy(gov.graphic_alt, g->graphic_alt);
8867 PACKET_STRVEC_COMPUTE(gov.helptext, g->helptext);
8868
8870
8871 /* Send one packet_government_ruler_title per ruler title. */
8873 const struct nation_type *pnation = ruler_title_nation(pruler_title);
8874
8875 title.gov = government_number(g);
8876 title.nation = pnation ? nation_number(pnation) : nation_count();
8877 sz_strlcpy(title.male_title,
8879 sz_strlcpy(title.female_title,
8884}
8885
8886/**********************************************************************/
8890static void send_ruleset_nations(struct conn_list *dest)
8891{
8892 struct packet_ruleset_nation_sets sets_packet;
8893 struct packet_ruleset_nation_groups groups_packet;
8894 struct packet_ruleset_nation packet;
8895 int i;
8896
8897 sets_packet.nsets = nation_set_count();
8898 i = 0;
8899 nation_sets_iterate(pset) {
8900 sz_strlcpy(sets_packet.names[i], nation_set_untranslated_name(pset));
8901 sz_strlcpy(sets_packet.rule_names[i], nation_set_rule_name(pset));
8902 sz_strlcpy(sets_packet.descriptions[i], nation_set_description(pset));
8903 i++;
8905 lsend_packet_ruleset_nation_sets(dest, &sets_packet);
8906
8907 groups_packet.ngroups = nation_group_count();
8908 i = 0;
8909 nation_groups_iterate(pgroup) {
8910 sz_strlcpy(groups_packet.groups[i],
8912 groups_packet.hidden[i] = pgroup->hidden;
8913 i++;
8915 lsend_packet_ruleset_nation_groups(dest, &groups_packet);
8916
8918 packet.id = nation_number(n);
8919 if (n->translation_domain == NULL) {
8920 packet.translation_domain[0] = '\0';
8921 } else {
8922 sz_strlcpy(packet.translation_domain, n->translation_domain);
8923 }
8924 sz_strlcpy(packet.adjective, untranslated_name(&n->adjective));
8925 sz_strlcpy(packet.rule_name, rule_name_get(&n->adjective));
8926 sz_strlcpy(packet.noun_plural, untranslated_name(&n->noun_plural));
8927 sz_strlcpy(packet.graphic_str, n->flag_graphic_str);
8928 sz_strlcpy(packet.graphic_alt, n->flag_graphic_alt);
8929
8930 i = 0;
8932 sz_strlcpy(packet.leader_name[i], nation_leader_name(pleader));
8933 packet.leader_is_male[i] = nation_leader_is_male(pleader);
8934 i++;
8936 packet.leader_count = i;
8937
8938 packet.style = style_number(n->style);
8939 packet.is_playable = n->is_playable;
8940 packet.barbarian_type = n->barb_type;
8941
8942 sz_strlcpy(packet.legend, n->legend);
8943
8944 i = 0;
8945 nation_set_list_iterate(n->sets, pset) {
8946 packet.sets[i++] = nation_set_number(pset);
8948 packet.nsets = i;
8949
8950 i = 0;
8951 nation_group_list_iterate(n->groups, pgroup) {
8952 packet.groups[i++] = nation_group_number(pgroup);
8954 packet.ngroups = i;
8955
8956 packet.init_government_id = n->init_government
8957 ? government_number(n->init_government) : government_count();
8958 fc_assert(ARRAY_SIZE(packet.init_techs) == ARRAY_SIZE(n->init_techs));
8959 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
8960 if (n->init_techs[i] != A_LAST) {
8961 packet.init_techs[i] = n->init_techs[i];
8962 } else {
8963 break;
8964 }
8965 }
8966 packet.init_techs_count = i;
8967 fc_assert(ARRAY_SIZE(packet.init_units) == ARRAY_SIZE(n->init_units));
8968 for (i = 0; i < MAX_NUM_UNIT_LIST; i++) {
8969 const struct unit_type *t = n->init_units[i];
8970 if (t) {
8971 packet.init_units[i] = utype_number(t);
8972 } else {
8973 break;
8974 }
8975 }
8976 packet.init_units_count = i;
8978 == ARRAY_SIZE(n->init_buildings));
8979 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
8980 if (n->init_buildings[i] != B_LAST) {
8981 /* Impr_type_id to int */
8982 packet.init_buildings[i] = n->init_buildings[i];
8983 } else {
8984 break;
8985 }
8986 }
8987 packet.init_buildings_count = i;
8988
8989 lsend_packet_ruleset_nation(dest, &packet);
8991
8992 /* Send initial values of is_pickable */
8994}
8995
8996/**********************************************************************/
9000static void send_ruleset_styles(struct conn_list *dest)
9001{
9002 struct packet_ruleset_style packet;
9003
9004 styles_iterate(s) {
9005 packet.id = style_index(s);
9006 sz_strlcpy(packet.name, untranslated_name(&s->name));
9007 sz_strlcpy(packet.rule_name, rule_name_get(&s->name));
9008
9009 lsend_packet_ruleset_style(dest, &packet);
9011}
9012
9013/**********************************************************************/
9016static void send_ruleset_clauses(struct conn_list *dest)
9017{
9018 struct packet_ruleset_clause packet;
9019 int i;
9020
9021 for (i = 0; i < CLAUSE_COUNT; i++) {
9022 struct clause_info *info = clause_info_get(i);
9023 int j;
9024
9025 packet.type = i;
9026 packet.enabled = info->enabled;
9027
9028 j = 0;
9030 packet.giver_reqs[j++] = *preq;
9032 packet.giver_reqs_count = j;
9033
9034 j = 0;
9036 packet.receiver_reqs[j++] = *preq;
9038 packet.receiver_reqs_count = j;
9039
9040 lsend_packet_ruleset_clause(dest, &packet);
9041 }
9042}
9043
9044/**********************************************************************/
9048static void send_ruleset_multipliers(struct conn_list *dest)
9049{
9050 multipliers_iterate(pmul) {
9051 int j;
9052 struct packet_ruleset_multiplier packet;
9053
9054 packet.id = multiplier_number(pmul);
9055 packet.start = pmul->start;
9056 packet.stop = pmul->stop;
9057 packet.step = pmul->step;
9058 packet.def = pmul->def;
9059 packet.offset = pmul->offset;
9060 packet.factor = pmul->factor;
9061 packet.minimum_turns = pmul->minimum_turns;
9062
9063 sz_strlcpy(packet.name, untranslated_name(&pmul->name));
9064 sz_strlcpy(packet.rule_name, rule_name_get(&pmul->name));
9065
9066 j = 0;
9067 requirement_vector_iterate(&pmul->reqs, preq) {
9068 packet.reqs[j++] = *preq;
9070 packet.reqs_count = j;
9071
9072 PACKET_STRVEC_COMPUTE(packet.helptext, pmul->helptext);
9073
9074 lsend_packet_ruleset_multiplier(dest, &packet);
9076}
9077
9078/**********************************************************************/
9082static void send_ruleset_cities(struct conn_list *dest)
9083{
9084 struct packet_ruleset_city city_p;
9085 int k, j;
9086
9087 for (k = 0; k < game.control.styles_count; k++) {
9088 city_p.style_id = k;
9089
9090 j = 0;
9092 city_p.reqs[j++] = *preq;
9094 city_p.reqs_count = j;
9095
9101
9102 lsend_packet_ruleset_city(dest, &city_p);
9103 }
9104}
9105
9106/**********************************************************************/
9110static void send_ruleset_musics(struct conn_list *dest)
9111{
9112 struct packet_ruleset_music packet;
9113
9114 music_styles_iterate(pmus) {
9115 int j;
9116
9117 packet.id = pmus->id;
9118
9119 sz_strlcpy(packet.music_peaceful, pmus->music_peaceful);
9120 sz_strlcpy(packet.music_combat, pmus->music_combat);
9121
9122 j = 0;
9123 requirement_vector_iterate(&(pmus->reqs), preq) {
9124 packet.reqs[j++] = *preq;
9126 packet.reqs_count = j;
9127
9128 lsend_packet_ruleset_music(dest, &packet);
9130}
9131
9132/**********************************************************************/
9136static void send_ruleset_game(struct conn_list *dest)
9137{
9138 struct packet_ruleset_game misc_p;
9139 int i;
9140
9141 fc_assert_ret(game.veteran != NULL);
9142
9143 /* Per unit veteran system definition. */
9145
9146 for (i = 0; i < misc_p.veteran_levels; i++) {
9147 const struct veteran_level *vlevel = game.veteran->definitions + i;
9148
9149 sz_strlcpy(misc_p.veteran_name[i], untranslated_name(&vlevel->name));
9150 misc_p.power_fact[i] = vlevel->power_fact;
9151 misc_p.move_bonus[i] = vlevel->move_bonus;
9152 misc_p.base_raise_chance[i] = vlevel->base_raise_chance;
9153 misc_p.work_raise_chance[i] = vlevel->work_raise_chance;
9154 }
9155
9156 fc_assert(sizeof(misc_p.global_init_techs)
9157 == sizeof(game.rgame.global_init_techs));
9160 for (i = 0; i < MAX_NUM_TECH_LIST; i++) {
9161 if (game.rgame.global_init_techs[i] != A_LAST) {
9163 } else {
9164 break;
9165 }
9166 }
9167 misc_p.global_init_techs_count = i;
9168
9171 for (i = 0; i < MAX_NUM_BUILDING_LIST; i++) {
9173 /* Impr_type_id to int */
9174 misc_p.global_init_buildings[i] =
9176 } else {
9177 break;
9178 }
9179 }
9180 misc_p.global_init_buildings_count = i;
9181
9183
9185
9189
9190 lsend_packet_ruleset_game(dest, &misc_p);
9191}
9192
9193/**********************************************************************/
9197static void send_ruleset_team_names(struct conn_list *dest)
9198{
9199 struct packet_team_name_info team_name_info_p;
9200
9201 team_slots_iterate(tslot) {
9202 const char *name = team_slot_defined_name(tslot);
9203
9204 if (NULL == name) {
9205 /* End of defined names. */
9206 break;
9207 }
9208
9209 team_name_info_p.team_id = team_slot_index(tslot);
9210 sz_strlcpy(team_name_info_p.team_name, name);
9211
9212 lsend_packet_team_name_info(dest, &team_name_info_p);
9214}
9215
9216/**********************************************************************/
9219static void notify_ruleset_fallback(const char *msg)
9220{
9221 notify_conn(NULL, NULL, E_LOG_FATAL, ftc_warning, "%s", msg);
9222}
9223
9224/**********************************************************************/
9227bool load_rulesets(const char *restore, const char *alt, bool compat_mode,
9228 rs_conversion_logger logger,
9229 bool act, bool buffer_script, bool load_luadata)
9230{
9231 set_ruleset_compat_mode(compat_mode);
9232
9233 if (load_rulesetdir(game.server.rulesetdir, compat_mode, logger,
9234 act, buffer_script, load_luadata)) {
9236 return TRUE;
9237 }
9238
9239 if (alt != NULL) {
9240 if (load_rulesetdir(alt, compat_mode, logger, act, buffer_script,
9241 load_luadata)) {
9243
9245 return TRUE;
9246 }
9247 }
9248
9249 /* Fallback to previous one. */
9250 if (restore != NULL) {
9251 if (load_rulesetdir(restore, compat_mode, logger, act, buffer_script, TRUE)) {
9252 sz_strlcpy(game.server.rulesetdir, restore);
9253
9254 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous one."));
9255
9257
9259
9260 /* We're in sane state as restoring previous ruleset succeeded,
9261 * but return failure to indicate that this is not what caller
9262 * wanted. */
9263 return FALSE;
9264 }
9265 }
9266
9268
9270
9271 /* Fallback to default one, but not if that's what we tried already */
9273 && (restore == NULL || strcmp(GAME_DEFAULT_RULESETDIR, restore))) {
9274 if (load_rulesetdir(GAME_DEFAULT_RULESETDIR, FALSE, NULL, act, buffer_script, TRUE)) {
9275 /* We're in sane state as fallback ruleset loading succeeded,
9276 * but return failure to indicate that this is not what caller
9277 * wanted. */
9279
9280 notify_ruleset_fallback(_("Ruleset couldn't be loaded. Switching to default one."));
9281
9282 return FALSE;
9283 }
9284 }
9285
9286#ifdef FREECIV_WEB
9287 log_normal(_("Cannot load any ruleset. Freeciv-web ruleset is available from "
9288 "https://github.com/freeciv/freeciv-web"));
9289#endif /* FREECIV_WEB */
9290
9291 /* Cannot load even default ruleset, we're in completely unusable state */
9292 exit(EXIT_FAILURE);
9293
9295}
9296
9297/**********************************************************************/
9301{
9302 if (file != NULL) {
9303 secfile_destroy(file);
9304 }
9305}
9306
9307/**********************************************************************/
9312{
9314 requirement_vector_free(&reqs_list);
9315}
9316
9317/**********************************************************************/
9321static bool load_rulesetdir(const char *rsdir, bool compat_mode,
9322 rs_conversion_logger logger,
9323 bool act, bool buffer_script, bool load_luadata)
9324{
9325 struct section_file *techfile, *unitfile, *buildfile, *govfile, *terrfile;
9326 struct section_file *stylefile, *cityfile, *nationfile, *effectfile, *gamefile;
9327 bool ok = TRUE;
9328 struct rscompat_info compat_info;
9329
9330 log_normal(_("Loading rulesets."));
9331
9332 rscompat_init_info(&compat_info);
9333 compat_info.compat_mode = compat_mode;
9334 compat_info.log_cb = logger;
9335
9337 /* Reset the list of available player colors. */
9341
9342 if (script_buffer != NULL) {
9344 script_buffer = NULL;
9345 }
9346 if (parser_buffer != NULL) {
9348 parser_buffer = NULL;
9349 }
9350
9351 server.playable_nations = 0;
9352
9353 techfile = openload_ruleset_file("techs", rsdir);
9354 buildfile = openload_ruleset_file("buildings", rsdir);
9355 govfile = openload_ruleset_file("governments", rsdir);
9356 unitfile = openload_ruleset_file("units", rsdir);
9357 terrfile = openload_ruleset_file("terrain", rsdir);
9358 stylefile = openload_ruleset_file("styles", rsdir);
9359 cityfile = openload_ruleset_file("cities", rsdir);
9360 nationfile = openload_ruleset_file("nations", rsdir);
9361 effectfile = openload_ruleset_file("effects", rsdir);
9362 gamefile = openload_ruleset_file("game", rsdir);
9363 if (load_luadata) {
9365 } else {
9366 game.server.luadata = NULL;
9367 }
9368
9369 if (techfile == NULL
9370 || buildfile == NULL
9371 || govfile == NULL
9372 || unitfile == NULL
9373 || terrfile == NULL
9374 || stylefile == NULL
9375 || cityfile == NULL
9376 || nationfile == NULL
9377 || effectfile == NULL
9378 || gamefile == NULL) {
9379 ok = FALSE;
9380 }
9381
9382 if (ok) {
9383 /* Note: Keep load_game_names first so that compat_info.version is
9384 * correctly initialized. */
9385 ok = load_game_names(gamefile, &compat_info)
9386 && load_tech_names(techfile, &compat_info)
9387 && load_building_names(buildfile, &compat_info)
9388 && load_government_names(govfile, &compat_info)
9389 && load_unit_names(unitfile, &compat_info)
9390 && load_terrain_names(terrfile, &compat_info)
9391 && load_style_names(stylefile, &compat_info)
9392 && load_nation_names(nationfile, &compat_info);
9393 }
9394
9395 if (ok) {
9396 ok = rscompat_names(&compat_info);
9397 }
9398
9399 if (ok) {
9400 ok = load_ruleset_techs(techfile, &compat_info);
9401 }
9402 if (ok) {
9403 ok = load_ruleset_styles(stylefile, &compat_info);
9404 }
9405 if (ok) {
9406 ok = load_ruleset_cities(cityfile, &compat_info);
9407 }
9408 if (ok) {
9409 ok = load_ruleset_governments(govfile, &compat_info);
9410 }
9411 if (ok) {
9412 /* terrain must precede nations and units */
9413 ok = load_ruleset_terrain(terrfile, &compat_info);
9414 }
9415 if (ok) {
9416 ok = load_ruleset_units(unitfile, &compat_info);
9417 }
9418 if (ok) {
9419 ok = load_ruleset_buildings(buildfile, &compat_info);
9420 }
9421 if (ok) {
9422 ok = load_ruleset_nations(nationfile, &compat_info);
9423 }
9424 if (ok) {
9425 ok = load_ruleset_effects(effectfile, &compat_info);
9426 }
9427 if (ok) {
9428 ok = load_ruleset_game(gamefile, act, &compat_info);
9429 }
9430
9431 if (ok) {
9432 rscompat_adjust_pre_sanity(&compat_info);
9433
9434 /* Init nations we just loaded. */
9436
9437 /* Needed by role_unit_precalcs(). */
9439
9440 /* Prepare caches we want to sanity check. */
9444
9446 && sanity_check_ruleset_data(&compat_info);
9447 }
9448
9449 if (ok) {
9450 /* Only load settings for a sane ruleset */
9451 ok = settings_ruleset(gamefile, "settings", act);
9452
9453 if (ok) {
9454 secfile_check_unused(gamefile);
9455 }
9456 }
9457
9458 nullcheck_secfile_destroy(techfile);
9459 nullcheck_secfile_destroy(stylefile);
9460 nullcheck_secfile_destroy(cityfile);
9462 nullcheck_secfile_destroy(terrfile);
9463 nullcheck_secfile_destroy(unitfile);
9464 nullcheck_secfile_destroy(buildfile);
9465 nullcheck_secfile_destroy(nationfile);
9466 nullcheck_secfile_destroy(effectfile);
9467 nullcheck_secfile_destroy(gamefile);
9468
9469 if (extra_sections) {
9470 free(extra_sections);
9471 extra_sections = NULL;
9472 }
9473 if (base_sections) {
9474 free(base_sections);
9475 base_sections = NULL;
9476 }
9477 if (road_sections) {
9478 free(road_sections);
9479 road_sections = NULL;
9480 }
9481 if (resource_sections) {
9482 free(resource_sections);
9483 resource_sections = NULL;
9484 }
9485 if (terrain_sections) {
9486 free(terrain_sections);
9487 terrain_sections = NULL;
9488 }
9489
9490 if (ok) {
9491 rscompat_postprocess(&compat_info);
9492 }
9493
9494 if (ok) {
9495 char **buffer = buffer_script ? &script_buffer : NULL;
9496
9498
9500
9501 ok = (openload_script_file("script", rsdir, buffer, FALSE) == TRI_YES);
9502 }
9503
9504 if (ok) {
9505 enum fc_tristate pret;
9506 char **buffer = buffer_script ? &parser_buffer : NULL;
9507
9508 pret = openload_script_file("parser", rsdir, buffer, compat_info.compat_mode);
9509
9510 if (pret == TRI_MAYBE && buffer_script) {
9512 "-- This file is for lua-functionality for parsing luadata.txt\n-- of this ruleset.");
9513 }
9514
9515 ok = (pret != TRI_NO);
9516 }
9517
9518 if (ok && !buffer_script) {
9519 ok = (openload_script_file("default", rsdir, NULL, FALSE) == TRI_YES);
9520 }
9521
9522 if (ok && act) {
9523 /* Populate remaining caches. */
9526 unit_class_iterate(pclass) {
9527 set_unit_class_caches(pclass);
9529 unit_type_iterate(ptype) {
9530 ptype->unknown_move_cost = utype_unknown_move_cost(ptype);
9531 set_unit_type_caches(ptype);
9534
9535 /* Build advisors unit class cache corresponding to loaded rulesets */
9537 CALL_FUNC_EACH_AI(units_ruleset_init);
9538
9539 /* We may need to adjust the number of AI players
9540 * if the number of available nations changed. */
9541 (void) aifill(game.info.aifill);
9542 }
9543
9544 return ok;
9545}
9546
9547/**********************************************************************/
9551{
9552 struct section_file *file;
9553 bool ok = TRUE;
9554
9556 if (file == NULL) {
9558 "Could not load game.ruleset:\n%s",
9559 secfile_error());
9560 ok = FALSE;
9561 }
9562 if (ok) {
9563 settings_ruleset(file, "settings", TRUE);
9564 secfile_destroy(file);
9565 }
9566
9567 return ok;
9568}
9569
9570/**********************************************************************/
9573void send_rulesets(struct conn_list *dest)
9574{
9576
9577 /* ruleset_control also indicates to client that ruleset sending starts. */
9579
9580 /* Currently containing control-kind of data of nation sets and groups,
9581 * this too must be sent before any requirement vector may depend on
9582 * that data. */
9584
9585 send_ruleset_game(dest);
9594 send_ruleset_techs(dest);
9597 send_ruleset_units(dest);
9599 send_ruleset_extras(dest);
9600 send_ruleset_bases(dest);
9601 send_ruleset_roads(dest);
9604 send_ruleset_goods(dest);
9606 send_ruleset_styles(dest);
9608 send_ruleset_cities(dest);
9610 send_ruleset_musics(dest);
9611 send_ruleset_cache(dest);
9612
9613 /* Indicate client that all rulesets have now been sent. */
9615
9616 /* changed game settings will be send in
9617 * connecthand.c:establish_new_connection() */
9618
9620}
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:488
#define action_auto_perf_iterate_end
Definition actions.h:593
#define action_enablers_iterate_end
Definition actions.h:526
#define ACTION_AUTO_MOVED_ADJ
Definition actions.h:617
#define action_id_get_sub_target_kind(act_id)
Definition actions.h:659
#define ACTION_AUTO_UPKEEP_GOLD
Definition actions.h:615
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
#define NUM_ACTIONS
Definition actions.h:297
#define ACTION_AUTO_ESCAPE_STACK
Definition actions.h:621
#define action_has_result(_act_, _res_)
Definition actions.h:448
#define ACTION_AUTO_ESCAPE_CITY
Definition actions.h:620
#define action_enabler_list_iterate_end
Definition actions.h:457
#define ACTION_DISTANCE_UNLIMITED
Definition actions.h:352
#define action_by_result_iterate_end
Definition actions.h:492
#define ACTION_AUTO_UPKEEP_SHIELD
Definition actions.h:616
#define ACTION_AUTO_POST_BRIBE
Definition actions.h:618
#define action_iterate_end
Definition actions.h:472
#define action_enablers_iterate(_enabler_)
Definition actions.h:520
#define action_enabler_list_iterate(action_enabler_list, aenabler)
Definition actions.h:455
#define action_iterate(_act_)
Definition actions.h:467
#define action_auto_perf_iterate(_act_perf_)
Definition actions.h:581
#define ACTION_AUTO_UPKEEP_FOOD
Definition actions.h:614
#define ACTION_AUTO_POST_ATTACK
Definition actions.h:619
#define ACTION_NONE
Definition actions.h:293
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:885
#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:2471
void playercolor_free(void)
Definition plrhand.c:3171
void playercolor_init(void)
Definition plrhand.c:3162
int playercolor_count(void)
Definition plrhand.c:3210
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3190
void count_playable_nations(void)
Definition plrhand.c:2428
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:9321
#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:8221
#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:8034
static void send_ruleset_governments(struct conn_list *dest)
Definition ruleset.c:8847
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:9311
static bool load_action_ui_name(struct section_file *file, int act, const char *entry_name, const char *compat_name)
Definition ruleset.c:6278
static void send_ruleset_resources(struct conn_list *dest)
Definition ruleset.c:8454
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:9300
static void send_ruleset_clauses(struct conn_list *dest)
Definition ruleset.c:9016
static void send_ruleset_game(struct conn_list *dest)
Definition ruleset.c:9136
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:6142
static void send_ruleset_nations(struct conn_list *dest)
Definition ruleset.c:8890
static void send_ruleset_roads(struct conn_list *dest)
Definition ruleset.c:8609
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:8203
static void send_ruleset_action_enablers(struct conn_list *dest)
Definition ruleset.c:8762
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:9227
#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:9110
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:6240
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:8649
static const char name_too_long[]
Definition ruleset.c:115
bool reload_rulesets_settings(void)
Definition ruleset.c:9550
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:6351
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:8175
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:8790
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:9197
static void send_ruleset_cities(struct conn_list *dest)
Definition ruleset.c:9082
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:6300
void send_rulesets(struct conn_list *dest)
Definition ruleset.c:9573
#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:6416
static void send_ruleset_styles(struct conn_list *dest)
Definition ruleset.c:9000
#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:8681
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:6531
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:8711
#define SCRIPT_SUFFIX
Definition ruleset.c:83
static void send_ruleset_bases(struct conn_list *dest)
Definition ruleset.c:8587
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:6399
static bool load_action_post_success_force(struct section_file *file, const char *filename, int performer_slot, struct action *paction)
Definition ruleset.c:6460
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:6377
static void send_ruleset_multipliers(struct conn_list *dest)
Definition ruleset.c:9048
char * get_script_buffer(void)
Definition ruleset.c:545
static void send_ruleset_actions(struct conn_list *dest)
Definition ruleset.c:8732
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:7986
#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:8473
#define rs_sanity_veteran(_path, _entry, _i, _condition, _action)
static void send_ruleset_terrain(struct conn_list *dest)
Definition ruleset.c:8351
#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:8826
static void notify_ruleset_fallback(const char *msg)
Definition ruleset.c:9219
static bool lookup_bv_actions(struct section_file *file, const char *filename, bv_actions *target, const char *path)
Definition ruleset.c:6497
static void send_ruleset_buildings(struct conn_list *dest)
Definition ruleset.c:8313
#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:574
enum action_auto_perf_cause cause
Definition actions.h:570
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:578
action_id action
Definition actions.h:439
struct requirement_vector actor_reqs
Definition actions.h:440
struct requirement_vector target_reqs
Definition actions.h:441
action_id id
Definition actions.h:380
bool actor_consuming_always
Definition actions.h:412
int max_distance
Definition actions.h:395
bool quiet
Definition actions.h:402
enum action_result result
Definition actions.h:382
char ui_name[MAX_LEN_NAME]
Definition actions.h:398
bv_action_sub_results sub_results
Definition actions.h:383
enum action_actor_kind actor_kind
Definition actions.h:385
bv_actions blocked_by
Definition actions.h:406
enum action_target_kind target_kind
Definition actions.h:386
int min_distance
Definition actions.h:395
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:164
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