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 /* common */
19 #include "base.h"
20 #include "effects.h"
21 #include "movement.h"
22 #include "unittype.h"
23 
24 #include "advruleset.h"
25 
26 /**************************************************************************
27   Initialise the unit data from the ruleset for the advisors.
28 **************************************************************************/
adv_units_ruleset_init(void)29 void adv_units_ruleset_init(void)
30 {
31   unit_class_iterate(pclass) {
32     bool move_land_enabled  = FALSE; /* Can move at some land terrains */
33     bool move_land_disabled = FALSE; /* Cannot move at some land terrains */
34     bool move_sea_enabled   = FALSE; /* Can move at some ocean terrains */
35     bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */
36 
37     terrain_type_iterate(pterrain) {
38       if (is_native_to_class(pclass, pterrain, NULL)) {
39         /* Can move at terrain */
40         if (is_ocean(pterrain)) {
41           move_sea_enabled = TRUE;
42         } else {
43           move_land_enabled = TRUE;
44         }
45       } else {
46         /* Cannot move at terrain */
47         if (is_ocean(pterrain)) {
48           move_sea_disabled = TRUE;
49         } else {
50           move_land_disabled = TRUE;
51         }
52       }
53     } terrain_type_iterate_end;
54 
55     if (move_land_enabled && !move_land_disabled) {
56       pclass->adv.land_move = MOVE_FULL;
57     } else if (move_land_enabled && move_land_disabled) {
58       pclass->adv.land_move = MOVE_PARTIAL;
59     } else {
60       fc_assert(!move_land_enabled);
61       pclass->adv.land_move = MOVE_NONE;
62     }
63 
64     if (move_sea_enabled && !move_sea_disabled) {
65       pclass->adv.sea_move = MOVE_FULL;
66     } else if (move_sea_enabled && move_sea_disabled) {
67       pclass->adv.sea_move = MOVE_PARTIAL;
68     } else {
69       fc_assert(!move_sea_enabled);
70       pclass->adv.sea_move = MOVE_NONE;
71     }
72 
73   } unit_class_iterate_end;
74 
75   unit_type_iterate(ptype) {
76     ptype->adv.igwall = TRUE;
77 
78     effect_list_iterate(get_effects(EFT_DEFEND_BONUS), peffect) {
79       if (peffect->value > 0) {
80         requirement_vector_iterate(&peffect->reqs, preq) {
81           if (!is_req_active(NULL, NULL, NULL, NULL, NULL, NULL, ptype,
82                              NULL, NULL, preq, RPT_POSSIBLE)) {
83             ptype->adv.igwall = FALSE;
84             break;
85           }
86         } requirement_vector_iterate_end;
87       }
88       if (!ptype->adv.igwall) {
89         break;
90       }
91     } effect_list_iterate_end;
92   } unit_type_iterate_end;
93 }
94