From c0230d26624aa4ceb925f412c41b44e06c95bb12 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 28 Aug 2014 19:50:38 +0200 Subject: [PATCH] In the game, there is only ever one special direction, and it is for the astral space. less XML, more code. cleaning up the special direction parsing a bit. --- conf/e2/config.xml | 1 - conf/e3/config.xml | 1 - conf/e4/config.xml | 1 - game-e2/config.xml | 1 - game-e3/config.xml | 2 -- res/directions.xml | 4 ---- src/kernel/xmlreader.c | 28 ---------------------------- src/move.c | 6 +++++- src/spells.c | 1 + src/util/language.c | 9 +++++++++ src/util/language.h | 3 ++- src/util/translation.c | 2 +- src/vortex.c | 15 ++++----------- src/vortex.h | 3 +-- 14 files changed, 23 insertions(+), 54 deletions(-) delete mode 100644 res/directions.xml diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 2ca33346c..7265cbb89 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -22,7 +22,6 @@ - diff --git a/conf/e3/config.xml b/conf/e3/config.xml index b30ad8bfc..32f941cb8 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -10,7 +10,6 @@ - diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 44cc35471..fff10fbc3 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -10,7 +10,6 @@ - diff --git a/game-e2/config.xml b/game-e2/config.xml index 871f893d8..ec8a8855e 100644 --- a/game-e2/config.xml +++ b/game-e2/config.xml @@ -22,7 +22,6 @@ - diff --git a/game-e3/config.xml b/game-e3/config.xml index 5841fe90b..a66b20393 100644 --- a/game-e3/config.xml +++ b/game-e3/config.xml @@ -1,7 +1,5 @@ - - diff --git a/res/directions.xml b/res/directions.xml deleted file mode 100644 index 0e2e0b5fe..000000000 --- a/res/directions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d0554a4f8..d93ec6309 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -461,33 +461,6 @@ static int parse_calendar(xmlDocPtr doc) return rv; } -static int parse_directions(xmlDocPtr doc) -{ - xmlXPathContextPtr xpath = xmlXPathNewContext(doc); - xmlXPathObjectPtr xpathDirections; - xmlNodeSetPtr nsetDirections; - int rv = 0; - - /* reading eressea/directions/dir */ - xpathDirections = - xmlXPathEvalExpression(BAD_CAST "/eressea/directions/dir", xpath); - nsetDirections = xpathDirections->nodesetval; - if (nsetDirections != NULL) { - int k; - for (k = 0; k != nsetDirections->nodeNr; ++k) { - xmlNodePtr dir = nsetDirections->nodeTab[k]; - xmlChar *propValue = xmlGetProp(dir, BAD_CAST "name"); - - register_special_direction((const char *)propValue); - xmlFree(propValue); - } - } - xmlXPathFreeObject(xpathDirections); - xmlXPathFreeContext(xpath); - - return rv; -} - static int parse_ships(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -2309,6 +2282,5 @@ void register_xmlreader(void) xml_register_callback(parse_equipment); /* requires spells */ xml_register_callback(parse_races); /* requires spells */ xml_register_callback(parse_calendar); - xml_register_callback(parse_directions); } #endif diff --git a/src/move.c b/src/move.c index c86a61be2..bf87d6fda 100644 --- a/src/move.c +++ b/src/move.c @@ -1086,7 +1086,11 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp) break; case NODIRECTION: - r2 = find_special_direction(r, token, u->faction->locale); + token = (const char *)get_translation(u->faction->locale, token, UT_SPECDIR); + if (!token) { + return E_MOVE_NOREGION; + } + r2 = find_special_direction(r, token); if (r2 == NULL) { return E_MOVE_NOREGION; } diff --git a/src/spells.c b/src/spells.c index 41b6e313c..ba7c9c578 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6868,6 +6868,7 @@ void register_spells(void) register_function((pf_generic)sp_kampfzauber, "combat_spell"); register_spelldata(); + register_special_direction("vortex"); register_unitcurse(); register_regioncurse(); diff --git a/src/util/language.c b/src/util/language.c index 6c7afdba4..e0384e9b6 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -234,6 +234,15 @@ void ** get_translations(const struct locale *lang, int index) return lstrs[0].tokens + index; } +void *get_translation(const struct locale *lang, const char *str, int index) { + void **tokens = get_translations(lang, index); + variant var; + if (findtoken(*tokens, str, &var) == E_TOK_SUCCESS) { + return var.v; + } + return NULL; +} + void free_locales(void) { while (locales) { diff --git a/src/util/language.h b/src/util/language.h index aeb79ab64..7083dec1f 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -65,7 +65,8 @@ extern "C" { UT_MAX }; - void ** get_translations(const struct locale *lang, int index); + void ** get_translations(const struct locale *lang, int type); + void * get_translation(const struct locale *lang, const char *str, int type); #ifdef __cplusplus } diff --git a/src/util/translation.c b/src/util/translation.c index 1c93c0bb2..b384acc64 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -48,7 +48,7 @@ void opstack_push(opstack ** stackp, variant data) opstack *stack = *stackp; if (stack == NULL) { stack = (opstack *) malloc(sizeof(opstack)); - stack->size = 1; + stack->size = 2; stack->begin = malloc(sizeof(variant) * stack->size); stack->top = stack->begin; *stackp = stack; diff --git a/src/vortex.c b/src/vortex.c index 5a0f6482e..5584bbfe2 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -39,7 +39,7 @@ void register_special_direction(const char *name) var.v = str; addtoken(tokens, token, var); - if (lang == default_locale) { + if (lang == locales) { dir_lookup *dl = malloc(sizeof(dir_lookup)); dl->name = str; dl->oldname = token; @@ -134,8 +134,7 @@ attrib_type at_direction = { a_readdirection }; -region *find_special_direction(const region * r, const char *token, - const struct locale *lang) +region *find_special_direction(const region * r, const char *token) { attrib *a; spec_direction *d; @@ -146,14 +145,8 @@ region *find_special_direction(const region * r, const char *token, a = a->next) { d = (spec_direction *)(a->data.v); - if (d->active) { - void **tokens = get_translations(lang, UT_SPECDIR); - variant var; - if (findtoken(*tokens, token, &var) == E_TOK_SUCCESS) { - if (strcmp((const char *)var.v, d->keyword) == 0) { - return findregion(d->x, d->y); - } - } + if (d->active && strcmp(token, d->keyword) == 0) { + return findregion(d->x, d->y); } } diff --git a/src/vortex.h b/src/vortex.h index 910811cd1..905e1d8d5 100644 --- a/src/vortex.h +++ b/src/vortex.h @@ -6,7 +6,6 @@ extern "C" { struct region; struct attrib; - struct locale; typedef struct spec_direction { int x, y; @@ -19,7 +18,7 @@ extern "C" { extern struct attrib_type at_direction; struct region *find_special_direction(const struct region *r, - const char *token, const struct locale *lang); + const char *token); void register_special_direction(const char *name); struct spec_direction *special_direction(const struct region * from, const struct region * to);