Freeciv-3.1
Loading...
Searching...
No Matches
advruleset.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/* common */
19#include "base.h"
20#include "effects.h"
21#include "map.h"
22#include "movement.h"
23#include "unittype.h"
24
25/* server/advisors */
26#include "autosettlers.h"
27
28#include "advruleset.h"
29
30/**********************************************************************/
34{
35 unit_class_iterate(pclass) {
36 bool move_land_enabled = FALSE; /* Can move at some land terrains */
37 bool move_land_disabled = FALSE; /* Cannot move at some land terrains */
38 bool move_sea_enabled = FALSE; /* Can move at some ocean terrains */
39 bool move_sea_disabled = FALSE; /* Cannot move at some ocean terrains */
40
41 terrain_type_iterate(pterrain) {
42 if (is_native_to_class(pclass, pterrain, NULL)) {
43 /* Can move at terrain */
44 if (is_ocean(pterrain)) {
45 move_sea_enabled = TRUE;
46 } else {
47 move_land_enabled = TRUE;
48 }
49 } else {
50 /* Cannot move at terrain */
51 if (is_ocean(pterrain)) {
52 move_sea_disabled = TRUE;
53 } else {
54 move_land_disabled = TRUE;
55 }
56 }
58
59 if (move_land_enabled && !move_land_disabled) {
60 pclass->adv.land_move = MOVE_FULL;
61 } else if (move_land_enabled && move_land_disabled) {
62 pclass->adv.land_move = MOVE_PARTIAL;
63 } else {
64 fc_assert(!move_land_enabled);
65 pclass->adv.land_move = MOVE_NONE;
66 }
67
68 if (move_sea_enabled && !move_sea_disabled) {
69 pclass->adv.sea_move = MOVE_FULL;
70 } else if (move_sea_enabled && move_sea_disabled) {
71 pclass->adv.sea_move = MOVE_PARTIAL;
72 } else {
73 fc_assert(!move_sea_enabled);
74 pclass->adv.sea_move = MOVE_NONE;
75 }
76
77 pclass->adv.ferry_types = 0;
79
80 unit_type_iterate(ptype) {
81 const struct req_context context = { .unittype = ptype };
82
83 ptype->adv.igwall = TRUE;
84
85 effect_list_iterate(get_effects(EFT_DEFEND_BONUS), peffect) {
86 if (peffect->value > 0) {
87 requirement_vector_iterate(&peffect->reqs, preq) {
88 if (!is_req_active(&context, NULL, preq, RPT_POSSIBLE)) {
89 ptype->adv.igwall = FALSE;
90 break;
91 }
93 }
94 if (!ptype->adv.igwall) {
95 break;
96 }
98
99 if (utype_has_role(ptype, L_FERRYBOAT)) {
100 unit_class_iterate(aclass) {
101 if (BV_ISSET(ptype->cargo, uclass_index(aclass))) {
102 aclass->adv.ferry_types++;
103 }
105 }
106
107 ptype->adv.worker
108 = (utype_has_flag(ptype, UTYF_SETTLERS)
109 && (utype_can_do_action_result(ptype, ACTRES_CULTIVATE)
110 || utype_can_do_action_result(ptype, ACTRES_PLANT)
111 || utype_can_do_action_result(ptype, ACTRES_IRRIGATE)
112 || utype_can_do_action_result(ptype, ACTRES_MINE)
113 || utype_can_do_action_result(ptype, ACTRES_TRANSFORM_TERRAIN)));
115
116 /* Initialize autosettlers actions */
118}
void adv_units_ruleset_init(void)
Definition advruleset.c:33
void auto_settlers_ruleset_init(void)
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:136
#define effect_list_iterate_end
Definition effects.h:375
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:373
@ RPT_POSSIBLE
Definition fc_types.h:585
#define fc_assert(condition)
Definition log.h:176
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:327
bool is_req_active(const struct req_context *context, const struct player *other_player, const struct requirement *req, const enum req_problem_type prob_type)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
const struct unit_type * unittype
struct unit_type::@87 adv
bool igwall
Definition unittype.h:555
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define terrain_type_iterate(_p)
Definition terrain.h:358
#define is_ocean(pterrain)
Definition terrain.h:287
#define terrain_type_iterate_end
Definition terrain.h:364
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:193
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:459
#define unit_class_iterate(_p)
Definition unittype.h:879
@ MOVE_PARTIAL
Definition unittype.h:131
@ MOVE_FULL
Definition unittype.h:131
@ MOVE_NONE
Definition unittype.h:131
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 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