Freeciv-3.1
Loading...
Searching...
No Matches
rssanity.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/* utility */
19#include "deprecations.h"
20
21/* common */
22#include "achievements.h"
23#include "actions.h"
24#include "effects.h"
25#include "game.h"
26#include "government.h"
27#include "map.h"
28#include "movement.h"
29#include "player.h"
30#include "road.h"
31#include "specialist.h"
32#include "tech.h"
33
34/* server */
35#include "ruleset.h"
36#include "settings.h"
37
38#include "rssanity.h"
39
40/**********************************************************************/
44{
45 if (game.ruleset_summary != NULL
47 ruleset_error(logger,
48 LOG_ERROR, "Too long ruleset summary. It can be only %d bytes long. "
49 "Put longer explanations to ruleset description.",
51 return FALSE;
52 }
53
54 return TRUE;
55}
56
57/**********************************************************************/
60static bool nation_has_initial_tech(struct nation_type *pnation,
61 struct advance *tech)
62{
63 int i;
64
65 /* See if it's given as global init tech */
66 for (i = 0; i < MAX_NUM_TECH_LIST
67 && game.rgame.global_init_techs[i] != A_LAST; i++) {
69 return TRUE;
70 }
71 }
72
73 /* See if it's given as national init tech */
74 for (i = 0;
75 i < MAX_NUM_TECH_LIST && pnation->init_techs[i] != A_LAST;
76 i++) {
77 if (pnation->init_techs[i] == advance_number(tech)) {
78 return TRUE;
79 }
80 }
81
82 return FALSE;
83}
84
85/**********************************************************************/
89static bool sanity_check_setting_is_seen(struct setting *pset)
90{
91 return setting_is_visible_at_level(pset, ALLOW_INFO);
92}
93
94/**********************************************************************/
99{
100 if ((setting_category(pset) == SSET_INTERNAL
101 || setting_category(pset) == SSET_NETWORK)
102 /* White list for SSET_INTERNAL and SSET_NETWORK settings. */
103 && !(pset == setting_by_name("phasemode")
104 || pset == setting_by_name("timeout")
105 || pset == setting_by_name("timeaddenemymove")
106 || pset == setting_by_name("unitwaittime")
107 || pset == setting_by_name("victories"))) {
108 /* The given server setting is a server operator related setting (like
109 * the compression type of savegames), not a game rule. */
110 return FALSE;
111 }
112
113 if (pset == setting_by_name("naturalcitynames")) {
114 /* This setting is about "look", not rules. */
115 return FALSE;
116 }
117
118 return TRUE;
119}
120
121/**********************************************************************/
126{
128 struct setting *pset;
129
130 /* TODO: use ssetv_setting_get() if setting value becomes multiplexed with
131 * the server setting id. */
132 id = (server_setting_id)ssetval;
134
135 if (server_setting_type_get(id) != SST_BOOL) {
136 /* Not supported yet. */
137 return FALSE;
138 }
139
140 pset = setting_by_number(id);
141
142 return (sanity_check_setting_is_seen(pset)
144}
145
146/**********************************************************************/
153 struct requirement *preq,
154 const char *list_for)
155{
156 switch (preq->source.kind) {
157 case VUT_IMPROVEMENT:
158 /* This check corresponds to what is_req_active() will support.
159 * It can't be done in req_from_str(), as we may not have
160 * loaded all building information at that time. */
161 {
162 const struct impr_type *pimprove = preq->source.value.building;
163
164 if (preq->range == REQ_RANGE_WORLD && !is_great_wonder(pimprove)) {
165 ruleset_error(logger, LOG_ERROR,
166 "%s: World-ranged requirement not supported for "
167 "%s (only great wonders supported)", list_for,
169 return FALSE;
170 } else if (preq->range > REQ_RANGE_TRADE_ROUTE && !is_wonder(pimprove)) {
171 ruleset_error(logger, LOG_ERROR,
172 "%s: %s-ranged requirement not supported for "
173 "%s (only wonders supported)", list_for,
174 req_range_name(preq->range),
176 return FALSE;
177 }
178 }
179 break;
180 case VUT_MINCALFRAG:
181 /* Currently [calendar] is loaded after some requirements are
182 * parsed, so we can't do this in universal_value_from_str(). */
184 ruleset_error(logger, LOG_ERROR,
185 "%s: MinCalFrag requirement used in ruleset without "
186 "calendar fragments", list_for);
187 return FALSE;
189 ruleset_error(logger, LOG_ERROR,
190 "%s: MinCalFrag requirement %d out of range (max %d in "
191 "this ruleset)", list_for, preq->source.value.mincalfrag,
193 return FALSE;
194 }
195 break;
196 case VUT_SERVERSETTING:
197 /* There is currently no way to check a server setting's category and
198 * access level that works in both the client and the server. */
199 {
201 struct setting *pset;
202
205 pset = setting_by_number(id);
206
207 if (!sanity_check_setting_is_seen(pset)) {
208 ruleset_error(logger, LOG_ERROR,
209 "%s: ServerSetting requirement %s isn't visible enough "
210 "to appear in a requirement. Everyone should be able to "
211 "see the value of a server setting that appears in a "
212 "requirement.", list_for, server_setting_name_get(id));
213 return FALSE;
214 }
215
217 /* This is a server operator related setting (like the compression
218 * type of savegames), not a game rule. */
219 ruleset_error(logger, LOG_ERROR,
220 "%s: ServerSetting requirement setting %s isn't about a "
221 "game rule.",
222 list_for, server_setting_name_get(id));
223 return FALSE;
224 }
225 }
226 break;
227 default:
228 /* No other universals have checks that can't be done at ruleset
229 * load time. See req_from_str(). */
230 break;
231 }
232 return TRUE;
233}
234
235/**********************************************************************/
239 int reqs_of_type[],
240 int local_reqs_of_type[],
241 struct requirement *preq, bool conjunctive,
242 int max_tiles, const char *list_for)
243{
244 int rc;
245
246 fc_assert_ret_val(universals_n_is_valid(preq->source.kind), FALSE);
247
248 if (!sanity_check_req_individual(logger, preq, list_for)) {
249 return FALSE;
250 }
251
252 if (!conjunctive) {
253 /* All the checks below are only meaningful for conjunctive lists. */
254 /* FIXME: we could add checks suitable for disjunctive lists. */
255 return TRUE;
256 }
257
258 /* Add to counter for positive requirements. */
259 if (preq->present) {
260 reqs_of_type[preq->source.kind]++;
261 }
262 rc = reqs_of_type[preq->source.kind];
263
264 if (preq->range == REQ_RANGE_LOCAL && preq->present) {
265 local_reqs_of_type[preq->source.kind]++;
266
267 switch (preq->source.kind) {
268 case VUT_TERRAINCLASS:
269 if (local_reqs_of_type[VUT_TERRAIN] > 0) {
270 ruleset_error(logger, LOG_ERROR,
271 "%s: Requirement list has both local terrain and terrainclass requirement",
272 list_for);
273 return FALSE;
274 }
275 break;
276 case VUT_TERRAIN:
277 if (local_reqs_of_type[VUT_TERRAINCLASS] > 0) {
278 ruleset_error(logger, LOG_ERROR,
279 "%s: Requirement list has both local terrain and terrainclass requirement",
280 list_for);
281 return FALSE;
282 }
283 break;
284 default:
285 break;
286 }
287 }
288
289 if (rc > 1 && preq->present) {
290 /* Multiple requirements of the same type */
291 switch (preq->source.kind) {
292 case VUT_GOVERNMENT:
293 case VUT_UTYPE:
294 case VUT_UCLASS:
295 case VUT_ACTION:
296 case VUT_ACTIVITY:
297 case VUT_OTYPE:
298 case VUT_SPECIALIST:
299 case VUT_MINSIZE: /* Breaks nothing, but has no sense either */
300 case VUT_MINFOREIGNPCT:
301 case VUT_MINMOVES: /* Breaks nothing, but has no sense either */
302 case VUT_MINVETERAN: /* Breaks nothing, but has no sense either */
303 case VUT_MINHP: /* Breaks nothing, but has no sense either */
304 case VUT_MINYEAR:
305 case VUT_MINCALFRAG:
306 case VUT_AI_LEVEL:
307 case VUT_TERRAINALTER: /* Local range only */
308 case VUT_STYLE:
309 case VUT_IMPR_GENUS:
310 case VUT_CITYSTATUS:
311 /* There can be only one requirement of these types (with current
312 * range limitations)
313 * Requirements might be identical, but we consider multiple
314 * declarations error anyway. */
315
316 ruleset_error(logger, LOG_ERROR,
317 "%s: Requirement list has multiple %s requirements",
318 list_for, universal_type_rule_name(&preq->source));
319 return FALSE;
320 break;
321
322 case VUT_TERRAIN:
323 /* There can be only up to max_tiles requirements of these types */
324 if (max_tiles != -1 && rc > max_tiles) {
325 ruleset_error(logger, LOG_ERROR,
326 "%s: Requirement list has more %s requirements than "
327 "can ever be fulfilled.", list_for,
329 return FALSE;
330 }
331 break;
332
333 case VUT_TERRAINCLASS:
334 if (rc > 2 || (max_tiles != -1 && rc > max_tiles)) {
335 ruleset_error(logger, LOG_ERROR,
336 "%s: Requirement list has more %s requirements than "
337 "can ever be fulfilled.", list_for,
339 return FALSE;
340 }
341 break;
342
343 case VUT_AGE:
344 /* There can be age of the city, unit, and player */
345 if (rc > 3) {
346 ruleset_error(logger, LOG_ERROR,
347 "%s: Requirement list has more %s requirements than "
348 "can ever be fulfilled.", list_for,
350 return FALSE;
351 }
352 break;
353
354 case VUT_MINTECHS:
355 /* At ranges 'Player' and 'World' */
356 if (rc > 2) {
357 ruleset_error(logger, LOG_ERROR,
358 "%s: Requirement list has more %s requirements than "
359 "can ever be fulfilled.", list_for,
361 return FALSE;
362 }
363 break;
364
365 case VUT_SERVERSETTING:
366 /* Can have multiple, since there are many settings. */
367 case VUT_TOPO:
368 /* Can have multiple, since it's flag based (iso & wrapx & wrapy & hex) */
369 case VUT_EXTRA:
370 /* Note that there can be more than 1 extra / tile. */
371 case VUT_MAXTILEUNITS:
372 /* Can require different numbers on e.g. local/adjacent tiles. */
373 case VUT_NATION:
374 /* Can require multiple nations at Team/Alliance/World range. */
375 case VUT_NATIONGROUP:
376 /* Nations can be in multiple groups. */
377 case VUT_NONE:
378 case VUT_ADVANCE:
379 case VUT_TECHFLAG:
380 case VUT_IMPROVEMENT:
381 case VUT_UNITSTATE:
382 case VUT_CITYTILE:
383 case VUT_GOOD:
384 /* Can check different properties. */
385 case VUT_UTFLAG:
386 case VUT_UCFLAG:
387 case VUT_TERRFLAG:
388 case VUT_ROADFLAG:
389 case VUT_EXTRAFLAG:
390 case VUT_NATIONALITY:
391 case VUT_MINCULTURE:
392 case VUT_ACHIEVEMENT:
393 case VUT_DIPLREL:
394 case VUT_DIPLREL_TILE:
395 case VUT_DIPLREL_TILE_O:
396 case VUT_DIPLREL_UNITANY:
397 case VUT_DIPLREL_UNITANY_O:
398 /* Can have multiple requirements of these types */
399 break;
400 case VUT_COUNT:
401 /* Should never be in requirement vector */
403 return FALSE;
404 break;
405 /* No default handling here, as we want compiler warning
406 * if new requirement type is added to enum and it's not handled
407 * here. */
408 }
409 }
410
411 return TRUE;
412}
413
414/**********************************************************************/
422static bool
424 const struct requirement_vector *preqs,
425 bool conjunctive, const char *list_for)
426{
427 bool has_singlepole_req = FALSE;
428
429 requirement_vector_iterate(preqs, preq) {
431 struct setting *pset;
432
433 if (preq->source.kind != VUT_SERVERSETTING) {
434 continue;
435 }
436
437 id = ssetv_setting_get(preq->source.value.ssetval);
439 pset = setting_by_number(id);
440
441 if (pset == setting_by_name("singlepole")) {
442 has_singlepole_req = TRUE;
443 } else if (pset == setting_by_name("alltemperate")
444 && XOR(conjunctive, preq->present)) {
445 return TRUE;
446 }
448
449 if (!has_singlepole_req) {
450 /* all good */
451 return TRUE;
452 }
453
454 if (conjunctive) {
455 ruleset_error(logger, LOG_ERROR,
456 "%s: Requirement list containing 'singlepole' server"
457 " setting requirement must also have negated (!present)"
458 " 'alltemperate' requirement", list_for);
459 } else {
460 ruleset_error(logger, LOG_ERROR,
461 "%s: Disjunctive requirement list containing 'singlepole'"
462 " server setting requirement must also have present"
463 " 'alltemperate' requirement", list_for);
464 }
465
466 return FALSE;
467}
468
469/**********************************************************************/
486 const struct requirement_vector *preqs,
487 bool conjunctive, int max_tiles,
488 const char *list_for)
489{
490 struct req_vec_problem *problem;
491 int reqs_of_type[VUT_COUNT];
492 int local_reqs_of_type[VUT_COUNT];
493
494 /* Initialize requirement counters */
495 memset(reqs_of_type, 0, sizeof(reqs_of_type));
496 memset(local_reqs_of_type, 0, sizeof(local_reqs_of_type));
497
498 requirement_vector_iterate(preqs, preq) {
499 if (!sanity_check_req_set(logger,
500 reqs_of_type, local_reqs_of_type, preq,
501 conjunctive, max_tiles, list_for)) {
502 return FALSE;
503 }
505
506 if (!sanity_check_req_vec_singlepole(logger, preqs, conjunctive, list_for)) {
507 return FALSE;
508 }
509
510 problem = req_vec_suggest_repair(preqs, req_vec_vector_number, preqs);
511 if (problem != NULL) {
512 ruleset_error(logger, LOG_ERROR, "%s: %s.", list_for, problem->description);
513 req_vec_problem_free(problem);
514 return FALSE;
515 }
516
517 return TRUE;
518}
519
520typedef struct {
521 struct {
523 } base_effects;
525} els_data;
526
527/**********************************************************************/
530static bool effect_list_sanity_cb(struct effect *peffect, void *data)
531{
532 int one_tile = -1; /* TODO: Determine correct value from effect.
533 * -1 disables checking */
534 els_data *els = (els_data *)data;
535 struct astring astr;
536
537 /* TODO: Refactor this to be more reusable when we check
538 * for more than one base effect. */
539 if (peffect->type == EFT_CITY_VISION_RADIUS_SQ) {
540 if (requirement_vector_size(&peffect->reqs) == 0) {
542 }
543 } else if (peffect->type == EFT_ACTION_SUCCESS_TARGET_MOVE_COST) {
544 /* Only unit targets can pay in move fragments. */
545 requirement_vector_iterate(&peffect->reqs, preq) {
546 if (preq->source.kind == VUT_ACTION) {
547 if (action_get_target_kind(preq->source.value.action) != ATK_UNIT) {
548 /* TODO: support for ATK_UNITS could be added. That would require
549 * manually calling action_success_target_pay_mp() in each
550 * supported unit stack targeted action performer (like
551 * action_consequence_success() does) or to have the unit stack
552 * targeted actions return a list of targets. */
554 "The effect Action_Success_Target_Move_Cost has the"
555 " requirement {%s} but the action %s isn't"
556 " (single) unit targeted.",
557 req_to_fstring(preq, &astr),
558 universal_rule_name(&preq->source));
559 astr_free(&astr);
560 return FALSE;
561 }
562 }
564 } else if (peffect->type == EFT_ACTION_SUCCESS_MOVE_COST) {
565 /* Only unit actors can pay in move fragments. */
566 requirement_vector_iterate(&peffect->reqs, preq) {
567 if (preq->source.kind == VUT_ACTION && preq->present) {
568 if (action_get_actor_kind(preq->source.value.action) != AAK_UNIT) {
570 "The effect Action_Success_Actor_Move_Cost has the"
571 " requirement {%s} but the action %s isn't"
572 " performed by a unit.",
573 req_to_fstring(preq, &astr),
574 universal_rule_name(&preq->source));
575 astr_free(&astr);
576 return FALSE;
577 }
578 }
580 } else if (peffect->type == EFT_ACTION_ODDS_PCT) {
581 /* Catch trying to set Action_Odds_Pct for non supported actions. */
582 requirement_vector_iterate(&peffect->reqs, preq) {
583 if (preq->source.kind == VUT_ACTION && preq->present) {
584 if (action_dice_roll_initial_odds(preq->source.value.action)
587 "The effect Action_Odds_Pct has the"
588 " requirement {%s} but the action %s doesn't"
589 " roll the dice to see if it fails.",
590 req_to_fstring(preq, &astr),
591 universal_rule_name(&preq->source));
592 astr_free(&astr);
593 return FALSE;
594 }
595 }
597 }
598
599 if (!sanity_check_req_vec(els->logger, &peffect->reqs, TRUE, one_tile,
600 effect_type_name(peffect->type))) {
602 "Effects have conflicting or invalid requirements!");
603
604 return FALSE;
605 }
606
607 return TRUE;
608}
609
610/**********************************************************************/
614{
615 if (num_role_units(L_BARBARIAN) > 0) {
616 if (num_role_units(L_BARBARIAN_LEADER) == 0) {
617 ruleset_error(logger, LOG_ERROR, "No role barbarian leader units");
618 return FALSE;
619 }
620 if (num_role_units(L_BARBARIAN_BUILD) == 0) {
621 ruleset_error(logger, LOG_ERROR, "No role barbarian build units");
622 return FALSE;
623 }
624 if (num_role_units(L_BARBARIAN_BOAT) == 0) {
625 ruleset_error(logger, LOG_ERROR, "No role barbarian ship units");
626 return FALSE;
627 } else if (num_role_units(L_BARBARIAN_BOAT) > 0) {
628 bool sea_capable = FALSE;
629 struct unit_type *u = get_role_unit(L_BARBARIAN_BOAT, 0);
630
632 if (is_ocean(pterr)
633 && BV_ISSET(pterr->native_to, uclass_index(utype_class(u)))) {
634 sea_capable = TRUE;
635 break;
636 }
638
639 if (!sea_capable) {
640 ruleset_error(logger, LOG_ERROR,
641 "Barbarian boat (%s) needs to be able to move at sea.",
642 utype_rule_name(u));
643 return FALSE;
644 }
645 }
646 if (num_role_units(L_BARBARIAN_SEA) == 0) {
647 ruleset_error(logger, LOG_ERROR, "No role sea raider barbarian units");
648 return FALSE;
649 }
650
652 if (utype_has_role(ptype, L_BARBARIAN_BOAT)) {
653 if (ptype->transport_capacity <= 1) {
654 ruleset_error(logger, LOG_ERROR,
655 "Barbarian boat %s has no capacity for both "
656 "leader and at least one man.",
657 utype_rule_name(ptype));
658 return FALSE;
659 }
660
662 if (utype_has_role(pbarb, L_BARBARIAN_SEA)
663 || utype_has_role(pbarb, L_BARBARIAN_SEA_TECH)
664 || utype_has_role(pbarb, L_BARBARIAN_LEADER)) {
665 if (!can_unit_type_transport(ptype, utype_class(pbarb))) {
666 ruleset_error(logger, LOG_ERROR,
667 "Barbarian boat %s cannot transport "
668 "barbarian cargo %s.",
669 utype_rule_name(ptype),
670 utype_rule_name(pbarb));
671 return FALSE;
672 }
673 }
675 }
677 }
678
679 return TRUE;
680}
681
682/**********************************************************************/
686{
687 /* Check some required flags and roles etc: */
688 if (num_role_units(UTYF_SETTLERS) == 0) {
689 ruleset_error(logger, LOG_ERROR, "No flag Settler units");
690 return FALSE;
691 }
692 if (num_role_units(L_START_EXPLORER) == 0) {
693 ruleset_error(logger, LOG_ERROR, "No role Start Explorer units");
694 return FALSE;
695 }
696 if (num_role_units(L_FERRYBOAT) == 0) {
697 ruleset_error(logger, LOG_ERROR, "No role Ferryboat units");
698 return FALSE;
699 }
700 if (num_role_units(L_FIRSTBUILD) == 0) {
701 ruleset_error(logger, LOG_ERROR, "No role Firstbuild units");
702 return FALSE;
703 }
704
705 if (num_role_units(L_FERRYBOAT) > 0) {
706 bool sea_capable = FALSE;
707 struct unit_type *u = get_role_unit(L_FERRYBOAT, 0);
708
710 if (is_ocean(pterr)
711 && BV_ISSET(pterr->native_to, uclass_index(utype_class(u)))) {
712 sea_capable = TRUE;
713 break;
714 }
716
717 if (!sea_capable) {
718 ruleset_error(logger, LOG_ERROR,
719 "Ferryboat (%s) needs to be able to move at sea.",
720 utype_rule_name(u));
721 return FALSE;
722 }
723 }
724
725 if (num_role_units(L_PARTISAN) == 0
726 && effect_cumulative_max(EFT_INSPIRE_PARTISANS, NULL, 0) > 0) {
727 ruleset_error(logger, LOG_ERROR,
728 "Inspire_Partisans effect present, but no units with partisan role.");
729 return FALSE;
730 }
731
732 unit_type_iterate(ptype) {
733 bool cargo = FALSE;
734
735 unit_class_iterate(pclass) {
736 if (BV_ISSET(ptype->cargo, uclass_index(pclass))) {
737 cargo = TRUE;
738 break;
739 }
741
742 if (ptype->transport_capacity > 0) {
743 if (!cargo) {
744 ruleset_error(logger, LOG_ERROR,
745 "%s has transport capacity %d, but no cargo types.",
746 utype_rule_name(ptype), ptype->transport_capacity);
747 return FALSE;
748 }
749 } else if (cargo) {
750 ruleset_error(logger, LOG_ERROR,
751 "%s has cargo types, but no transport capacity.",
752 utype_rule_name(ptype));
753 return FALSE;
754 }
756
757 return TRUE;
758}
759
760/**********************************************************************/
764{
765 /* Special Genus */
767 if (improvement_has_flag(pimprove, IF_GOLD)
768 && pimprove->genus != IG_SPECIAL) {
769 ruleset_error(logger, LOG_ERROR,
770 "Gold producing improvement %s with genus other than \"Special\"",
771 improvement_rule_name(pimprove));
772
773 return FALSE;
774 }
775 if (improvement_has_flag(pimprove, IF_DISASTER_PROOF)
776 && pimprove->genus != IG_IMPROVEMENT) {
777 ruleset_error(logger, LOG_ERROR,
778 "Disasterproof improvement %s with genus other than \"Improvement\"",
779 improvement_rule_name(pimprove));
780
781 return FALSE;
782 }
783 if (pimprove->genus != IG_SPECIAL
784 && (get_potential_improvement_bonus(pimprove, NULL, EFT_SS_STRUCTURAL,
786 || get_potential_improvement_bonus(pimprove, NULL, EFT_SS_COMPONENT,
788 || get_potential_improvement_bonus(pimprove, NULL, EFT_SS_MODULE,
789 RPT_POSSIBLE, FALSE))) {
790 ruleset_error(logger, LOG_ERROR,
791 "Space part %s with genus other than \"Special\"",
792 improvement_rule_name(pimprove));
793 return FALSE;
794 }
795
796 if (is_wonder(pimprove) && pimprove->upkeep != 0) {
797 ruleset_error(logger, LOG_ERROR,
798 "%s is a wonder with a nonzero upkeep value",
799 improvement_rule_name(pimprove));
800 return FALSE;
801 }
803
804 return TRUE;
805}
806
807/**********************************************************************/
811{
812 enum effect_type boolean_effects[] =
813 {
814 EFT_ANY_GOVERNMENT,
815 EFT_ENABLE_NUKE,
816 EFT_ENABLE_SPACE,
817 EFT_HAVE_EMBASSIES,
818 EFT_NO_ANARCHY,
819 EFT_NUKE_PROOF,
820 EFT_REVEAL_CITIES,
821 EFT_REVEAL_MAP,
822 EFT_SIZE_UNLIMIT,
823 EFT_SS_STRUCTURAL,
824 EFT_SS_COMPONENT,
825 EFT_NO_UNHAPPY,
826 EFT_RAPTURE_GROW,
827 EFT_HAS_SENATE,
828 EFT_INSPIRE_PARTISANS,
829 EFT_HAPPINESS_TO_GOLD,
830 EFT_FANATICS,
831 EFT_NO_DIPLOMACY,
832 EFT_GOV_CENTER,
833 EFT_NOT_TECH_SOURCE,
834 EFT_VICTORY,
835 EFT_HAVE_CONTACTS,
836 EFT_COUNT
837 };
838 int i;
839 bool ret = TRUE;
840
841 for (i = 0; boolean_effects[i] != EFT_COUNT; i++) {
842 if (effect_cumulative_min(boolean_effects[i], NULL) < 0
843 && effect_cumulative_max(boolean_effects[i], NULL, 0) == 0) {
844 ruleset_error(logger, LOG_ERROR,
845 "Boolean effect %s can get disabled, but it can't get "
846 "enabled before that.", effect_type_name(boolean_effects[i]));
847 ret = FALSE;
848 }
849 }
850
851 return ret;
852}
853
854/**********************************************************************/
862{
863 int num_utypes;
864 int i;
865 bool ok = TRUE; /* Store failures to variable instead of returning
866 * immediately so all errors get printed, not just first
867 * one. */
868 bool default_gov_failed = FALSE;
869 bool obsoleted_by_loop = FALSE;
870 els_data els;
871 rs_conversion_logger logger = ((compat != NULL) ? compat->log_cb : NULL);
872
873 if (!sanity_check_metadata(logger)) {
874 ok = FALSE;
875 }
876
877 if (game.info.tech_cost_style == TECH_COST_CIV1CIV2
878 && game.info.free_tech_method == FTM_CHEAPEST) {
879 ruleset_error(logger, LOG_ERROR,
880 "Cost based free tech method, but tech cost style "
881 "\"Civ I|II\" so all techs cost the same.");
882 ok = FALSE;
883 }
884
885 /* Advances. */
886 advance_re_active_iterate(padvance) {
887 for (i = AR_ONE; i < AR_SIZE; i++) {
888 const struct advance *preq;
889
890 if (i == AR_ROOT) {
891 /* Self rootreq is a feature. */
892 continue;
893 }
894
895 preq = advance_requires(padvance, i);
896
897 if (A_NEVER == preq) {
898 continue;
899 } else if (preq == padvance) {
900 ruleset_error(logger, LOG_ERROR, "Tech \"%s\" requires itself.",
901 advance_rule_name(padvance));
902 ok = FALSE;
903 continue;
904 }
905
906 advance_req_iterate(preq, preqreq) {
907 if (preqreq == padvance) {
908 ruleset_error(logger, LOG_ERROR,
909 "Tech \"%s\" requires itself indirectly via \"%s\".",
910 advance_rule_name(padvance),
911 advance_rule_name(preq));
912 ok = FALSE;
913 }
915 }
916
917 requirement_vector_iterate(&(padvance->research_reqs), preq) {
918 if (preq->source.kind == VUT_ADVANCE) {
919 /* Don't allow this even if allowing changing reqs. Players will
920 * expect all tech reqs to appear in the client tech tree. That
921 * should be taken care of first. */
922 ruleset_error(logger, LOG_ERROR,
923 "Tech \"%s\" requires a tech in its research_reqs."
924 " This isn't supported yet. Please keep using req1"
925 " and req2 like before.",
926 advance_rule_name(padvance));
927 ok = FALSE;
928 } else if (is_req_unchanging(NULL, preq) < REQUCH_HACK
929 /* If we get an obsolete improvement before the game,
930 * almost surely it is going to become not obsolete later.
931 * This check must catch it. */) {
932 struct astring astr;
933
934 /* Only support unchanging requirements until the reachability code
935 * can handle it and the tech tree can display changing
936 * requirements. */
937 ruleset_error(logger, LOG_ERROR,
938 "Tech \"%s\" has the requirement %s in its"
939 " research_reqs. This requirement may change during"
940 " the game. Changing requirements aren't supported"
941 " yet.",
942 advance_rule_name(padvance),
943 req_to_fstring(preq, &astr));
944 astr_free(&astr);
945 ok = FALSE;
946 }
948
949 if (padvance->bonus_message != NULL) {
950 if (!formats_match(padvance->bonus_message, "%s")) {
951 ruleset_error(logger, LOG_ERROR,
952 "Tech \"%s\" bonus message is not format with %%s for a bonus tech name.",
953 advance_rule_name(padvance));
954 ok = FALSE;
955 }
956 }
958
960 ruleset_error(logger, LOG_ERROR,
961 "The government form %s reserved for revolution handling has been set as "
962 "default_government.",
964 ok = FALSE;
965 default_gov_failed = TRUE;
966 }
967
968 /* Check that all players can have their initial techs */
970 int techi;
971
972 /* Check global initial techs */
973 for (techi = 0; techi < MAX_NUM_TECH_LIST
974 && game.rgame.global_init_techs[techi] != A_LAST; techi++) {
976 struct advance *a = valid_advance_by_number(tech);
977
978 if (a == NULL) {
979 ruleset_error(logger, LOG_ERROR,
980 "Tech %s does not exist, but is initial "
981 "tech for everyone.",
983 ok = FALSE;
984 } else if (advance_by_number(A_NONE) != a->require[AR_ROOT]
985 && !nation_has_initial_tech(pnation, a->require[AR_ROOT])) {
986 /* Nation has no root_req for tech */
987 ruleset_error(logger, LOG_ERROR,
988 "Tech %s is initial for everyone, but %s has "
989 "no root_req for it.",
991 nation_rule_name(pnation));
992 ok = FALSE;
993 }
994 }
995
996 /* Check national initial techs */
997 for (techi = 0;
998 techi < MAX_NUM_TECH_LIST && pnation->init_techs[techi] != A_LAST;
999 techi++) {
1000 Tech_type_id tech = pnation->init_techs[techi];
1001 struct advance *a = valid_advance_by_number(tech);
1002
1003 if (a == NULL) {
1004 ruleset_error(logger, LOG_ERROR,
1005 "Tech %s does not exist, but is initial tech for %s.",
1007 nation_rule_name(pnation));
1008 ok = FALSE;
1009 } else if (advance_by_number(A_NONE) != a->require[AR_ROOT]
1010 && !nation_has_initial_tech(pnation, a->require[AR_ROOT])) {
1011 /* Nation has no root_req for tech */
1012 ruleset_error(logger, LOG_ERROR,
1013 "Tech %s is initial for %s, but they have "
1014 "no root_req for it.",
1016 nation_rule_name(pnation));
1017 ok = FALSE;
1018 }
1019 }
1020
1021 /* Check national initial buildings */
1022 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN
1023 && pnation->init_buildings[0] != B_LAST) {
1024 ruleset_error(logger, LOG_ERROR,
1025 "Barbarian nation %s has init_buildings set but will "
1026 "never see them", nation_rule_name(pnation));
1027 }
1028
1029 if (!default_gov_failed && pnation->init_government == game.government_during_revolution) {
1030 ruleset_error(logger, LOG_ERROR,
1031 "The government form %s reserved for revolution handling has been set as "
1032 "initial government for %s.",
1034 nation_rule_name(pnation));
1035 ok = FALSE;
1036 }
1038
1039 /* Check against unit upgrade loops */
1040 num_utypes = game.control.num_unit_types;
1042 int chain_length = 0;
1043 const struct unit_type *upgraded = putype;
1044
1045 while (upgraded != NULL && !obsoleted_by_loop) {
1046 upgraded = upgraded->obsoleted_by;
1047 chain_length++;
1048 if (chain_length > num_utypes) {
1049 ruleset_error(logger, LOG_ERROR,
1050 "There seems to be obsoleted_by loop in update "
1051 "chain that starts from %s", utype_rule_name(putype));
1052 ok = FALSE;
1053 obsoleted_by_loop = TRUE;
1054 }
1055 }
1057
1058 /* Some unit type properties depend on other unit type properties to work
1059 * properly. */
1061 /* "Spy" is a better "Diplomat". Until all the places that assume that
1062 * "Diplomat" is set if "Spy" is set is changed this limitation must be
1063 * kept. */
1064 if (utype_has_flag(putype, UTYF_SPY)
1065 && !utype_has_flag(putype, UTYF_DIPLOMAT)) {
1066 ruleset_error(logger, LOG_ERROR,
1067 "The unit type '%s' has the 'Spy' unit type flag but "
1068 "not the 'Diplomat' unit type flag.",
1069 utype_rule_name(putype));
1070 ok = FALSE;
1071 }
1073
1074 /* Check that unit type fields are in range. */
1076 if (putype->paratroopers_range < 0
1077 || putype->paratroopers_range > UNIT_MAX_PARADROP_RANGE) {
1078 /* Paradrop range is limited by the network protocol. */
1079 ruleset_error(logger, LOG_ERROR,
1080 "The paratroopers_range of the unit type '%s' is %d. "
1081 "That is out of range. Max range is %d.",
1082 utype_rule_name(putype),
1083 putype->paratroopers_range, UNIT_MAX_PARADROP_RANGE);
1084 ok = FALSE;
1085 }
1086 /* never fires if game.scenario.prevent_new_cities is TRUE */
1087 if ((putype->city_size <= 0 || putype->city_size > MAX_CITY_SIZE)
1088 && utype_is_cityfounder(putype)) {
1089 ruleset_error(logger, LOG_ERROR,
1090 "Unit type '%s' would build size %d cities. "
1091 "City sizes must be from 1 to %d.",
1092 utype_rule_name(putype), putype->city_size,
1094 ok = FALSE;
1095 }
1097
1098 memset(&els, 0, sizeof(els));
1099 els.logger = logger;
1100
1101 /* Check requirement sets against conflicting requirements.
1102 * For effects check also other sanity in the same iteration */
1104 ok = FALSE;
1105 }
1106
1108 if (compat != NULL && compat->compat_mode && compat->version < RSFORMAT_3_1) {
1109 log_deprecation("There is no base City_Vision_Radius_Sq effect.");
1110 if (compat->log_cb != NULL) {
1111 compat->log_cb(_("Missing base City_Vision_Radius_Sq effect. Please add one."));
1112 }
1113 } else {
1114 ruleset_error(logger, LOG_ERROR,
1115 "There is no base City_Vision_Radius_Sq effect.");
1116 ok = FALSE;
1117 }
1118 }
1119
1120 if (!sanity_check_boolean_effects(logger)) {
1121 ok = FALSE;
1122 }
1123
1124 /* Others use requirement vectors */
1125
1126 /* Disasters */
1128 if (!sanity_check_req_vec(logger, &pdis->reqs, TRUE, -1,
1129 disaster_rule_name(pdis))) {
1130 ruleset_error(logger, LOG_ERROR,
1131 "Disasters have conflicting or invalid requirements!");
1132 ok = FALSE;
1133 }
1135
1136 /* Goods */
1138 if (!sanity_check_req_vec(logger, &pgood->reqs, TRUE, -1,
1139 goods_rule_name(pgood))) {
1140 ruleset_error(logger, LOG_ERROR,
1141 "Goods have conflicting or invalid requirements!");
1142 ok = FALSE;
1143 }
1145
1146 /* Buildings */
1148 if (!sanity_check_req_vec(logger, &pimprove->reqs, TRUE, -1,
1149 improvement_rule_name(pimprove))) {
1150 ruleset_error(logger, LOG_ERROR,
1151 _("Buildings have conflicting or invalid requirements!"));
1152 ok = FALSE;
1153 }
1154 if (!sanity_check_req_vec(logger, &pimprove->obsolete_by, FALSE, -1,
1155 improvement_rule_name(pimprove))) {
1156 ruleset_error(logger, LOG_ERROR,
1157 _("Buildings have conflicting or invalid obsolescence req!"));
1158 ok = FALSE;
1159 }
1161
1162 /* Governments */
1164 if (!sanity_check_req_vec(logger, &pgov->reqs, TRUE, -1,
1165 government_rule_name(pgov))) {
1166 ruleset_error(logger, LOG_ERROR,
1167 "Governments have conflicting or invalid requirements!");
1168 ok = FALSE;
1169 }
1171
1172 /* Specialists */
1174 if (!sanity_check_req_vec(logger, &psp->reqs, TRUE, -1,
1175 specialist_rule_name(psp))) {
1176 ruleset_error(logger, LOG_ERROR,
1177 "Specialists have conflicting or invalid requirements!");
1178 ok = FALSE;
1179 }
1181
1182 /* Extras */
1184 if (!sanity_check_req_vec(logger, &pextra->reqs, TRUE, -1,
1185 extra_rule_name(pextra))) {
1186 ruleset_error(logger, LOG_ERROR,
1187 "Extras have conflicting or invalid requirements!");
1188 ok = FALSE;
1189 }
1190 if (!sanity_check_req_vec(logger, &pextra->rmreqs, TRUE, -1,
1191 extra_rule_name(pextra))) {
1192 ruleset_error(logger, LOG_ERROR,
1193 "Extras have conflicting or invalid removal requirements!");
1194 ok = FALSE;
1195 }
1196 if ((requirement_vector_size(&pextra->rmreqs) > 0)
1197 && !(pextra->rmcauses
1198 & (ERM_ENTER | ERM_CLEANPOLLUTION
1199 | ERM_CLEANFALLOUT | ERM_PILLAGE))) {
1200 ruleset_error(logger, LOG_WARN,
1201 "Requirements for extra removal defined but not "
1202 "a valid remove cause!");
1203 }
1205
1206 /* Roads */
1207 extra_type_by_cause_iterate(EC_ROAD, pextra) {
1208 struct road_type *proad = extra_road_get(pextra);
1209
1210 extra_type_list_iterate(proad->integrators, iextra) {
1211 struct road_type *iroad = extra_road_get(iextra);
1212 int pnbr = road_number(proad);
1213
1214 if (pnbr != road_number(iroad)
1215 && !BV_ISSET(iroad->integrates, pnbr)) {
1216 /* We don't support non-symmetric integrator relationships yet. */
1217 ruleset_error(logger, LOG_ERROR,
1218 "Road '%s' integrates with '%s' but not vice versa!",
1219 extra_rule_name(pextra),
1220 extra_rule_name(iextra));
1221 ok = FALSE;
1222 }
1225
1226 /* City styles */
1227 for (i = 0; i < game.control.styles_count; i++) {
1228 if (!sanity_check_req_vec(logger,
1229 &city_styles[i].reqs, TRUE, -1,
1231 ruleset_error(logger, LOG_ERROR,
1232 "City styles have conflicting or invalid requirements!");
1233 ok = FALSE;
1234 }
1235 }
1236
1237 /* Actions */
1238 action_iterate(act) {
1239 struct action *paction = action_by_number(act);
1240
1242 paction->target_kind)) {
1243 ruleset_error(logger, LOG_ERROR, "Action \"%s\": unsupported target kind %s.",
1245 action_target_kind_name(paction->target_kind));
1246 ok = FALSE;
1247 }
1248
1249 if (paction->min_distance < 0) {
1250 ruleset_error(logger, LOG_ERROR, "Action %s: negative min distance (%d).",
1251 action_id_rule_name(act), paction->min_distance);
1252 ok = FALSE;
1253 }
1254
1256 ruleset_error(logger, LOG_ERROR,
1257 "Action %s: min distance (%d) larger than "
1258 "any distance on a map can be (%d).",
1259 action_id_rule_name(act), paction->min_distance,
1261 ok = FALSE;
1262 }
1263
1264 if (paction->max_distance > ACTION_DISTANCE_MAX) {
1265 ruleset_error(logger, LOG_ERROR,
1266 "Action %s: max distance is %d. "
1267 "A map can't be that big.",
1268 action_id_rule_name(act), paction->max_distance);
1269 ok = FALSE;
1270 }
1271
1272 if (!action_distance_inside_max(paction, paction->min_distance)) {
1273 ruleset_error(logger, LOG_ERROR,
1274 "Action %s: min distance is %d but max distance is %d.",
1276 paction->min_distance, paction->max_distance);
1277 ok = FALSE;
1278 }
1279
1280 action_iterate(blocker) {
1281 if (BV_ISSET(paction->blocked_by, blocker)
1282 && action_id_get_target_kind(blocker) == ATK_UNIT
1283 && action_id_get_target_kind(act) != ATK_UNIT) {
1284 /* Can't find an individual unit target to evaluate the blocking
1285 * action against. (A tile may have more than one individual
1286 * unit) */
1287 ruleset_error(logger, LOG_ERROR,
1288 "The action %s can't block %s.",
1289 action_id_rule_name(blocker),
1290 action_id_rule_name(act));
1291 ok = FALSE;
1292 }
1294
1296 if (!sanity_check_req_vec(logger, &(enabler->actor_reqs), TRUE, -1,
1297 "Action Enabler Actor Reqs")
1298 || !sanity_check_req_vec(logger, &(enabler->target_reqs), TRUE, -1,
1299 "Action Enabler Target Reqs")) {
1300 ruleset_error(logger, LOG_ERROR,
1301 "Action enabler for %s has conflicting or invalid "
1302 "requirements!", action_id_rule_name(act));
1303 ok = FALSE;
1304 }
1305
1306 if (action_id_get_target_kind(enabler->action) == ATK_SELF) {
1307 /* Special test for self targeted actions. */
1308
1309 if (requirement_vector_size(&(enabler->target_reqs)) > 0) {
1310 /* Shouldn't have target requirements since the action doesn't
1311 * have a target. */
1312 ruleset_error(logger, LOG_ERROR,
1313 "An action enabler for %s has a target "
1314 "requirement vector. %s doesn't have a target.",
1316 action_id_rule_name(act));
1317 ok = FALSE;
1318 }
1319 }
1320
1321 requirement_vector_iterate(&(enabler->target_reqs), preq) {
1322 if (preq->source.kind == VUT_DIPLREL
1323 && preq->range == REQ_RANGE_LOCAL) {
1324 struct astring astr;
1325
1326 /* A Local DiplRel requirement can be expressed as a requirement
1327 * in actor_reqs. Demand that it is there. This avoids breaking
1328 * code that reasons about actions. */
1329 ruleset_error(logger, LOG_ERROR,
1330 "Action enabler for %s has a local DiplRel "
1331 "requirement %s in target_reqs! Please read the "
1332 "section \"Requirement vector rules\" in "
1333 "doc/README.actions",
1335 req_to_fstring(preq, &astr));
1336 astr_free(&astr);
1337 ok = FALSE;
1338 }
1340
1341 if (compat == NULL || !compat->compat_mode
1342 || compat->version >= RSFORMAT_3_1) {
1343 /* Support for letting some of the following hard requirements be
1344 * implicit were retired in Freeciv 3.0. Others were retired later.
1345 * Make sure that the opposite of each hard action requirement
1346 * blocks all its action enablers. */
1347
1348 struct req_vec_problem *problem
1350
1351 if (problem != NULL) {
1352 ruleset_error(logger, LOG_ERROR, "%s", problem->description);
1353 req_vec_problem_free(problem);
1354 ok = FALSE;
1355 }
1356
1357 problem = action_enabler_suggest_improvement(enabler);
1358 if (problem != NULL) {
1359 /* There is a potential for improving this enabler. */
1360 log_deprecation("%s", problem->description);
1361 req_vec_problem_free(problem);
1362 }
1363 }
1365
1367 /* The action performer, action_dice_roll_initial_odds() and the
1368 * action probability calculation in action_prob() must probably all
1369 * be updated to add a new action here. */
1370 && !(action_has_result_safe(paction, ACTRES_STRIKE_BUILDING)
1371 || action_has_result_safe(paction, ACTRES_STRIKE_PRODUCTION)
1372 || action_has_result_safe(paction, ACTRES_SPY_SPREAD_PLAGUE)
1373 || action_has_result_safe(paction, ACTRES_SPY_POISON)
1374 || action_has_result_safe(paction, ACTRES_SPY_STEAL_TECH)
1375 || action_has_result_safe(paction,
1376 ACTRES_SPY_TARGETED_STEAL_TECH)
1377 || action_has_result_safe(paction, ACTRES_SPY_INCITE_CITY)
1378 || action_has_result_safe(paction, ACTRES_SPY_SABOTAGE_CITY)
1379 || action_has_result_safe(paction,
1380 ACTRES_SPY_TARGETED_SABOTAGE_CITY)
1381 || action_has_result_safe(paction,
1382 ACTRES_SPY_SABOTAGE_CITY_PRODUCTION)
1383 || action_has_result_safe(paction, ACTRES_SPY_STEAL_GOLD)
1384 || action_has_result_safe(paction, ACTRES_STEAL_MAPS)
1385 || action_has_result_safe(paction, ACTRES_SPY_NUKE))) {
1386 ruleset_error(logger, LOG_ERROR,
1387 "diplchance_initial_odds: \"%s\" not supported.",
1388 action_rule_name(paction));
1389 ok = FALSE;
1390 }
1391
1392 if (BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_ENTER)
1393 && BV_ISSET(paction->sub_results, ACT_SUB_RES_HUT_FRIGHTEN)) {
1394 ruleset_error(logger, LOG_ERROR,
1395 "%s both enters and frightens a hut at the same time.",
1396 action_rule_name(paction));
1397 ok = FALSE;
1398 }
1400
1401 /* Auto attack */
1402 {
1403 struct action_auto_perf *auto_perf;
1404
1406
1407 action_auto_perf_actions_iterate(auto_perf, act_id) {
1408 struct action *paction = action_by_number(act_id);
1409
1410 if (!(action_has_result(paction, ACTRES_CAPTURE_UNITS)
1411 || action_has_result(paction, ACTRES_BOMBARD)
1412 || action_has_result(paction, ACTRES_ATTACK))) {
1413 /* Only allow removing and changing the order of old auto
1414 * attack actions for now. Other actions need more testing and
1415 * fixing of issues caused by a worst case action probability of
1416 * 0%. */
1417 ruleset_error(logger, LOG_ERROR, "auto_attack: %s not supported in"
1418 " attack_actions.",
1419 action_rule_name(paction));
1420 ok = FALSE;
1421 }
1423 }
1424
1425 /* There must be basic city style for each nation style to start with */
1426 styles_re_active_iterate(pstyle) {
1427 if (basic_city_style_for_style(pstyle) < 0) {
1428 ruleset_error(logger, LOG_ERROR,
1429 "There's no basic city style for nation style %s",
1430 style_rule_name(pstyle));
1431 ok = FALSE;
1432 }
1434
1435 /* Music styles */
1437 if (!sanity_check_req_vec(logger, &pmus->reqs, TRUE, -1, "Music Style")) {
1438 ruleset_error(logger, LOG_ERROR,
1439 "Music Styles have conflicting or invalid requirements!");
1440 ok = FALSE;
1441 }
1443
1445 struct extra_type **pres;
1446
1447 if (pterr->animal != NULL) {
1448 if (!is_native_to_class(utype_class(pterr->animal), pterr, NULL)) {
1449 ruleset_error(logger, LOG_ERROR,
1450 "%s has %s as animal to appear, but it's not native to the terrain.",
1451 terrain_rule_name(pterr), utype_rule_name(pterr->animal));
1452 ok = FALSE;
1453 }
1454 }
1455
1456 for (pres = pterr->resources; *pres != NULL; pres++) {
1457 if (!is_extra_caused_by((*pres), EC_RESOURCE)) {
1458 ruleset_error(logger, LOG_ERROR,
1459 "%s has %s as a resource, but it's not a resource extra.",
1460 terrain_rule_name(pterr), extra_rule_name(*pres));
1461 ok = FALSE;
1462 }
1463 }
1465
1466 /* Check that all unit classes can exist somewhere */
1468 if (!uclass_has_flag(pclass, UCF_BUILD_ANYWHERE)) {
1469 bool can_exist = FALSE;
1470
1472 if (BV_ISSET(pterr->native_to, uclass_index(pclass))) {
1473 can_exist = TRUE;
1474 break;
1475 }
1477
1478 if (!can_exist) {
1480 if (BV_ISSET(pextra->native_to, uclass_index(pclass))
1481 && extra_has_flag(pextra, EF_NATIVE_TILE)) {
1482 can_exist = TRUE;
1483 break;
1484 }
1486 }
1487
1488 if (!can_exist) {
1489 ruleset_error(logger, LOG_ERROR,
1490 "Unit class %s cannot exist anywhere.",
1491 uclass_rule_name(pclass));
1492 ok = FALSE;
1493 }
1494 }
1496
1498 if (!pach->unique && pach->cons_msg == NULL) {
1499 ruleset_error(logger, LOG_ERROR,
1500 "Achievement %s has no message for consecutive gainers though "
1501 "it's possible to be gained by multiple players",
1502 achievement_rule_name(pach));
1503 ok = FALSE;
1504 }
1506
1507 if (game.server.ruledit.embedded_nations != NULL) {
1508 int nati;
1509
1510 for (nati = 0; nati < game.server.ruledit.embedded_nations_count; nati++) {
1511 struct nation_type *pnat
1513
1514 if (pnat == NULL) {
1515 ruleset_error(logger, LOG_ERROR,
1516 "There's nation %s listed in embedded nations, but there's "
1517 "no such nation.",
1519 ok = FALSE;
1520 }
1521 }
1522 }
1523
1524 if (ok) {
1525 ok = rs_common_units(logger);
1526 }
1527 if (ok) {
1528 ok = rs_barbarian_units(logger);
1529 }
1530 if (ok) {
1531 ok = rs_buildings(logger);
1532 }
1533
1534 return ok;
1535}
1536
1537/**********************************************************************/
1543{
1544 bool ok = TRUE;
1545
1546 extra_type_by_cause_iterate(EC_RESOURCE, pextra) {
1547 extra_type_by_cause_iterate(EC_RESOURCE, pextra2) {
1548 if (pextra != pextra2) {
1549 int idx = extra_index(pextra2);
1550
1551 if (!BV_ISSET(pextra->conflicts, idx)) {
1552 log_debug("Autoconflicting resource %s with %s",
1553 extra_rule_name(pextra), extra_rule_name(pextra2));
1554 BV_SET(pextra->conflicts, extra_index(pextra2));
1555 }
1556 }
1559
1560 /* Hard coded action blocking. */
1561 {
1562 const struct {
1563 const enum action_result blocked;
1564 const enum action_result blocker;
1565 } must_block[] = {
1566 /* Hard code that Help Wonder blocks Disband Unit Recover. This must be done
1567 * because caravan_shields makes it possible to avoid the
1568 * consequences of choosing to do Disband Unit Recover rather than having it
1569 * do Help Wonder.
1570 *
1571 * Explanation: Disband Unit Recover adds 50% of the shields used to produce
1572 * the unit to the production of the city where it is located. Help
1573 * Wonder adds 100%. If a unit that can do Help Wonder is disbanded with
1574 * production recovery in a city and the production later is changed
1575 * to something that can receive help from Help Wonder the remaining 50%
1576 * of the shields are added. This can be done because the city remembers
1577 * them in caravan_shields.
1578 *
1579 * If a unit that can do Help Wonder intentionally is disbanded with recovery
1580 * rather than making it do Help Wonder its shields will still be
1581 * remembered. The target city that got 50% of the shields can
1582 * therefore get 100% of them by changing its production. This trick
1583 * makes the ability to select Disband Unit Recover when Help Wonder is legal
1584 * pointless. */
1585 { ACTRES_DISBAND_UNIT_RECOVER, ACTRES_HELP_WONDER },
1586
1587 /* Allowing regular disband when ACTION_HELP_WONDER or
1588 * ACTION_DISBAND_UNIT_RECOVER is legal while ACTION_HELP_WONDER always
1589 * blocks ACTION_DISBAND_UNIT_RECOVER doesn't work well with the force_*
1590 * semantics. Should move to the ruleset once it has blocked_by
1591 * semantics. */
1592 { ACTRES_DISBAND_UNIT, ACTRES_HELP_WONDER },
1593 { ACTRES_DISBAND_UNIT, ACTRES_DISBAND_UNIT_RECOVER },
1594
1595 /* Hard code that the ability to perform a regular attack blocks city
1596 * conquest. Is redundant as long as the requirement that the target
1597 * tile has no units remains hard coded. Kept "just in case" that
1598 * changes. */
1599 { ACTRES_CONQUER_CITY, ACTRES_ATTACK },
1600
1601 /* Hard code that the ability to perform a regular attack blocks
1602 * extras conquest. Is redundant as long as the requirement that the
1603 * target tile has no non-allied units remains hard coded. Kept "just
1604 * in case" that changes. */
1605 { ACTRES_CONQUER_EXTRAS, ACTRES_ATTACK },
1606
1607 /* Hard code that the ability to enter or frighten a hut blocks
1608 * regular disembarking. */
1609 { ACTRES_TRANSPORT_DISEMBARK, ACTRES_CONQUER_EXTRAS },
1610 { ACTRES_TRANSPORT_DISEMBARK, ACTRES_HUT_ENTER },
1611 { ACTRES_TRANSPORT_DISEMBARK, ACTRES_HUT_FRIGHTEN },
1612 };
1613
1614 int i;
1615
1616 for (i = 0; i < ARRAY_SIZE(must_block); i++) {
1617 enum action_result blocked_result = must_block[i].blocked;
1618 enum action_result blocker_result = must_block[i].blocker;
1619
1620 action_by_result_iterate(blocked, blocked_result) {
1621 action_by_result_iterate(blocker, blocker_result) {
1622 if (!action_would_be_blocked_by(blocked, blocker)) {
1623 log_verbose("Autoblocking %s with %s",
1624 action_rule_name(blocked),
1625 action_rule_name(blocker));
1626 BV_SET(blocked->blocked_by, blocker->id);
1627 }
1630 }
1631 }
1632
1633 return ok;
1634}
1635
1636/**********************************************************************/
1640{
1641 bool ok = TRUE;
1642
1643 if (num_role_units(L_BARBARIAN) == 0) {
1644 struct setting *pset = setting_by_name("barbarians");
1645
1646 log_normal(_("Disabling 'barbarians' setting for lack of suitable "
1647 "unit types."));
1648 setting_lock_set(pset, FALSE);
1649 if (!setting_enum_set(pset, "DISABLED", NULL, NULL, 0)) {
1650 ok = FALSE;
1651 }
1652 setting_lock_set(pset, TRUE);
1653 }
1654
1655 return ok;
1656}
const char * achievement_rule_name(struct achievement *pach)
#define achievements_re_active_iterate(_p)
#define achievements_re_active_iterate_end
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1833
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1730
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:7349
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:2838
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:2904
bool action_result_legal_target_kind(enum action_result result, enum action_target_kind tgt_kind)
Definition actions.c:8609
const char * action_rule_name(const struct action *action)
Definition actions.c:1876
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1899
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1856
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:6979
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1740
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:2475
#define action_by_result_iterate(_paction_, _result_)
Definition actions.h:488
#define ACTION_DISTANCE_MAX
Definition actions.h:354
#define ACTION_AUTO_MOVED_ADJ
Definition actions.h:617
#define action_auto_perf_actions_iterate_end
Definition actions.h:609
static struct action * action_by_number(action_id act_id)
Definition actions.h:638
#define action_enabler_list_re_iterate_end
Definition actions.h:463
#define ACTION_DISTANCE_LAST_NON_SIGNAL
Definition actions.h:350
#define action_enabler_list_re_iterate(action_enabler_list, aenabler)
Definition actions.h:459
#define action_has_result(_act_, _res_)
Definition actions.h:448
#define action_by_result_iterate_end
Definition actions.h:492
#define action_auto_perf_actions_iterate(_autoperf_, _act_id_)
Definition actions.h:606
#define action_iterate_end
Definition actions.h:472
#define action_has_result_safe(paction, result)
Definition actions.h:666
#define action_iterate(_act_)
Definition actions.h:467
#define action_id_get_target_kind(act_id)
Definition actions.h:655
#define ACTION_ODDS_PCT_DICE_ROLL_NA
Definition actions.h:946
void astr_free(struct astring *astr)
Definition astring.c:153
#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
const char * city_style_rule_name(const int style)
Definition city.c:1738
#define MAX_CITY_SIZE
Definition city.h:98
#define MAX_LEN_CONTENT
Definition connection.h:59
#define log_deprecation(message,...)
const char * disaster_rule_name(struct disaster_type *pdis)
Definition disaster.c:105
#define disaster_type_re_active_iterate(_p)
Definition disaster.h:91
#define disaster_type_re_active_iterate_end
Definition disaster.h:94
int int id
Definition editgui_g.h:28
struct @21::@22 reqs
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1245
int get_potential_improvement_bonus(const struct impr_type *pimprove, const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type, bool consider_multipliers)
Definition effects.c:1126
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:331
int effect_cumulative_min(enum effect_type type, struct universal *for_uni)
Definition effects.c:367
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:810
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:195
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
#define is_extra_caused_by(e, c)
Definition extras.h:196
#define extra_index(_e_)
Definition extras.h:177
#define extra_type_re_active_iterate_end
Definition extras.h:305
#define extra_type_list_iterate_end
Definition extras.h:161
#define extra_road_get(_e_)
Definition extras.h:185
#define extra_type_re_active_iterate(_p)
Definition extras.h:301
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
int server_setting_id
Definition fc_types.h:924
int Tech_type_id
Definition fc_types.h:347
int ssetv
Definition fc_types.h:578
@ RPT_POSSIBLE
Definition fc_types.h:585
#define MAX_NUM_TECH_LIST
Definition fc_types.h:44
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
const char * government_rule_name(const struct government *pgovern)
Definition government.c:132
#define governments_re_active_iterate(_p)
Definition government.h:126
#define governments_re_active_iterate_end
Definition government.h:130
const char * improvement_rule_name(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_re_active_iterate_end
#define improvement_re_active_iterate(_p)
#define B_LAST
Definition improvement.h:42
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
@ LOG_ERROR
Definition log.h:30
@ LOG_WARN
Definition log.h:31
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:327
bool can_unit_type_transport(const struct unit_type *transporter, const struct unit_class *transported)
Definition movement.c:826
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
struct nation_type * nation_by_rule_name(const char *name)
Definition nation.c:120
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
#define nations_re_active_iterate_end
Definition nation.h:341
#define nations_re_active_iterate(_pnat_)
Definition nation.h:338
const char * req_to_fstring(const struct requirement *req, struct astring *astr)
req_vec_num_in_item req_vec_vector_number(const void *parent_item, const struct requirement_vector *vec)
struct req_vec_problem * req_vec_suggest_repair(const struct requirement_vector *vec, requirement_vector_number get_num, const void *parent_item)
const char * universal_rule_name(const struct universal *psource)
void req_vec_problem_free(struct req_vec_problem *issue)
const char * universal_type_rule_name(const struct universal *psource)
enum req_unchanging_status is_req_unchanging(const struct req_context *context, const struct requirement *req)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
@ REQUCH_HACK
Road_type_id road_number(const struct road_type *proad)
Definition road.c:32
bool sanity_check_ruleset_data(struct rscompat_info *compat)
Definition rssanity.c:861
static bool sanity_check_req_vec(rs_conversion_logger logger, const struct requirement_vector *preqs, bool conjunctive, int max_tiles, const char *list_for)
Definition rssanity.c:485
bool sanity_check_server_setting_value_in_req(ssetv ssetval)
Definition rssanity.c:125
static bool sanity_check_boolean_effects(rs_conversion_logger logger)
Definition rssanity.c:810
static bool sanity_check_setting_is_seen(struct setting *pset)
Definition rssanity.c:89
static bool sanity_check_req_vec_singlepole(rs_conversion_logger logger, const struct requirement_vector *preqs, bool conjunctive, const char *list_for)
Definition rssanity.c:423
static bool sanity_check_req_individual(rs_conversion_logger logger, struct requirement *preq, const char *list_for)
Definition rssanity.c:152
static bool sanity_check_req_set(rs_conversion_logger logger, int reqs_of_type[], int local_reqs_of_type[], struct requirement *preq, bool conjunctive, int max_tiles, const char *list_for)
Definition rssanity.c:238
static bool rs_buildings(rs_conversion_logger logger)
Definition rssanity.c:763
static bool sanity_check_metadata(rs_conversion_logger logger)
Definition rssanity.c:43
bool autolock_settings(void)
Definition rssanity.c:1639
static bool rs_common_units(rs_conversion_logger logger)
Definition rssanity.c:685
bool autoadjust_ruleset_data(void)
Definition rssanity.c:1542
static bool rs_barbarian_units(rs_conversion_logger logger)
Definition rssanity.c:613
static bool effect_list_sanity_cb(struct effect *peffect, void *data)
Definition rssanity.c:530
static bool sanity_check_setting_is_game_rule(struct setting *pset)
Definition rssanity.c:98
static bool nation_has_initial_tech(struct nation_type *pnation, struct advance *tech)
Definition rssanity.c:60
void(* rs_conversion_logger)(const char *msg)
Definition ruleset.h:40
#define ruleset_error(logger, level, format,...)
Definition ruleset.h:57
#define RSFORMAT_3_1
Definition ruleset.h:36
static struct compatibility compat[]
Definition savecompat.c:101
const char * server_setting_name_get(server_setting_id id)
enum sset_type server_setting_type_get(server_setting_id id)
server_setting_id ssetv_setting_get(ssetv enc)
bool server_setting_exists(server_setting_id id)
struct setting * setting_by_name(const char *name)
Definition settings.c:3138
struct setting * setting_by_number(int id)
Definition settings.c:3130
enum sset_category setting_category(const struct setting *pset)
Definition settings.c:3207
void setting_lock_set(struct setting *pset, bool lock)
Definition settings.c:4428
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3832
bool setting_is_visible_at_level(const struct setting *pset, enum cmdlevel plevel)
Definition settings.c:3316
bool formats_match(const char *format1, const char *format2)
Definition shared.c:2433
#define ARRAY_SIZE(x)
Definition shared.h:85
#define XOR(p, q)
Definition shared.h:71
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
#define specialist_type_re_active_iterate_end
Definition specialist.h:88
#define specialist_type_re_active_iterate(_p)
Definition specialist.h:83
action_id id
Definition actions.h:380
int max_distance
Definition actions.h:395
enum action_result result
Definition actions.h:382
bv_action_sub_results sub_results
Definition actions.h:383
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
struct civ_game::@29 rgame
struct civ_game::@30::@34 server
struct packet_ruleset_control control
Definition game.h:83
char * ruleset_summary
Definition game.h:84
int global_init_techs[MAX_NUM_TECH_LIST]
Definition game.h:107
struct packet_game_info info
Definition game.h:89
char ** embedded_nations
Definition game.h:275
struct civ_game::@30::@34::@39 ruledit
size_t embedded_nations_count
Definition game.h:276
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 requirement_vector reqs
Definition effects.h:353
enum effect_type type
Definition effects.h:341
struct els_data::@98 base_effects
rs_conversion_logger logger
Definition rssanity.c:524
bool city_vision_radius_sq
Definition rssanity.c:522
int init_techs[MAX_NUM_TECH_LIST]
Definition nation.h:121
enum free_tech_method free_tech_method
bv_actions diplchance_initial_odds
enum tech_cost_style tech_cost_style
char description[500]
enum req_range range
struct universal source
struct extra_type_list * integrators
Definition road.h:93
bv_max_extras integrates
Definition road.h:88
bv_unit_classes cargo
Definition unittype.h:539
const struct unit_type * obsoleted_by
Definition unittype.h:510
enum universals_n kind
Definition fc_types.h:758
universals_u value
Definition fc_types.h:757
const char * style_rule_name(const struct nation_style *pstyle)
Definition style.c:108
int basic_city_style_for_style(struct nation_style *pstyle)
Definition style.c:210
#define music_styles_re_active_iterate_end
Definition style.h:88
#define music_styles_re_active_iterate(_p)
Definition style.h:85
#define styles_re_active_iterate_end
Definition style.h:60
#define styles_re_active_iterate(_p)
Definition style.h:56
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Definition tech.c:136
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define advance_re_active_iterate(_p)
Definition tech.h:275
#define A_NEVER
Definition tech.h:51
#define advance_req_iterate(_goal, _padvance)
Definition tech.h:293
@ AR_ROOT
Definition tech.h:113
@ AR_ONE
Definition tech.h:111
@ AR_SIZE
Definition tech.h:114
#define advance_re_active_iterate_end
Definition tech.h:279
#define advance_req_iterate_end
Definition tech.h:297
#define A_NONE
Definition tech.h:43
#define A_LAST
Definition tech.h:45
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
#define terrain_re_active_iterate_end
Definition terrain.h:373
#define is_ocean(pterrain)
Definition terrain.h:287
#define terrain_re_active_iterate(_p)
Definition terrain.h:369
const char * goods_rule_name(struct goods_type *pgood)
#define goods_type_re_active_iterate_end
#define goods_type_re_active_iterate(_p)
const struct impr_type * building
Definition fc_types.h:598
ssetv ssetval
Definition fc_types.h:642
bool utype_is_cityfounder(const struct unit_type *utype)
Definition unittype.c:2981
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2301
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:193
int num_role_units(int role)
Definition unittype.c:2251
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1630
const char * uclass_rule_name(const struct unit_class *pclass)
Definition unittype.c:1693
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:753
#define unit_type_re_active_iterate(_p)
Definition unittype.h:853
#define utype_class(_t_)
Definition unittype.h:736
#define unit_class_iterate(_p)
Definition unittype.h:879
#define unit_class_re_active_iterate_end
Definition unittype.h:895
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:604
#define unit_type_iterate(_p)
Definition unittype.h:841
#define unit_class_re_active_iterate(_p)
Definition unittype.h:891
#define UNIT_MAX_PARADROP_RANGE
Definition unittype.h:54
#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 unit_type_re_active_iterate_end
Definition unittype.h:857