forked from github/server
refactoring prior to removing static variable
This commit is contained in:
parent
eb8db3bfb9
commit
0ac30c65a1
|
@ -119,6 +119,8 @@ extern "C" {
|
||||||
|
|
||||||
extern int num_races;
|
extern int num_races;
|
||||||
|
|
||||||
|
typedef const char *(*race_name_func)(const struct unit *);
|
||||||
|
|
||||||
typedef struct race {
|
typedef struct race {
|
||||||
char *_name;
|
char *_name;
|
||||||
float magres;
|
float magres;
|
||||||
|
|
|
@ -1416,7 +1416,8 @@ void name_unit(unit * u)
|
||||||
if (u_race(u)->generate_name) {
|
if (u_race(u)->generate_name) {
|
||||||
const char *gen_name = u_race(u)->generate_name(u);
|
const char *gen_name = u_race(u)->generate_name(u);
|
||||||
if (gen_name) {
|
if (gen_name) {
|
||||||
unit_setname(u, gen_name);
|
free(u->_name);
|
||||||
|
u->_name = _strdup(gen_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
|
||||||
|
|
|
@ -1797,7 +1797,7 @@ static int parse_races(xmlDocPtr doc)
|
||||||
}
|
}
|
||||||
assert(propValue != NULL);
|
assert(propValue != NULL);
|
||||||
if (strcmp((const char *)propValue, "name") == 0) {
|
if (strcmp((const char *)propValue, "name") == 0) {
|
||||||
rc->generate_name = (const char *(*)(const struct unit *))fun;
|
rc->generate_name = (race_name_func)fun;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "describe") == 0) {
|
else if (strcmp((const char *)propValue, "describe") == 0) {
|
||||||
rc->describe =
|
rc->describe =
|
||||||
|
|
|
@ -23,7 +23,6 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct unit;
|
struct unit;
|
||||||
typedef const char *(*name_func)(const struct unit *);
|
|
||||||
void register_names(void);
|
void register_names(void);
|
||||||
const char *abkz(const char *s, char *buf, size_t size, size_t maxchars);
|
const char *abkz(const char *s, char *buf, size_t size, size_t maxchars);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "names.h"
|
#include "names.h"
|
||||||
|
|
||||||
|
#include <kernel/race.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/functions.h>
|
#include <util/functions.h>
|
||||||
|
|
||||||
|
@ -10,14 +11,14 @@
|
||||||
|
|
||||||
static void test_names(CuTest * tc)
|
static void test_names(CuTest * tc)
|
||||||
{
|
{
|
||||||
name_func foo;
|
race_name_func foo;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
register_names();
|
register_names();
|
||||||
default_locale = test_create_locale();
|
default_locale = test_create_locale();
|
||||||
locale_setstring(default_locale, "undead_prefix_0", "Kleine");
|
locale_setstring(default_locale, "undead_prefix_0", "Kleine");
|
||||||
locale_setstring(default_locale, "undead_name_0", "Graue");
|
locale_setstring(default_locale, "undead_name_0", "Graue");
|
||||||
locale_setstring(default_locale, "undead_postfix_0", "Kobolde");
|
locale_setstring(default_locale, "undead_postfix_0", "Kobolde");
|
||||||
CuAssertPtrNotNull(tc, foo = (name_func)get_function("nameundead"));
|
CuAssertPtrNotNull(tc, foo = (race_name_func)get_function("nameundead"));
|
||||||
CuAssertStrEquals(tc, "Kleine Graue Kobolde", foo(NULL));
|
CuAssertStrEquals(tc, "Kleine Graue Kobolde", foo(NULL));
|
||||||
CuAssertPtrNotNull(tc, get_function("nameskeleton"));
|
CuAssertPtrNotNull(tc, get_function("nameskeleton"));
|
||||||
CuAssertPtrNotNull(tc, get_function("namezombie"));
|
CuAssertPtrNotNull(tc, get_function("namezombie"));
|
||||||
|
|
Loading…
Reference in New Issue