remove rtype->uget funpointer, and lua callbacks.

fix a missing lua_pop that trashed the heap.
This commit is contained in:
Enno Rehling 2017-03-04 20:59:43 +01:00
parent 50bdc71c1b
commit acfb666539
11 changed files with 28 additions and 26 deletions

View File

@ -1,5 +1,4 @@
<?xml version="1.0"?>
<resource name="hp" pooled="false">
<function name="change" value="lua_changeresource"/>
<function name="get" value="lua_getresource"/>
</resource>

View File

@ -1,5 +1,4 @@
<?xml version="1.0"?>
<resource name="peasant" pooled="false">
<function name="change" value="lua_changeresource"/>
<function name="get" value="lua_getresource"/>
</resource>

View File

@ -4,13 +4,13 @@
<xi:include href="config://core/weapons/catapult.xml"/>
<xi:include href="config://core/weapons/mallornbow.xml"/>
<xi:include href="config://core/weapons/mallornspear.xml"/>
<xi:include href="config://core/weapons/rep_crossbow.xml"/>
<xi:include href="config://core/weapons/runesword.xml"/>
<xi:include href="config://core/weapons/rustyaxe.xml"/>
<xi:include href="config://core/weapons/rustysword.xml"/>
<xi:include href="config://core/weapons/spear.xml"/>
<xi:include href="config://core/weapons/sword.xml"/>
<xi:include href="config://core/weapons/firesword.xml"/>
<xi:include href="config://game/weapons/rep_crossbow.xml"/>
<xi:include href="config://game/weapons/lance.xml"/>
<xi:include href="config://game/weapons/axe.xml"/>
<xi:include href="config://game/weapons/crossbow.xml"/>

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<resource name="rep_crossbow">
<item weight="100" allow="dwarf halfling">
<construction skill="weaponsmithing" minskill="5">
<modifier function="mod_dwarves_only"/>
<requirement type="log" quantity="1"/>
<requirement type="iron" quantity="1"/>
</construction>
<weapon armorpiercing="true" pierce="true" missile="true" skill="crossbow" offmod="0" defmod="0" reload="1">
<damage type="rider" value="3d4+5"/>
<damage type="footman" value="3d4+5"/>
<modifier type="missile_target" value="0"/>
</weapon>
</item>
</resource>

View File

@ -1,9 +1,5 @@
-- global functions used in items.xml
function peasant_getresource(u)
return u.region:get_resource("peasant")
end
function peasant_changeresource(u, delta)
local p = u.region:get_resource("peasant")
p = p + delta
@ -14,10 +10,6 @@ function peasant_changeresource(u, delta)
return p
end
function hp_getresource(u)
return u.hp
end
function hp_changeresource(u, delta)
local hp = u.hp + delta

View File

@ -496,13 +496,13 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
}
return result;
}
lua_pop(L, 1);
if (itype->rtype->ptype) {
return use_potion(u, itype, amount, ord);
} else {
log_error("no such callout: %s", fname);
}
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
return result;
}

View File

@ -68,8 +68,6 @@ extern "C" {
typedef int(*rtype_uchange) (struct unit * user,
const struct resource_type * rtype, int delta);
typedef int(*rtype_uget) (const struct unit * user,
const struct resource_type * rtype);
typedef char *(*rtype_name) (const struct resource_type * rtype, int flags);
typedef struct resource_type {
/* --- constants --- */
@ -77,7 +75,6 @@ extern "C" {
unsigned int flags;
/* --- functions --- */
rtype_uchange uchange;
rtype_uget uget;
rtype_name name;
struct rawmaterial_type *raw;
struct resource_mod *modifiers;

View File

@ -40,11 +40,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
int get_resource(const unit * u, const resource_type * rtype)
{
assert(rtype);
if (rtype->uget) {
/* this resource is probably special */
int i = rtype->uget(u, rtype);
if (i >= 0)
return i;
if (rtype == get_resourcetype(R_PEASANT)) {
return u->region->land ? u->region->land->peasants : 0;
}
else if (rtype == rt_find("hp")) {
return u->hp;
}
else if (rtype->uchange) {
/* this resource is probably special */
@ -176,7 +176,7 @@ int count)
}
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
for (v = r->units; v && use < count; v = v->next)
if (u != v && (v->items || rtype->uget)) {
if (u != v) {
int mask;
if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
@ -234,8 +234,6 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
int mask;
if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
continue;
if (v->items == NULL && rtype->uget == NULL)
continue;
if (v->faction == f) {
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);

View File

@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "unit.h"
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <util/bsdstring.h>
#include <util/gamedata.h>
@ -697,6 +698,7 @@ void r_setdemand(region * r, const luxury_type * ltype, int value)
d = *dp;
if (!d) {
d = *dp = malloc(sizeof(struct demand));
assert_alloc(d);
d->next = NULL;
d->type = ltype;
}
@ -768,6 +770,7 @@ region *new_region(int x, int y, struct plane *pl, int uid)
return r;
}
r = calloc(1, sizeof(region));
assert_alloc(r);
r->x = x;
r->y = y;
r->uid = uid;

View File

@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <triggers/timeout.h>
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
@ -646,6 +647,7 @@ unit *read_unit(struct gamedata *data)
}
else {
u = calloc(sizeof(unit), 1);
assert_alloc(u);
u->no = n;
uhash(u);
}

View File

@ -972,9 +972,6 @@ static int parse_resources(xmlDocPtr doc)
if (strcmp((const char *)propValue, "change") == 0) {
rtype->uchange = (rtype_uchange)fun;
}
else if (strcmp((const char *)propValue, "get") == 0) {
rtype->uget = (rtype_uget)fun;
}
else if (strcmp((const char *)propValue, "name") == 0) {
rtype->name = (rtype_name)fun;
}