Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/specialist.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
specialist.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 "fcintl.h"
20#include "log.h"
21#include "string_vector.h"
22
23/* common */
24#include "city.h"
25#include "effects.h"
26#include "game.h"
27
28#include "specialist.h"
29
30 struct specialist specialists[SP_MAX];
31 int default_specialist;
32
33/**********************************************************************/
36 void specialists_init(void)
37{
38 int i;
39
40 for (i = 0; i < ARRAY_SIZE(specialists); i++) {
41 struct specialist *p = &specialists[i];
42
43 p->item_number = i;
44 p->ruledit_disabled = FALSE;
45
46 requirement_vector_init(&p->reqs);
47 }
48}
49
50/**********************************************************************/
53 void specialists_free(void)
54{
55 int i;
56
57 for (i = 0; i < ARRAY_SIZE(specialists); i++) {
58 struct specialist *p = &specialists[i];
59
60 requirement_vector_free(&p->reqs);
61 if (NULL != p->helptext) {
62 strvec_destroy(p->helptext);
63 p->helptext = NULL;
64 }
65 }
66}
67
68/**********************************************************************/
71 Specialist_type_id specialist_count(void)
72{
73 return game.control.num_specialist_types;
74}
75
76/**********************************************************************/
82 Specialist_type_id specialist_index(const struct specialist *sp)
83{
84 fc_assert_ret_val(NULL != sp, -1);
85 return sp - specialists;
86}
87
88/**********************************************************************/
91 Specialist_type_id specialist_number(const struct specialist *sp)
92{
93 fc_assert_ret_val(NULL != sp, -1);
94 return sp->item_number;
95}
96
97/**********************************************************************/
100 struct specialist *specialist_by_number(const Specialist_type_id id)
101{
102 if (id < 0 || id >= game.control.num_specialist_types) {
103 return NULL;
104 }
105 return &specialists[id];
106}
107
108/**********************************************************************/
112 struct specialist *specialist_by_rule_name(const char *name)
113{
114 const char *qname = Qn_(name);
115
116 specialist_type_iterate(i) {
117 struct specialist *sp = specialist_by_number(i);
118 if (0 == fc_strcasecmp(specialist_rule_name(sp), qname)) {
119 return sp;
120 }
121 } specialist_type_iterate_end;
122
123 return NULL;
124}
125
126/**********************************************************************/
130 struct specialist *specialist_by_translated_name(const char *name)
131{
132 specialist_type_iterate(i) {
133 struct specialist *sp = specialist_by_number(i);
134 if (0 == strcmp(specialist_plural_translation(sp), name)) {
135 return sp;
136 }
137 } specialist_type_iterate_end;
138
139 return NULL;
140}
141
142/**********************************************************************/
146 const char *specialist_rule_name(const struct specialist *sp)
147{
148 return rule_name_get(&sp->name);
149}
150
151/**********************************************************************/
155 const char *specialist_plural_translation(const struct specialist *sp)
156{
157 return name_translation_get(&sp->name);
158}
159
160/**********************************************************************/
164 const char *specialist_abbreviation_translation(const struct specialist *sp)
165{
166 return name_translation_get(&sp->abbreviation);
167}
168
169/**********************************************************************/
174 const char *specialists_abbreviation_string(void)
175{
176 static char buf[5 * SP_MAX];
177
178 buf[0] = '\0';
179
180 specialist_type_iterate(sp) {
181 char *separator = (buf[0] == '\0') ? "" : "/";
182
183 cat_snprintf(buf, sizeof(buf), "%s%s", separator,
184 specialist_abbreviation_translation(specialist_by_number(sp)));
185 } specialist_type_iterate_end;
186
187 return buf;
188}
189
190/**********************************************************************/
199 const char *specialists_string(const citizens *specialist_list)
200{
201 static char buf[5 * SP_MAX];
202
203 buf[0] = '\0';
204
205 specialist_type_iterate(sp) {
206 char *separator = (buf[0] == '\0') ? "" : "/";
207
208 cat_snprintf(buf, sizeof(buf), "%s%d", separator, specialist_list[sp]);
209 } specialist_type_iterate_end;
210
211 return buf;
212}
213
214/**********************************************************************/
217 int get_specialist_output(const struct city *pcity,
218 Specialist_type_id sp, Output_type_id otype)
219{
220 struct specialist *pspecialist = &specialists[sp];
221 struct output_type *poutput = get_output_type(otype);
222
223 return get_city_specialist_output_bonus(pcity, pspecialist, poutput,
224 EFT_SPECIALIST_OUTPUT);
225}
get_output_type
struct output_type * get_output_type(Output_type_id output)
Definition city.c:632
city.h
id
int int id
Definition editgui_g.h:28
get_city_specialist_output_bonus
int get_city_specialist_output_bonus(const struct city *pcity, const struct specialist *pspecialist, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:807
effects.h
citizens
unsigned char citizens
Definition fc_types.h:358
SP_MAX
#define SP_MAX
Definition fc_types.h:379
Specialist_type_id
int Specialist_type_id
Definition fc_types.h:345
Output_type_id
enum output_type_id Output_type_id
Definition fc_types.h:348
fcintl.h
Qn_
#define Qn_(String)
Definition fcintl.h:89
game
struct civ_game game
Definition game.c:57
game.h
name
const char * name
Definition inputfile.c:127
log.h
fc_assert_ret_val
#define fc_assert_ret_val(condition, val)
Definition log.h:194
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
ARRAY_SIZE
#define ARRAY_SIZE(x)
Definition shared.h:85
specialists
struct specialist specialists[SP_MAX]
Definition specialist.c:30
specialists_abbreviation_string
const char * specialists_abbreviation_string(void)
Definition specialist.c:174
specialist_by_rule_name
struct specialist * specialist_by_rule_name(const char *name)
Definition specialist.c:112
specialist_by_number
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:100
specialist_index
Specialist_type_id specialist_index(const struct specialist *sp)
Definition specialist.c:82
specialist_number
Specialist_type_id specialist_number(const struct specialist *sp)
Definition specialist.c:91
specialist_rule_name
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
default_specialist
int default_specialist
Definition specialist.c:31
specialist_plural_translation
const char * specialist_plural_translation(const struct specialist *sp)
Definition specialist.c:155
specialists_free
void specialists_free(void)
Definition specialist.c:53
specialist_count
Specialist_type_id specialist_count(void)
Definition specialist.c:71
specialist_abbreviation_translation
const char * specialist_abbreviation_translation(const struct specialist *sp)
Definition specialist.c:164
specialists_init
void specialists_init(void)
Definition specialist.c:36
specialists_string
const char * specialists_string(const citizens *specialist_list)
Definition specialist.c:199
specialist_by_translated_name
struct specialist * specialist_by_translated_name(const char *name)
Definition specialist.c:130
get_specialist_output
int get_specialist_output(const struct city *pcity, Specialist_type_id sp, Output_type_id otype)
Definition specialist.c:217
specialist.h
specialist_type_iterate_end
#define specialist_type_iterate_end
Definition specialist.h:79
specialist_type_iterate
#define specialist_type_iterate(sp)
Definition specialist.h:73
strvec_destroy
void strvec_destroy(struct strvec *psv)
Definition string_vector.c:71
string_vector.h
city
Definition city.h:309
civ_game::control
struct packet_ruleset_control control
Definition game.h:83
output_type
Definition city.h:251
packet_ruleset_control::num_specialist_types
int num_specialist_types
Definition packets_gen.h:1474
specialist
Definition specialist.h:29
specialist::item_number
int item_number
Definition specialist.h:30
specialist::reqs
struct requirement_vector reqs
Definition specialist.h:38
specialist::ruledit_disabled
bool ruledit_disabled
Definition specialist.h:33
specialist::helptext
struct strvec * helptext
Definition specialist.h:40
specialist::name
struct name_translation name
Definition specialist.h:31
specialist::abbreviation
struct name_translation abbreviation
Definition specialist.h:32
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
FALSE
#define FALSE
Definition support.h:47