* Schiffe werden in XML-Datei gespeichert.

This commit is contained in:
Enno Rehling 2002-01-31 22:18:00 +00:00
parent 0d76ceabb9
commit 8df7894084
14 changed files with 235 additions and 26 deletions

View File

@ -113,7 +113,7 @@ typedef struct construction {
int reqsize; /* size of object using up 1 set of requirement. */ int reqsize; /* size of object using up 1 set of requirement. */
requirement * materials; /* material req'd to build one object */ 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 /* next level, if upgradable. if more than one of these items
* can be built (weapons, armour) per turn, must not be NULL, * can be built (weapons, armour) per turn, must not be NULL,
* but point to the same type again: * but point to the same type again:

View File

@ -222,7 +222,7 @@ static requirement castle_req[] = {
}; };
#if LARGE_CASTLES #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, 2, 1, castle_req, &castle_bld[1] },
{ SK_BUILDING, 1, 8, 1, castle_req, &castle_bld[2] }, { SK_BUILDING, 1, 8, 1, castle_req, &castle_bld[2] },
{ SK_BUILDING, 2, 40, 1, castle_req, &castle_bld[3] }, { 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 } { SK_BUILDING, 6, -1, 1, castle_req, NULL }
}; };
#else #else
static const construction castle_bld[MAXBUILDINGS] = { static construction castle_bld[MAXBUILDINGS] = {
{ SK_BUILDING, 1, 2, 1, castle_req, &castle_bld[1] }, { SK_BUILDING, 1, 2, 1, castle_req, &castle_bld[1] },
{ SK_BUILDING, 2, 8, 1, castle_req, &castle_bld[2] }, { SK_BUILDING, 2, 8, 1, castle_req, &castle_bld[2] },
{ SK_BUILDING, 3, 40, 1, castle_req, &castle_bld[3] }, { SK_BUILDING, 3, 40, 1, castle_req, &castle_bld[3] },

View File

@ -2233,6 +2233,7 @@ attrib_init(void)
bt_register(&bt_generic); bt_register(&bt_generic);
bt_register(&bt_caldera); bt_register(&bt_caldera);
#ifdef NOXMLBOATS
/* Schiffstypen registrieren: */ /* Schiffstypen registrieren: */
st_register(&st_boat); st_register(&st_boat);
st_register(&st_balloon); st_register(&st_balloon);
@ -2240,6 +2241,7 @@ attrib_init(void)
st_register(&st_dragonship); st_register(&st_dragonship);
st_register(&st_caravelle); st_register(&st_caravelle);
st_register(&st_trireme); st_register(&st_trireme);
#endif
/* disable: st_register(&st_transport); */ /* disable: st_register(&st_transport); */

View File

@ -259,7 +259,7 @@ give_starting_equipment(struct region *r, struct unit *u)
break; break;
case RC_AQUARIAN: case RC_AQUARIAN:
{ {
ship *sh = new_ship(&st_boat, r); ship *sh = new_ship(st_find("boat"), r);
sh->size = sh->type->construction->maxsize; sh->size = sh->type->construction->maxsize;
addlist(&r->ships, sh); addlist(&r->ships, sh);
u->ship = sh; u->ship = sh;

View File

@ -1299,9 +1299,13 @@ readgame(boolean backup)
rds(F, &sh->display); rds(F, &sh->display);
if (global.data_version < SHIPTYPE_VERSION) { if (global.data_version < SHIPTYPE_VERSION) {
#ifdef NOXMLBOATS
const ship_type * oldship[] = { &st_boat, &st_balloon, &st_longboat, &st_dragonship, &st_caravelle, &st_trireme }; const ship_type * oldship[] = { &st_boat, &st_balloon, &st_longboat, &st_dragonship, &st_caravelle, &st_trireme };
int i = ri(F); int i = ri(F);
sh->type = oldship[i]; sh->type = oldship[i];
#else
assert(!"cannot read old datafile with xml ship support");
#endif
} }
else { else {
rs(F, buf); rs(F, buf);

View File

@ -20,10 +20,12 @@
#include "unit.h" #include "unit.h"
#include "item.h" #include "item.h"
#include "region.h" #include "region.h"
#include "skill.h"
/* util includes */ /* util includes */
#include <base36.h> #include <base36.h>
#include <event.h> #include <event.h>
#include <xml.h>
#include <language.h> #include <language.h>
/* libc includes */ /* libc includes */
@ -66,9 +68,9 @@ st_find(const char* name)
{ {
const struct ship_typelist * stl = shiptypes; const struct ship_typelist * stl = shiptypes;
while (stl && strcasecmp(stl->type->name[0], name)) stl = stl->next; while (stl && strcasecmp(stl->type->name[0], name)) stl = stl->next;
if (!stl) { if (!stl) { /* compatibility for old datafiles */
stl = shiptypes; 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; return stl?stl->type:NULL;
} }
@ -81,16 +83,6 @@ st_register(const ship_type * type) {
shiptypes = stl; 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 #define SMAXHASH 8191
ship *shiphash[SMAXHASH]; ship *shiphash[SMAXHASH];
void void
@ -155,6 +147,17 @@ captain(ship *sh, region *r)
/* Alte Schiffstypen: */ /* 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[] = { static requirement boat_req[] = {
{I_WOOD, 1}, {I_WOOD, 1},
{0, 0} {0, 0}
@ -263,6 +266,7 @@ const ship_type st_trireme = {
4, 1, 120, coast_large, 4, 1, 120, coast_large,
&trireme_bld &trireme_bld
}; };
#endif
ship * ship *
new_ship(const ship_type * stype, region * r) new_ship(const ship_type * stype, region * r)
@ -343,3 +347,149 @@ shipowner(const region * r, const ship * sh)
fset(first, FL_OWNER); fset(first, FL_OWNER);
return first; 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, "<ship name=\"%s\" range=\"%u\" storm=\"%.2f\" damage=\"%.2f\" cabins=\"%u\" cargo=\"%u\" cptskill=\"%u\" minskill=\"%u\" sumskill=\"%u\"",
locale_string(find_locale("en"), st->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<coast terrain=\"%s\"></coast>\n", terrain[st->coast[i]].name);
}
fprintf(F, "\t<construction skill=\"%s\" minskill=\"%u\" maxsize=\"%u\" reqsize=\"%u\">\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<requirement type=\"%s\" quantity=\"%d\"></requirement>\n",
oldresourcetype[st->construction->materials[i].type]->_name[0],
st->construction->materials[i].number);
}
fputs("\t</construction>\n", F);
fputs("</ship>\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
}

View File

@ -40,9 +40,9 @@ typedef struct ship_type {
int minskill; /* min. skill to sail this (crew) */ int minskill; /* min. skill to sail this (crew) */
int sumskill; /* min. sum of crew+captain */ 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; } ship_type;
typedef struct ship_typelist { typedef struct ship_typelist {
@ -53,15 +53,15 @@ typedef struct ship_typelist {
extern ship_typelist *shiptypes; extern ship_typelist *shiptypes;
/* Alte Schiffstypen: */ /* Alte Schiffstypen: */
#ifdef NOXMLBOATS
extern const ship_type st_boat; extern const ship_type st_boat;
extern const ship_type st_balloon; extern const ship_type st_balloon;
extern const ship_type st_longboat; extern const ship_type st_longboat;
extern const ship_type st_dragonship; extern const ship_type st_dragonship;
extern const ship_type st_caravelle; extern const ship_type st_caravelle;
extern const ship_type st_trireme; extern const ship_type st_trireme;
extern const ship_type st_transport; extern const ship_type st_transport;
#endif
extern const ship_type * st_find(const char* name); extern const ship_type * st_find(const char* name);
extern void st_register(const ship_type * type); 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 const struct ship_type * findshiptype(const char *s, const struct locale * lang);
extern void register_ships(void);
#endif #endif

View File

@ -164,6 +164,7 @@ game_init(void)
debug_language("locales.log"); debug_language("locales.log");
register_races(); register_races();
register_resources(); register_resources();
register_ships();
register_items(); register_items();
register_spells(); register_spells();
register_dungeon(); register_dungeon();
@ -582,7 +583,8 @@ main(int argc, char *argv[])
kernel_init(); kernel_init();
game_init(); game_init();
#if defined(BETA_CODE) && 0 #if defined(BETA_CODE) && 0
xml_writeitems("items.xml"); xml_writeships();
/* xml_writeitems("items.xml"); */
return 0; return 0;
#endif #endif

View File

@ -1467,6 +1467,7 @@ main(int argc, char *argv[])
register_races(); register_races();
register_resources(); register_resources();
register_ships();
register_items(); register_items();
register_spells(); register_spells();
/* register_dungeon(); */ /* register_dungeon(); */

View File

@ -2,6 +2,7 @@
_d: dativ (wir erklären allen /Trollen/ den Krieg) _d: dativ (wir erklären allen /Trollen/ den Krieg)
_p: plural (13 /Trolle/) _p: plural (13 /Trolle/)
_x: preposition (15 /Troll/schwerter) _x: preposition (15 /Troll/schwerter)
_a: including article (ein Troll, a troll)
</comment> </comment>
<strings> <strings>
@ -194,19 +195,41 @@
</string> </string>
<comment>Schiffstypen</comment> <comment>Schiffstypen</comment>
<string name="Karavelle"> <string name="balloon_a">
<text locale="de">ein Ballon</text>
</string>
<string name="caravel_a">
<text locale="de">eine Karavelle</text>
</string>
<string name="boat_a">
<text locale="de">ein Boot</text>
</string>
<string name="longboat_a">
<text locale="de">ein Langboot</text>
</string>
<string name="dragonship_a">
<text locale="de">ein Drachenschiff</text>
</string>
<string name="Trireme_a">
<text locale="de">eine Trireme</text>
</string>
<string name="balloon">
<text locale="de">Ballon</text>
</string>
<string name="caravel">
<text locale="de">Karavelle</text> <text locale="de">Karavelle</text>
</string> </string>
<string name="Boot"> <string name="boat">
<text locale="de">Boot</text> <text locale="de">Boot</text>
</string> </string>
<string name="Langboot"> <string name="longboat">
<text locale="de">Langboot</text> <text locale="de">Langboot</text>
</string> </string>
<string name="Drachenschiff"> <string name="dragonship">
<text locale="de">Drachenschiff</text> <text locale="de">Drachenschiff</text>
</string> </string>
<string name="Trireme"> <string name="trireme">
<text locale="de">Trireme</text> <text locale="de">Trireme</text>
</string> </string>

View File

@ -62,6 +62,29 @@
<string name="Trireme"> <string name="Trireme">
<text locale="en">trireme</text> <text locale="en">trireme</text>
</string> </string>
<string name="balloon">
<text locale="en">balloon</text>
</string>
<comment>Schiffstypen</comment>
<string name="caravel_a">
<text locale="en">a caravel</text>
</string>
<string name="boat_a">
<text locale="en">a boat</text>
</string>
<string name="longboat_a">
<text locale="en">a longboat</text>
</string>
<string name="balloon_a">
<text locale="en">a balloon</text>
</string>
<string name="dragonship_a">
<text locale="en">a dragonship</text>
</string>
<string name="trireme_a">
<text locale="en">a trireme</text>
</string>
<comment> Terraintypen</comment> <comment> Terraintypen</comment>
<string name="activevolcano"> <string name="activevolcano">

View File

@ -9,6 +9,7 @@
<include file="races.xml"></include> <include file="races.xml"></include>
<include file="resources.xml"></include> <include file="resources.xml"></include>
<include file="ships.xml"></include>
<game name="Eressea" welcome="eressea"> <game name="Eressea" welcome="eressea">
<comment>Game specific</comment> <comment>Game specific</comment>

View File

@ -9,6 +9,7 @@
<include file="races.xml"></include> <include file="races.xml"></include>
<include file="resources.xml"></include> <include file="resources.xml"></include>
<include file="ships.xml"></include>
<game name="Vinyambar I" units="250" welcome="vinyambar"> <game name="Vinyambar I" units="250" welcome="vinyambar">
<comment>Game specific</comment> <comment>Game specific</comment>

View File

@ -9,6 +9,7 @@
<include file="races.xml"></include> <include file="races.xml"></include>
<include file="resources.xml"></include> <include file="resources.xml"></include>
<include file="ships.xml"></include>
<game name="Vinyambar II" units="250" welcome="vinyambar"> <game name="Vinyambar II" units="250" welcome="vinyambar">
<comment>Game specific</comment> <comment>Game specific</comment>