From e0a5ba60b4556fd82feb05e8d86250876ae16647 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 17 Jan 2018 17:37:37 +0100 Subject: [PATCH] enhance foolpotion test. --- scripts/tests/e2/items.lua | 15 +++++++++------ src/battle.test.c | 8 ++++---- src/bind_unit.c | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index c2f479460..ad24bde58 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -133,23 +133,26 @@ function test_foolpotion() local f = faction.create("human", "noreply@eressea.de", "de") local u = unit.create(f, r, 1) turn_begin() - u:add_item("p7", 1) + u:add_item('p7', 2) u:clear_orders() u:add_order("BENUTZEN 1 Dumpfbackenbrot 4242") turn_process() - assert_equal(1, u:get_item("p7")) + assert_equal(2, u:get_item('p7')) assert_equal(1, f:count_msg_type('feedback_unit_not_found')) local u2 = unit.create(f, r, 1) u:clear_orders() - u:add_order("BENUTZEN 1 Dumpfbackenbrot " .. itoa36(u2.id)) + u:add_order("BENUTZEN 2 Dumpfbackenbrot " .. itoa36(u2.id)) turn_process() - assert_equal(1, u:get_item("p7")) + assert_equal(2, u:get_item('p7')) assert_equal(1, f:count_msg_type('error64')) - u:set_skill("stealth", 1); + u:set_skill("stealth", 1) + u2:set_skill('crossbow', 1) turn_process() - assert_equal(0, u:get_item("p7")) + assert_equal(0, u:get_item('p7')) + assert_equal(0, u2:effect('p7')) + assert_equal(0, u2:get_skill('crossbow')) assert_equal(1, f:count_msg_type('givedumb')) turn_end() end diff --git a/src/battle.test.c b/src/battle.test.c index 07107383e..19d256fd8 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -499,15 +499,15 @@ static void test_battle_skilldiff_building(CuTest *tc) test_teardown(); } -static void assert_skill(CuTest *tc, char *msg, unit *u, skill_t sk, int level, int week, int weekmax) +static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax) { skill *sv = unit_skill(u, sk); char buf[256]; if (sv) { sprintf(buf, "%s level %d != %d", msg, sv->level, level); - CuAssertIntEquals_Msg(tc, (const char *)&buf, level, sv->level); + CuAssertIntEquals_Msg(tc, buf, level, sv->level); sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax); - CuAssert(tc, (const char *)&buf, sv->weeks >= week && sv->weeks <= weekmax); + CuAssert(tc, buf, sv->weeks >= week && sv->weeks <= weekmax); } else { CuAssertIntEquals_Msg(tc, msg, level, 0); @@ -518,7 +518,7 @@ static void assert_skill(CuTest *tc, char *msg, unit *u, skill_t sk, int level, static void test_drain_exp(CuTest *tc) { unit *u; - char *msg; + const char *msg; int i; double rand; diff --git a/src/bind_unit.c b/src/bind_unit.c index aea404597..ec7a799f0 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -505,6 +505,19 @@ static int tolua_unit_addnotice(lua_State * L) return 0; } +static int bind_unit_effect(lua_State * L) +{ + unit *u = (unit *)tolua_tousertype(L, 1, NULL); + const char *str = tolua_tostring(L, 2, NULL); + const item_type *itype = it_find(str); + if (itype) { + int effect = get_effect(u, itype); + lua_pushinteger(L, effect); + return 1; + } + return 0; +} + static void unit_castspell(unit * u, const char *name, int level) { spell *sp = find_spell(name); @@ -1030,6 +1043,7 @@ void tolua_unit_open(lua_State * L) tolua_function(L, TOLUA_CAST "add_spell", tolua_unit_addspell); tolua_variable(L, TOLUA_CAST "spells", tolua_unit_get_spells, 0); tolua_function(L, TOLUA_CAST "cast_spell", tolua_unit_castspell); + tolua_function(L, TOLUA_CAST "effect", bind_unit_effect); tolua_variable(L, TOLUA_CAST "magic", tolua_unit_get_magic, tolua_unit_set_magic);