Freeciv-3.1
Loading...
Searching...
No Matches
road.h
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#ifndef FC__ROAD_H
14#define FC__ROAD_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* common */
21#include "world_object.h"
22
23
24/* Used in the network protocol. */
25#define SPECENUM_NAME road_flag_id
26#define SPECENUM_VALUE0 RF_RIVER
27/* TRANS: this and following strings are 'road flags', which may rarely
28 * be presented to the player in ruleset help text */
29#define SPECENUM_VALUE0NAME N_("River")
30#define SPECENUM_VALUE1 RF_UNRESTRICTED_INFRA
31#define SPECENUM_VALUE1NAME N_("UnrestrictedInfra")
32#define SPECENUM_VALUE2 RF_JUMP_FROM
33#define SPECENUM_VALUE2NAME N_("JumpFrom")
34#define SPECENUM_VALUE3 RF_JUMP_TO
35#define SPECENUM_VALUE3NAME N_("JumpTo")
36#define SPECENUM_COUNT RF_COUNT
37#define SPECENUM_BITVECTOR bv_road_flags
38#include "specenum_gen.h"
39
40/* Used in the network protocol. */
41#define SPECENUM_NAME road_move_mode
42#define SPECENUM_VALUE0 RMM_CARDINAL
43#define SPECENUM_VALUE0NAME "Cardinal"
44#define SPECENUM_VALUE1 RMM_RELAXED
45#define SPECENUM_VALUE1NAME "Relaxed"
46#define SPECENUM_VALUE2 RMM_FAST_ALWAYS
47#define SPECENUM_VALUE2NAME "FastAlways"
48#include "specenum_gen.h"
49
50/* Used in the network protocol. */
51#define SPECENUM_NAME road_gui_type
52#define SPECENUM_VALUE0 ROAD_GUI_ROAD
53#define SPECENUM_VALUE0NAME "Road"
54#define SPECENUM_VALUE1 ROAD_GUI_RAILROAD
55#define SPECENUM_VALUE1NAME "Railroad"
56#define SPECENUM_VALUE2 ROAD_GUI_MAGLEV
57#define SPECENUM_VALUE2NAME "Maglev"
58#define SPECENUM_VALUE3 ROAD_GUI_OTHER
59#define SPECENUM_VALUE3NAME "Other"
60#include "specenum_gen.h"
61
62struct road_type;
63
64/* get 'struct road_type_list' and related functions: */
65#define SPECLIST_TAG road_type
66#define SPECLIST_TYPE struct road_type
67#include "speclist.h"
68
69#define road_type_list_iterate(roadlist, proad) \
70 TYPED_LIST_ITERATE(struct road_type, roadlist, proad)
71#define road_type_list_iterate_end LIST_ITERATE_END
72
73struct extra_type;
74
75struct road_type {
76 int id;
77
79 enum road_move_mode move_mode;
84 enum road_gui_type gui_type;
85
86 struct requirement_vector first_reqs;
87
88 bv_max_extras integrates;
89 bv_road_flags flags;
90
91 /* Same information as in integrates, but iterating through this list is much
92 * faster than through all road types to check for compatible roads. */
93 struct extra_type_list *integrators;
94
96};
97
98#define ROAD_NONE (-1)
99
100/* General road type accessor functions. */
102Road_type_id road_number(const struct road_type *proad);
103
105struct extra_type *road_extra_get(const struct road_type *proad);
106
107enum road_compat road_compat_special(const struct road_type *proad);
109
110struct road_type *road_by_gui_type(enum road_gui_type gui_type);
111
112int count_road_near_tile(struct civ_map *nmap, const struct tile *ptile,
113 const struct road_type *proad);
114int count_river_near_tile(struct civ_map *nmap,
115 const struct tile *ptile,
116 const struct extra_type *priver);
117int count_river_type_tile_card(struct civ_map *nmap,
118 const struct tile *ptile,
119 const struct extra_type *priver,
120 bool percentage);
121int count_river_type_near_tile(struct civ_map *nmap,
122 const struct tile *ptile,
123 const struct extra_type *priver,
124 bool percentage);
125
126/* Functions to operate on a road flag. */
127bool road_has_flag(const struct road_type *proad, enum road_flag_id flag);
128bool is_road_flag_card_near(const struct civ_map *nmap, const struct tile *ptile,
129 enum road_flag_id flag);
130bool is_road_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile,
131 enum road_flag_id flag);
132
133bool road_can_be_built(const struct road_type *proad, const struct tile *ptile);
134bool can_build_road(const struct civ_map *nmap,
135 struct road_type *proad,
136 const struct unit *punit,
137 const struct tile *ptile);
138bool player_can_build_road(const struct civ_map *nmap,
139 const struct road_type *proad,
140 const struct player *pplayer,
141 const struct tile *ptile);
142
143bool is_native_tile_to_road(const struct road_type *proad,
144 const struct tile *ptile);
145
146bool is_cardinal_only_road(const struct extra_type *pextra);
147
148bool road_provides_move_bonus(const struct road_type *proad);
149
150/* Sorting */
151int compare_road_move_cost(const struct extra_type *const *p,
152 const struct extra_type *const *q);
153
154/* Initialization and iteration */
155void road_type_init(struct extra_type *pextra, int idx);
157void road_types_free(void);
158
159#define road_deps_iterate(_reqs, _dep) \
160{ \
161 requirement_vector_iterate(_reqs, preq) { \
162 if (preq->source.kind == VUT_EXTRA \
163 && preq->present \
164 && is_extra_caused_by(preq->source.value.extra, EC_ROAD)) { \
165 struct road_type *_dep = extra_road_get(preq->source.value.extra);
166
167
168#define road_deps_iterate_end \
169 } \
170 } requirement_vector_iterate_end; \
171}
172
173#ifdef __cplusplus
174}
175#endif /* __cplusplus */
176
177#endif /* FC__ROAD_H */
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
int Road_type_id
Definition fc_types.h:354
road_compat
Definition fc_types.h:1105
@ O_LAST
Definition fc_types.h:91
Road_type_id road_count(void)
Definition road.c:50
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:295
struct extra_type * road_extra_get(const struct road_type *proad)
Definition road.c:42
Road_type_id road_number(const struct road_type *proad)
Definition road.c:32
bool road_has_flag(const struct road_type *proad, enum road_flag_id flag)
Definition road.c:410
bool is_cardinal_only_road(const struct extra_type *pextra)
Definition road.c:483
void road_integrators_cache_init(void)
Definition road.c:111
enum road_compat road_compat_special(const struct road_type *proad)
Definition road.c:151
bool is_road_flag_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum road_flag_id flag)
Definition road.c:440
bool road_provides_move_bonus(const struct road_type *proad)
Definition road.c:499
void road_types_free(void)
Definition road.c:134
int count_river_type_tile_card(struct civ_map *nmap, const struct tile *ptile, const struct extra_type *priver, bool percentage)
Definition road.c:356
struct road_type * road_by_number(Road_type_id id)
Definition road.c:58
void road_type_init(struct extra_type *pextra, int idx)
Definition road.c:93
bool is_native_tile_to_road(const struct road_type *proad, const struct tile *ptile)
Definition road.c:460
int compare_road_move_cost(const struct extra_type *const *p, const struct extra_type *const *q)
Definition road.c:75
struct road_type * road_by_compat_special(enum road_compat compat)
Definition road.c:160
bool road_can_be_built(const struct road_type *proad, const struct tile *ptile)
Definition road.c:200
int count_river_type_near_tile(struct civ_map *nmap, const struct tile *ptile, const struct extra_type *priver, bool percentage)
Definition road.c:383
int count_river_near_tile(struct civ_map *nmap, const struct tile *ptile, const struct extra_type *priver)
Definition road.c:334
bool player_can_build_road(const struct civ_map *nmap, const struct road_type *proad, const struct player *pplayer, const struct tile *ptile)
Definition road.c:280
struct road_type * road_by_gui_type(enum road_gui_type gui_type)
Definition road.c:180
bool is_road_flag_card_near(const struct civ_map *nmap, const struct tile *ptile, enum road_flag_id flag)
Definition road.c:419
int count_road_near_tile(struct civ_map *nmap, const struct tile *ptile, const struct road_type *proad)
Definition road.c:313
static struct compatibility compat[]
Definition savecompat.c:101
struct extra_type * self
Definition road.h:95
enum road_gui_type gui_type
Definition road.h:84
struct requirement_vector first_reqs
Definition road.h:86
enum road_move_mode move_mode
Definition road.h:79
int id
Definition road.h:76
struct extra_type_list * integrators
Definition road.h:93
int tile_bonus[O_LAST]
Definition road.h:82
int tile_incr_const[O_LAST]
Definition road.h:80
int tile_incr[O_LAST]
Definition road.h:81
bv_road_flags flags
Definition road.h:89
int move_cost
Definition road.h:78
enum road_compat compat
Definition road.h:83
bv_max_extras integrates
Definition road.h:88
Definition tile.h:49
Definition unit.h:138