Freeciv21
Develop your civilization from humble roots to a global empire
base.h
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 #pragma once
14 
15 // common
16 #include "fc_types.h"
17 #include "requirements.h"
18 
19 // Used in the network protocol.
20 #define SPECENUM_NAME base_gui_type
21 #define SPECENUM_VALUE0 BASE_GUI_FORTRESS
22 #define SPECENUM_VALUE0NAME "Fortress"
23 #define SPECENUM_VALUE1 BASE_GUI_AIRBASE
24 #define SPECENUM_VALUE1NAME "Airbase"
25 #define SPECENUM_VALUE2 BASE_GUI_OTHER
26 #define SPECENUM_VALUE2NAME "Other"
27 #include "specenum_gen.h"
28 
29 // Used in the network protocol.
30 #define SPECENUM_NAME base_flag_id
31 // Unit inside are not considered aggressive if base is close to city
32 #define SPECENUM_VALUE0 BF_NOT_AGGRESSIVE
33 /* TRANS: this and following strings are 'base flags', which may rarely
34  * be presented to the player in ruleset help text */
35 #define SPECENUM_VALUE0NAME N_("NoAggressive")
36 
37 #define SPECENUM_COUNT BF_COUNT
38 #define SPECENUM_BITVECTOR bv_base_flags
39 #include "specenum_gen.h"
40 
41 struct extra_type;
42 
43 struct base_type {
45  enum base_gui_type gui_type;
46  int border_sq;
50 
51  bv_base_flags flags;
52 
53  struct extra_type *self;
54 };
55 
56 #define BASE_NONE -1
57 
58 // General base accessor functions.
60 Base_type_id base_number(const struct base_type *pbase);
61 
62 struct base_type *base_by_number(const Base_type_id id);
63 
64 struct extra_type *base_extra_get(const struct base_type *pbase);
65 
66 // Functions to operate on a base flag.
67 bool base_has_flag(const struct base_type *pbase, enum base_flag_id flag);
68 bool is_base_flag_card_near(const struct tile *ptile,
69  enum base_flag_id flag);
70 bool is_base_flag_near_tile(const struct tile *ptile,
71  enum base_flag_id flag);
72 bool base_flag_is_retired(enum base_flag_id flag);
73 bool base_has_flag_for_utype(const struct base_type *pbase,
74  enum base_flag_id flag,
75  const struct unit_type *punittype);
76 
77 // Ancillary functions
78 bool can_build_base(const struct unit *punit, const struct base_type *pbase,
79  const struct tile *ptile);
80 
81 struct base_type *get_base_by_gui_type(enum base_gui_type type,
82  const struct unit *punit,
83  const struct tile *ptile);
84 
85 bool territory_claiming_base(const struct base_type *pbase);
86 
87 // Initialization and iteration
88 void base_type_init(struct extra_type *pextra, int idx);
89 void base_types_free();
90 
91 #define base_deps_iterate(_reqs, _dep) \
92  { \
93  requirement_vector_iterate(_reqs, preq) \
94  { \
95  if (preq->source.kind == VUT_EXTRA && preq->present \
96  && is_extra_caused_by(preq->source.value.extra, EC_BASE)) { \
97  struct base_type *_dep = extra_base_get(preq->source.value.extra);
98 
99 #define base_deps_iterate_end \
100  } \
101  } \
102  requirement_vector_iterate_end; \
103  }
bool base_flag_is_retired(enum base_flag_id flag)
Returns TRUE iff the given flag is retired.
Definition: base.cpp:78
Base_type_id base_number(const struct base_type *pbase)
Return the base index.
Definition: base.cpp:135
void base_type_init(struct extra_type *pextra, int idx)
Initialize base_type structures.
Definition: base.cpp:157
bool base_has_flag(const struct base_type *pbase, enum base_flag_id flag)
Check if base provides effect.
Definition: base.cpp:24
bool is_base_flag_card_near(const struct tile *ptile, enum base_flag_id flag)
Returns TRUE iff any cardinally adjacent tile contains a base with the given flag (does not check pti...
Definition: base.cpp:33
void base_types_free()
Free the memory associated with base types.
Definition: base.cpp:170
struct extra_type * base_extra_get(const struct base_type *pbase)
Return extra that base is.
Definition: base.cpp:144
bool base_has_flag_for_utype(const struct base_type *pbase, enum base_flag_id flag, const struct unit_type *punittype)
Base provides base flag for unit? Checks if base provides flag and if base is native to unit.
Definition: base.cpp:90
struct base_type * base_by_number(const Base_type_id id)
Returns base_type entry for an ID value.
Definition: base.cpp:119
bool can_build_base(const struct unit *punit, const struct base_type *pbase, const struct tile *ptile)
Can unit build base to given tile?
Definition: base.cpp:101
Base_type_id base_count()
Return the number of base_types.
Definition: base.cpp:152
struct base_type * get_base_by_gui_type(enum base_gui_type type, const struct unit *punit, const struct tile *ptile)
Get best gui_type base for given parameters.
Definition: base.cpp:175
bool is_base_flag_near_tile(const struct tile *ptile, enum base_flag_id flag)
Returns TRUE iff any adjacent tile contains a base with the given flag (does not check ptile itself)
Definition: base.cpp:56
bool territory_claiming_base(const struct base_type *pbase)
Does this base type claim territory?
Definition: base.cpp:196
int Base_type_id
Definition: fc_types.h:300
Definition: base.h:43
int border_sq
Definition: base.h:46
int vision_main_sq
Definition: base.h:47
enum base_gui_type gui_type
Definition: base.h:45
bv_base_flags flags
Definition: base.h:51
int vision_invis_sq
Definition: base.h:48
Base_type_id item_number
Definition: base.h:44
int vision_subs_sq
Definition: base.h:49
Definition: tile.h:42
Definition: unit.h:134