neue items über XML Datei hinzufügbar.

This commit is contained in:
Enno Rehling 2001-12-30 07:56:03 +00:00
parent 4c3c1c0369
commit 43f0d37ca8
8 changed files with 233 additions and 103 deletions

View File

@ -1251,28 +1251,6 @@ extern int fuzzy_hits;
boolean enable_fuzzy = false; boolean enable_fuzzy = false;
#endif /* FUZZY_BASE36 */ #endif /* FUZZY_BASE36 */
static faction *
makemonsters(void)
{
faction * f = calloc(sizeof(faction), 1);
f->next=factions;
f->race=new_race[RC_TEMPLATE];
f->alive=1;
f->email=strdup("");
f->lastorders=0;
f->locale=default_locale;
factions=f;
f->options = Pow(O_REPORT);
f->no=MONSTER_FACTION;
register_faction_id(f->no);
f->unique_id = ++max_unique_id;
f->name=strdup("Monster");
f->passw=strdup("abc123");
fhash(f);
return f;
}
faction * faction *
findfaction (int n) findfaction (int n)
{ {
@ -2144,6 +2122,8 @@ parse_tagbegin(struct xml_stack *stack, void *data)
} }
} }
} }
} else if (strcmp(tag->name, "resource")==0) {
xml_readresource(stack->stream, stack);
} else if (strcmp(tag->name, "races")==0) { } else if (strcmp(tag->name, "races")==0) {
read_races(stack->stream, stack); read_races(stack->stream, stack);
} else if (strcmp(tag->name, "strings")==0) { } else if (strcmp(tag->name, "strings")==0) {

View File

@ -253,8 +253,8 @@ new_weapontype(item_type * itype,
wtype = calloc(sizeof(weapon_type), 1); wtype = calloc(sizeof(weapon_type), 1);
if (damage) { if (damage) {
wtype->damage[0] = damage[0]; wtype->damage[0] = strdup(damage[0]);
wtype->damage[1] = damage[1]; wtype->damage[1] = strdup(damage[1]);
} }
wtype->defmod = defmod; wtype->defmod = defmod;
wtype->flags |= wflags; wtype->flags |= wflags;
@ -2567,3 +2567,125 @@ xml_writeitems(const char * file)
fclose(stream); fclose(stream);
return 0; return 0;
} }
#include <xml.h>
typedef struct xml_state {
struct item_type * itype;
struct resource_type * rtype;
struct weapon_type * wtype;
int wmods;
} xml_state;
static int
tagend(struct xml_stack * stack, void * data)
{
unused(stack);
unused(data);
return XML_OK;
}
static int
tagbegin(struct xml_stack * stack, void * data)
{
xml_state * state = (xml_state*)data;
const xml_tag * tag = stack->tag;
if (strcmp(tag->name, "resource")==0) {
char *names[2], *appearance[2];
const char *tmp;
unsigned int flags = RTF_NONE;
if (xml_bvalue(tag, "pooled")) flags |= RTF_POOLED;
memset(state, 0, sizeof(xml_state));
tmp = xml_value(tag, "name");
assert(tmp || "resource needs a name");
names[0] = strdup(tmp);
names[1] = strcat(strcpy((char*)malloc(strlen(tmp)+3), tmp), "_p");
tmp = xml_value(tag, "appearance");
if (tmp!=NULL) {
appearance[0] = strdup(tmp);
appearance[1] = strcat(strcpy((char*)malloc(strlen(tmp)+3), tmp), "_p");
state->rtype = new_resourcetype(names, appearance, flags);
free(appearance[0]);
free(appearance[1]);
} else {
state->rtype = new_resourcetype(names, NULL, flags);
}
free(names[0]);
free(names[1]);
} else if (strcmp(tag->name, "item")==0) {
unsigned int flags = ITF_NONE;
int weight = xml_ivalue(tag, "weight");
int capacity = xml_ivalue(tag, "capacity");
assert(state->itype==NULL);
if (xml_bvalue(tag, "cursed")) flags |= ITF_CURSED;
if (xml_bvalue(tag, "notlost")) flags |= ITF_NOTLOST;
if (xml_bvalue(tag, "big")) flags |= ITF_BIG;
if (xml_bvalue(tag, "animal")) flags |= ITF_ANIMAL;
state->rtype->flags |= RTF_ITEM;
state->itype = new_itemtype(state->rtype, flags, weight, capacity);
} else if (strcmp(tag->name, "weapon")==0) {
skill_t skill = sk_find(xml_value(tag, "skill"));
int minskill = xml_ivalue(tag, "minskill");
int offmod = xml_ivalue(tag, "offmod");
int defmod = xml_ivalue(tag, "defmod");
int reload = xml_ivalue(tag, "reload");
double magres = xml_fvalue(tag, "magres");
unsigned int flags = WTF_NONE;
const char * damage[2] = { NULL, NULL };
assert(strcmp(stack->next->tag->name, "item")==0);
assert(state->itype!=NULL);
state->itype->flags |= ITF_WEAPON;
state->wtype = new_weapontype(state->itype,
flags, magres, damage, offmod, defmod, reload, skill, minskill);
} else if (strcmp(tag->name, "damage")==0) {
/* damage of a weapon */
int pos = 0;
const char * type = xml_value(tag, "type");
assert(strcmp(stack->next->tag->name, "weapon")==0);
if (strcmp(type, "default")!=0) pos = 1;
if (state->wtype->damage[pos]) free(state->wtype->damage[pos]);
state->wtype->damage[pos] = strdup(xml_value(tag, "value"));
} else if (strcmp(tag->name, "modifier")==0) {
int value = xml_ivalue(tag, "value");
assert(strcmp(stack->next->tag->name, "weapon")==0);
if (value!=0) {
int flags = 0;
weapon_mod * mods = calloc(sizeof(weapon_mod), state->wmods+2);
assert(state->wtype);
if (xml_bvalue(tag, "walking")) flags|=WMF_WALKING;
if (xml_bvalue(tag, "riding")) flags|=WMF_RIDING;
if (xml_bvalue(tag, "against_walking")) flags|=WMF_AGAINST_WALKING;
if (xml_bvalue(tag, "against_riding")) flags|=WMF_AGAINST_RIDING;
if (xml_bvalue(tag, "offensive")) flags|=WMF_OFFENSIVE;
if (xml_bvalue(tag, "defensive")) flags|=WMF_DEFENSIVE;
if (xml_bvalue(tag, "damage")) flags|=WMF_DAMAGE;
if (xml_bvalue(tag, "skill")) flags|=WMF_SKILL;
if (xml_bvalue(tag, "missile_target")) flags|=WMF_MISSILE_TARGET;
if (state->wmods) {
memcpy(mods, state->wtype->modifiers, sizeof(weapon_mod)*state->wmods);
free(state->wtype->modifiers);
}
mods[state->wmods].value = value;
mods[state->wmods].flags = flags;
state->wtype->modifiers = mods;
++state->wmods;
}
} else {
return XML_USERERROR;
}
return XML_OK;
}
static xml_callbacks xml_resource = {
NULL, tagbegin, tagend, NULL
};
int
xml_readresource(FILE * F, struct xml_stack * stack)
{
xml_state state;
return xml_parse(F, &xml_resource, &state, stack);
}

View File

@ -119,8 +119,6 @@ typedef struct item_type {
unsigned int flags; unsigned int flags;
int weight; int weight;
int capacity; int capacity;
/* int minskill;
skill_t skill; */
const struct construction * construction; const struct construction * construction;
/* --- functions --- */ /* --- functions --- */
int (*use)(struct unit * user, const struct item_type * itype, const char * cmd); int (*use)(struct unit * user, const struct item_type * itype, const char * cmd);
@ -185,7 +183,7 @@ typedef struct weapon_mod {
typedef struct weapon_type { typedef struct weapon_type {
const item_type * itype; const item_type * itype;
const char * damage[2]; char * damage[2];
unsigned int flags; unsigned int flags;
skill_t skill; skill_t skill;
int minskill; int minskill;
@ -553,4 +551,7 @@ extern void init_resources(void);
extern void init_items(void); extern void init_items(void);
extern const char* resname(resource_t res, int index); extern const char* resname(resource_t res, int index);
extern int xml_readresource(FILE * F, struct xml_stack * stack);
#endif /* _ITEM_H */ #endif /* _ITEM_H */

View File

@ -134,33 +134,6 @@ make_gates(region * r)
add_trigger(&b->attribs, "timer", trigger_xmasgate(b)); add_trigger(&b->attribs, "timer", trigger_xmasgate(b));
} }
static unit *
make_santa(region * r)
{
unit * santa = ufindhash(atoi36("xmas"));
while (santa && santa->race!=new_race[RC_ILLUSION]) {
uunhash(santa);
santa->no = newunitid();
uhash(santa);
santa = ufindhash(atoi36("xmas"));
}
if (!santa) {
faction * f = findfaction(atoi36("rr"));
if (f==NULL) return NULL;
f->alive = true;
santa = createunit(r, f, 1, new_race[RC_ILLUSION]);
uunhash(santa);
santa->no = atoi36("xmas");
uhash(santa);
fset(santa, FL_PARTEITARNUNG);
santa->irace = new_race[RC_GNOME];
set_string(&santa->name, "Ein dicker Gnom mit einem Rentierschlitten");
set_string(&santa->display, "hat: 12 Rentiere, Schlitten, Sack mit Geschenken, Kekse für Khorne");
}
return santa;
}
static void static void
santa_comes_to_town(region * r) santa_comes_to_town(region * r)
{ {
@ -225,7 +198,7 @@ create_xmas2000(int x, int y)
if (n==NULL) n = new_region(x + delta_x[dir], y + delta_y[dir]); if (n==NULL) n = new_region(x + delta_x[dir], y + delta_y[dir]);
terraform(n, T_OCEAN); terraform(n, T_OCEAN);
} }
santa_comes_to_town(r); santa_comes_to_town(r, make_santa(r), NULL);
for (f = factions; f != NULL; f = f->next) if (f->alive && f->units) { for (f = factions; f != NULL; f = f->next) if (f->alive && f->units) {
char zText[128]; char zText[128];
unit * u; unit * u;

View File

@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 5.00
############################################################################### ###############################################################################
Project: "askalon"=".\askalon\askalon-5.dsp" - Package Owner=<4> Project: "attributes"=.\common\attributes\attributes.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -11,26 +11,50 @@ Package=<5>
Package=<4> Package=<4>
{{{ {{{
}}}
###############################################################################
Project: "eressea"=.\eressea\eressea.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name kernel
End Project Dependency
Begin Project Dependency
Project_Dep_Name util
End Project Dependency
Begin Project Dependency
Project_Dep_Name gamecode
End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name attributes Project_Dep_Name attributes
End Project Dependency End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name gamecode Project_Dep_Name items
End Project Dependency End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name kernel Project_Dep_Name modules
End Project Dependency
Begin Project Dependency
Project_Dep_Name races
End Project Dependency
Begin Project Dependency
Project_Dep_Name spells
End Project Dependency End Project Dependency
Begin Project Dependency Begin Project Dependency
Project_Dep_Name triggers Project_Dep_Name triggers
End Project Dependency End Project Dependency
Begin Project Dependency
Project_Dep_Name util
End Project Dependency
}}} }}}
############################################################################### ###############################################################################
Project: "attributes"=".\common\attributes\attributes-5.dsp" - Package Owner=<4> Project: "gamecode"=.\common\gamecode\gamecode.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -42,28 +66,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "eressea"=".\eressea\eressea-5.dsp" - Package Owner=<4> Project: "items"=.\common\items\items.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name kernel
End Project Dependency
Begin Project Dependency
Project_Dep_Name util
End Project Dependency
Begin Project Dependency
Project_Dep_Name gamecode
End Project Dependency
}}}
###############################################################################
Project: "gamecode"=".\common\gamecode\gamecode-5.dsp" - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -75,7 +78,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "items"=".\common\items\items-5.dsp" - Package Owner=<4> Project: "kernel"=.\common\kernel\kernel.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -87,19 +90,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "kernel"=".\common\kernel\kernel-5.dsp" - Package Owner=<4> Project: "mapper"=.\mapper\mapper.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "mapper"=".\mapper\mapper-5.dsp" - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -135,7 +126,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "modules"=".\common\modules\modules-5.dsp" - Package Owner=<4> Project: "modules"=.\common\modules\modules.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -147,7 +138,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "races"=".\common\races\races-5.dsp" - Package Owner=<4> Project: "races"=.\common\races\races.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -159,7 +150,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "spells"=".\common\spells\spells-5.dsp" - Package Owner=<4> Project: "spells"=.\common\spells\spells.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -171,7 +162,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "triggers"=".\common\triggers\triggers-5.dsp" - Package Owner=<4> Project: "triggers"=.\common\triggers\triggers.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{
@ -183,7 +174,7 @@ Package=<4>
############################################################################### ###############################################################################
Project: "util"=".\common\util\util-5.dsp" - Package Owner=<4> Project: "util"=.\common\util\util.dsp - Package Owner=<4>
Package=<5> Package=<5>
{{{ {{{

View File

@ -1370,6 +1370,28 @@ extern char * g_datadir;
extern char * g_resourcedir; extern char * g_resourcedir;
extern char * g_basedir; extern char * g_basedir;
static faction *
makemonsters(void)
{
faction * f = calloc(sizeof(faction), 1);
f->next=factions;
f->race=new_race[RC_TEMPLATE];
f->alive=1;
f->email=strdup("");
f->lastorders=0;
f->locale=default_locale;
factions=f;
f->options = Pow(O_REPORT);
f->no=MONSTER_FACTION;
register_faction_id(f->no);
f->unique_id = ++max_unique_id;
f->name=strdup("Monster");
f->passw=strdup("abc123");
fhash(f);
return f;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -1465,6 +1487,9 @@ main(int argc, char *argv[])
sprintf(datafile, "%s/%d", datapath(), turn); sprintf(datafile, "%s/%d", datapath(), turn);
readgame(backup); readgame(backup);
if (findfaction(MONSTER_FACTION)==NULL) {
makemonsters();
}
#ifdef OLD_ITEMS #ifdef OLD_ITEMS
make_xref(); make_xref();

View File

@ -8,6 +8,7 @@
<include file="en/strings.xml"></include> <include file="en/strings.xml"></include>
<include file="races.xml"></include> <include file="races.xml"></include>
<include file="resources.xml"></include>
<include file="items.xml"></include> <include file="items.xml"></include>
<game name="Eressea" welcome="eressea"> <game name="Eressea" welcome="eressea">

37
src/res/resources.xml Normal file
View File

@ -0,0 +1,37 @@
<resource name="magicbox">
<comment>A magic box that increases the user's capacity by 10 WU</comment>
<item cursed weight="0" capacity="1000">
</item>
</resource>
<strings>
<string name="magicbox">
<text locale="de">Magische Kiste</text>
<text locale="en">magical box</text>
</string>
<string name="magicbox_p">
<text locale="de">Magische Kisten</text>
<text locale="en">magical boxes</text>
</string>
</strings>
<resource name="odinshammer">
<comment>Odin's Hammer, reward for a quest. Can't be traded or lost</comment>
<item cursed notlost weight="200">
<weapon minskill="7" skill="sk_melee" magres="0.15" blunt>
<modifier value="-1" riding against_riding against_walking offensive skill></modifier>
<modifier value="1" walking against_riding defensive skill></modifier>
<damage type="default" value="1d20+6"></damage>
<damage type="riding" value="1d10+6"></damage>
</weapon>
</item>
</resource>
<strings>
<string name="odinshammer">
<text locale="de">Odins Hammer</text>
<text locale="en">hammer of Odin</text>
</string>
<string name="odinshammer_p">
<text locale="de">Odins Hämmer</text>
<text locale="en">hammers of Odin</text>
</string>
</strings>