Freeciv-3.4
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 = nullptr;
30
31static struct music_style *music_styles = nullptr;
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{
53 free(styles);
54 styles = nullptr;
55}
56
57/**********************************************************************/
60int style_count(void)
61{
62 return game.control.num_styles;
63}
64
65/**********************************************************************/
69{
70 return pstyle->id;
71}
72
73/**********************************************************************/
77{
78 return pstyle - styles;
79}
80
81/**********************************************************************/
85{
86 fc_assert_ret_val(id >= 0 && id < game.control.num_styles, nullptr);
87
88 return &styles[id];
89}
90
91/**********************************************************************/
95const char *style_name_translation(const struct nation_style *pstyle)
96{
97 return name_translation_get(&pstyle->name);
98}
99
100/**********************************************************************/
104const char *style_rule_name(const struct nation_style *pstyle)
105{
106 return rule_name_get(&pstyle->name);
107}
108
109/**********************************************************************/
114{
115 const char *qs = Qn_(name);
116
119 return pstyle;
120 }
122
123 return nullptr;
124}
125
126/**********************************************************************/
129void music_styles_alloc(int count)
130{
131 int i;
132
133 music_styles = fc_malloc(count * sizeof(struct music_style));
134
135 for (i = 0; i < count; i++) {
136 music_styles[i].id = i;
138 }
139}
140
141/**********************************************************************/
145{
149
151 music_styles = nullptr;
152}
153
154/**********************************************************************/
158{
159 return pms->id;
160}
161
162/**********************************************************************/
166{
167 fc_assert_ret_val(id >= 0 && id < game.control.num_music_styles, nullptr);
168
169 if (music_styles == nullptr) {
170 return nullptr;
171 }
172
173 return &music_styles[id];
174}
175
176/**********************************************************************/
180{
181 struct music_style *best = nullptr;
182 const struct req_context plr_context = { .player = plr };
183
185 if (are_reqs_active(&plr_context, nullptr, &pms->reqs, RPT_CERTAIN)) {
186 best = pms;
187 }
189
190 return best;
191}
192
193/**********************************************************************/
196int style_of_city(const struct city *pcity)
197{
198 return pcity->style;
199}
200
201/**********************************************************************/
205{
206 int i;
207
208 for (i = game.control.num_city_styles - 1; i >= 0; i--) {
210
212 if (preq->source.kind == VUT_STYLE
213 && preq->source.value.style == pstyle
214 && style_style != TRI_NO) {
216 } else {
217 /* No any other requirements allowed at the moment.
218 * TODO: Allow some other reqs */
220 break;
221 }
223
224 if (style_style == TRI_YES) {
225 return i;
226 }
227 }
228
229 return -1;
230}
231
232/**********************************************************************/
236{
237 int i;
238 const struct req_context context = {
240 .city = pcity,
241 .tile = city_tile(pcity),
242 };
243
244 for (i = game.control.num_city_styles - 1; i >= 0; i--) {
245 if (are_reqs_active(&context, nullptr,
247 return i;
248 }
249 }
250
251 return 0;
252}
static const struct city struct citystyle * city_styles
Definition city.c:84
#define city_tile(_pcity_)
Definition city.h:565
#define city_owner(_pcity_)
Definition city.h:564
char * incite_cost
Definition comments.c:77
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
int int id
Definition editgui_g.h:28
struct @22::@23 reqs
@ RPT_CERTAIN
Definition fc_types.h:516
#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:195
#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 req_context *other_context, 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:318
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
struct tile * tile
Definition unit.h:142
int city_style(struct city *pcity)
Definition style.c:235
void styles_free(void)
Definition style.c:51
struct nation_style * style_by_rule_name(const char *name)
Definition style.c:113
static struct nation_style * styles
Definition style.c:29
struct nation_style * style_by_number(int id)
Definition style.c:84
const char * style_name_translation(const struct nation_style *pstyle)
Definition style.c:95
struct music_style * player_music_style(struct player *plr)
Definition style.c:179
void styles_alloc(int count)
Definition style.c:36
int music_style_number(const struct music_style *pms)
Definition style.c:157
int style_of_city(const struct city *pcity)
Definition style.c:196
struct music_style * music_style_by_number(int id)
Definition style.c:165
const char * style_rule_name(const struct nation_style *pstyle)
Definition style.c:104
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:144
void music_styles_alloc(int count)
Definition style.c:129
int style_count(void)
Definition style.c:60
int style_index(const struct nation_style *pstyle)
Definition style.c:76
int basic_city_style_for_style(struct nation_style *pstyle)
Definition style.c:204
#define music_styles_iterate(_p)
Definition style.h:75
#define music_styles_iterate_end
Definition style.h:82
#define styles_iterate(_p)
Definition style.h:48
#define styles_iterate_end
Definition style.h:54
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define FALSE
Definition support.h:47