Freeciv-3.4
Loading...
Searching...
No Matches
counters.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
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#include <stdlib.h>
19
20/* common */
21#include "game.h"
22
23/* utility */
24#include "fcintl.h"
25
26#include "counters.h"
27
28/* All (of each type) counters array + related data.
29 * The number of length of data in this array
30 * game kept in game control packet/struct */
32
33/* City counters array + related data */
36
37/************************************************************************/
40void counters_init(void)
41{
43
45}
46
47
48/************************************************************************/
51void counters_free(void)
52{
53 /* TODO: Is freeing translated name needed? If is, write the right
54 * code here
55 */
56
57 int i;
58
59 for (i = 0; i < game.control.num_counters; i++) {
60
61 if (counters[i].helptext != nullptr) {
63 counters[i].helptext = nullptr;
64 }
65 }
66
69}
70
71/************************************************************************/
78
79/************************************************************************/
82struct counter *counter_by_id(int id)
83{
85
86 return &counters[id];
87}
88
89/************************************************************************/
101
102/************************************************************************/
106{
107 fc_assert_ret_val(pcount != nullptr, -1);
108
109 return pcount - counters;
110}
111
112/************************************************************************/
117{
118 int i;
119 fc_assert_ret_val(name != nullptr, nullptr);
120 fc_assert_ret_val('\0' != name[0], nullptr);
121
122 for (i = 0; i < game.control.num_counters; i++)
123 {
125 {
126 return &counters[i];
127 }
128 }
129
130 return nullptr;
131}
132
133/************************************************************************/
138{
139 int i;
140 fc_assert_ret_val(name != nullptr, nullptr);
141 fc_assert_ret_val('\0' != name[0], nullptr);
142
143 for (i = 0; i < game.control.num_counters; i++)
144 {
145 if (0 == fc_strcasecmp(name,
147 {
148 return &counters[i];
149 }
150 }
151
152 return nullptr;
153}
154
155/************************************************************************/
158const char *counter_name_translation(const struct counter *counter)
159{
161}
162
163/************************************************************************/
166const char *counter_rule_name(struct counter *pcount)
167{
168 fc_assert_ret_val(pcount != nullptr, nullptr);
169
170 return rule_name_get(&pcount->name);
171}
172
173/************************************************************************/
176int counter_index(const struct counter *pcount)
177{
178 fc_assert_ret_val(pcount != nullptr, -1);
179
180 return pcount->index;
181}
182
183/************************************************************************/
187{
188 switch (target)
189 {
190 case CTGT_CITY:
191 return counters_city[index];
192 }
193
194 return nullptr;
195}
char * incite_cost
Definition comments.c:77
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:186
static int number_city_counters
Definition counters.c:35
int counter_index(const struct counter *pcount)
Definition counters.c:176
void counters_init(void)
Definition counters.c:40
const char * counter_name_translation(const struct counter *counter)
Definition counters.c:158
struct counter * counter_by_rule_name(const char *name)
Definition counters.c:116
struct counter * counter_by_translated_name(const char *name)
Definition counters.c:137
const char * counter_rule_name(struct counter *pcount)
Definition counters.c:166
int counters_get_city_counters_count(void)
Definition counters.c:74
static struct counter counters[MAX_COUNTERS]
Definition counters.c:31
void counters_free(void)
Definition counters.c:51
struct counter * counter_by_id(int id)
Definition counters.c:82
int counter_id(struct counter *pcount)
Definition counters.c:105
static struct counter * counters_city[MAX_COUNTERS]
Definition counters.c:34
void attach_city_counter(struct counter *counter)
Definition counters.c:94
int int id
Definition editgui_g.h:28
counter_target
Definition fc_types.h:128
@ CTGT_CITY
Definition fc_types.h:128
#define MAX_COUNTERS
Definition fc_types.h:108
struct civ_game game
Definition game.c:62
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
void strvec_destroy(struct strvec *psv)
struct packet_ruleset_control control
Definition game.h:83
enum counter_target target
Definition counters.h:32
bool ruledit_disabled
Definition counters.h:30
int index
Definition counters.h:37
struct name_translation name
Definition counters.h:28
struct strvec * helptext
Definition counters.h:29
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define FALSE
Definition support.h:47