translate seed_%race% equipment from xml to lua.

This commit is contained in:
Enno Rehling 2018-05-12 20:52:10 +02:00
parent 298e220cfd
commit 40125bb75e
6 changed files with 104 additions and 101 deletions

View File

@ -1,73 +1,6 @@
<?xml version="1.0"?>
<eressea><equipment>
<!-- one equipment-set per player-race for the first unit in a faction -->
<set name="seed_dwarf">
<item name="axe" amount="1"/>
<item name="chainmail" amount="1"/>
<skill name="melee" level="1"/>
</set>
<set name="seed_elf">
<item name="fairyboot" amount="1"/>
<callback name="equip_newunits"/>
</set>
<set name="seed_orc">
<skill name="polearm" level="4"/>
<skill name="melee" level="4"/>
<skill name="crossbow" level="4"/>
<skill name="catapult" level="4"/>
<skill name="bow" level="4"/>
</set>
<set name="seed_goblin">
<item name="roi" amount="1"/>
<callback name="equip_newunits"/>
</set>
<set name="seed_human">
<callback name="equip_newunits"/>
</set>
<set name="seed_troll">
<skill name="building" level="1"/>
<skill name="perception" level="3"/>
<item name="stone" amount="50"/>
</set>
<set name="seed_demon">
<skill name="stamina" level="15"/>
</set>
<set name="seed_insect">
<item name="nestwarmth" amount="9"/>
</set>
<set name="seed_halfling">
<skill name="trade" level="1"/>
<skill name="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"/>
</set>
<set name="seed_cat">
<item name="roi" amount="1"/>
<callback name="equip_newunits"/>
</set>
<set name="seed_aquarian">
<skill name="sailing" level="1"/>
<callback name="equip_newunits"/>
</set>
<!-- equipment-sets for random encounters -->
<set name="rand_desert">
<skill name="melee" level="d2"/>

View File

@ -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

View File

@ -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;
}

View File

@ -12,7 +12,6 @@
#include "races.h"
#include <kernel/building.h>
#include <kernel/equipment.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/pathfinder.h>
@ -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");

View File

@ -18,6 +18,7 @@ extern "C" {
void register_races(void);
void make_undead_unit(struct unit *);
void equip_newunits(struct unit *u);
#ifdef __cplusplus
}

View File

@ -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);