Freeciv-3.2
Loading...
Searching...
No Matches
style.c
Go to the documentation of this file.
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)
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
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "mem.h"
20
21/* common */
22#include "fc_types.h"
23#include "game.h"
24#include "name_translation.h"
25
26
27#include "style.h"
28
29static struct nation_style *styles = NULL;
30
31static struct music_style *music_styles = NULL;
32
33/**********************************************************************/
36void styles_alloc(int count)
37{
38 int i;
39
40 styles = fc_malloc(count * sizeof(struct nation_style));
41
42 for (i = 0; i < count; i++) {
43 styles[i].id = i;
45 }
46}
47
48/**********************************************************************/
51void styles_free(void)
52{
54 styles = NULL;
55}
56
57/**********************************************************************/
60int style_count(void)
61{
62 return game.control.num_styles;
63}
64
65/**********************************************************************/
69{
71
72 return pstyle->id;
73}
74
75/**********************************************************************/
79{
81
82 return pstyle - styles;
83}
84
85/**********************************************************************/
89{
91
92 return &styles[id];
93}
94
95/**********************************************************************/
99const char *style_name_translation(const struct nation_style *pstyle)
100{
101 return name_translation_get(&pstyle->name);
102}
103
104/**********************************************************************/
108const char *style_rule_name(const struct nation_style *pstyle)
109{
110 return rule_name_get(&pstyle->name);
111}
112
113/**********************************************************************/
118{
119 const char *qs = Qn_(name);
120
123 return pstyle;
124 }
126
127 return NULL;
128}
129
130/**********************************************************************/
133void music_styles_alloc(int count)
134{
135 int i;
136
137 music_styles = fc_malloc(count * sizeof(struct music_style));
138
139 for (i = 0; i < count; i++) {
140 music_styles[i].id = i;
142 }
143}
144
145/**********************************************************************/
157
158/**********************************************************************/
162{
163 fc_assert_ret_val(NULL != pms, -1);
164
165 return pms->id;
166}
167
168/**********************************************************************/
172{
174
175 if (music_styles == NULL) {
176 return NULL;
177 }
178
179 return &music_styles[id];
180}
181
182/**********************************************************************/
186{
187 struct music_style *best = NULL;
188 const struct req_context plr_context = { .player = plr };
189
192 best = pms;
193 }
195
196 return best;
197}
198
199/**********************************************************************/
202int style_of_city(const struct city *pcity)
203{
204 return pcity->style;
205}
206
207/**********************************************************************/
211{
212 int i;
213
214 for (i = game.control.num_city_styles - 1; i >= 0; i--) {
216
218 if (preq->source.kind == VUT_STYLE
219 && preq->source.value.style == pstyle
220 && style_style != TRI_NO) {
222 } else {
223 /* No any other requirements allowed at the moment.
224 * TODO: Allow some other reqs */
226 break;
227 }
229
230 if (style_style == TRI_YES) {
231 return i;
232 }
233 }
234
235 return -1;
236}
237
238/**********************************************************************/
241int city_style(struct city *pcity)
242{
243 int i;
244 const struct req_context context = {
245 .player = city_owner(pcity),
246 .city = pcity,
247 .tile = city_tile(pcity),
248 };
249
250 for (i = game.control.num_city_styles - 1; i >= 0; i--) {
253 return i;
254 }
255 }
256
257 return 0;
258}
static const struct city struct citystyle * city_styles
Definition city.c:84
#define city_tile(_pcity_)
Definition city.h:564
#define city_owner(_pcity_)
Definition city.h:563
char * incite_cost
Definition comments.c:75
int int id
Definition editgui_g.h:28
struct @21::@22 reqs
@ RPT_CERTAIN
Definition fc_types.h:701
#define Qn_(String)
Definition fcintl.h:89
struct civ_game game
Definition game.c:62
const char * name
Definition inputfile.c:127
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_malloc(sz)
Definition mem.h:34
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
bool are_reqs_active(const struct req_context *context, const struct player *other_player, const struct requirement_vector *reqs, const enum req_problem_type prob_type)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
fc_tristate
Definition shared.h:46
@ TRI_YES
Definition shared.h:46
@ TRI_NO
Definition shared.h:46
@ TRI_MAYBE
Definition shared.h:46
Definition city.h:320
int style
Definition city.h:327
struct tile * tile
Definition city.h:322
struct packet_ruleset_control control
Definition game.h:83
int id
Definition style.h:30
bool ruledit_disabled
Definition style.h:25
const struct player * player
int city_style(struct city *pcity)
Definition style.c:241
void styles_free(void)
Definition style.c:51
struct nation_style * style_by_rule_name(const char *name)
Definition style.c:117
static struct nation_style * styles
Definition style.c:29
struct nation_style * style_by_number(int id)
Definition style.c:88
const char * style_name_translation(const struct nation_style *pstyle)
Definition style.c:99
struct music_style * player_music_style(struct player *plr)
Definition style.c:185
void styles_alloc(int count)
Definition style.c:36
int music_style_number(const struct music_style *pms)
Definition style.c:161
int style_of_city(const struct city *pcity)
Definition style.c:202
struct music_style * music_style_by_number(int id)
Definition style.c:171
const char * style_rule_name(const struct nation_style *pstyle)
Definition style.c:108
int style_number(const struct nation_style *pstyle)
Definition style.c:68
static struct music_style * music_styles
Definition style.c:31
void music_styles_free(void)
Definition style.c:148
void music_styles_alloc(int count)
Definition style.c:133
int style_count(void)
Definition style.c:60
int style_index(const struct nation_style *pstyle)
Definition style.c:78
int basic_city_style_for_style(struct nation_style *pstyle)
Definition style.c:210
#define music_styles_iterate(_p)
Definition style.h:72
#define music_styles_iterate_end
Definition style.h:79
#define styles_iterate(_p)
Definition style.h:46
#define styles_iterate_end
Definition style.h:52
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define FALSE
Definition support.h:47