From 8df7894084c2709f906a8305f12b572138b0c6fd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 31 Jan 2002 22:18:00 +0000 Subject: [PATCH] * Schiffe werden in XML-Datei gespeichert. --- src/common/kernel/build.h | 2 +- src/common/kernel/building.c | 4 +- src/common/kernel/eressea.c | 2 + src/common/kernel/race.c | 2 +- src/common/kernel/save.c | 4 + src/common/kernel/ship.c | 174 +++++++++++++++++++++++++++++++--- src/common/kernel/ship.h | 9 +- src/eressea/main.c | 4 +- src/mapper/mapper.c | 1 + src/res/de/strings.xml | 33 ++++++- src/res/en/strings.xml | 23 +++++ src/res/eressea.xml | 1 + src/res/vinyambar-classic.xml | 1 + src/res/vinyambar.xml | 1 + 14 files changed, 235 insertions(+), 26 deletions(-) diff --git a/src/common/kernel/build.h b/src/common/kernel/build.h index 905e72ac8..823bdba18 100644 --- a/src/common/kernel/build.h +++ b/src/common/kernel/build.h @@ -113,7 +113,7 @@ typedef struct construction { int reqsize; /* size of object using up 1 set of requirement. */ requirement * materials; /* material req'd to build one object */ - const struct construction * improvement; + struct construction * improvement; /* next level, if upgradable. if more than one of these items * can be built (weapons, armour) per turn, must not be NULL, * but point to the same type again: diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 2319d3051..282b3de6d 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -222,7 +222,7 @@ static requirement castle_req[] = { }; #if LARGE_CASTLES -static const construction castle_bld[MAXBUILDINGS] = { +static construction castle_bld[MAXBUILDINGS] = { { SK_BUILDING, 1, 2, 1, castle_req, &castle_bld[1] }, { SK_BUILDING, 1, 8, 1, castle_req, &castle_bld[2] }, { SK_BUILDING, 2, 40, 1, castle_req, &castle_bld[3] }, @@ -232,7 +232,7 @@ static const construction castle_bld[MAXBUILDINGS] = { { SK_BUILDING, 6, -1, 1, castle_req, NULL } }; #else -static const construction castle_bld[MAXBUILDINGS] = { +static construction castle_bld[MAXBUILDINGS] = { { SK_BUILDING, 1, 2, 1, castle_req, &castle_bld[1] }, { SK_BUILDING, 2, 8, 1, castle_req, &castle_bld[2] }, { SK_BUILDING, 3, 40, 1, castle_req, &castle_bld[3] }, diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 3486baa1f..d79852834 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2233,6 +2233,7 @@ attrib_init(void) bt_register(&bt_generic); bt_register(&bt_caldera); +#ifdef NOXMLBOATS /* Schiffstypen registrieren: */ st_register(&st_boat); st_register(&st_balloon); @@ -2240,6 +2241,7 @@ attrib_init(void) st_register(&st_dragonship); st_register(&st_caravelle); st_register(&st_trireme); +#endif /* disable: st_register(&st_transport); */ diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index ca5f03bc2..668081ee5 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -259,7 +259,7 @@ give_starting_equipment(struct region *r, struct unit *u) break; case RC_AQUARIAN: { - ship *sh = new_ship(&st_boat, r); + ship *sh = new_ship(st_find("boat"), r); sh->size = sh->type->construction->maxsize; addlist(&r->ships, sh); u->ship = sh; diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 994a2a09d..417ab92b8 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1299,9 +1299,13 @@ readgame(boolean backup) rds(F, &sh->display); if (global.data_version < SHIPTYPE_VERSION) { +#ifdef NOXMLBOATS const ship_type * oldship[] = { &st_boat, &st_balloon, &st_longboat, &st_dragonship, &st_caravelle, &st_trireme }; int i = ri(F); sh->type = oldship[i]; +#else + assert(!"cannot read old datafile with xml ship support"); +#endif } else { rs(F, buf); diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index 4b84fe99e..9f5f325d6 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -20,10 +20,12 @@ #include "unit.h" #include "item.h" #include "region.h" +#include "skill.h" /* util includes */ #include #include +#include #include /* libc includes */ @@ -66,9 +68,9 @@ st_find(const char* name) { const struct ship_typelist * stl = shiptypes; while (stl && strcasecmp(stl->type->name[0], name)) stl = stl->next; - if (!stl) { + if (!stl) { /* compatibility for old datafiles */ stl = shiptypes; - while (stl && strncasecmp(stl->type->name[0], name, strlen(name))) stl = stl->next; + while (stl && strcasecmp(locale_string(default_locale, stl->type->name[0]), name)) stl = stl->next; } return stl?stl->type:NULL; } @@ -81,16 +83,6 @@ st_register(const ship_type * type) { shiptypes = stl; } -static const terrain_t coast_large[] = { - T_OCEAN, T_PLAIN, NOTERRAIN -}; - -static const terrain_t coast_small[] = { - T_OCEAN, T_PLAIN, T_SWAMP, T_DESERT, T_HIGHLAND, T_MOUNTAIN, T_GLACIER, - T_GRASSLAND, T_VOLCANO, T_VOLCANO_SMOKING, T_ICEBERG_SLEEP, T_ICEBERG, - NOTERRAIN -}; - #define SMAXHASH 8191 ship *shiphash[SMAXHASH]; void @@ -155,6 +147,17 @@ captain(ship *sh, region *r) /* Alte Schiffstypen: */ +#ifdef NOXMLBOATS +static const terrain_t coast_large[] = { + T_OCEAN, T_PLAIN, NOTERRAIN +}; + +static terrain_t coast_small[] = { + T_OCEAN, T_PLAIN, T_SWAMP, T_DESERT, T_HIGHLAND, T_MOUNTAIN, T_GLACIER, + T_GRASSLAND, T_VOLCANO, T_VOLCANO_SMOKING, T_ICEBERG_SLEEP, T_ICEBERG, + NOTERRAIN +}; + static requirement boat_req[] = { {I_WOOD, 1}, {0, 0} @@ -263,6 +266,7 @@ const ship_type st_trireme = { 4, 1, 120, coast_large, &trireme_bld }; +#endif ship * new_ship(const ship_type * stype, region * r) @@ -343,3 +347,149 @@ shipowner(const region * r, const ship * sh) fset(first, FL_OWNER); return first; } + +#ifdef NOXMLBOATS +void +xml_writeships(void) +{ + FILE * F = fopen("ships.xml", "w"); + ship_typelist *stl= shiptypes; + while (stl) { + int i; + const ship_type * st = stl->type; + fprintf(F, "name[0]), st->range, st->storm, st->damage, st->cabins, st->cargo, + st->cptskill, st->minskill, st->sumskill); + if (st->flags & SFL_OPENSEA) fputs(" opensea", F); + if (st->flags & SFL_FLY) fputs(" fly", F); + fputs(">\n", F); + for (i=0;st->coast[i]!=NOTERRAIN;++i) { + fprintf(F, "\t\n", terrain[st->coast[i]].name); + } + fprintf(F, "\t\n", + skillname(st->construction->skill, NULL), st->construction->minskill, + st->construction->maxsize, st->construction->reqsize); + for (i=0;st->construction->materials[i].number!=0;++i) { + fprintf(F, "\t\t\n", + oldresourcetype[st->construction->materials[i].type]->_name[0], + st->construction->materials[i].number); + } + fputs("\t\n", F); + fputs("\n\n", F); + stl=stl->next; + } + fclose(F); +} +#endif + +static int +tagend(struct xml_stack * stack) +{ + const xml_tag * tag = stack->tag; + if (strcmp(tag->name, "ship")==0) { + st_register((ship_type*)stack->state); + stack->state = 0; + } + return XML_OK; +} + +static int +tagbegin(struct xml_stack * stack) +{ + ship_type * st = (ship_type *)stack->state; + const xml_tag * tag = stack->tag; + if (strcmp(tag->name, "ship")==0) { + const char * name = xml_value(tag, "name"); + if (name!=NULL) { + st = stack->state = calloc(sizeof(ship_type), 1); + st->name[0] = strdup(name); + st->name[1] = strcat(strcpy(malloc(strlen(name)+3), name),"_a"); + st->cabins = xml_ivalue(tag, "cabins"); + st->cargo = xml_ivalue(tag, "cargo"); + st->combat = xml_ivalue(tag, "combat"); + st->cptskill = xml_ivalue(tag, "cptskill"); + st->damage = xml_fvalue(tag, "damage"); + if (xml_bvalue(tag, "fly")) st->flags |= SFL_FLY; + if (xml_bvalue(tag, "opensea")) st->flags |= SFL_OPENSEA; + st->minskill = xml_ivalue(tag, "minskill"); + st->range = xml_ivalue(tag, "range"); + st->storm = xml_fvalue(tag, "storm"); + st->sumskill = xml_ivalue(tag, "sumskill"); + } + } else if (st!=NULL) { + if (strcmp(tag->name, "coast")==0) { + int size=0; + terrain_t t; + terrain_t * add; + const char * tname = xml_value(tag, "terrain"); + if (tname!=NULL) { + if (st->coast) { + terrain_t * tnew; + for (;st->coast[size++];); + tnew = malloc(sizeof(terrain_t) * (size+2)); + memcpy(tnew, st->coast, size*sizeof(terrain_t)); + free(st->coast); + st->coast = tnew; + add = st->coast+size; + } else { + st->coast = malloc(sizeof(terrain_t) * 2); + add = st->coast; + } + add[0] = NOTERRAIN; + for (t=0;t!=MAXTERRAINS;++t) if (strcmp(tname, terrain[t].name)==0) { + add[0] = t; + break; + } + add[1] = NOTERRAIN; + } + } else if (strcmp(tag->name, "construction")==0) { + construction * con = st->construction = calloc(sizeof(construction), 1); + con->maxsize = xml_ivalue(tag, "maxsize"); + con->minskill = xml_ivalue(tag, "minskill"); + con->reqsize = xml_ivalue(tag, "reqsize"); + con->skill = sk_find(xml_value(tag, "skill")); + } else if (strcmp(tag->name, "requirement")==0) { + construction * con = st->construction; + if (con!=NULL) { + const resource_type * rtype; + resource_t type = NORESOURCE; + requirement * radd = con->materials; + if (radd) { + requirement * rnew; + int size; + for (size=0;radd[size++].number;); + rnew = malloc(sizeof(requirement) * (size+2)); + memcpy(rnew, radd, size*sizeof(requirement)); + free(radd); + con->materials = rnew; + radd = rnew+size; + } else { + radd = con->materials = calloc(sizeof(requirement), 2); + } + radd[0].number = xml_ivalue(tag, "quantity"); + rtype = rt_find(xml_value(tag, "type")); + for (type=0;type!=MAX_RESOURCES;++type) { + if (oldresourcetype[type]==rtype) { + radd[0].type = type; + break; + } + } + radd[1].number = 0; + radd[1].type = 0; + } + } + } + return XML_OK; +} + +static xml_callbacks xml_ships = { + tagbegin, tagend, NULL +}; + +void +register_ships(void) +{ +#ifndef NOXMLBOATS + xml_register(&xml_ships, "eressea ship", 0); +#endif +} \ No newline at end of file diff --git a/src/common/kernel/ship.h b/src/common/kernel/ship.h index 67d1152ee..659d39951 100644 --- a/src/common/kernel/ship.h +++ b/src/common/kernel/ship.h @@ -40,9 +40,9 @@ typedef struct ship_type { int minskill; /* min. skill to sail this (crew) */ int sumskill; /* min. sum of crew+captain */ - const terrain_t * coast; /* coast that this ship can land on */ + terrain_t * coast; /* coast that this ship can land on */ - const construction * construction; /* how to build a ship */ + construction * construction; /* how to build a ship */ } ship_type; typedef struct ship_typelist { @@ -53,15 +53,15 @@ typedef struct ship_typelist { extern ship_typelist *shiptypes; /* Alte Schiffstypen: */ - +#ifdef NOXMLBOATS extern const ship_type st_boat; extern const ship_type st_balloon; extern const ship_type st_longboat; extern const ship_type st_dragonship; extern const ship_type st_caravelle; extern const ship_type st_trireme; - extern const ship_type st_transport; +#endif extern const ship_type * st_find(const char* name); extern void st_register(const ship_type * type); @@ -95,4 +95,5 @@ extern ship *findship(int n); extern const struct ship_type * findshiptype(const char *s, const struct locale * lang); +extern void register_ships(void); #endif diff --git a/src/eressea/main.c b/src/eressea/main.c index 9a3387a22..049a0138e 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -164,6 +164,7 @@ game_init(void) debug_language("locales.log"); register_races(); register_resources(); + register_ships(); register_items(); register_spells(); register_dungeon(); @@ -582,7 +583,8 @@ main(int argc, char *argv[]) kernel_init(); game_init(); #if defined(BETA_CODE) && 0 - xml_writeitems("items.xml"); + xml_writeships(); + /* xml_writeitems("items.xml"); */ return 0; #endif diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 44d8a4ad1..ac03666f2 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -1467,6 +1467,7 @@ main(int argc, char *argv[]) register_races(); register_resources(); + register_ships(); register_items(); register_spells(); /* register_dungeon(); */ diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 06fcc69d7..2d61f7054 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -2,6 +2,7 @@ _d: dativ (wir erklären allen /Trollen/ den Krieg) _p: plural (13 /Trolle/) _x: preposition (15 /Troll/schwerter) + _a: including article (ein Troll, a troll) @@ -194,19 +195,41 @@ Schiffstypen - + + ein Ballon + + + eine Karavelle + + + ein Boot + + + ein Langboot + + + ein Drachenschiff + + + eine Trireme + + + + Ballon + + Karavelle - + Boot - + Langboot - + Drachenschiff - + Trireme diff --git a/src/res/en/strings.xml b/src/res/en/strings.xml index f5ed78c40..3a1278d0a 100644 --- a/src/res/en/strings.xml +++ b/src/res/en/strings.xml @@ -62,6 +62,29 @@ trireme + + balloon + + + Schiffstypen + + a caravel + + + a boat + + + a longboat + + + a balloon + + + a dragonship + + + a trireme + Terraintypen diff --git a/src/res/eressea.xml b/src/res/eressea.xml index 3b6d1b7bd..3b19dc37f 100644 --- a/src/res/eressea.xml +++ b/src/res/eressea.xml @@ -9,6 +9,7 @@ + Game specific diff --git a/src/res/vinyambar-classic.xml b/src/res/vinyambar-classic.xml index 5e187356d..059f730c1 100644 --- a/src/res/vinyambar-classic.xml +++ b/src/res/vinyambar-classic.xml @@ -9,6 +9,7 @@ + Game specific diff --git a/src/res/vinyambar.xml b/src/res/vinyambar.xml index 6f83202c8..1f66e1b11 100644 --- a/src/res/vinyambar.xml +++ b/src/res/vinyambar.xml @@ -9,6 +9,7 @@ + Game specific