Feature #1422 ยป 0063-tiledef-Add-functions-dealing-with-the-tiledef-name.patch
common/tiledef.c | ||
---|---|---|
return &tiledefs[id];
|
||
}
|
||
/************************************************************************//**
|
||
Return the (translated) name of the tiledef.
|
||
You don't have to free the return pointer.
|
||
****************************************************************************/
|
||
const char *tiledef_name_translation(const struct tiledef *td)
|
||
{
|
||
return name_translation_get(&td->name);
|
||
}
|
||
/************************************************************************//**
|
||
Return the (untranslated) rule name of the tiledef.
|
||
You don't have to free the return pointer.
|
||
****************************************************************************/
|
||
const char *tiledef_rule_name(const struct tiledef *td)
|
||
{
|
||
return rule_name_get(&td->name);
|
||
}
|
||
/************************************************************************//**
|
||
Returns tiledef matching rule name or nullptr if there is no tiledef
|
||
with such name.
|
||
****************************************************************************/
|
||
struct tiledef *tiledef_by_rule_name(const char *name)
|
||
{
|
||
const char *qs;
|
||
if (name == nullptr) {
|
||
return nullptr;
|
||
}
|
||
qs = Qn_(name);
|
||
tiledef_iterate(td) {
|
||
if (!fc_strcasecmp(tiledef_rule_name(td), qs)) {
|
||
return td;
|
||
}
|
||
} tiledef_iterate_end;
|
||
return nullptr;
|
||
}
|
||
/************************************************************************//**
|
||
Returns tiledef matching the translated name, or nullptr if there is no
|
||
tiledef with that name.
|
||
****************************************************************************/
|
||
struct tiledef *tiledef_by_translated_name(const char *name)
|
||
{
|
||
tiledef_iterate(td) {
|
||
if (0 == strcmp(tiledef_name_translation(td), name)) {
|
||
return td;
|
||
}
|
||
} tiledef_iterate_end;
|
||
return nullptr;
|
||
}
|
common/tiledef.h | ||
---|---|---|
* correct implementation too. */
|
||
#define tiledef_index(_td_) (_td_)->id
|
||
const char *tiledef_name_translation(const struct tiledef *td);
|
||
const char *tiledef_rule_name(const struct tiledef *td);
|
||
struct tiledef *tiledef_by_rule_name(const char *name);
|
||
struct tiledef *tiledef_by_translated_name(const char *name);
|
||
#define tiledef_iterate(_p) \
|
||
{ \
|
||
int _i_##_p; \
|
||
for (_i_##_p = 0; _i_##_p < game.control.num_tiledef_types; _i_##_p++) { \
|
||
struct tiledef *_p = tiledef_by_number(_i_##_p);
|
||
#define tiledef_iterate_end \
|
||
} \
|
||
}
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif /* __cplusplus */
|