forked from github/server
starting equipment & skills for new factions is read from the equipment.xml file instead of hardcoded. Makes give_starting_equipment a lot smaller and reduces the number of I_* item-constants used in the code.
This commit is contained in:
parent
1049ef4a76
commit
a72a43c384
16 changed files with 2301 additions and 2170 deletions
|
@ -978,7 +978,6 @@ gebaeude_stuerzt_ein(region * r, building * b)
|
|||
{
|
||||
unit *u;
|
||||
int n, i;
|
||||
direction_t d;
|
||||
int opfer = 0;
|
||||
int road = 0;
|
||||
struct message * msg;
|
||||
|
|
|
@ -394,8 +394,10 @@ static const char * it_aliases[][2] = {
|
|||
{ "p12", "truthpotion" },
|
||||
{ "p1", "goliathwater" },
|
||||
{ "p5", "peasantblood" },
|
||||
{ "p8", "nestwarmth" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static const char *
|
||||
it_alias(const char * zname)
|
||||
{
|
||||
|
|
|
@ -172,41 +172,89 @@ set_show_item(faction *f, item_t i)
|
|||
a->data.v = (void*)olditemtype[i];
|
||||
}
|
||||
|
||||
static item * equipment;
|
||||
void add_equipment(const item_type * itype, int number)
|
||||
typedef struct equipment {
|
||||
const struct race * rc;
|
||||
item * items;
|
||||
int skills[MAXSKILLS];
|
||||
struct equipment * next;
|
||||
} equipment;
|
||||
|
||||
static equipment * starting_equipment;
|
||||
|
||||
static equipment *
|
||||
make_equipment(const struct race * rc)
|
||||
{
|
||||
if (itype!=NULL) i_change(&equipment, itype, number);
|
||||
equipment ** eqp = &starting_equipment;
|
||||
while (*eqp) {
|
||||
struct equipment * eq = *eqp;
|
||||
if (eq->rc==rc) break;
|
||||
eqp = &eq->next;
|
||||
}
|
||||
if (*eqp == NULL) {
|
||||
struct equipment * eq = malloc(sizeof(equipment));
|
||||
eq->rc = rc;
|
||||
eq->next = NULL;
|
||||
eq->items = NULL;
|
||||
memset(eq->skills, 0, sizeof(eq->skills));
|
||||
*eqp = eq;
|
||||
} else {
|
||||
struct equipment * eq = *eqp;
|
||||
eq->rc = rc;
|
||||
eq->items = NULL;
|
||||
}
|
||||
return *eqp;
|
||||
}
|
||||
|
||||
void
|
||||
startup_skill(skill_t sk, int value, const struct race * rc)
|
||||
{
|
||||
if (value>0) {
|
||||
equipment * eq = make_equipment(rc);
|
||||
eq->skills[sk] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
startup_equipment(const item_type * itype, int number, const struct race * rc)
|
||||
{
|
||||
if (itype!=NULL && number>0) {
|
||||
equipment * eq = make_equipment(rc);
|
||||
i_change(&eq->items, itype, number);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
give_equipment(unit * u, const struct race * rc)
|
||||
{
|
||||
equipment * eq = starting_equipment;
|
||||
while (eq && eq->rc!=rc) {
|
||||
eq = eq->next;
|
||||
}
|
||||
if (eq) {
|
||||
skill_t sk;
|
||||
item * itm;
|
||||
for (sk=0;sk!=MAXSKILLS;++sk) {
|
||||
if (eq->skills[sk]>0) {
|
||||
set_level(u, sk, eq->skills[sk]);
|
||||
}
|
||||
}
|
||||
for (itm=eq->items;itm!=NULL;itm=itm->next) {
|
||||
i_add(&u->items, i_new(itm->type, itm->number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
give_starting_equipment(struct region *r, struct unit *u)
|
||||
{
|
||||
item * itm = equipment;
|
||||
while (itm!=NULL) {
|
||||
i_add(&u->items, i_new(itm->type, itm->number));
|
||||
itm=itm->next;
|
||||
}
|
||||
give_equipment(u, NULL);
|
||||
give_equipment(u, u->race);
|
||||
|
||||
switch(old_race(u->race)) {
|
||||
case RC_DWARF:
|
||||
set_level(u, SK_SWORD, 1);
|
||||
set_item(u, I_AXE, 1);
|
||||
set_item(u, I_CHAIN_MAIL, 1);
|
||||
break;
|
||||
case RC_ELF:
|
||||
set_item(u, I_FEENSTIEFEL, 1);
|
||||
set_show_item(u->faction, I_FEENSTIEFEL);
|
||||
break;
|
||||
case RC_ORC:
|
||||
case RC_URUK:
|
||||
set_level(u, SK_SPEAR, 4);
|
||||
set_level(u, SK_SWORD, 4);
|
||||
set_level(u, SK_CROSSBOW, 4);
|
||||
set_level(u, SK_LONGBOW, 4);
|
||||
set_level(u, SK_CATAPULT, 4);
|
||||
break;
|
||||
case RC_GOBLIN:
|
||||
set_item(u, I_RING_OF_INVISIBILITY, 1);
|
||||
set_show_item(u->faction, I_RING_OF_INVISIBILITY);
|
||||
scale_number(u, 10);
|
||||
break;
|
||||
|
@ -218,34 +266,7 @@ give_starting_equipment(struct region *r, struct unit *u)
|
|||
fset(u, UFL_OWNER);
|
||||
}
|
||||
break;
|
||||
case RC_TROLL:
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
set_level(u, SK_OBSERVATION, 3);
|
||||
set_item(u, I_STONE, 50);
|
||||
break;
|
||||
case RC_DAEMON:
|
||||
set_level(u, SK_AUSDAUER, 15);
|
||||
u->hp = unit_max_hp(u);
|
||||
break;
|
||||
case RC_INSECT:
|
||||
/* TODO: Potion-Beschreibung ausgeben */
|
||||
i_change(&u->items, oldpotiontype[P_WARMTH]->itype, 9);
|
||||
break;
|
||||
case RC_HALFLING:
|
||||
set_level(u, SK_TRADE, 1);
|
||||
set_level(u, SK_RIDING, 2);
|
||||
set_item(u, I_HORSE, 2);
|
||||
set_item(u, I_WAGON, 1);
|
||||
set_item(u, I_BALM, 5);
|
||||
set_item(u, I_SPICES, 5);
|
||||
set_item(u, I_JEWELERY, 5);
|
||||
set_item(u, I_MYRRH, 5);
|
||||
set_item(u, I_OIL, 5);
|
||||
set_item(u, I_SILK, 5);
|
||||
set_item(u, I_INCENSE, 5);
|
||||
break;
|
||||
case RC_CAT:
|
||||
set_item(u, I_RING_OF_INVISIBILITY, 1);
|
||||
set_show_item(u->faction, I_RING_OF_INVISIBILITY);
|
||||
break;
|
||||
case RC_AQUARIAN:
|
||||
|
@ -255,12 +276,12 @@ give_starting_equipment(struct region *r, struct unit *u)
|
|||
u->ship = sh;
|
||||
fset(u, UFL_OWNER);
|
||||
}
|
||||
set_level(u, SK_SAILING, 1);
|
||||
break;
|
||||
case RC_CENTAUR:
|
||||
rsethorses(r, 250+rand()%51+rand()%51);
|
||||
break;
|
||||
}
|
||||
u->hp = unit_max_hp(u);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -181,7 +181,8 @@ extern int read_race_reference(const struct race ** rp, FILE * F);
|
|||
|
||||
extern const char * raceprefix(const struct unit *u);
|
||||
|
||||
extern void add_equipment(const struct item_type * itype, int number);
|
||||
extern void startup_equipment(const struct item_type * itype, int number, const struct race * rc);
|
||||
extern void startup_skill(skill_t sk, int value, const struct race * rc);
|
||||
extern void give_starting_equipment(struct region *r, struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -868,19 +868,11 @@ parse_resources(xmlDocPtr doc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_equipment(xmlDocPtr doc)
|
||||
static void
|
||||
add_items(xmlNodeSetPtr nsetItems, const race * rc)
|
||||
{
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr items;
|
||||
xmlNodeSetPtr nsetItems;
|
||||
int i;
|
||||
|
||||
/* reading eressea/races/race */
|
||||
items = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/item", xpath);
|
||||
nsetItems = items->nodesetval;
|
||||
|
||||
if (nsetItems!=NULL) {
|
||||
int i;
|
||||
for (i=0;i!=nsetItems->nodeNr;++i) {
|
||||
xmlNodePtr node = nsetItems->nodeTab[i];
|
||||
xmlChar * property;
|
||||
|
@ -897,11 +889,75 @@ parse_equipment(xmlDocPtr doc)
|
|||
num = atoi((const char*)property);
|
||||
xmlFree(property);
|
||||
}
|
||||
add_equipment(itype, num);
|
||||
startup_equipment(itype, num, rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
xmlXPathFreeObject(items);
|
||||
}
|
||||
|
||||
static void
|
||||
add_skills(xmlNodeSetPtr nsetSkills, const race * rc)
|
||||
{
|
||||
if (nsetSkills!=NULL) {
|
||||
int i;
|
||||
for (i=0;i!=nsetSkills->nodeNr;++i) {
|
||||
xmlNodePtr node = nsetSkills->nodeTab[i];
|
||||
xmlChar * property;
|
||||
skill_t sk;
|
||||
|
||||
property = xmlGetProp(node, BAD_CAST "name");
|
||||
assert(property!=NULL);
|
||||
sk = sk_find((const char*)property);
|
||||
xmlFree(property);
|
||||
if (sk!=NOSKILL) {
|
||||
int num = 0;
|
||||
property = xmlGetProp(node, BAD_CAST "level");
|
||||
if (property!=NULL) {
|
||||
num = atoi((const char*)property);
|
||||
xmlFree(property);
|
||||
}
|
||||
startup_skill(sk, num, rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
parse_equipment(xmlDocPtr doc)
|
||||
{
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr xpathRaces;
|
||||
|
||||
/* reading eressea/races/race */
|
||||
xpathRaces = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/startup", xpath);
|
||||
if (xpathRaces->nodesetval) {
|
||||
xmlNodeSetPtr nsetRaces = xpathRaces->nodesetval;
|
||||
int i;
|
||||
|
||||
for (i=0;i!=nsetRaces->nodeNr;++i) {
|
||||
xmlNodePtr node = nsetRaces->nodeTab[i];
|
||||
const struct race * rc = NULL;
|
||||
xmlChar * property = xmlGetProp(node, BAD_CAST "race");
|
||||
xmlXPathObjectPtr xpathResult;
|
||||
|
||||
if (property!=NULL) {
|
||||
rc = rc_find((const char*)property);
|
||||
assert(rc!=NULL);
|
||||
}
|
||||
|
||||
xpath->node = node;
|
||||
xpathResult = xmlXPathEvalExpression(BAD_CAST "item", xpath);
|
||||
add_items(xpathResult->nodesetval, rc);
|
||||
xmlXPathFreeObject(xpathResult);
|
||||
|
||||
xpath->node = node;
|
||||
xpathResult = xmlXPathEvalExpression(BAD_CAST "skill", xpath);
|
||||
add_skills(xpathResult->nodesetval, rc);
|
||||
xmlXPathFreeObject(xpathResult);
|
||||
}
|
||||
}
|
||||
|
||||
xmlXPathFreeObject(xpathRaces);
|
||||
xmlXPathFreeContext(xpath);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -37,11 +37,13 @@
|
|||
using namespace luabind;
|
||||
|
||||
static int
|
||||
lua_addequipment(const char * iname, int number)
|
||||
lua_addequipment(const char * iname, int number, const char * rcname)
|
||||
{
|
||||
race * rc = rc_find(rcname);
|
||||
const struct item_type * itype = it_find(iname);
|
||||
if (rc==NULL && strlen(rcname)>0) return -1;
|
||||
if (itype==NULL) return -1;
|
||||
add_equipment(itype, number);
|
||||
startup_equipment(itype, number, rc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -226,7 +228,7 @@ bind_eressea(lua_State * L)
|
|||
def("write_summary", &write_summary),
|
||||
def("read_orders", &readorders),
|
||||
def("process_orders", &process_orders),
|
||||
def("add_equipment", &lua_addequipment),
|
||||
def("startup_equipment", &lua_addequipment),
|
||||
def("get_turn", &get_turn),
|
||||
def("remove_empty_units", &remove_empty_units),
|
||||
|
||||
|
|
|
@ -1799,7 +1799,7 @@
|
|||
<string name="p7">
|
||||
<text locale="de">Dumpfbackenbrot</text>
|
||||
</string>
|
||||
<string name="p8">
|
||||
<string name="nestwarmth">
|
||||
<text locale="de">Nestwärme</text>
|
||||
</string>
|
||||
<string name="p9">
|
||||
|
@ -1845,7 +1845,7 @@
|
|||
<string name="p7_p">
|
||||
<text locale="de">Dumpfbackenbrote</text>
|
||||
</string>
|
||||
<string name="p8_p">
|
||||
<string name="nestwarmth_p">
|
||||
<text locale="de">Nestwärme</text>
|
||||
</string>
|
||||
<string name="p9_p">
|
||||
|
|
|
@ -1128,10 +1128,10 @@
|
|||
<string name="p7_p">
|
||||
<text locale="en">duncebuns</text>
|
||||
</string>
|
||||
<string name="p8">
|
||||
<string name="nestwarmth">
|
||||
<text locale="en">potion of nest warmth</text>
|
||||
</string>
|
||||
<string name="p8_p">
|
||||
<string name="nestwarmth_p">
|
||||
<text locale="en">potions of nest warmth</text>
|
||||
</string>
|
||||
<string name="p9">
|
||||
|
|
|
@ -6,5 +6,53 @@
|
|||
<item name="stone" amount="30"/>
|
||||
<item name="money" amount="4200"/>
|
||||
-->
|
||||
<startup race="dwarf">
|
||||
<item name="axe" amount="1"/>
|
||||
<item name="chainmail" amount="1"/>
|
||||
<skill name="sk_sword" level="1"/>
|
||||
</startup>
|
||||
<startup race="elf">
|
||||
<item name="fairyboot" amount="1"/>
|
||||
</startup>
|
||||
<startup race="uruk">
|
||||
<skill name="sk_spear" level="4"/>
|
||||
<skill name="sk_sword" level="4"/>
|
||||
<skill name="sk_crossbow" level="4"/>
|
||||
<skill name="sk_catapult" level="4"/>
|
||||
<skill name="sk_bow" level="4"/>
|
||||
</startup>
|
||||
<startup race="goblin">
|
||||
<item name="roi" amount="1"/>
|
||||
</startup>
|
||||
<startup race="troll">
|
||||
<skill name="sk_building" level="1"/>
|
||||
<skill name="sk_perception" level="3"/>
|
||||
<item name="stone" amount="50"/>
|
||||
</startup>
|
||||
<startup race="daemon">
|
||||
<skill name="sk_stamina" level="15"/>
|
||||
</startup>
|
||||
<startup race="insect">
|
||||
<item name="nestwarmth" amount="9"/>
|
||||
</startup>
|
||||
<startup race="halfling">
|
||||
<skill name="sk_trade" level="1"/>
|
||||
<skill name="sk_riding" level="2"/>
|
||||
<item name="horse" amount="2"/>
|
||||
<item name="cart" amount="1"/>
|
||||
<item name="balm" amount="5"/>
|
||||
<item name="spice" amount="5"/>
|
||||
<item name="myrrh" amount="5"/>
|
||||
<item name="jewel" amount="5"/>
|
||||
<item name="oil" amount="5"/>
|
||||
<item name="silk" amount="5"/>
|
||||
<item name="incense" amount="5"/>
|
||||
</startup>
|
||||
<startup race="cat">
|
||||
<item name="roi" amount="1"/>
|
||||
</startup>
|
||||
<startup race="aquarian">
|
||||
<skill name="sk_sailing" level="1"/>
|
||||
</startup>
|
||||
</equipment>
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
<xi:include href="eressea/calendar.xml"/>
|
||||
<xi:include href="equipment.xml"/>
|
||||
|
||||
<game name="Eressea" welcome="eressea">
|
||||
<comment>Game specific</comment>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@
|
|||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
<xi:include href="calendar.xml"/>
|
||||
<xi:include href="equipment.xml"/>
|
||||
|
||||
<game name="Tutorial" welcome="tutorial">
|
||||
<comment>Game specific</comment>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<xi:include href="ships.xml"/>
|
||||
<xi:include href="buildings.xml"/>
|
||||
<xi:include href="calendar.xml"/>
|
||||
<xi:include href="equipment.xml"/>
|
||||
|
||||
<game name="Wettstreit der Weisen" unitsperalliance="yes" units="1000" welcome="vinyambar">
|
||||
<comment>Game specific</comment>
|
||||
|
|
|
@ -19,6 +19,12 @@ function write_emails()
|
|||
end
|
||||
|
||||
function process(orders)
|
||||
-- initialize starting equipment for new players
|
||||
startup_equipment("conquesttoken", 1, "");
|
||||
startup_equipment("wood", 30, "");
|
||||
startup_equipment("stone", 30, "");
|
||||
startup_equipment("money", 4200, "");
|
||||
|
||||
file = "" .. get_turn()
|
||||
if read_game(file)~=0 then
|
||||
print("could not read game")
|
||||
|
@ -32,13 +38,6 @@ function process(orders)
|
|||
plan_monsters()
|
||||
process_orders()
|
||||
|
||||
-- initialize starting equipment for new players
|
||||
-- probably not necessary, since mapper sets new players, not server
|
||||
add_equipment("conquesttoken", 1);
|
||||
add_equipment("wood", 30);
|
||||
add_equipment("stone", 30);
|
||||
add_equipment("money", 4200);
|
||||
|
||||
-- use newfactions file to place out new players
|
||||
autoseed(basepath .. "/newfactions", true)
|
||||
|
||||
|
|
|
@ -53,6 +53,12 @@ function write_emails()
|
|||
end
|
||||
|
||||
function process(orders)
|
||||
-- initialize starting equipment for new players
|
||||
startup_equipment("conquesttoken", 1, "");
|
||||
startup_equipment("log", 30, "");
|
||||
startup_equipment("stone", 30, "");
|
||||
startup_equipment("money", 4200, "");
|
||||
|
||||
file = "" .. get_turn()
|
||||
if read_game(file)~=0 then
|
||||
print("could not read game")
|
||||
|
@ -70,12 +76,6 @@ function process(orders)
|
|||
end
|
||||
run_scripts()
|
||||
|
||||
-- initialize starting equipment for new players
|
||||
add_equipment("conquesttoken", 1);
|
||||
add_equipment("log", 30);
|
||||
add_equipment("stone", 30);
|
||||
add_equipment("money", 4200);
|
||||
|
||||
plan_monsters()
|
||||
process_orders()
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ skills = {
|
|||
|
||||
function wdw_setup()
|
||||
-- initialize starting equipment for new players
|
||||
-- add_equipment("magicskillboost", 1)
|
||||
-- startup_equipment("magicskillboost", 1, "")
|
||||
|
||||
init_positions()
|
||||
|
||||
|
|
Loading…
Reference in a new issue