Freeciv-3.3: /fast/freeciv/nightly/main/server/advisors/advruleset.c Source File

Freeciv-3.3

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 "autoworkers.h"
27
28#include "advruleset.h"
29
30/**********************************************************************/
33 void adv_units_ruleset_init(void)
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 }
57 } terrain_type_iterate_end;
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;
78 } unit_class_iterate_end;
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 }
92 } requirement_vector_iterate_end;
93 }
94 if (!ptype->adv.igwall) {
95 break;
96 }
97 } effect_list_iterate_end;
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 }
104 } unit_class_iterate_end;
105 }
106
107 ptype->adv.worker = utype_has_flag(ptype, UTYF_WORKERS);
108 } unit_type_iterate_end;
109
110 /* Initialize autoworkers actions */
111 auto_workers_ruleset_init();
112}
adv_units_ruleset_init
void adv_units_ruleset_init(void)
Definition advruleset.c:33
advruleset.h
auto_workers_ruleset_init
void auto_workers_ruleset_init(void)
Definition autoworkers.c:95
autoworkers.h
base.h
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
incite_cost
char * incite_cost
Definition comments.c:74
get_effects
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
effects.h
effect_list_iterate_end
#define effect_list_iterate_end
Definition effects.h:81
effect_list_iterate
#define effect_list_iterate(effect_list, peffect)
Definition effects.h:79
RPT_POSSIBLE
@ RPT_POSSIBLE
Definition fc_types.h:707
fc_assert
#define fc_assert(condition)
Definition log.h:176
map.h
is_native_to_class
bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, const bv_extras *extras)
Definition movement.c:341
movement.h
is_req_active
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)
Definition requirements.c:5616
requirement_vector_iterate_end
#define requirement_vector_iterate_end
Definition requirements.h:94
requirement_vector_iterate
#define requirement_vector_iterate(req_vec, preq)
Definition requirements.h:92
req_context
Definition requirements.h:100
req_context::unittype
const struct unit_type * unittype
Definition requirements.h:107
unit_type::adv
struct unit_type::@87 adv
unit_type::igwall
bool igwall
Definition unittype.h:581
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
terrain_type_iterate
#define terrain_type_iterate(_p)
Definition terrain.h:266
is_ocean
#define is_ocean(pterrain)
Definition terrain.h:194
terrain_type_iterate_end
#define terrain_type_iterate_end
Definition terrain.h:272
utype_has_role
bool utype_has_role(const struct unit_type *punittype, int role)
Definition unittype.c:199
unittype.h
unit_class_iterate
#define unit_class_iterate(_p)
Definition unittype.h:912
MOVE_PARTIAL
@ MOVE_PARTIAL
Definition unittype.h:144
MOVE_FULL
@ MOVE_FULL
Definition unittype.h:144
MOVE_NONE
@ MOVE_NONE
Definition unittype.h:144
utype_has_flag
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
unit_type_iterate
#define unit_type_iterate(_p)
Definition unittype.h:859
uclass_index
#define uclass_index(_c_)
Definition unittype.h:749
unit_class_iterate_end
#define unit_class_iterate_end
Definition unittype.h:919
unit_type_iterate_end
#define unit_type_iterate_end
Definition unittype.h:866