diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml index 94d0deb07..d64a5e3e4 100644 --- a/res/eressea/equipment.xml +++ b/res/eressea/equipment.xml @@ -1,73 +1,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/scripts/eressea/equipment.lua b/scripts/eressea/equipment.lua index d3ef5ccbb..ffe910e7a 100644 --- a/scripts/eressea/equipment.lua +++ b/scripts/eressea/equipment.lua @@ -24,24 +24,115 @@ local sets = { ['perception'] = 30, ['melee'] = 1 } + }, + ['seed_dwarf'] = { + ['items'] = { + ['axe'] = 1, + ['chainmail'] = 1, + }, + ['skills'] = { + ['melee'] = 1 + } + }, + ['seed_elf'] = { + ['items'] = { + ['fairyboot'] = 1, + }, + ['callback'] = equip_newunits + }, + ['seed_orc'] = { + ['skills'] = { + ['polearm'] = 4, + ['melee'] = 4, + ['crossbow'] = 4, + ['catapult'] = 4, + ['bow'] = 4, + } + }, + ['seed_goblin'] = { + ['items'] = { + ['roi'] = 1 + }, + ['callback'] = equip_newunits + }, + ['seed_human'] = { + ['callback'] = equip_newunits + }, + ['seed_troll'] = { + ['items'] = { + ['stone'] = 50, + }, + ['skills'] = { + ['building'] = 1, + ['perception'] = 3, + } + }, + ['seed_demon'] = { + ['skills'] = { + ['stamina'] = 15 + } + }, + ['seed_insect'] = { + ['items'] = { + ['nestwarmth'] =9 + } + }, + ['seed_halfling'] = { + ['items'] = { + ['horse'] = 2, + ['cart'] = 1, + ['balm'] = 5, + ['spice'] = 5, + ['myrrh'] = 5, + ['jewel'] = 5, + ['oil'] = 5, + ['silk'] = 5, + ['incense'] = 5 + }, + ['skills'] = { + ['trade'] = 1, + ['riding'] = 2 + } + }, + ['seed_cat'] = { + ['items'] = { + ['roi'] = 1 + }, + ['callback'] = equip_newunits + }, + ['seed_aquarian'] = { + ['skills'] = { + ['sailing'] = 1 + }, + ['callback'] = equip_newunits } } function equip_unit(u, name, flags) - set = sets[name] + local set = sets[name] if set then - items = set['items'] + local items = set['items'] if items then for k,v in pairs(items) do u:add_item(k, v) end end - skills = set['skills'] + local skills = set['skills'] if skills then for k,v in pairs(skills) do u:set_skill(k, v) end end + local spells = set['spells'] + if spells then + for k, v in ipairs(spells) do + u:add_spell(v) + end + end + local callback = set['callback'] + if callback and type(callback) == 'function' then + callback(u) + end return true end return false diff --git a/src/bindings.c b/src/bindings.c index 72a2db782..bbea46e60 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -23,6 +23,7 @@ #include "kernel/save.h" #include "kernel/spell.h" #include "kernel/spellbook.h" +#include "races/races.h" #include "bind_unit.h" #include "bind_storage.h" @@ -845,8 +846,13 @@ static int init_data(const char *filename) return 0; } +static int tolua_equip_newunits(lua_State * L) { + unit *u = (unit *)tolua_tousertype(L, 1, 0); + equip_newunits(u); + return 0; +} -int tolua_read_xml(lua_State * L) +static int tolua_read_xml(lua_State * L) { const char *filename = tolua_tostring(L, 1, "config.xml"); lua_pushinteger(L, init_data(filename)); @@ -1023,6 +1029,7 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "translate", &tolua_translate); tolua_function(L, TOLUA_CAST "spells", tolua_get_spells); tolua_function(L, TOLUA_CAST "read_xml", tolua_read_xml); + tolua_function(L, TOLUA_CAST "equip_newunits", tolua_equip_newunits); } tolua_endmodule(L); return 1; } diff --git a/src/races/races.c b/src/races/races.c index 92a3d3e3d..120a15dd9 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -12,7 +12,6 @@ #include "races.h" #include -#include #include #include #include @@ -36,7 +35,7 @@ void age_skeleton(struct unit *u); void age_zombie(struct unit *u); void age_ghoul(struct unit *u); -static void equip_newunits(const struct equipment *eq, struct unit *u) +void equip_newunits(struct unit *u) { struct region *r = u->region; const struct resource_type *rtype; @@ -81,8 +80,6 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { - register_function((pf_generic)equip_newunits, "equip_newunits"); - /* function age for race->age() */ register_function((pf_generic)age_undead, "age_undead"); register_function((pf_generic)age_skeleton, "age_skeleton"); diff --git a/src/races/races.h b/src/races/races.h index ea7be1337..78c8b062f 100644 --- a/src/races/races.h +++ b/src/races/races.h @@ -18,6 +18,7 @@ extern "C" { void register_races(void); void make_undead_unit(struct unit *); + void equip_newunits(struct unit *u); #ifdef __cplusplus } diff --git a/src/xmlreader.c b/src/xmlreader.c index 5b6f7d8c1..cbae06f58 100644 --- a/src/xmlreader.c +++ b/src/xmlreader.c @@ -862,27 +862,6 @@ static void add_items(equipment * eq, xmlNodeSetPtr nsetItems) } } -static void add_callbacks(equipment * eq, xmlNodeSetPtr nsetItems) -{ - if (nsetItems != NULL && nsetItems->nodeNr > 0) { - int i; - for (i = 0; i != nsetItems->nodeNr; ++i) { - xmlNodePtr node = nsetItems->nodeTab[i]; - xmlChar *propValue; - pf_generic fun; - - propValue = xmlGetProp(node, BAD_CAST "name"); - if (propValue != NULL) { - fun = get_function((const char *)propValue); - if (fun) { - equipment_setcallback(eq, (equip_callback_fun)fun); - } - xmlFree(propValue); - } - } - } -} - static void add_spells(equipment * eq, xmlNodeSetPtr nsetItems) { if (nsetItems != NULL && nsetItems->nodeNr > 0) { @@ -1021,11 +1000,6 @@ static int parse_equipment(xmlDocPtr doc) xpath->node = node; - xpathResult = xmlXPathEvalExpression(BAD_CAST "callback", xpath); - assert(!eq->callback); - add_callbacks(eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - xpathResult = xmlXPathEvalExpression(BAD_CAST "item", xpath); assert(!eq->items); add_items(eq, xpathResult->nodesetval);