Freeciv21
Develop your civilization from humble roots to a global empire
road.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 // Used in the network protocol.
16 #define SPECENUM_NAME road_flag_id
17 #define SPECENUM_VALUE0 RF_RIVER
18 /* TRANS: this and following strings are 'road flags', which may rarely
19  * be presented to the player in ruleset help text */
20 #define SPECENUM_VALUE0NAME N_("River")
21 #define SPECENUM_VALUE1 RF_UNRESTRICTED_INFRA
22 #define SPECENUM_VALUE1NAME N_("UnrestrictedInfra")
23 #define SPECENUM_VALUE2 RF_JUMP_FROM
24 #define SPECENUM_VALUE2NAME N_("JumpFrom")
25 #define SPECENUM_VALUE3 RF_JUMP_TO
26 #define SPECENUM_VALUE3NAME N_("JumpTo")
27 #define SPECENUM_COUNT RF_COUNT
28 #define SPECENUM_BITVECTOR bv_road_flags
29 #include "specenum_gen.h"
30 
31 // Used in the network protocol.
32 #define SPECENUM_NAME road_move_mode
33 #define SPECENUM_VALUE0 RMM_CARDINAL
34 #define SPECENUM_VALUE0NAME "Cardinal"
35 #define SPECENUM_VALUE1 RMM_RELAXED
36 #define SPECENUM_VALUE1NAME "Relaxed"
37 #define SPECENUM_VALUE2 RMM_FAST_ALWAYS
38 #define SPECENUM_VALUE2NAME "FastAlways"
39 #include "specenum_gen.h"
40 
41 struct road_type;
42 
43 // get 'struct road_type_list' and related functions:
44 #define SPECLIST_TAG road_type
45 #define SPECLIST_TYPE struct road_type
46 #include "speclist.h"
47 
48 #define road_type_list_iterate(roadlist, proad) \
49  TYPED_LIST_ITERATE(struct road_type, roadlist, proad)
50 #define road_type_list_iterate_end LIST_ITERATE_END
51 
52 struct extra_type;
53 
54 struct road_type {
55  int id;
56 
57  int move_cost;
58  enum road_move_mode move_mode;
62  enum road_compat compat;
63 
64  struct requirement_vector first_reqs;
65 
66  bv_roads integrates;
67  bv_road_flags flags;
68 
69  /* Same information as in integrates, but iterating through this list is
70  * much faster than through all road types to check for compatible roads.
71  */
72  struct extra_type_list *integrators;
73 
74  struct extra_type *self;
75 };
76 
77 #define ROAD_NONE (-1)
78 
79 // General road type accessor functions.
81 Road_type_id road_number(const struct road_type *proad);
82 
84 struct extra_type *road_extra_get(const struct road_type *proad);
85 
86 enum road_compat road_compat_special(const struct road_type *proad);
88 
89 int count_river_near_tile(const struct tile *ptile,
90  const struct extra_type *priver);
91 int count_river_type_tile_card(const struct tile *ptile,
92  const struct extra_type *priver,
93  bool percentage);
94 int count_river_type_near_tile(const struct tile *ptile,
95  const struct extra_type *priver,
96  bool percentage);
97 
98 // Functions to operate on a road flag.
99 bool road_has_flag(const struct road_type *proad, enum road_flag_id flag);
100 bool is_road_flag_card_near(const struct tile *ptile,
101  enum road_flag_id flag);
102 bool is_road_flag_near_tile(const struct tile *ptile,
103  enum road_flag_id flag);
104 
105 bool road_can_be_built(const struct road_type *proad,
106  const struct tile *ptile);
107 bool can_build_road(struct road_type *proad, const struct unit *punit,
108  const struct tile *ptile);
109 bool player_can_build_road(const struct road_type *proad,
110  const struct player *pplayer,
111  const struct tile *ptile);
112 
113 bool is_cardinal_only_road(const struct extra_type *pextra);
114 
115 bool road_provides_move_bonus(const struct road_type *proad);
116 
117 // Sorting
118 int compare_road_move_cost(const struct extra_type *const *p,
119  const struct extra_type *const *q);
120 
121 // Initialization and iteration
122 void road_type_init(struct extra_type *pextra, int idx);
124 void road_types_free();
125 
126 #define road_deps_iterate(_reqs, _dep) \
127  { \
128  requirement_vector_iterate(_reqs, preq) \
129  { \
130  if (preq->source.kind == VUT_EXTRA && preq->present \
131  && is_extra_caused_by(preq->source.value.extra, EC_ROAD)) { \
132  struct road_type *_dep = extra_road_get(preq->source.value.extra);
133 
134 #define road_deps_iterate_end \
135  } \
136  } \
137  requirement_vector_iterate_end; \
138  }
int Road_type_id
Definition: fc_types.h:301
road_compat
Definition: fc_types.h:1067
@ O_LAST
Definition: fc_types.h:91
Road_type_id road_number(const struct road_type *proad)
Return the road id.
Definition: road.cpp:23
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Check if road provides effect.
Definition: road.cpp:367
bool is_road_flag_card_near(const struct tile *ptile, enum road_flag_id flag)
Returns TRUE iff any cardinally adjacent tile contains a road with the given flag (does not check pti...
Definition: road.cpp:376
bool is_cardinal_only_road(const struct extra_type *pextra)
Is extra cardinal only road.
Definition: road.cpp:421
bool is_road_flag_near_tile(const struct tile *ptile, enum road_flag_id flag)
Returns TRUE iff any adjacent tile contains a road with the given flag (does not check ptile itself).
Definition: road.cpp:399
enum road_compat road_compat_special(const struct road_type *proad)
Return tile special that used to represent this road type.
Definition: road.cpp:143
int count_river_near_tile(const struct tile *ptile, const struct extra_type *priver)
Count tiles with any river near the tile.
Definition: road.cpp:290
int count_river_type_near_tile(const struct tile *ptile, const struct extra_type *priver, bool percentage)
Count tiles with river of specific type near the tile.
Definition: road.cpp:340
bool road_provides_move_bonus(const struct road_type *proad)
Does road type provide move bonus.
Definition: road.cpp:437
bool player_can_build_road(const struct road_type *proad, const struct player *pplayer, const struct tile *ptile)
Tells if player can build road to tile with suitable unit.
Definition: road.cpp:261
struct road_type * road_by_compat_special(enum road_compat compat)
Return road type represented by given compatibility special, or nullptr if special does not represent...
Definition: road.cpp:152
void road_integrators_cache_init()
Initialize the road integrators cache.
Definition: road.cpp:97
int count_river_type_tile_card(const struct tile *ptile, const struct extra_type *priver, bool percentage)
Count tiles with river of specific type cardinally adjacent to the tile.
Definition: road.cpp:313
Road_type_id road_count()
Return the number of road_types.
Definition: road.cpp:41
void road_type_init(struct extra_type *pextra, int idx)
Initialize road_type structures.
Definition: road.cpp:81
int compare_road_move_cost(const struct extra_type *const *p, const struct extra_type *const *q)
This function is passed to road_type_list_sort() to sort a list of roads in ascending move_cost (fast...
Definition: road.cpp:63
void road_types_free()
Free the memory associated with road types.
Definition: road.cpp:124
bool road_can_be_built(const struct road_type *proad, const struct tile *ptile)
Tells if road can build to tile if all other requirements are met.
Definition: road.cpp:173
struct road_type * road_by_number(Road_type_id id)
Return road type of given id.
Definition: road.cpp:46
struct extra_type * road_extra_get(const struct road_type *proad)
Return extra that road is.
Definition: road.cpp:33
bool can_build_road(struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Tells if unit can build road on tile.
Definition: road.cpp:275
static struct compatibility compat[]
Definition: savecompat.cpp:109
Definition: player.h:231
Definition: road.h:54
struct requirement_vector first_reqs
Definition: road.h:64
enum road_move_mode move_mode
Definition: road.h:58
int id
Definition: road.h:55
struct extra_type_list * integrators
Definition: road.h:72
int tile_bonus[O_LAST]
Definition: road.h:61
int tile_incr_const[O_LAST]
Definition: road.h:59
int tile_incr[O_LAST]
Definition: road.h:60
bv_roads integrates
Definition: road.h:66
bv_road_flags flags
Definition: road.h:67
int move_cost
Definition: road.h:57
enum road_compat compat
Definition: road.h:62
Definition: tile.h:42
Definition: unit.h:134