1 /***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
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)
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 ***********************************************************************/
15 #include <fc_config.h>
24 #include "name_translation.h"
29 static struct nation_style
*styles
= NULL
;
31 static struct music_style
*music_styles
= NULL
;
33 /****************************************************************************
34 Initialise styles structures.
35 ****************************************************************************/
36 void styles_alloc(int count
)
40 styles
= fc_malloc(count
* sizeof(struct nation_style
));
42 for (i
= 0; i
< count
; i
++) {
44 styles
[i
].disabled
= FALSE
;
48 /****************************************************************************
49 Free the memory associated with styles
50 ****************************************************************************/
51 void styles_free(void)
57 /**************************************************************************
58 Return the number of styles.
59 **************************************************************************/
62 return game
.control
.num_styles
;
65 /**************************************************************************
67 **************************************************************************/
68 int style_number(const struct nation_style
*pstyle
)
70 fc_assert_ret_val(NULL
!= pstyle
, -1);
75 /**************************************************************************
76 Return the style index.
77 **************************************************************************/
78 int style_index(const struct nation_style
*pstyle
)
80 fc_assert_ret_val(NULL
!= pstyle
, -1);
82 return pstyle
- styles
;
85 /****************************************************************************
86 Return style of given id.
87 ****************************************************************************/
88 struct nation_style
*style_by_number(int id
)
90 fc_assert_ret_val(id
>= 0 && id
< game
.control
.num_styles
, NULL
);
95 /**************************************************************************
96 Return the (translated) name of the style.
97 You don't have to free the return pointer.
98 **************************************************************************/
99 const char *style_name_translation(const struct nation_style
*pstyle
)
101 return name_translation_get(&pstyle
->name
);
104 /**************************************************************************
105 Return the (untranslated) rule name of the style.
106 You don't have to free the return pointer.
107 **************************************************************************/
108 const char *style_rule_name(const struct nation_style
*pstyle
)
110 return rule_name_get(&pstyle
->name
);
113 /**************************************************************************
114 Returns style matching rule name or NULL if there is no style
116 **************************************************************************/
117 struct nation_style
*style_by_rule_name(const char *name
)
119 const char *qs
= Qn_(name
);
121 styles_iterate(pstyle
) {
122 if (!fc_strcasecmp(style_rule_name(pstyle
), qs
)) {
125 } styles_iterate_end
;
130 /****************************************************************************
131 Initialise music styles structures.
132 ****************************************************************************/
133 void music_styles_alloc(int count
)
137 music_styles
= fc_malloc(count
* sizeof(struct music_style
));
139 for (i
= 0; i
< count
; i
++) {
140 music_styles
[i
].id
= i
;
141 requirement_vector_init(&(music_styles
[i
].reqs
));
145 /****************************************************************************
146 Free the memory associated with music styles
147 ****************************************************************************/
148 void music_styles_free(void)
150 music_styles_iterate(pmus
) {
151 requirement_vector_free(&(pmus
->reqs
));
152 } music_styles_iterate_end
;
154 FC_FREE(music_styles
);
158 /**************************************************************************
159 Return the music style id.
160 **************************************************************************/
161 int music_style_number(const struct music_style
*pms
)
163 fc_assert_ret_val(NULL
!= pms
, -1);
168 /****************************************************************************
169 Return music style of given id.
170 ****************************************************************************/
171 struct music_style
*music_style_by_number(int id
)
173 fc_assert_ret_val(id
>= 0 && id
< game
.control
.num_music_styles
, NULL
);
175 if (music_styles
== NULL
) {
179 return &music_styles
[id
];
182 /****************************************************************************
183 Return music style for player
184 ****************************************************************************/
185 struct music_style
*player_music_style(struct player
*plr
)
187 struct music_style
*best
= NULL
;
189 music_styles_iterate(pms
) {
190 if (are_reqs_active(plr
, NULL
, NULL
, NULL
, NULL
,
191 NULL
, NULL
, NULL
, NULL
, NULL
, &pms
->reqs
,
195 } music_styles_iterate_end
;
200 /**************************************************************************
201 Evaluate which style should be used to draw a city.
202 **************************************************************************/
203 int style_of_city(const struct city
*pcity
)
208 /**************************************************************************
209 Return basic city style representing nation style.
210 **************************************************************************/
211 int basic_city_style_for_style(struct nation_style
*pstyle
)
213 enum fc_tristate style_style
;
216 for (i
= game
.control
.styles_count
- 1; i
>= 0; i
--) {
217 style_style
= TRI_MAYBE
;
219 requirement_vector_iterate(&city_styles
[i
].reqs
, preq
) {
220 if (preq
->source
.kind
== VUT_STYLE
221 && preq
->source
.value
.style
== pstyle
222 && style_style
!= TRI_NO
) {
223 style_style
= TRI_YES
;
225 /* No any other requirements allowed at the moment.
226 * TODO: Allow some other reqs */
227 style_style
= TRI_NO
;
230 } requirement_vector_iterate_end
;
232 if (style_style
== TRI_YES
) {
237 if (style_style
== TRI_YES
) {
244 /**************************************************************************
245 Return citystyle of the city.
246 **************************************************************************/
247 int city_style(struct city
*pcity
)
250 struct player
*plr
= city_owner(pcity
);
252 for (i
= game
.control
.styles_count
- 1; i
>= 0; i
--) {
253 if (are_reqs_active(plr
, NULL
, pcity
, NULL
, city_tile(pcity
),
254 NULL
, NULL
, NULL
, NULL
, NULL
,
255 &city_styles
[i
].reqs
, RPT_CERTAIN
)) {