Unicode WIP, does not compile.

- monsters use create_order instead of parse_order because that means less use of sprintf and buf[].
- rename drachen_name to dragon_name.
This commit is contained in:
Enno Rehling 2007-06-26 21:50:07 +00:00
parent 8be7d65977
commit ea07884657
6 changed files with 30 additions and 60 deletions

View File

@ -127,17 +127,12 @@ is_waiting(const unit * u)
static order * static order *
monster_attack(unit * u, const unit * target) monster_attack(unit * u, const unit * target)
{ {
char zText[20];
if (u->region!=target->region) return NULL; if (u->region!=target->region) return NULL;
if (u->faction==target->faction) return NULL; if (u->faction==target->faction) return NULL;
if (!cansee(u->faction, u->region, target, 0)) return NULL; if (!cansee(u->faction, u->region, target, 0)) return NULL;
if (is_waiting(u)) return NULL; if (is_waiting(u)) return NULL;
sprintf(zText, "%s %s", return create_order(K_ATTACK, u->faction->locale, "%i", u->no);
locale_string(u->faction->locale, keywords[K_ATTACK]),
unitid(target));
return parse_order((xmlChar*)zText, u->faction->locale);
} }
@ -159,7 +154,7 @@ get_money_for_dragon(region * r, unit * u, int wanted)
if (rmoney(r) >= wanted) { if (rmoney(r) >= wanted) {
/* 5% chance, dass der drache aus einer laune raus attackiert */ /* 5% chance, dass der drache aus einer laune raus attackiert */
if (chance(1.0-u->race->aggression)) { if (chance(1.0-u->race->aggression)) {
return parse_order(LOC(default_locale, keywords[K_TAX]), default_locale); return create_order(K_TAX, default_locale, "");
} }
} }
@ -182,7 +177,7 @@ get_money_for_dragon(region * r, unit * u, int wanted)
/* falls die einnahmen erreicht werden, bleibt das monster noch eine /* falls die einnahmen erreicht werden, bleibt das monster noch eine
* runde hier. */ * runde hier. */
if (n + rmoney(r) >= wanted) { if (n + rmoney(r) >= wanted) {
return parse_order(LOC(default_locale, keywords[K_TAX]), default_locale); return create_order(K_TAX, default_locale, "");
} }
/* wenn wir NULL zurückliefern, macht der drache was anderes, z.b. weggehen */ /* wenn wir NULL zurückliefern, macht der drache was anderes, z.b. weggehen */
@ -355,7 +350,6 @@ static order *
monster_move(region * r, unit * u) monster_move(region * r, unit * u)
{ {
direction_t d = NODIRECTION; direction_t d = NODIRECTION;
xmlChar zOrder[64];
if (is_waiting(u)) return NULL; if (is_waiting(u)) return NULL;
switch(old_race(u->race)) { switch(old_race(u->race)) {
@ -378,11 +372,8 @@ monster_move(region * r, unit * u)
if (d == NODIRECTION) if (d == NODIRECTION)
return NULL; return NULL;
sprintf((char*)zOrder, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
locale_string(u->faction->locale, directions[d]));
reduce_weight(u); reduce_weight(u);
return parse_order(zOrder, u->faction->locale); return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[d]));
} }
/* Wir machen das mal autoconf-style: */ /* Wir machen das mal autoconf-style: */
@ -491,7 +482,6 @@ monster_seeks_target(region *r, unit *u)
int dist, dist2; int dist, dist2;
direction_t i; direction_t i;
region *nr; region *nr;
xmlChar zOrder[128];
/* Das Monster sucht ein bestimmtes Opfer. Welches, steht /* Das Monster sucht ein bestimmtes Opfer. Welches, steht
* in einer Referenz/attribut * in einer Referenz/attribut
@ -539,9 +529,7 @@ monster_seeks_target(region *r, unit *u)
} }
assert(d != NODIRECTION ); assert(d != NODIRECTION );
sprintf((char *)zOrder, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]), return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[d]));
locale_string(u->faction->locale, directions[d]));
return parse_order(zOrder, u->faction->locale);
} }
unit * unit *
@ -757,10 +745,7 @@ monster_learn(unit *u)
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
if (sv->level>0) { if (sv->level>0) {
if (++c == n) { if (++c == n) {
xmlChar zOrder[128]; return create_order(K_STUDY, lang, "'%s'", skillname(sv->id, lang));
sprintf((char*)zOrder, "%s \"%s\"", locale_string(lang, keywords[K_STUDY]),
skillname(sv->id, lang));
return parse_order(zOrder, lang);
} }
} }
} }
@ -816,13 +801,11 @@ recruit_dracoids(unit * dragon, int size)
setstatus(un, ST_FIGHT); setstatus(un, ST_FIGHT);
for (weapon=un->items;weapon;weapon=weapon->next) { for (weapon=un->items;weapon;weapon=weapon->next) {
const weapon_type * wtype = weapon->type->rtype->wtype; const weapon_type * wtype = weapon->type->rtype->wtype;
xmlChar zOrder[128];
if (wtype && (wtype->flags & WTF_MISSILE)) { if (wtype && (wtype->flags & WTF_MISSILE)) {
setstatus(un, ST_BEHIND); setstatus(un, ST_BEHIND);
} }
sprintf((char*)zOrder, "%s \"%s\"", keywords[K_STUDY], new_order = create_order(K_STUDY, f->locale, "'%s'",
skillname(weapon->type->rtype->wtype->skill, f->locale)); skillname(weapon->type->rtype->wtype->skill, f->locale));
new_order = parse_order(zOrder, default_locale);
} }
if (new_order!=NULL) { if (new_order!=NULL) {
@ -892,13 +875,13 @@ plan_dragon(unit * u)
break; break;
} }
if (rng_int()%100 < 15) { if (rng_int()%100 < 15) {
const struct locale * lang = u->faction->locale;
/* do a growl */ /* do a growl */
if (rname(tr, u->faction->locale)) { if (rname(tr, lang)) {
sprintf(buf, addlist(&u->orders, create_order(K_MAIL, lang, "%s '%s %s %s %s'",
"botschaft an region %s~...~%s~etwas~in~%s.", LOC(lang, parameters[P_REGION]), random_growl(),
estring(random_growl()), u->number==1?"Ich~rieche":"Wir~riechen", u->number==1?"Ich rieche":"Wir riechen",
estring(rname(tr, u->faction->locale))); "etwas in", rname(tr, u->faction->locale)));
addlist(&u->orders, parse_order(buf, u->faction->locale));
} }
} }
} else { } else {
@ -919,9 +902,8 @@ plan_dragon(unit * u)
} }
} }
if (long_order==NULL) { if (long_order==NULL) {
sprintf(buf, "%s \"%s\"", keywords[K_STUDY], long_order = create_order(K_STUDY, u->faction->locale, "'%s'",
skillname(SK_OBSERVATION, u->faction->locale)); skillname(SK_OBSERVATION, u->faction->locale));
long_order = parse_order(buf, default_locale);
} }
return long_order; return long_order;
} }
@ -970,8 +952,7 @@ plan_monsters(void)
if (ta && !is_waiting(u)) { if (ta && !is_waiting(u)) {
unit * tu = (unit *)ta->data.v; unit * tu = (unit *)ta->data.v;
if (tu && tu->region==r) { if (tu && tu->region==r) {
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_ATTACK]), itoa36(tu->no)); addlist(&u->orders, create_order(K_ATTACK, u->faction->locale, "%i", tu->no));
addlist(&u->orders, parse_order(buf, u->faction->locale));
} else if (tu) { } else if (tu) {
tu = findunitg(ta->data.i, NULL); tu = findunitg(ta->data.i, NULL);
if (tu!=NULL) { if (tu!=NULL) {
@ -983,8 +964,7 @@ plan_monsters(void)
/* All monsters guard the region: */ /* All monsters guard the region: */
if (!is_waiting(u) && r->land) { if (!is_waiting(u) && r->land) {
const char * cmd = locale_string(u->faction->locale, keywords[K_GUARD]); addlist(&u->orders, create_order(K_GUARD, u->faction->locale, ""));
addlist(&u->orders, parse_order(cmd, u->faction->locale));
} }
/* Einheiten mit Bewegungsplan kriegen ein NACH: */ /* Einheiten mit Bewegungsplan kriegen ein NACH: */
@ -1006,10 +986,7 @@ plan_monsters(void)
* zu bewachen: */ * zu bewachen: */
if (u->race->bonus[SK_WEAPONLESS] != -99) { if (u->race->bonus[SK_WEAPONLESS] != -99) {
if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) { if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) {
sprintf(buf, "%s \"%s\"", long_order = create_order(K_STUDY, f->locale, "'%s'", skillname(SK_WEAPONLESS, f->locale));
locale_string(f->locale, keywords[K_STUDY]),
skillname(SK_WEAPONLESS, f->locale));
long_order = parse_order(buf, f->locale);
} }
} }
} }
@ -1019,7 +996,7 @@ plan_monsters(void)
switch (old_race(u->race)) { switch (old_race(u->race)) {
case RC_SEASERPENT: case RC_SEASERPENT:
long_order = parse_order(keywords[K_PIRACY], default_locale); long_order = create_order(K_PIRACY, f->locale, "");
break; break;
case RC_ALP: case RC_ALP:
long_order = monster_seeks_target(r, u); long_order = monster_seeks_target(r, u);
@ -1088,7 +1065,6 @@ spawn_dragons(void)
set_level(u, SK_OBSERVATION, 3); set_level(u, SK_OBSERVATION, 3);
set_level(u, SK_STEALTH, 2); set_level(u, SK_STEALTH, 2);
set_level(u, SK_AUSDAUER, 1); set_level(u, SK_AUSDAUER, 1);
set_string(&u->name, "Seeschlange");
} }
if ((rterrain(r) == T_GLACIER || r->terrain == newterrain(T_SWAMP) || rterrain(r) == T_DESERT) && rng_int() % 10000 < (5 + 100 * chaosfactor(r))) if ((rterrain(r) == T_GLACIER || r->terrain == newterrain(T_SWAMP) || rterrain(r) == T_DESERT) && rng_int() % 10000 < (5 + 100 * chaosfactor(r)))

View File

@ -589,8 +589,7 @@ jihad_attacks(void)
if (sf) sf->status = sf->status & (HELP_ALL - HELP_FIGHT); if (sf) sf->status = sf->status & (HELP_ALL - HELP_FIGHT);
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_ATTACK]), unitid(u)); addlist(&u2->orders, create_order(K_ATTACK, u->faction->locale, "%i", u->no));
addlist(&u2->orders, parse_order(buf, u->faction->locale));
} }
} }
} }

View File

@ -120,7 +120,7 @@ describe_braineater(unit * u, const struct locale * lang)
} }
const char * const char *
untoten_name(const unit * u) undead_name(const unit * u)
{ {
int uv, uu, un; int uv, uu, un;
static char name[NAMESIZE + 1]; static char name[NAMESIZE + 1];
@ -526,7 +526,7 @@ generic_name(const unit *u)
} }
const xmlChar * const xmlChar *
drachen_name(const unit *u) dragon_name(const unit *u)
{ {
static char name[NAMESIZE + 1]; static char name[NAMESIZE + 1];
int rnd = rng_int() % DTITEL; int rnd = rng_int() % DTITEL;
@ -722,11 +722,11 @@ register_names(void)
/* function name /* function name
* generate a name for a nonplayerunit * generate a name for a nonplayerunit
* race->generate_name() */ * race->generate_name() */
register_function((pf_generic)untoten_name, "nameundead"); register_function((pf_generic)undead_name, "nameundead");
register_function((pf_generic)skeleton_name, "nameskeleton"); register_function((pf_generic)skeleton_name, "nameskeleton");
register_function((pf_generic)zombie_name, "namezombie"); register_function((pf_generic)zombie_name, "namezombie");
register_function((pf_generic)ghoul_name, "nameghoul"); register_function((pf_generic)ghoul_name, "nameghoul");
register_function((pf_generic)drachen_name, "namedragon"); register_function((pf_generic)dragon_name, "namedragon");
register_function((pf_generic)dracoid_name, "namedracoid"); register_function((pf_generic)dracoid_name, "namedracoid");
register_function((pf_generic)generic_name, "namegeneric"); register_function((pf_generic)generic_name, "namegeneric");
} }

View File

@ -19,11 +19,11 @@
extern "C" { extern "C" {
#endif #endif
extern void register_names(void); extern void register_names(void);
const xmlChar *untoten_name(const struct unit * u); const xmlChar *undead_name(const struct unit * u);
const xmlChar *skeleton_name(const struct unit * u); const xmlChar *skeleton_name(const struct unit * u);
const xmlChar *zombie_name(const struct unit * u); const xmlChar *zombie_name(const struct unit * u);
const xmlChar *ghoul_name(const struct unit * u); const xmlChar *ghoul_name(const struct unit * u);
const xmlChar *drachen_name(const struct unit *u); const xmlChar *dragon_name(const struct unit *u);
const xmlChar *dracoid_name(const struct unit *u); const xmlChar *dracoid_name(const struct unit *u);
const xmlChar *generic_name(const struct unit *u); const xmlChar *generic_name(const struct unit *u);
const xmlChar *abkz(const xmlChar *s, size_t max); const xmlChar *abkz(const xmlChar *s, size_t max);

View File

@ -267,27 +267,20 @@ create_order(keyword_t kwd, const struct locale * lang, const char * params, ...
va_list marker; va_list marker;
char zBuffer[DISPLAYSIZE]; char zBuffer[DISPLAYSIZE];
char * sptr = zBuffer; char * sptr = zBuffer;
char quote = 0;
va_start(marker, params); va_start(marker, params);
while (params) { while (params) {
switch (*params) { switch (*params) {
case '%': case '%':
case ' ':
/* ignore these, they are syntactical sugar */ /* ignore these, they are syntactical sugar */
break; break;
case '"': case '"':
case '\'': case '\'':
case ' ':
*sptr++ = *params; *sptr++ = *params;
if (!quote) quote = *params;
else if (quote==*params) {
quote = 0;
*sptr++ = ' ';
}
break; break;
case 's': case 's':
sptr += strlcpy(sptr, va_arg(marker, const char *), sizeof(zBuffer)-(sptr-zBuffer)); sptr += strlcpy(sptr, va_arg(marker, const char *), sizeof(zBuffer)-(sptr-zBuffer));
if (!quote) *sptr++ = ' ';
break; break;
case 'd': case 'd':
sptr += strlcpy(sptr, itoa10(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer)); sptr += strlcpy(sptr, itoa10(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer));
@ -295,6 +288,8 @@ create_order(keyword_t kwd, const struct locale * lang, const char * params, ...
case 'i': case 'i':
sptr += strlcpy(sptr, itoa36(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer)); sptr += strlcpy(sptr, itoa36(va_arg(marker, int)), sizeof(zBuffer)-(sptr-zBuffer));
break; break;
default:
assert(!"unknown format-character in create_order");
} }
} }
va_end(marker); va_end(marker);

View File

@ -1160,7 +1160,7 @@
</race> </race>
<race name="seaserpent" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="5000" weight="20000" capacity="5000" speed="1.000000" hp="600" ac="3" damage="2d15" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="4" scarepeasants="yes" swim="yes" teach="no" getitem="yes" resistbash="yes"> <race name="seaserpent" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="5000" weight="20000" capacity="5000" speed="1.000000" hp="600" ac="3" damage="2d15" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="4" scarepeasants="yes" swim="yes" teach="no" getitem="yes" resistbash="yes">
<ai splitsize="6" killpeasants="yes" moverandom="yes" learn="yes"/> <ai splitsize="6" killpeasants="yes" moverandom="yes" learn="yes"/>
<function name="name" value="namedragon"/> <function name="name" value="namegeneric"/>
<function name="move" value="moveswimming"/> <function name="move" value="moveswimming"/>
<skill name="tactics" modifier="4"/> <skill name="tactics" modifier="4"/>
<attack type="4" damage="1d30"/> <attack type="4" damage="1d30"/>