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
++) {
47 /****************************************************************************
48 Free the memory associated with styles
49 ****************************************************************************/
50 void styles_free(void)
56 /**************************************************************************
57 Return the number of styles.
58 **************************************************************************/
61 return game
.control
.num_styles
;
64 /**************************************************************************
66 **************************************************************************/
67 int style_number(const struct nation_style
*pstyle
)
69 fc_assert_ret_val(NULL
!= pstyle
, -1);
74 /**************************************************************************
75 Return the style index.
76 **************************************************************************/
77 int style_index(const struct nation_style
*pstyle
)
79 fc_assert_ret_val(NULL
!= pstyle
, -1);
81 return pstyle
- styles
;
84 /****************************************************************************
85 Return style of given id.
86 ****************************************************************************/
87 struct nation_style
*style_by_number(int id
)
89 fc_assert_ret_val(id
>= 0 && id
< game
.control
.num_styles
, NULL
);
94 /**************************************************************************
95 Return the (translated) name of the style.
96 You don't have to free the return pointer.
97 **************************************************************************/
98 const char *style_name_translation(const struct nation_style
*pstyle
)
100 return name_translation_get(&pstyle
->name
);
103 /**************************************************************************
104 Return the (untranslated) rule name of the style.
105 You don't have to free the return pointer.
106 **************************************************************************/
107 const char *style_rule_name(const struct nation_style
*pstyle
)
109 return rule_name_get(&pstyle
->name
);
112 /**************************************************************************
113 Returns style matching rule name or NULL if there is no style
115 **************************************************************************/
116 struct nation_style
*style_by_rule_name(const char *name
)
118 const char *qs
= Qn_(name
);
120 styles_iterate(pstyle
) {
121 if (!fc_strcasecmp(style_rule_name(pstyle
), qs
)) {
124 } styles_iterate_end
;
129 /****************************************************************************
130 Initialise music styles structures.
131 ****************************************************************************/
132 void music_styles_alloc(int count
)
136 music_styles
= fc_malloc(count
* sizeof(struct music_style
));
138 for (i
= 0; i
< count
; i
++) {
139 music_styles
[i
].id
= i
;
140 requirement_vector_init(&(music_styles
[i
].reqs
));
144 /****************************************************************************
145 Free the memory associated with music styles
146 ****************************************************************************/
147 void music_styles_free(void)
149 music_styles_iterate(pmus
) {
150 requirement_vector_free(&(pmus
->reqs
));
151 } music_styles_iterate_end
;
153 FC_FREE(music_styles
);
157 /**************************************************************************
158 Return the music style id.
159 **************************************************************************/
160 int music_style_number(const struct music_style
*pms
)
162 fc_assert_ret_val(NULL
!= pms
, -1);
167 /****************************************************************************
168 Return music style of given id.
169 ****************************************************************************/
170 struct music_style
*music_style_by_number(int id
)
172 fc_assert_ret_val(id
>= 0 && id
< game
.control
.num_music_styles
, NULL
);
174 if (music_styles
== NULL
) {
178 return &music_styles
[id
];
181 /****************************************************************************
182 Return music style for player
183 ****************************************************************************/
184 struct music_style
*player_music_style(struct player
*plr
)
186 struct music_style
*best
= NULL
;
188 music_styles_iterate(pms
) {
189 if (are_reqs_active(plr
, NULL
, NULL
, NULL
, NULL
,
190 NULL
, NULL
, NULL
, NULL
, &pms
->reqs
,
194 } music_styles_iterate_end
;
199 /**************************************************************************
200 Evaluate which style should be used to draw a city.
201 **************************************************************************/
202 int style_of_city(const struct city
*pcity
)
207 /**************************************************************************
208 Return basic city style representing nation style.
209 **************************************************************************/
210 int basic_city_style_for_style(struct nation_style
*pstyle
)
212 enum fc_tristate style_style
;
215 for (i
= game
.control
.styles_count
- 1; i
>= 0; i
--) {
216 style_style
= TRI_MAYBE
;
218 requirement_vector_iterate(&city_styles
[i
].reqs
, preq
) {
219 if (preq
->source
.kind
== VUT_STYLE
220 && preq
->source
.value
.style
== pstyle
221 && style_style
!= TRI_NO
) {
222 style_style
= TRI_YES
;
224 /* No any other requirements allowed at the moment.
225 * TODO: Allow some other reqs */
226 style_style
= TRI_NO
;
229 } requirement_vector_iterate_end
;
231 if (style_style
== TRI_YES
) {
236 if (style_style
== TRI_YES
) {
243 /**************************************************************************
244 Return citystyle of the city.
245 **************************************************************************/
246 int city_style(struct city
*pcity
)
249 struct player
*plr
= city_owner(pcity
);
251 for (i
= game
.control
.styles_count
- 1; i
>= 0; i
--) {
252 if (are_reqs_active(plr
, NULL
, pcity
, NULL
, city_tile(pcity
),
253 NULL
, NULL
, NULL
, NULL
, &city_styles
[i
].reqs
,