forked from github/server
Merge pull request #532 from ennorehling/develop
fix stardust item and some small memory leaks
This commit is contained in:
commit
aa7fcd3589
|
@ -15,6 +15,23 @@ local function error_message(msg, u, ord)
|
|||
return -1
|
||||
end
|
||||
|
||||
|
||||
local function usepotion_message(u, type)
|
||||
msg = message.create("usepotion")
|
||||
msg:set_unit("unit", u)
|
||||
msg:set_resource("potion", type)
|
||||
return msg
|
||||
end
|
||||
|
||||
function use_stardust(u, amount)
|
||||
local p = u.region:get_resource("peasant")
|
||||
p = math.ceil(1.5 * p)
|
||||
u.region:set_resource("peasant", p)
|
||||
local msg = usepotion_message(u, "stardust")
|
||||
msg:send_region(u.region)
|
||||
return 1
|
||||
end
|
||||
|
||||
function use_snowglobe(u, amount, token, ord)
|
||||
local transform = {
|
||||
ocean = "glacier",
|
||||
|
@ -59,9 +76,7 @@ function use_xmastree(u, amount)
|
|||
local trees = u.region:get_resource("tree")
|
||||
u.region:set_key("xm06", true)
|
||||
u.region:set_resource("tree", 10+trees)
|
||||
local msg = message.create("usepotion")
|
||||
msg:set_unit("unit", u)
|
||||
msg:set_resource("potion", "xmastree")
|
||||
local msg = usepotion_message(u, "xmastree")
|
||||
msg:send_region(u.region)
|
||||
return amount
|
||||
end
|
||||
|
|
|
@ -82,3 +82,18 @@ function test_xmastree()
|
|||
r = use_tree("plain")
|
||||
assert_equal(10, r:get_resource("tree"))
|
||||
end
|
||||
|
||||
function test_stardust()
|
||||
-- fix random peasant changes:
|
||||
eressea.settings.set("rules.economy.repopulate_maximum", 0)
|
||||
local r = region.create(0, 0, "plain")
|
||||
r:set_resource("peasant", 10)
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 5)
|
||||
u:add_item("stardust", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Sternenstaub")
|
||||
process_orders()
|
||||
assert_equal(15, r:get_resource("peasant"))
|
||||
assert_equal(0, u:get_item('stardust'))
|
||||
end
|
||||
|
|
|
@ -458,6 +458,7 @@ static int tolua_region_create(lua_State * L)
|
|||
const terrain_type *terrain = get_terrain(tname);
|
||||
region *r, *result;
|
||||
if (!terrain) {
|
||||
log_error("lua: region.create with invalid terrain %s", tname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -481,6 +482,7 @@ static int tolua_region_create(lua_State * L)
|
|||
tolua_pushusertype(L, result, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
log_error("lua: region.create with invalid terrain %s", tname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1188,6 +1188,7 @@ static item *default_spoil(const struct race *rc, int size)
|
|||
}
|
||||
|
||||
static void free_itype(item_type *itype) {
|
||||
assert(itype);
|
||||
free(itype->construction);
|
||||
free(itype->_appearance[0]);
|
||||
free(itype->_appearance[1]);
|
||||
|
@ -1195,14 +1196,14 @@ static void free_itype(item_type *itype) {
|
|||
}
|
||||
|
||||
static void free_wtype(weapon_type *wtype) {
|
||||
assert(wtype);
|
||||
free(wtype->damage[0]);
|
||||
free(wtype->damage[1]);
|
||||
free(wtype);
|
||||
}
|
||||
|
||||
int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
|
||||
resource_type *rtype;
|
||||
cb_get_kv(match, &rtype, sizeof(rtype));
|
||||
void free_rtype(resource_type *rtype) {
|
||||
assert(rtype);
|
||||
if (rtype->wtype) {
|
||||
free_wtype(rtype->wtype);
|
||||
}
|
||||
|
@ -1214,6 +1215,12 @@ int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbd
|
|||
}
|
||||
free(rtype->_name);
|
||||
free(rtype);
|
||||
}
|
||||
|
||||
int free_rtype_cb(const void * match, const void * key, size_t keylen, void *cbdata) {
|
||||
resource_type *rtype;
|
||||
cb_get_kv(match, &rtype, sizeof(rtype));
|
||||
free_rtype(rtype);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
static critbit_tree cb_spells;
|
||||
quicklist * spells;
|
||||
|
||||
static void free_spell_cb(void *cbdata) {
|
||||
spell *sp = (spell *)cbdata;
|
||||
static void free_spell(spell *sp) {
|
||||
free(sp->syntax);
|
||||
free(sp->parameter);
|
||||
free(sp->sname);
|
||||
|
@ -45,6 +44,10 @@ static void free_spell_cb(void *cbdata) {
|
|||
free(sp);
|
||||
}
|
||||
|
||||
static void free_spell_cb(void *cbdata) {
|
||||
free_spell((spell *)cbdata);
|
||||
}
|
||||
|
||||
void free_spells(void) {
|
||||
cb_clear(&cb_spells);
|
||||
ql_foreach(spells, free_spell_cb);
|
||||
|
|
|
@ -317,6 +317,12 @@ static void setup_spell_fixture(spell_fixture * spf) {
|
|||
spf->sbe = spellbook_get(spf->spb, spf->sp);
|
||||
}
|
||||
|
||||
static void cleanup_spell_fixture(spell_fixture *spf) {
|
||||
spellbook_clear(spf->spb);
|
||||
free(spf->spb);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
|
||||
stream strm;
|
||||
char buf[1024];
|
||||
|
@ -405,9 +411,8 @@ static void test_write_spell_syntax(CuTest *tc) {
|
|||
set_parameter(spell, "kc+");
|
||||
check_spell_syntax(tc, "kc+", &spell,
|
||||
" ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr>\n [<snr> ...] | BURG <bnr> [<bnr> ...] )");
|
||||
spellbook_clear(spell.spb);
|
||||
free(spell.spb);
|
||||
test_cleanup();
|
||||
|
||||
cleanup_spell_fixture(&spell);
|
||||
}
|
||||
|
||||
CuSuite *get_reports_suite(void)
|
||||
|
|
Loading…
Reference in New Issue