~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to common/nation.h

  • Committer: Package Import Robot
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2011-08-28 22:40:00 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: package-import@ubuntu.com-20110828224000-j2r1erewlem25dox
Tags: 2.3.0-1
[ Karl Goetz ]
* New upstream version.
* Fix themes_sdl_use_system_fonts.diff to apply cleanly on 2.3.0
* Massage work_around_unity_induced_breakage.diff to get it
  applying to the new codebase (The patch assumes commits made
  after 2.3.0 was tagged upstream).

[ Clint Adams ]
* Fudge build system to think there is no libtool mismatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#ifndef FC__NATION_H
14
14
#define FC__NATION_H
15
15
 
16
 
#include "shared.h"             /* MAX_LEN_NAME */
 
16
/* utility */
 
17
#include "iterator.h"
17
18
 
 
19
/* common */
18
20
#include "fc_types.h"
 
21
#include "name_translation.h"
19
22
#include "terrain.h"            /* MAX_NUM_TERRAINS */
20
23
 
21
 
#define MAX_NUM_TECH_GOALS 10
 
24
#define NO_NATION_SELECTED (NULL)
22
25
 
23
26
/* Changing this value will break network compatibility. */
24
 
#define NO_NATION_SELECTED (NULL)
25
 
 
26
27
#define NATION_NONE -1
27
28
#define NATION_ANY  -2
28
29
 
29
 
/* 
30
 
 * Purpose of this constant is to catch invalid ruleset and network
31
 
 * data and to allow static allocation of the nation_info packet.
32
 
 */
33
 
#define MAX_NUM_LEADERS MAX_NUM_ITEMS
34
 
 
35
 
#define MAX_NUM_NATION_GROUPS 128
36
 
 
37
 
/*
38
 
 * The nation_city structure holds information about a default choice for
39
 
 * the city name.  The "name" field is, of course, just the name for
40
 
 * the city.  The "river" and "terrain" fields are entries recording
41
 
 * whether the terrain is present near the city - we give higher priority
42
 
 * to cities which have matching terrain.  In the case of a river we only
43
 
 * care if the city is _on_ the river, for other terrain features we give
44
 
 * the bonus if the city is close to the terrain.  Both of these entries
45
 
 * may hold a value of 0 (no preference), 1 (city likes the terrain), or -1
46
 
 * (city doesn't like the terrain).
47
 
 *
48
 
 * This is controlled through the nation's ruleset like this:
49
 
 *   cities = "Washington (ocean, river, swamp)", "New York (!mountains)"
50
 
 */
51
 
typedef int ternary;
52
 
 
53
 
struct nation_city {
54
 
  char *name;
55
 
  ternary river;
56
 
  ternary terrain[MAX_NUM_TERRAINS];    
57
 
};
58
 
 
59
 
struct nation_leader {
60
 
  char *name;
61
 
  bool is_male;
62
 
};
63
 
 
64
 
struct nation_group {
65
 
  int item_number;
66
 
 
67
 
  char name[MAX_LEN_NAME];
68
 
  
69
 
  /* How much the AI will try to select a nation in the same group */
70
 
  int match;
71
 
};
 
30
/* Nation city (server only). */
 
31
struct nation_city;
 
32
 
 
33
enum nation_city_preference {
 
34
  NCP_DISLIKE = -1,
 
35
  NCP_NONE = 0,
 
36
  NCP_LIKE = 1
 
37
};
 
38
 
 
39
#define SPECLIST_TAG nation_city
 
40
#define SPECLIST_TYPE struct nation_city
 
41
#include "speclist.h"
 
42
#define nation_city_list_iterate(citylist, pncity)                          \
 
43
  TYPED_LIST_ITERATE(struct nation_city, citylist, pncity)
 
44
#define nation_city_list_iterate_end LIST_ITERATE_END
 
45
 
 
46
/* Nation leader. */
 
47
struct nation_leader;
 
48
#define SPECLIST_TAG nation_leader
 
49
#define SPECLIST_TYPE struct nation_leader
 
50
#include "speclist.h"
 
51
#define nation_leader_list_iterate(leaderlist, pleader)                     \
 
52
  TYPED_LIST_ITERATE(struct nation_leader, leaderlist, pleader)
 
53
#define nation_leader_list_iterate_end LIST_ITERATE_END
 
54
 
 
55
/* Nation group. */
 
56
struct nation_group;
 
57
#define SPECLIST_TAG nation_group
 
58
#define SPECLIST_TYPE struct nation_group
 
59
#include "speclist.h"
 
60
#define nation_group_list_iterate(grouplist, pgroup)                        \
 
61
  TYPED_LIST_ITERATE(struct nation_group, grouplist, pgroup)
 
62
#define nation_group_list_iterate_end LIST_ITERATE_END
 
63
 
 
64
/* Nation list. */
 
65
struct nation_type;
 
66
#define SPECLIST_TAG nation
 
67
#define SPECLIST_TYPE struct nation_type
 
68
#include "speclist.h"
 
69
#define nation_list_iterate(nationlist, pnation)                            \
 
70
  TYPED_LIST_ITERATE(struct nation_type, nationlist, pnation)
 
71
#define nation_list_iterate_end LIST_ITERATE_END
 
72
 
 
73
/* Nation hash. */
 
74
#define SPECHASH_TAG nation
 
75
#define SPECHASH_KEY_TYPE struct nation_type *
 
76
#define SPECHASH_DATA_TYPE void *
 
77
#include "spechash.h"
 
78
#define nation_hash_iterate(nationhash, pnation)                            \
 
79
  TYPED_HASH_KEYS_ITERATE(struct nation_type *, nationhash, pnation)
 
80
#define nation_hash_iterate_end HASH_KEYS_ITERATE_END
72
81
 
73
82
/* Pointer values are allocated on load then freed in free_nations(). */
74
83
struct nation_type {
77
86
  struct name_translation noun_plural;
78
87
  char flag_graphic_str[MAX_LEN_NAME];
79
88
  char flag_graphic_alt[MAX_LEN_NAME];
80
 
  int  leader_count;
81
 
  struct nation_leader *leaders;
 
89
  struct nation_leader_list *leaders;
82
90
  int city_style;
83
 
  struct nation_city *city_names;       /* The default city names. */
84
91
  char *legend;                         /* may be empty */
85
92
 
86
93
  bool is_playable;
87
94
  enum barbarian_type barb_type;
88
95
 
89
 
  /* civilwar_nations is a NO_NATION_SELECTED-terminated list of index of
90
 
   * the nations that can fork from this one.  parent_nations is the inverse
91
 
   * of this array.  Server only. */
92
 
  struct nation_type **civilwar_nations;
93
 
  struct nation_type **parent_nations;
94
 
 
95
 
  /* Items given to this nation at game start.  Server only. */
96
 
  int init_techs[MAX_NUM_TECH_LIST];
97
 
  int init_buildings[MAX_NUM_BUILDING_LIST];
98
 
  struct government *init_government;
99
 
  struct unit_type *init_units[MAX_NUM_UNIT_LIST];
100
 
 
101
 
  /* Groups which this nation is assigned to */
102
 
  int num_groups;
103
 
  struct nation_group **groups;
104
 
  
105
 
  /* Nations which we don't want in the same game.
106
 
   * For example, British and English.
107
 
   * Terminated with NO_NATION_SELECTED. */
108
 
  struct nation_type **conflicts_with;
109
 
 
110
96
  /* Unavailable nations aren't allowed to be chosen in the scenario. */
111
97
  bool is_available;
112
98
 
 
99
  /* Groups which this nation is assigned to */
 
100
  struct nation_group_list *groups;
 
101
 
113
102
  struct player *player; /* Who's using the nation, or NULL. */
 
103
 
 
104
  union {
 
105
    struct {
 
106
      /* Only used in the server (./ai/ and ./server/). */
 
107
 
 
108
      struct nation_city_list *default_cities;
 
109
 
 
110
      /* 'civilwar_nations' is a list of the nations that can fork from
 
111
       * this one. 'parent_nations' is the inverse of this list. */
 
112
      struct nation_list *civilwar_nations;
 
113
      struct nation_list *parent_nations;
 
114
 
 
115
      /* Nations which we don't want in the same game. For example,
 
116
       * British and English. */
 
117
      struct nation_list *conflicts_with;
 
118
 
 
119
      /* Items given to this nation at game start. */
 
120
      int init_techs[MAX_NUM_TECH_LIST];
 
121
      int init_buildings[MAX_NUM_BUILDING_LIST];
 
122
      struct government *init_government;
 
123
      struct unit_type *init_units[MAX_NUM_UNIT_LIST];
 
124
    } server;
 
125
 
 
126
    struct {
 
127
      /* Only used at the client. */
 
128
      /* Nothing yet. */
 
129
    } client;
 
130
  };
114
131
};
115
132
 
116
133
/* General nation accessor functions. */
123
140
struct nation_type *nation_of_city(const struct city *pcity);
124
141
struct nation_type *nation_of_unit(const struct unit *punit);
125
142
 
126
 
struct nation_type *find_nation_by_rule_name(const char *name);
127
 
struct nation_type *find_nation_by_translated_name(const char *name);
 
143
struct nation_type *nation_by_rule_name(const char *name);
 
144
struct nation_type *nation_by_translated_name(const char *name);
128
145
 
129
146
const char *nation_rule_name(const struct nation_type *pnation);
130
147
 
131
 
const char *nation_adjective_translation(struct nation_type *pnation);
 
148
const char *nation_adjective_translation(const struct nation_type *pnation);
132
149
const char *nation_adjective_for_player(const struct player *pplayer);
133
 
const char *nation_plural_translation(struct nation_type *pnation);
 
150
const char *nation_plural_translation(const struct nation_type *pnation);
134
151
const char *nation_plural_for_player(const struct player *pplayer);
135
152
 
136
153
int city_style_of_nation(const struct nation_type *nation);
142
159
                                  const struct player *pplayer);
143
160
 
144
161
/* General nation leader accessor functions. */
145
 
struct nation_leader *get_nation_leaders(const struct nation_type *nation, int *dim);
146
 
struct nation_type **get_nation_civilwar(const struct nation_type *nation);
147
 
bool get_nation_leader_sex(const struct nation_type *nation,
148
 
                           const char *name);
149
 
bool check_nation_leader_name(const struct nation_type *nation,
150
 
                              const char *name);
 
162
const struct nation_leader_list *
 
163
nation_leaders(const struct nation_type *pnation);
 
164
struct nation_leader *nation_leader_new(struct nation_type *pnation,
 
165
                                        const char *name, bool is_male);
 
166
struct nation_leader *
 
167
nation_leader_by_name(const struct nation_type *pnation, const char *name);
 
168
const char *nation_leader_name(const struct nation_leader *pleader);
 
169
bool nation_leader_is_male(const struct nation_leader *pleader);
 
170
 
 
171
/* General nation city accessor functions. */
 
172
struct terrain;
 
173
 
 
174
const struct nation_city_list *
 
175
nation_cities(const struct nation_type *pnation);
 
176
struct nation_city *nation_city_new(struct nation_type *pnation,
 
177
                                    const char *name);
 
178
 
 
179
const char *nation_city_name(const struct nation_city *pncity);
 
180
 
 
181
enum nation_city_preference
 
182
nation_city_preference_revert(enum nation_city_preference prefer);
 
183
void nation_city_set_terrain_preference(struct nation_city *pncity,
 
184
                                        const struct terrain *pterrain,
 
185
                                        enum nation_city_preference prefer);
 
186
void nation_city_set_river_preference(struct nation_city *pncity,
 
187
                                      enum nation_city_preference prefer);
 
188
enum nation_city_preference
 
189
nation_city_terrain_preference(const struct nation_city *pncity,
 
190
                               const struct terrain *pterrain);
 
191
enum nation_city_preference
 
192
nation_city_river_preference(const struct nation_city *pncity);
151
193
 
152
194
/* General nation group accessor routines */
153
195
int nation_group_count(void);
154
196
int nation_group_index(const struct nation_group *pgroup);
155
197
int nation_group_number(const struct nation_group *pgroup);
156
198
 
 
199
struct nation_group *nation_group_new(const char *name);
157
200
struct nation_group *nation_group_by_number(int id);
158
 
struct nation_group *find_nation_group_by_rule_name(const char *name);
159
 
 
160
 
bool is_nation_in_group(struct nation_type *nation,
161
 
                        struct nation_group *group);
 
201
struct nation_group *nation_group_by_rule_name(const char *name);
 
202
 
 
203
void nation_group_set_match(struct nation_group *pgroup, int match);
 
204
 
 
205
const char *nation_group_untranslated_name(const struct nation_group *pgroup);
 
206
const char *nation_group_rule_name(const struct nation_group *pgroup);
 
207
const char *nation_group_name_translation(const struct nation_group *pgroup);
 
208
 
 
209
bool nation_is_in_group(const struct nation_type *pnation,
 
210
                        const struct nation_group *pgroup);
162
211
 
163
212
/* Initialization and iteration */
 
213
void nation_groups_init(void);
164
214
void nation_groups_free(void);
165
 
struct nation_group *add_new_nation_group(const char *name);
166
 
 
167
 
struct nation_group *nation_group_array_first(void);
168
 
const struct nation_group *nation_group_array_last(void);
169
 
 
170
 
#define nation_groups_iterate(_p)                                       \
171
 
{                                                                       \
172
 
  struct nation_group *_p = nation_group_array_first();                 \
173
 
  if (NULL != _p) {                                                     \
174
 
    for (; _p <= nation_group_array_last(); _p++) {
175
 
 
176
 
#define nation_groups_iterate_end                                       \
177
 
    }                                                                   \
178
 
  }                                                                     \
179
 
}
 
215
 
 
216
struct nation_group_iter;
 
217
size_t nation_group_iter_sizeof(void);
 
218
struct iterator *nation_group_iter_init(struct nation_group_iter *it);
 
219
 
 
220
#define nation_groups_iterate(NAME_pgroup)                                  \
 
221
  generic_iterate(struct nation_group_iter, struct nation_group *,          \
 
222
                  NAME_pgroup, nation_group_iter_sizeof,                    \
 
223
                  nation_group_iter_init)
 
224
#define nation_groups_iterate_end generic_iterate_end
180
225
 
181
226
/* Initialization and iteration */
182
227
void nations_alloc(int num);
183
228
void nations_free(void);
184
 
void nation_city_names_free(struct nation_city *city_names);
185
 
 
186
 
#include "iterator.h"
 
229
 
 
230
int nations_match(const struct nation_type *pnation1,
 
231
                  const struct nation_type *pnation2,
 
232
                  bool ignore_conflicts);
 
233
 
187
234
struct nation_iter;
188
235
size_t nation_iter_sizeof(void);
189
236
struct iterator *nation_iter_init(struct nation_iter *it);