Freeciv21
Develop your civilization from humble roots to a global empire
advruleset.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 // common
15 #include "base.h"
16 #include "effects.h"
17 #include "map.h"
18 #include "movement.h"
19 #include "unittype.h"
20 
21 /* server/advisors */
22 #include "autosettlers.h"
23 
24 #include "advruleset.h"
25 
30 {
31  unit_class_iterate(pclass)
32  {
33  bool move_land_enabled = false; // Can move at some land terrains
34  bool move_land_disabled = false; // Cannot move at some land terrains
35  bool move_sea_enabled = false; // Can move at some ocean terrains
36  bool move_sea_disabled = false; // Cannot move at some ocean terrains
37 
38  terrain_type_iterate(pterrain)
39  {
40  if (is_native_to_class(pclass, pterrain, nullptr)) {
41  // Can move at terrain
42  if (is_ocean(pterrain)) {
43  move_sea_enabled = true;
44  } else {
45  move_land_enabled = true;
46  }
47  } else {
48  // Cannot move at terrain
49  if (is_ocean(pterrain)) {
50  move_sea_disabled = true;
51  } else {
52  move_land_disabled = true;
53  }
54  }
55  }
57 
58  if (move_land_enabled && !move_land_disabled) {
59  pclass->adv.land_move = MOVE_FULL;
60  } else if (move_land_enabled) {
61  pclass->adv.land_move = MOVE_PARTIAL;
62  } else {
63  fc_assert(!move_land_enabled);
64  pclass->adv.land_move = MOVE_NONE;
65  }
66 
67  if (move_sea_enabled && !move_sea_disabled) {
68  pclass->adv.sea_move = MOVE_FULL;
69  } else if (move_sea_enabled) {
70  pclass->adv.sea_move = MOVE_PARTIAL;
71  } else {
72  fc_assert(!move_sea_enabled);
73  pclass->adv.sea_move = MOVE_NONE;
74  }
75  }
77 
78  unit_type_iterate(ptype)
79  {
80  ptype->adv.igwall = true;
81 
82  effect_list_iterate(get_effects(EFT_DEFEND_BONUS), peffect)
83  {
84  if (peffect->value > 0) {
85  requirement_vector_iterate(&peffect->reqs, preq)
86  {
87  if (!is_req_active(nullptr, nullptr, nullptr, nullptr, nullptr,
88  nullptr, ptype, nullptr, nullptr, nullptr, preq,
89  RPT_POSSIBLE)) {
90  ptype->adv.igwall = false;
91  break;
92  }
93  }
95  }
96  if (!ptype->adv.igwall) {
97  break;
98  }
99  }
101 
102  ptype->adv.worker = utype_has_flag(ptype, UTYF_SETTLERS);
103  }
105 
106  // Initialize autosettlers actions
108 }
void adv_units_ruleset_init()
Initialise the unit data from the ruleset for the advisors.
Definition: advruleset.cpp:29
void auto_settlers_ruleset_init()
Initialize auto settlers based on the ruleset.
const effect_list * get_effects()
Get a list of all effects.
Definition: effects.cpp:117
#define effect_list_iterate_end
Definition: effects.h:349
#define effect_list_iterate(effect_list, peffect)
Definition: effects.h:347
@ RPT_POSSIBLE
Definition: fc_types.h:567
#define fc_assert(condition)
Definition: log.h:89
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
This terrain is native to unit class.
Definition: movement.cpp:290
bool is_req_active(const struct player *target_player, const struct player *other_player, const struct city *target_city, const struct impr_type *target_building, const struct tile *target_tile, const struct unit *target_unit, const struct unit_type *target_unittype, const struct output_type *target_output, const struct specialist *target_specialist, const struct action *target_action, const struct requirement *req, const enum req_problem_type prob_type, const enum vision_layer vision_layer, const enum national_intelligence nintel)
Checks the requirement to see if it is active on the given target.
#define requirement_vector_iterate_end
Definition: requirements.h:80
#define requirement_vector_iterate(req_vec, preq)
Definition: requirements.h:78
#define terrain_type_iterate(_p)
Definition: terrain.h:331
#define is_ocean(pterrain)
Definition: terrain.h:276
#define terrain_type_iterate_end
Definition: terrain.h:337
#define unit_class_iterate(_p)
Definition: unittype.h:823
@ MOVE_PARTIAL
Definition: unittype.h:115
@ MOVE_FULL
Definition: unittype.h:115
@ MOVE_NONE
Definition: unittype.h:115
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition: unittype.h:584
#define unit_type_iterate(_p)
Definition: unittype.h:785
#define unit_class_iterate_end
Definition: unittype.h:829
#define unit_type_iterate_end
Definition: unittype.h:791