forked from github/server
make describe_braineater more generic (describe_race).
This commit is contained in:
parent
c18d75207e
commit
33701ab891
|
@ -619,7 +619,7 @@
|
||||||
<race name="braineater" magres="0.900000" 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="0.900000" 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_braineater"/>
|
<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,7 @@
|
||||||
regaura="1.000000" recruitcost="50000" 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" recruitcost="50000" 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_braineater"/>
|
<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"/>
|
||||||
|
|
|
@ -319,6 +319,10 @@ const char *dbrace(const struct race *rc)
|
||||||
return zText;
|
return zText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,8 @@ extern "C" {
|
||||||
struct param;
|
struct param;
|
||||||
struct spell;
|
struct spell;
|
||||||
|
|
||||||
|
extern int num_races;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RC_DWARF, /* 0 - Zwerg */
|
RC_DWARF, /* 0 - Zwerg */
|
||||||
RC_ELF,
|
RC_ELF,
|
||||||
|
@ -117,8 +119,7 @@ extern "C" {
|
||||||
int level;
|
int level;
|
||||||
} att;
|
} att;
|
||||||
|
|
||||||
extern int num_races;
|
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 {
|
||||||
|
@ -152,7 +153,7 @@ extern "C" {
|
||||||
signed char bonus[MAXSKILLS];
|
signed char bonus[MAXSKILLS];
|
||||||
|
|
||||||
race_name_func generate_name;
|
race_name_func generate_name;
|
||||||
const char *(*describe) (const struct unit *, const struct locale *);
|
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);
|
||||||
|
@ -168,8 +169,8 @@ extern "C" {
|
||||||
const struct race *data;
|
const struct race *data;
|
||||||
} race_list;
|
} race_list;
|
||||||
|
|
||||||
extern void racelist_clear(struct race_list **rl);
|
void racelist_clear(struct race_list **rl);
|
||||||
extern void racelist_insert(struct race_list **rl, const struct race *r);
|
void racelist_insert(struct race_list **rl, const struct race *r);
|
||||||
|
|
||||||
|
|
||||||
struct race_list *get_familiarraces(void);
|
struct race_list *get_familiarraces(void);
|
||||||
|
@ -178,8 +179,8 @@ extern "C" {
|
||||||
/** TODO: compatibility hacks: **/
|
/** TODO: compatibility hacks: **/
|
||||||
race_t old_race(const struct race *);
|
race_t old_race(const struct race *);
|
||||||
|
|
||||||
extern race *rc_get_or_create(const char *name);
|
race *rc_get_or_create(const char *name);
|
||||||
extern const race *rc_find(const char *);
|
const race *rc_find(const char *);
|
||||||
void free_races(void);
|
void free_races(void);
|
||||||
|
|
||||||
typedef enum name_t { NAME_SINGULAR, NAME_PLURAL, NAME_DEFINITIVE, NAME_CATEGORY } name_t;
|
typedef enum name_t { NAME_SINGULAR, NAME_PLURAL, NAME_DEFINITIVE, NAME_CATEGORY } name_t;
|
||||||
|
@ -236,7 +237,6 @@ extern "C" {
|
||||||
#define BF_INV_NONMAGIC (1<<5) /* Immun gegen nichtmagischen Schaden */
|
#define BF_INV_NONMAGIC (1<<5) /* Immun gegen nichtmagischen Schaden */
|
||||||
#define BF_NO_ATTACK (1<<6) /* Kann keine ATTACKIERE Befehle ausfuehren */
|
#define BF_NO_ATTACK (1<<6) /* Kann keine ATTACKIERE Befehle ausfuehren */
|
||||||
|
|
||||||
int unit_old_max_hp(struct unit *u);
|
|
||||||
const char *racename(const struct locale *lang, const struct unit *u,
|
const char *racename(const struct locale *lang, const struct unit *u,
|
||||||
const race * rc);
|
const race * rc);
|
||||||
|
|
||||||
|
@ -257,11 +257,9 @@ extern "C" {
|
||||||
variant read_race_reference(struct storage *store);
|
variant read_race_reference(struct storage *store);
|
||||||
|
|
||||||
const char *raceprefix(const struct unit *u);
|
const char *raceprefix(const struct unit *u);
|
||||||
|
|
||||||
void give_starting_equipment(const struct equipment *eq,
|
|
||||||
struct unit *u);
|
|
||||||
const char *dbrace(const struct race *rc);
|
const char *dbrace(const struct race *rc);
|
||||||
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 *);
|
||||||
char * race_namegen(const struct race *rc, struct unit *u);
|
char * race_namegen(const struct race *rc, struct unit *u);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -699,6 +699,7 @@ void write_attribs(storage *store, attrib *alist, const void *owner)
|
||||||
unit *read_unit(struct gamedata *data)
|
unit *read_unit(struct gamedata *data)
|
||||||
{
|
{
|
||||||
unit *u;
|
unit *u;
|
||||||
|
const race *rc;
|
||||||
int number, n, p;
|
int number, n, p;
|
||||||
order **orderp;
|
order **orderp;
|
||||||
char obuf[DISPLAYSIZE];
|
char obuf[DISPLAYSIZE];
|
||||||
|
@ -760,7 +761,9 @@ unit *read_unit(struct gamedata *data)
|
||||||
u->age = (short)n;
|
u->age = (short)n;
|
||||||
|
|
||||||
READ_TOK(data->store, rname, sizeof(rname));
|
READ_TOK(data->store, rname, sizeof(rname));
|
||||||
u_setrace(u, rc_find(rname));
|
rc = rc_find(rname);
|
||||||
|
assert(rc);
|
||||||
|
u_setrace(u, rc);
|
||||||
|
|
||||||
READ_TOK(data->store, rname, sizeof(rname));
|
READ_TOK(data->store, rname, sizeof(rname));
|
||||||
if (rname[0] && skill_enabled(SK_STEALTH))
|
if (rname[0] && skill_enabled(SK_STEALTH))
|
||||||
|
@ -768,8 +771,8 @@ unit *read_unit(struct gamedata *data)
|
||||||
else
|
else
|
||||||
u->irace = NULL;
|
u->irace = NULL;
|
||||||
|
|
||||||
if (u_race(u)->describe) {
|
if (rc->describe) {
|
||||||
const char *rcdisp = u_race(u)->describe(u, u->faction->locale);
|
const char *rcdisp = rc->describe(rc, u->faction->locale);
|
||||||
if (u->display && rcdisp) {
|
if (u->display && rcdisp) {
|
||||||
/* see if the data file contains old descriptions */
|
/* see if the data file contains old descriptions */
|
||||||
if (strcmp(rcdisp, u->display) == 0) {
|
if (strcmp(rcdisp, u->display) == 0) {
|
||||||
|
|
|
@ -470,7 +470,7 @@ const char *u_description(const unit * u, const struct locale *lang)
|
||||||
return u->display;
|
return u->display;
|
||||||
}
|
}
|
||||||
else if (u_race(u)->describe) {
|
else if (u_race(u)->describe) {
|
||||||
return u_race(u)->describe(u, lang);
|
return u_race(u)->describe(u->_race, lang);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1800,8 +1800,7 @@ static int parse_races(xmlDocPtr doc)
|
||||||
rc->generate_name = (race_name_func)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 = (race_desc_func)fun;
|
||||||
(const char *(*)(const struct unit *, const struct locale *))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;
|
||||||
|
|
|
@ -45,9 +45,11 @@ 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_braineater(unit * u, const struct locale *lang)
|
static const char *describe_race(const race * rc, const struct locale *lang)
|
||||||
{
|
{
|
||||||
return LOC(lang, "describe_braineater");
|
char zText[32];
|
||||||
|
sprintf(zText, "describe_%s", rc->_name);
|
||||||
|
return LOC(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)
|
||||||
|
@ -480,7 +482,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||||
|
|
||||||
void register_names(void)
|
void register_names(void)
|
||||||
{
|
{
|
||||||
register_function((pf_generic)describe_braineater, "describe_braineater");
|
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,7 @@ 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_braineater"));
|
CuAssertPtrNotNull(tc, get_function("describe_race"));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue