forked from github/server
remove race.describe funpointer
This commit is contained in:
parent
be14394529
commit
ba1fdcce59
|
@ -615,7 +615,6 @@
|
||||||
<race name="braineater" magres="90" maxaura="1.0" regaura="1.0" weight="100" capacity="540" speed="1.0" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes">
|
<race name="braineater" magres="90" maxaura="1.0" regaura="1.0" weight="100" capacity="540" speed="1.0" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes">
|
||||||
<ai splitsize="500" killpeasants="yes" moverandom="yes" learn="yes"/>
|
<ai splitsize="500" killpeasants="yes" moverandom="yes" learn="yes"/>
|
||||||
<function name="name" value="namegeneric"/>
|
<function name="name" value="namegeneric"/>
|
||||||
<function name="describe" value="describe_race"/>
|
|
||||||
<attack type="2" damage="3d15"/>
|
<attack type="2" damage="3d15"/>
|
||||||
<attack type="3" damage="1d1"/>
|
<attack type="3" damage="1d1"/>
|
||||||
<attack type="4" damage="1d1"/>
|
<attack type="4" damage="1d1"/>
|
||||||
|
|
|
@ -602,7 +602,6 @@
|
||||||
regaura="1.000000" weight="100" capacity="540" speed="1.000000" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes">
|
regaura="1.000000" weight="100" capacity="540" speed="1.000000" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" scarepeasants="yes" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes">
|
||||||
<ai splitsize="500" killpeasants="yes" moverandom="yes" learn="yes"/>
|
<ai splitsize="500" killpeasants="yes" moverandom="yes" learn="yes"/>
|
||||||
<function name="name" value="namegeneric"/>
|
<function name="name" value="namegeneric"/>
|
||||||
<function name="describe" value="describe_race"/>
|
|
||||||
<attack type="2" damage="3d15"/>
|
<attack type="2" damage="3d15"/>
|
||||||
<attack type="3" damage="1d1"/>
|
<attack type="3" damage="1d1"/>
|
||||||
<attack type="4" damage="1d1"/>
|
<attack type="4" damage="1d1"/>
|
||||||
|
|
|
@ -542,10 +542,6 @@ variant read_race_reference(struct storage *store)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_race_description_function(race_desc_func func, const char *name) {
|
|
||||||
register_function((pf_generic)func, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void register_race_name_function(race_name_func func, const char *name) {
|
void register_race_name_function(race_name_func func, const char *name) {
|
||||||
register_function((pf_generic)func, name);
|
register_function((pf_generic)func, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,6 @@ extern "C" {
|
||||||
int level;
|
int level;
|
||||||
} att;
|
} att;
|
||||||
|
|
||||||
typedef const char *(*race_desc_func)(const struct race *rc, const struct locale *lang);
|
|
||||||
typedef void (*race_name_func)(struct unit *);
|
typedef void (*race_name_func)(struct unit *);
|
||||||
|
|
||||||
typedef struct race {
|
typedef struct race {
|
||||||
|
@ -145,7 +144,6 @@ extern "C" {
|
||||||
signed char bonus[MAXSKILLS];
|
signed char bonus[MAXSKILLS];
|
||||||
|
|
||||||
race_name_func generate_name;
|
race_name_func generate_name;
|
||||||
race_desc_func describe;
|
|
||||||
void(*age) (struct unit * u);
|
void(*age) (struct unit * u);
|
||||||
bool(*move_allowed) (const struct region *, const struct region *);
|
bool(*move_allowed) (const struct region *, const struct region *);
|
||||||
struct item *(*itemdrop) (const struct race *, int size);
|
struct item *(*itemdrop) (const struct race *, int size);
|
||||||
|
@ -267,7 +265,6 @@ extern "C" {
|
||||||
|
|
||||||
const char *raceprefix(const struct unit *u);
|
const char *raceprefix(const struct unit *u);
|
||||||
void register_race_name_function(race_name_func, const char *);
|
void register_race_name_function(race_name_func, const char *);
|
||||||
void register_race_description_function(race_desc_func, const char *);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -695,17 +695,6 @@ unit *read_unit(struct gamedata *data)
|
||||||
else
|
else
|
||||||
u->irace = NULL;
|
u->irace = NULL;
|
||||||
|
|
||||||
if (rc->describe) {
|
|
||||||
const char *rcdisp = rc->describe(rc, u->faction->locale);
|
|
||||||
if (u->display && rcdisp) {
|
|
||||||
/* see if the data file contains old descriptions */
|
|
||||||
if (strcmp(rcdisp, u->display) == 0) {
|
|
||||||
free(u->display);
|
|
||||||
u->display = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
building * b = findbuilding(n);
|
building * b = findbuilding(n);
|
||||||
|
|
|
@ -531,8 +531,15 @@ const char *u_description(const unit * u, const struct locale *lang)
|
||||||
if (u->display && u->display[0]) {
|
if (u->display && u->display[0]) {
|
||||||
return u->display;
|
return u->display;
|
||||||
}
|
}
|
||||||
else if (u_race(u)->describe) {
|
else {
|
||||||
return u_race(u)->describe(u->_race, lang);
|
char zText[64];
|
||||||
|
const char * d;
|
||||||
|
const race * rc = u_race(u);
|
||||||
|
snprintf(zText, sizeof(zText), "describe_%s", rc->_name);
|
||||||
|
d = locale_getstring(lang, zText);
|
||||||
|
if (d) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -390,14 +390,24 @@ static void test_limited_skills(CuTest *tc) {
|
||||||
static void test_unit_description(CuTest *tc) {
|
static void test_unit_description(CuTest *tc) {
|
||||||
race *rc;
|
race *rc;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
struct locale *lang;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
lang = test_create_locale();
|
||||||
rc = test_create_race("hodor");
|
rc = test_create_race("hodor");
|
||||||
u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0));
|
u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0));
|
||||||
|
|
||||||
CuAssertPtrEquals(tc, 0, u->display);
|
CuAssertPtrEquals(tc, 0, u->display);
|
||||||
CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale));
|
CuAssertStrEquals(tc, 0, u_description(u, lang));
|
||||||
u->display = strdup("Hodor");
|
u->display = strdup("Hodor");
|
||||||
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
|
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
|
||||||
CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale));
|
CuAssertStrEquals(tc, "Hodor", u_description(u, lang));
|
||||||
|
|
||||||
|
free(u->display);
|
||||||
|
u->display = NULL;
|
||||||
|
locale_setstring(lang, "describe_hodor", "HODOR");
|
||||||
|
CuAssertStrEquals(tc, "HODOR", u_description(u, lang));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1795,9 +1795,6 @@ static int parse_races(xmlDocPtr doc)
|
||||||
if (strcmp((const char *)propValue, "name") == 0) {
|
if (strcmp((const char *)propValue, "name") == 0) {
|
||||||
rc->generate_name = (race_name_func)fun;
|
rc->generate_name = (race_name_func)fun;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "describe") == 0) {
|
|
||||||
rc->describe = (race_desc_func)fun;
|
|
||||||
}
|
|
||||||
else if (strcmp((const char *)propValue, "age") == 0) {
|
else if (strcmp((const char *)propValue, "age") == 0) {
|
||||||
rc->age = (void(*)(struct unit *))fun;
|
rc->age = (void(*)(struct unit *))fun;
|
||||||
}
|
}
|
||||||
|
|
28
src/names.c
28
src/names.c
|
@ -45,13 +45,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const char *describe_race(const race * rc, const struct locale *lang)
|
|
||||||
{
|
|
||||||
char zText[32];
|
|
||||||
sprintf(zText, "describe_%s", rc->_name);
|
|
||||||
return locale_getstring(lang, zText);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
|
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)
|
||||||
{
|
{
|
||||||
char zText[32];
|
char zText[32];
|
||||||
|
@ -395,29 +388,29 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
UNUSED_ARG(buflen);
|
UNUSED_ARG(buflen);
|
||||||
/* Prüfen, ob Kurz genug */
|
/* Pr<EFBFBD>fen, ob Kurz genug */
|
||||||
if (strlen(s) <= maxchars) {
|
if (strlen(s) <= maxchars) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
/* Anzahl der Wörter feststellen */
|
/* Anzahl der W<EFBFBD>rter feststellen */
|
||||||
|
|
||||||
while (*p != 0) {
|
while (*p != 0) {
|
||||||
|
|
||||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||||
|
|
||||||
/* Leerzeichen überspringen */
|
/* Leerzeichen <EFBFBD>berspringen */
|
||||||
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
||||||
p += size;
|
p += size;
|
||||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Counter erhöhen */
|
/* Counter erh<EFBFBD>hen */
|
||||||
if (*p != 0)
|
if (*p != 0)
|
||||||
++c;
|
++c;
|
||||||
|
|
||||||
/* alnums überspringen */
|
/* alnums <EFBFBD>berspringen */
|
||||||
while (*p != 0 && iswalnum((wint_t)ucs)) {
|
while (*p != 0 && iswalnum((wint_t)ucs)) {
|
||||||
p += size;
|
p += size;
|
||||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
@ -425,10 +418,10 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Buchstaben pro Teilkürzel = MAX(1,max/AnzWort) */
|
/* Buchstaben pro Teilk<EFBFBD>rzel = MAX(1,max/AnzWort) */
|
||||||
bpt = (c > 0) ? MAX(1, maxchars / c) : 1;
|
bpt = (c > 0) ? MAX(1, maxchars / c) : 1;
|
||||||
|
|
||||||
/* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */
|
/* Einzelne W<EFBFBD>rter anspringen und jeweils die ersten BpT kopieren */
|
||||||
|
|
||||||
p = s;
|
p = s;
|
||||||
c = 0;
|
c = 0;
|
||||||
|
@ -438,7 +431,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||||
|
|
||||||
while (*p != 0 && c < maxchars) {
|
while (*p != 0 && c < maxchars) {
|
||||||
/* Leerzeichen überspringen */
|
/* Leerzeichen <EFBFBD>berspringen */
|
||||||
|
|
||||||
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
||||||
p += size;
|
p += size;
|
||||||
|
@ -446,7 +439,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* alnums übertragen */
|
/* alnums <EFBFBD>bertragen */
|
||||||
|
|
||||||
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) {
|
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) {
|
||||||
memcpy(bufp, p, size);
|
memcpy(bufp, p, size);
|
||||||
|
@ -458,7 +451,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bis zum nächsten Leerzeichen */
|
/* Bis zum n<EFBFBD>chsten Leerzeichen */
|
||||||
|
|
||||||
while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) {
|
while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) {
|
||||||
p += size;
|
p += size;
|
||||||
|
@ -474,7 +467,6 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
|
|
||||||
void register_names(void)
|
void register_names(void)
|
||||||
{
|
{
|
||||||
register_race_description_function(describe_race, "describe_race");
|
|
||||||
/* function name
|
/* function name
|
||||||
* generate a name for a nonplayerunit
|
* generate a name for a nonplayerunit
|
||||||
* race->generate_name() */
|
* race->generate_name() */
|
||||||
|
|
|
@ -32,7 +32,6 @@ static void test_names(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, get_function("namedragon"));
|
CuAssertPtrNotNull(tc, get_function("namedragon"));
|
||||||
CuAssertPtrNotNull(tc, get_function("namedracoid"));
|
CuAssertPtrNotNull(tc, get_function("namedracoid"));
|
||||||
CuAssertPtrNotNull(tc, get_function("namegeneric"));
|
CuAssertPtrNotNull(tc, get_function("namegeneric"));
|
||||||
CuAssertPtrNotNull(tc, get_function("describe_race"));
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue