RTS/Archetypes (WIP):

- message and locale-fixes
This commit is contained in:
Enno Rehling 2007-05-28 21:10:59 +00:00
parent 5ca0e5cd8a
commit 0ebf9e3187
9 changed files with 76 additions and 65 deletions

View File

@ -47,36 +47,24 @@ register_archetype(archetype * arch)
archetypes = arch;
}
const archetype *
get_archetype(const char * name)
{
const archetype * arch = archetypes;
for (;arch;arch=arch->next) {
if (strcmp(name, arch->name)==0) {
return arch;
}
}
return NULL;
}
void
init_archetypes(void)
{
char zName[64];
const struct locale * lang = locales;
for (;lang;lang=nextlocale(lang)) {
variant var;
archetype * arch = archetypes;
struct tnode * tokens = get_translations(lang, UT_ARCHETYPES);
for (;arch;arch=arch->next) {
const char * s;
const char *s1, *s2;
var.v = arch;
s = locale_getstring(lang, arch->name);
if (s!=NULL) addtoken(tokens, s, var);
sprintf(zName, "%s_p", arch->name);
s = locale_getstring(lang, zName);
if (s!=NULL) addtoken(tokens, s, var);
s1 = LOC(lang, arch->name[0]);
addtoken(tokens, s1, var);
s2 = LOC(lang, arch->name[1]);
if (strcmp(s2, s1)!=0) {
addtoken(tokens, s2, var);
}
}
}
}
@ -84,6 +72,7 @@ init_archetypes(void)
static int
parse_archetypes(xmlDocPtr doc)
{
char zName[64];
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr result = xmlXPathEvalExpression(BAD_CAST "/eressea/archetypes/archetype", xpath);
xmlNodeSetPtr nodes = result->nodesetval;
@ -98,7 +87,9 @@ parse_archetypes(xmlDocPtr doc)
property = xmlGetProp(node, BAD_CAST "name");
assert(property!=NULL);
arch->name = strdup((const char *)property);
arch->name[0] = strdup((const char *)property);
sprintf(zName, "%s_p", arch->name[0]);
arch->name[1] = strdup(zName);
xmlFree(property);
property = xmlGetProp(node, BAD_CAST "equip");
@ -106,7 +97,7 @@ parse_archetypes(xmlDocPtr doc)
arch->equip = get_equipment((const char*)property);
xmlFree(property);
} else {
arch->equip = get_equipment(arch->name);
arch->equip = get_equipment(arch->name[0]);
}
property = xmlGetProp(node, BAD_CAST "building");

View File

@ -18,7 +18,7 @@ extern "C" {
#endif
typedef struct archetype {
char * name;
char * name[2];
int size;
struct building_type * btype;
struct equipment * equip;
@ -28,7 +28,6 @@ extern "C" {
extern const struct archetype * find_archetype(const char * s, const struct locale * lang);
extern void init_archetypes(void);
extern const struct archetype * get_archetype(const char * name);
extern void register_archetype(struct archetype * arch);
extern void register_archetypes(void);

View File

@ -1058,14 +1058,15 @@ maintain_buildings(region * r, boolean crash)
static int
recruit_archetype(unit * u, order * ord)
{
int n;
int want;
const char * s;
init_tokens(ord);
skip_token();
n = geti();
want = geti();
s = getstrtoken();
if (n>0 && s && s[0]) {
if (want>0 && s && s[0]) {
int n = want;
const archetype * arch = find_archetype(s, u->faction->locale);
attrib * a = NULL;
@ -1111,11 +1112,11 @@ recruit_archetype(unit * u, order * ord)
a->data.i += n*arch->size;
}
ADDMSG(&u->faction->msgs, msg_message("recruit_archetype",
"unit amount archetype", u, n, arch->name));
"unit amount archetype", u, n, arch->name[n==1]));
return n;
} else switch(n) {
case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype));
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype, want));
break;
case ELOWSKILL:
case ENEEDSKILL:
@ -1235,9 +1236,9 @@ manufacture(unit * u, const item_type * itype, int want)
return;
}
if(want==0)
want=maxbuild(u, itype->construction);
if (want==0) {
want = maxbuild(u, itype->construction);
}
n = build(u, itype->construction, 0, want);
switch (n) {
case ENEEDSKILL:
@ -1250,7 +1251,7 @@ manufacture(unit * u, const item_type * itype, int want)
sk, minskill, itype->rtype, 1));
return;
case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, itype->construction));
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, itype->construction, want));
return;
}
if (n>0) {
@ -1647,8 +1648,9 @@ create_potion(unit * u, const potion_type * ptype, int want)
{
int built;
if(want==0)
want=maxbuild(u, ptype->itype->construction);
if (want==0) {
want = maxbuild(u, ptype->itype->construction);
}
built = build(u, ptype->itype->construction, 0, want);
switch (built) {
case ELOWSKILL:
@ -1661,7 +1663,7 @@ create_potion(unit * u, const potion_type * ptype, int want)
break;
case ENOMATERIALS:
/* something missing from the list of materials */
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, ptype->itype->construction));
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, ptype->itype->construction, want));
return;
break;
default:

View File

@ -753,6 +753,16 @@ trailinto(const region * r, const struct locale * lang)
return "%s";
}
static void
eval_localize(struct opstack ** stack, const void * userdata) /* (string, locale) -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct locale * lang = f?f->locale:default_locale;
const char *c = (const char *)opop_v(stack);
c = locale_string(lang, c);
opush_v(stack, strcpy(balloc(strlen(c)+1), c));
}
static void
eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int */
{
@ -3105,6 +3115,7 @@ report_init(void)
add_function("direction", &eval_direction);
add_function("int36", &eval_int36);
add_function("trail", &eval_trail);
add_function("localize", &eval_localize);
add_function("spell", &eval_spell);
add_function("resources", &eval_resources);

View File

@ -769,15 +769,16 @@ build(unit * u, const construction * ctype, int completed, int want)
}
message *
msg_materials_required(unit * u, order * ord, const construction * ctype)
msg_materials_required(unit * u, order * ord, const construction * ctype, int multi)
{
/* something missing from the list of materials */
int c;
/* something missing from the list of materials */
resource * reslist = NULL;
if (multi<=0 || multi==INT_MAX) multi = 1;
for (c=0;ctype->materials[c].number; ++c) {
resource * res = malloc(sizeof(resource));
res->number = ctype->materials[c].number / ctype->reqsize;
res->number = multi * ctype->materials[c].number / ctype->reqsize;
res->type = ctype->materials[c].rtype;
res->next = reslist;
reslist = res;
@ -812,7 +813,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
{
region * r = u->region;
boolean newbuilding = false;
int built = 0, id;
int n = want, built = 0, id;
building * b = NULL;
/* einmalige Korrektur */
static char buffer[8 + IDSIZE + 1 + NAMESIZE + 1];
@ -869,26 +870,26 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
cmistake(u, ord, 318, MSG_PRODUCE);
return;
}
want = 1;
n = 1;
}
if (b) built = b->size;
if (want<=0 || want == INT_MAX) {
if (n<=0 || n == INT_MAX) {
if(b == NULL) {
if(btype->maxsize > 0) {
want = btype->maxsize - built;
n = btype->maxsize - built;
} else {
want = INT_MAX;
n = INT_MAX;
}
} else {
if(b->type->maxsize > 0) {
want = b->type->maxsize - built;
if (b->type->maxsize > 0) {
n = b->type->maxsize - built;
} else {
want = INT_MAX;
n = INT_MAX;
}
}
}
built = build(u, btype->construction, built, want);
built = build(u, btype->construction, built, n);
switch (built) {
case ECOMPLETE:
@ -896,7 +897,7 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
cmistake(u, ord, 4, MSG_PRODUCE);
return;
case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, btype->construction));
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, btype->construction, want));
return;
case ELOWSKILL:
case ENEEDSKILL:
@ -930,13 +931,13 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
btname = LOC(lang, btype->_name);
if (want-built <= 0) {
if (n-built <= 0) {
/* gebäude fertig */
strcpy(buffer, LOC(lang, "defaultorder"));
new_order = parse_order(buffer, lang);
} else if (want!=INT_MAX) {
} else if (n!=INT_MAX) {
/* reduzierte restgröße */
sprintf(buffer, "%s %d %s %s", LOC(lang, keywords[K_MAKE]), want-built, btname, buildingid(b));
sprintf(buffer, "%s %d %s %s", LOC(lang, keywords[K_MAKE]), n-built, btname, buildingid(b));
new_order = parse_order(buffer, lang);
} else if (btname) {
/* Neues Haus, Befehl mit Gebäudename */

View File

@ -79,7 +79,7 @@ void sunhash(struct ship * sh);
extern int build(struct unit * u, const construction * ctype, int completed, int want);
extern int maxbuild(const struct unit *u, const construction *cons);
extern struct message * msg_materials_required(struct unit * u, struct order * ord, const struct construction * ctype);
extern struct message * msg_materials_required(struct unit * u, struct order * ord, const struct construction * ctype, int multi);
/** error messages that build may return: */
#define ELOWSKILL -1
#define ENEEDSKILL -2

View File

@ -450,17 +450,6 @@ eval_int(opstack ** stack, const void * userdata)
opush(stack, var);
}
#include "language.h"
static void
eval_localize(opstack ** stack, const void * userdata) /* (string, locale) -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct locale *lang = f?f->locale:default_locale;
const char *c = (const char *)opop_v(stack);
c = locale_string(lang, c);
opush_v(stack, strcpy(balloc(strlen(c)+1), c));
}
void
translation_init(void)
{
@ -471,7 +460,6 @@ translation_init(void)
add_function("strlen", &eval_strlen);
add_function("if", &eval_if);
add_function("isnull", &eval_isnull);
add_function("localize", &eval_localize);
}
void

View File

@ -1,12 +1,22 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<strings>
<!-- OPTION [x] -->
<string name="gamedesigner">
<text locale="en">game designer</text>
<text locale="de">Spieldesigner</text>
</string>
<string name="gamedesigner_p">
<text locale="en">game designers</text>
<text locale="de">Spieldesigner</text>
</string>
<string name="knight">
<text locale="en">knight</text>
<text locale="de">Ritter</text>
</string>
<string name="knight_p">
<text locale="en">knights</text>
<text locale="de">Ritter</text>
</string>
<string name="craftsman">
<text locale="en">craftsman</text>
@ -14,6 +24,7 @@
</string>
<string name="craftsman_p">
<text locale="en">craftsmen</text>
<text locale="de">Handwerker</text>
</string>
<string name="swordsman">
<text locale="en">swordsman</text>
@ -21,6 +32,7 @@
</string>
<string name="swordsman_p">
<text locale="en">swordsmen</text>
<text locale="de">Schwertkämpfer</text>
</string>
<string name="pikeman">
<text locale="en">swordsman</text>

View File

@ -26,5 +26,12 @@
</construction>
</archetype>
<archetype name="gamedesigner" building="castle" cost="1">
<construction reqsize="1">
<requirement type="laen" quantity="100"/>
<requirement type="mallorn" quantity="100"/>
</construction>
</archetype>
</archetypes>