Freeciv-3.2
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 (NULL != counters[i].helptext) {
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{
108 return pcount - counters;
109}
110
111/************************************************************************/
116{
117 int i;
119 fc_assert_ret_val('\0' != name[0], NULL);
120
121 for (i = 0; i < game.control.num_counters; i++)
122 {
124 {
125 return &counters[i];
126 }
127 }
128
129 return NULL;
130}
131
132/************************************************************************/
137{
138 int i;
140 fc_assert_ret_val('\0' != name[0], NULL);
141
142 for (i = 0; i < game.control.num_counters; i++)
143 {
144 if (0 == fc_strcasecmp(name,
146 {
147 return &counters[i];
148 }
149 }
150
151 return NULL;
152}
153
154/************************************************************************/
157const char *counter_name_translation(const struct counter *counter)
158{
160}
161
162/************************************************************************/
165const char *counter_rule_name(struct counter *pcount)
166{
168 return rule_name_get(&pcount->name);
169}
170
171/************************************************************************/
174int counter_index(const struct counter *pcount)
175{
177 return pcount->index;
178}
179
180/************************************************************************/
184{
185 switch (target)
186 {
187 case CTGT_CITY:
188 return counters_city[index];
189 }
190
191 return NULL;
192}
char * incite_cost
Definition comments.c:75
struct counter * counter_by_index(int index, enum counter_target target)
Definition counters.c:183
static int number_city_counters
Definition counters.c:35
int counter_index(const struct counter *pcount)
Definition counters.c:174
void counters_init(void)
Definition counters.c:40
const char * counter_name_translation(const struct counter *counter)
Definition counters.c:157
struct counter * counter_by_rule_name(const char *name)
Definition counters.c:115
struct counter * counter_by_translated_name(const char *name)
Definition counters.c:136
const char * counter_rule_name(struct counter *pcount)
Definition counters.c:165
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:126
@ CTGT_CITY
Definition fc_types.h:126
#define MAX_COUNTERS
Definition fc_types.h:106
struct civ_game game
Definition game.c:62
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
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:189
#define FALSE
Definition support.h:47