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

View File

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

View File

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

View File

@ -753,6 +753,16 @@ trailinto(const region * r, const struct locale * lang)
return "%s"; 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 static void
eval_trail(struct opstack ** stack, const void * userdata) /* (int, int) -> int */ 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("direction", &eval_direction);
add_function("int36", &eval_int36); add_function("int36", &eval_int36);
add_function("trail", &eval_trail); add_function("trail", &eval_trail);
add_function("localize", &eval_localize);
add_function("spell", &eval_spell); add_function("spell", &eval_spell);
add_function("resources", &eval_resources); add_function("resources", &eval_resources);

View File

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

View File

@ -450,17 +450,6 @@ eval_int(opstack ** stack, const void * userdata)
opush(stack, var); 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 void
translation_init(void) translation_init(void)
{ {
@ -471,7 +460,6 @@ translation_init(void)
add_function("strlen", &eval_strlen); add_function("strlen", &eval_strlen);
add_function("if", &eval_if); add_function("if", &eval_if);
add_function("isnull", &eval_isnull); add_function("isnull", &eval_isnull);
add_function("localize", &eval_localize);
} }
void void

View File

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

View File

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