Feature #1411 ยป 0058-tiledef-Add-functions-dealing-with-the-tiledef-id.patch
| common/networking/packets.def | ||
|---|---|---|
|
UINT16 num_tech_classes;
|
||
|
UINT16 num_tech_types;
|
||
|
UINT16 num_extra_types;
|
||
|
UINT16 num_tiledef_types;
|
||
|
UINT16 num_base_types;
|
||
|
UINT16 num_road_types;
|
||
|
UINT16 num_resource_types;
|
||
| common/tiledef.c | ||
|---|---|---|
|
#include <fc_config.h>
|
||
|
#endif
|
||
|
/* common */
|
||
|
#include "game.h"
|
||
|
#include "tiledef.h"
|
||
|
static struct tiledef tiledefs[MAX_TILEDEFS];
|
||
| ... | ... | |
|
extra_type_list_destroy(tiledefs[i].extras);
|
||
|
}
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Return the number of tiledef_types
|
||
|
****************************************************************************/
|
||
|
int tiledef_count(void)
|
||
|
{
|
||
|
return game.control.num_tiledef_types;
|
||
|
}
|
||
|
/************************************************************************//**
|
||
|
Return the tiledef id.
|
||
|
****************************************************************************/
|
||
|
int tiledef_number(const struct tiledef *td)
|
||
|
{
|
||
|
fc_assert_ret_val(td != nullptr, -1);
|
||
|
return td->id;
|
||
|
}
|
||
|
#ifndef tiledef_index
|
||
|
/************************************************************************//**
|
||
|
Return the tiledef index.
|
||
|
****************************************************************************/
|
||
|
int tiledef_index(const struct tiledef *td)
|
||
|
{
|
||
|
fc_assert_ret_val(td != nullptr, -1);
|
||
|
return td - tiledefs;
|
||
|
}
|
||
|
#endif /* tiledef_index */
|
||
|
/************************************************************************//**
|
||
|
Return tiledef type of given id.
|
||
|
****************************************************************************/
|
||
|
struct tiledef *tiledef_by_number(int id)
|
||
|
{
|
||
|
fc_assert_ret_val(id >= 0 && id < MAX_TILEDEFS, nullptr);
|
||
|
return &tiledefs[id];
|
||
|
}
|
||
| common/tiledef.h | ||
|---|---|---|
|
void tiledefs_init(void);
|
||
|
void tiledefs_free(void);
|
||
|
int tiledef_count(void);
|
||
|
int tiledef_number(const struct tiledef *td);
|
||
|
struct tiledef *tiledef_by_number(int id);
|
||
|
/* For optimization purposes (being able to have it as macro instead of function
|
||
|
* call) this is now same as tiledef_number(). tiledef.c does have semantically
|
||
|
* correct implementation too. */
|
||
|
#define tiledef_index(_td_) (_td_)->id
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif /* __cplusplus */
|
||
| server/ruleset/ruleload.c | ||
|---|---|---|
|
section_list_destroy(sec);
|
||
|
sec = NULL;
|
||
|
game.control.num_tiledef_types = 0;
|
||
|
/* extra names */
|
||
|
if (ok) {
|
||