forked from github/server
remove rtype->uget funpointer, and lua callbacks.
fix a missing lua_pop that trashed the heap.
This commit is contained in:
parent
50bdc71c1b
commit
acfb666539
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<resource name="hp" pooled="false">
|
<resource name="hp" pooled="false">
|
||||||
<function name="change" value="lua_changeresource"/>
|
<function name="change" value="lua_changeresource"/>
|
||||||
<function name="get" value="lua_getresource"/>
|
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<resource name="peasant" pooled="false">
|
<resource name="peasant" pooled="false">
|
||||||
<function name="change" value="lua_changeresource"/>
|
<function name="change" value="lua_changeresource"/>
|
||||||
<function name="get" value="lua_getresource"/>
|
|
||||||
</resource>
|
</resource>
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
<xi:include href="config://core/weapons/catapult.xml"/>
|
<xi:include href="config://core/weapons/catapult.xml"/>
|
||||||
<xi:include href="config://core/weapons/mallornbow.xml"/>
|
<xi:include href="config://core/weapons/mallornbow.xml"/>
|
||||||
<xi:include href="config://core/weapons/mallornspear.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/runesword.xml"/>
|
||||||
<xi:include href="config://core/weapons/rustyaxe.xml"/>
|
<xi:include href="config://core/weapons/rustyaxe.xml"/>
|
||||||
<xi:include href="config://core/weapons/rustysword.xml"/>
|
<xi:include href="config://core/weapons/rustysword.xml"/>
|
||||||
<xi:include href="config://core/weapons/spear.xml"/>
|
<xi:include href="config://core/weapons/spear.xml"/>
|
||||||
<xi:include href="config://core/weapons/sword.xml"/>
|
<xi:include href="config://core/weapons/sword.xml"/>
|
||||||
<xi:include href="config://core/weapons/firesword.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/lance.xml"/>
|
||||||
<xi:include href="config://game/weapons/axe.xml"/>
|
<xi:include href="config://game/weapons/axe.xml"/>
|
||||||
<xi:include href="config://game/weapons/crossbow.xml"/>
|
<xi:include href="config://game/weapons/crossbow.xml"/>
|
||||||
|
|
|
@ -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>
|
|
@ -1,9 +1,5 @@
|
||||||
-- global functions used in items.xml
|
-- global functions used in items.xml
|
||||||
|
|
||||||
function peasant_getresource(u)
|
|
||||||
return u.region:get_resource("peasant")
|
|
||||||
end
|
|
||||||
|
|
||||||
function peasant_changeresource(u, delta)
|
function peasant_changeresource(u, delta)
|
||||||
local p = u.region:get_resource("peasant")
|
local p = u.region:get_resource("peasant")
|
||||||
p = p + delta
|
p = p + delta
|
||||||
|
@ -14,10 +10,6 @@ function peasant_changeresource(u, delta)
|
||||||
return p
|
return p
|
||||||
end
|
end
|
||||||
|
|
||||||
function hp_getresource(u)
|
|
||||||
return u.hp
|
|
||||||
end
|
|
||||||
|
|
||||||
function hp_changeresource(u, delta)
|
function hp_changeresource(u, delta)
|
||||||
local hp = u.hp + delta
|
local hp = u.hp + delta
|
||||||
|
|
||||||
|
|
|
@ -496,13 +496,13 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
if (itype->rtype->ptype) {
|
if (itype->rtype->ptype) {
|
||||||
return use_potion(u, itype, amount, ord);
|
return use_potion(u, itype, amount, ord);
|
||||||
} else {
|
} else {
|
||||||
log_error("no such callout: %s", fname);
|
log_error("no such callout: %s", fname);
|
||||||
}
|
}
|
||||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,6 @@ extern "C" {
|
||||||
|
|
||||||
typedef int(*rtype_uchange) (struct unit * user,
|
typedef int(*rtype_uchange) (struct unit * user,
|
||||||
const struct resource_type * rtype, int delta);
|
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 char *(*rtype_name) (const struct resource_type * rtype, int flags);
|
||||||
typedef struct resource_type {
|
typedef struct resource_type {
|
||||||
/* --- constants --- */
|
/* --- constants --- */
|
||||||
|
@ -77,7 +75,6 @@ extern "C" {
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
rtype_uchange uchange;
|
rtype_uchange uchange;
|
||||||
rtype_uget uget;
|
|
||||||
rtype_name name;
|
rtype_name name;
|
||||||
struct rawmaterial_type *raw;
|
struct rawmaterial_type *raw;
|
||||||
struct resource_mod *modifiers;
|
struct resource_mod *modifiers;
|
||||||
|
|
|
@ -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)
|
int get_resource(const unit * u, const resource_type * rtype)
|
||||||
{
|
{
|
||||||
assert(rtype);
|
assert(rtype);
|
||||||
if (rtype->uget) {
|
if (rtype == get_resourcetype(R_PEASANT)) {
|
||||||
/* this resource is probably special */
|
return u->region->land ? u->region->land->peasants : 0;
|
||||||
int i = rtype->uget(u, rtype);
|
}
|
||||||
if (i >= 0)
|
else if (rtype == rt_find("hp")) {
|
||||||
return i;
|
return u->hp;
|
||||||
}
|
}
|
||||||
else if (rtype->uchange) {
|
else if (rtype->uchange) {
|
||||||
/* this resource is probably special */
|
/* this resource is probably special */
|
||||||
|
@ -176,7 +176,7 @@ int count)
|
||||||
}
|
}
|
||||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||||
for (v = r->units; v && use < count; v = v->next)
|
for (v = r->units; v && use < count; v = v->next)
|
||||||
if (u != v && (v->items || rtype->uget)) {
|
if (u != v) {
|
||||||
int mask;
|
int mask;
|
||||||
|
|
||||||
if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
|
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;
|
int mask;
|
||||||
if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
|
if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
|
||||||
continue;
|
continue;
|
||||||
if (v->items == NULL && rtype->uget == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (v->faction == f) {
|
if (v->faction == f) {
|
||||||
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
||||||
|
|
|
@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/assert.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/bsdstring.h>
|
#include <util/bsdstring.h>
|
||||||
#include <util/gamedata.h>
|
#include <util/gamedata.h>
|
||||||
|
@ -697,6 +698,7 @@ void r_setdemand(region * r, const luxury_type * ltype, int value)
|
||||||
d = *dp;
|
d = *dp;
|
||||||
if (!d) {
|
if (!d) {
|
||||||
d = *dp = malloc(sizeof(struct demand));
|
d = *dp = malloc(sizeof(struct demand));
|
||||||
|
assert_alloc(d);
|
||||||
d->next = NULL;
|
d->next = NULL;
|
||||||
d->type = ltype;
|
d->type = ltype;
|
||||||
}
|
}
|
||||||
|
@ -768,6 +770,7 @@ region *new_region(int x, int y, struct plane *pl, int uid)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
r = calloc(1, sizeof(region));
|
r = calloc(1, sizeof(region));
|
||||||
|
assert_alloc(r);
|
||||||
r->x = x;
|
r->x = x;
|
||||||
r->y = y;
|
r->y = y;
|
||||||
r->uid = uid;
|
r->uid = uid;
|
||||||
|
|
|
@ -52,6 +52,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <triggers/timeout.h>
|
#include <triggers/timeout.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/assert.h>
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/bsdstring.h>
|
#include <util/bsdstring.h>
|
||||||
|
@ -646,6 +647,7 @@ unit *read_unit(struct gamedata *data)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
u = calloc(sizeof(unit), 1);
|
u = calloc(sizeof(unit), 1);
|
||||||
|
assert_alloc(u);
|
||||||
u->no = n;
|
u->no = n;
|
||||||
uhash(u);
|
uhash(u);
|
||||||
}
|
}
|
||||||
|
|
|
@ -972,9 +972,6 @@ static int parse_resources(xmlDocPtr doc)
|
||||||
if (strcmp((const char *)propValue, "change") == 0) {
|
if (strcmp((const char *)propValue, "change") == 0) {
|
||||||
rtype->uchange = (rtype_uchange)fun;
|
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) {
|
else if (strcmp((const char *)propValue, "name") == 0) {
|
||||||
rtype->name = (rtype_name)fun;
|
rtype->name = (rtype_name)fun;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue