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
21#include "tiledef.h"
22
24
25/************************************************************************/
28void tiledefs_init(void)
29{
30 int i;
31
32 for (i = 0; i < MAX_TILEDEFS; i++) {
33 tiledefs[i].id = i;
35 }
36}
37
38/************************************************************************/
41void tiledefs_free(void)
42{
43 int i;
44
45 for (i = 0; i < MAX_TILEDEFS; i++) {
47 }
48}
49
50/************************************************************************/
54{
56}
57
58/************************************************************************/
61int tiledef_number(const struct tiledef *td)
62{
63 fc_assert_ret_val(td != nullptr, -1);
64
65 return td->id;
66}
67
68#ifndef tiledef_index
69/************************************************************************/
72int tiledef_index(const struct tiledef *td)
73{
74 fc_assert_ret_val(td != nullptr, -1);
75
76 return td - tiledefs;
77}
78#endif /* tiledef_index */
79
80/************************************************************************/
84{
85 fc_assert_ret_val(id >= 0 && id < MAX_TILEDEFS, nullptr);
86
87 return &tiledefs[id];
88}
89
90/************************************************************************/
94const char *tiledef_name_translation(const struct tiledef *td)
95{
96 return name_translation_get(&td->name);
97}
98
99/************************************************************************/
103const char *tiledef_rule_name(const struct tiledef *td)
104{
105 return rule_name_get(&td->name);
106}
107
108/************************************************************************/
113{
114 const char *qs;
115
116 if (name == nullptr) {
117 return nullptr;
118 }
119
120 qs = Qn_(name);
121
124 return td;
125 }
127
128 return nullptr;
129}
130
131/************************************************************************/
136{
139 return td;
140 }
142
143 return nullptr;
144}
145
146/************************************************************************/
149bool tile_matches_tiledef(const struct tiledef *td, const struct tile *ptile)
150{
151 extra_type_list_iterate(td->extras, pextra) {
152 if (!tile_has_extra(ptile, pextra)) {
153 return FALSE;
154 }
156
157 return TRUE;
158}
char * incite_cost
Definition comments.c:76
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
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:103
int tiledef_number(const struct tiledef *td)
Definition tiledef.c:61
static struct tiledef tiledefs[MAX_TILEDEFS]
Definition tiledef.c:23
struct tiledef * tiledef_by_number(int id)
Definition tiledef.c:83
struct tiledef * tiledef_by_rule_name(const char *name)
Definition tiledef.c:112
int tiledef_count(void)
Definition tiledef.c:53
bool tile_matches_tiledef(const struct tiledef *td, const struct tile *ptile)
Definition tiledef.c:149
void tiledefs_init(void)
Definition tiledef.c:28
void tiledefs_free(void)
Definition tiledef.c:41
struct tiledef * tiledef_by_translated_name(const char *name)
Definition tiledef.c:135
const char * tiledef_name_translation(const struct tiledef *td)
Definition tiledef.c:94
#define tiledef_index(_td_)
Definition tiledef.h:41
#define tiledef_iterate_end
Definition tiledef.h:54
#define tiledef_iterate(_p)
Definition tiledef.h:48