Freeciv-3.4
Loading...
Searching...
No Matches
tiledef.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/* common */
19#include "game.h"
20#include "map.h"
21
22#include "tiledef.h"
23
25
26/************************************************************************/
29void tiledefs_init(void)
30{
31 int i;
32
33 for (i = 0; i < MAX_TILEDEFS; i++) {
34 tiledefs[i].id = i;
36 }
37}
38
39/************************************************************************/
42void tiledefs_free(void)
43{
44 int i;
45
46 for (i = 0; i < MAX_TILEDEFS; i++) {
48 }
49}
50
51/************************************************************************/
55{
57}
58
59/************************************************************************/
62int tiledef_number(const struct tiledef *td)
63{
64 fc_assert_ret_val(td != nullptr, -1);
65
66 return td->id;
67}
68
69#ifndef tiledef_index
70/************************************************************************/
73int tiledef_index(const struct tiledef *td)
74{
75 fc_assert_ret_val(td != nullptr, -1);
76
77 return td - tiledefs;
78}
79#endif /* tiledef_index */
80
81/************************************************************************/
85{
86 fc_assert_ret_val(id >= 0 && id < MAX_TILEDEFS, nullptr);
87
88 return &tiledefs[id];
89}
90
91/************************************************************************/
95const char *tiledef_name_translation(const struct tiledef *td)
96{
97 return name_translation_get(&td->name);
98}
99
100/************************************************************************/
104const char *tiledef_rule_name(const struct tiledef *td)
105{
106 return rule_name_get(&td->name);
107}
108
109/************************************************************************/
114{
115 const char *qs;
116
117 if (name == nullptr) {
118 return nullptr;
119 }
120
121 qs = Qn_(name);
122
125 return td;
126 }
128
129 return nullptr;
130}
131
132/************************************************************************/
137{
140 return td;
141 }
143
144 return nullptr;
145}
146
147/************************************************************************/
150bool tile_matches_tiledef(const struct tiledef *td, const struct tile *ptile)
151{
152 extra_type_list_iterate(td->extras, pextra) {
153 if (!tile_has_extra(ptile, pextra)) {
154 return FALSE;
155 }
157
158 return TRUE;
159}
160
161/************************************************************************/
165bool is_tiledef_card_near(const struct civ_map *nmap, const struct tile *ptile,
166 const struct tiledef *ptd)
167{
170 return TRUE;
171 }
173
174 return FALSE;
175}
176
177/************************************************************************/
181bool is_tiledef_near_tile(const struct civ_map *nmap, const struct tile *ptile,
182 const struct tiledef *ptd)
183{
184 adjc_iterate(nmap, ptile, adjc_tile) {
186 return TRUE;
187 }
189
190 return FALSE;
191}
char * incite_cost
Definition comments.c:77
int int id
Definition editgui_g.h:28
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_list_iterate_end
Definition extras.h:167
#define MAX_TILEDEFS
Definition fc_types.h:56
#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 adjc_iterate_end
Definition map.h:430
#define cardinal_adjc_iterate_end
Definition map.h:456
#define adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:425
#define cardinal_adjc_iterate(nmap, center_tile, itr_tile)
Definition map.h:452
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
struct packet_ruleset_control control
Definition game.h:83
Definition tile.h:50
int id
Definition tiledef.h:25
struct extra_type_list * extras
Definition tiledef.h:28
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
const char * tiledef_rule_name(const struct tiledef *td)
Definition tiledef.c:104
int tiledef_number(const struct tiledef *td)
Definition tiledef.c:62
static struct tiledef tiledefs[MAX_TILEDEFS]
Definition tiledef.c:24
struct tiledef * tiledef_by_number(int id)
Definition tiledef.c:84
struct tiledef * tiledef_by_rule_name(const char *name)
Definition tiledef.c:113
int tiledef_count(void)
Definition tiledef.c:54
bool tile_matches_tiledef(const struct tiledef *td, const struct tile *ptile)
Definition tiledef.c:150
bool is_tiledef_card_near(const struct civ_map *nmap, const struct tile *ptile, const struct tiledef *ptd)
Definition tiledef.c:165
void tiledefs_init(void)
Definition tiledef.c:29
void tiledefs_free(void)
Definition tiledef.c:42
struct tiledef * tiledef_by_translated_name(const char *name)
Definition tiledef.c:136
bool is_tiledef_near_tile(const struct civ_map *nmap, const struct tile *ptile, const struct tiledef *ptd)
Definition tiledef.c:181
const char * tiledef_name_translation(const struct tiledef *td)
Definition tiledef.c:95
#define tiledef_index(_td_)
Definition tiledef.h:41
#define tiledef_iterate_end
Definition tiledef.h:54
#define tiledef_iterate(_p)
Definition tiledef.h:48