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.
This commit is contained in:
Enno Rehling 2014-08-28 19:50:38 +02:00
parent 932a615837
commit c0230d2662
14 changed files with 23 additions and 54 deletions

View File

@ -22,7 +22,6 @@
<xi:include href="config:///game/familiars.xml"/>
<xi:include href="config:///core/terrains.xml"/>
<xi:include href="config:///game/terrains.xml"/>
<xi:include href="config:///default/directions.xml"/>
<xi:include href="config:///game/artrewards.xml"/>
<xi:include href="config:///game/buildings.xml"/>
<xi:include href="config:///core/calendar.xml"/>

View File

@ -10,7 +10,6 @@
<xi:include href="config:///core/common/buildings.xml"/>
<xi:include href="config:///game/familiars.xml"/>
<xi:include href="config:///default/directions.xml"/>
<xi:include href="config:///default/adamantium.xml" />
<xi:include href="config:///game/ships.xml"/>

View File

@ -10,7 +10,6 @@
<xi:include href="config:///core/common/buildings.xml"/>
<xi:include href="config:///game/familiars.xml"/>
<xi:include href="config:///default/directions.xml"/>
<xi:include href="config:///default/adamantium.xml" />
<xi:include href="config:///game/ships.xml"/>

View File

@ -22,7 +22,6 @@
<xi:include href="config:///game/familiars.xml"/>
<xi:include href="config:///core/terrains.xml"/>
<xi:include href="config:///game/terrains.xml"/>
<xi:include href="config:///default/directions.xml"/>
<xi:include href="config:///game/artrewards.xml"/>
<xi:include href="config:///game/buildings.xml"/>
<xi:include href="config:///core/calendar.xml"/>

View File

@ -1,7 +1,5 @@
<?xml version="1.0"?>
<eressea xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="config:///default/directions.xml"/>
<xi:include href="config:///core/messages.xml"/>
<xi:include href="config:///core/de/strings.xml"/>

View File

@ -1,4 +0,0 @@
<?xml version="1.0"?>
<directions>
<dir name="vortex" desc="vortex_desc"/>
</directions>

View File

@ -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

View File

@ -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;
}

View File

@ -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();

View File

@ -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) {

View File

@ -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
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);