Merge branch 'release-3-5' into develop

Conflicts:
	s/runtests
	src/buildno.h
This commit is contained in:
Enno Rehling 2015-05-24 14:10:42 +02:00
commit 59400b1e27
13 changed files with 86 additions and 37 deletions

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
set -e set -e
ROOT=$(pwd) ROOT=$(pwd)

View File

@ -1,16 +1,9 @@
function use_snowman(u, amount) function use_snowman(u, amount)
local have = u:get_item("snowman")
if have<amount then
amount = have
end
if amount>0 and u.region.terrain == "glacier" then if amount>0 and u.region.terrain == "glacier" then
local man = unit.create(u.faction, u.region) local man = unit.create(u.faction, u.region)
man.race = "snowman" man.race = "snowman"
man.number = amount man.number = amount
if u:add_item("snowman", -amount)~= nil then return amount
return -1
end
return 0
end end
return -4 return -4
end end

View File

@ -11,8 +11,7 @@ function use_stardust(u, amount)
u.region:set_resource("peasant", p) u.region:set_resource("peasant", p)
local msg = usepotion_message(u, "stardust") local msg = usepotion_message(u, "stardust")
msg:send_region(u.region) msg:send_region(u.region)
u:use_pooled("stardust", amount) return amount
return 0
end end
local self = {} local self = {}

View File

@ -1,11 +1,10 @@
function use_xmastree(u, amount) function use_xmastree(u, amount)
u.region:set_key("xm06", true) u.region:set_key("xm06", true)
u:use_pooled("xmastree", amount)
local msg = message.create("usepotion") local msg = message.create("usepotion")
msg:set_unit("unit", u) msg:set_unit("unit", u)
msg:set_resource("potion", "xmastree") msg:set_resource("potion", "xmastree")
msg:send_region(u.region) msg:send_region(u.region)
return 0 return amount
end end
local self = {} local self = {}

View File

@ -1,14 +1,15 @@
function use_xmastree(u, amount) function use_xmastree(u, amount)
if u.region.herb~=nil then if u.region.herb~=nil then
-- TODO: else?
local trees = u.region:get_resource("tree") local trees = u.region:get_resource("tree")
u.region:set_resource("tree", 10+trees) u.region:set_resource("tree", 10+trees)
u:use_pooled("xmastree", amount)
local msg = message.create("usepotion") local msg = message.create("usepotion")
msg:set_unit("unit", u) msg:set_unit("unit", u)
msg:set_resource("potion", "xmastree") msg:set_resource("potion", "xmastree")
msg:send_region(u.region) msg:send_region(u.region)
return 0 return amount
end end
return 0
end end
local xmas = {} local xmas = {}

View File

@ -61,6 +61,7 @@ end
function test_give_divisor() function test_give_divisor()
eressea.settings.set("rules.items.give_divisor", 2) eressea.settings.set("rules.items.give_divisor", 2)
eressea.settings.set("GiveRestriction", 0)
local r = region.create(1, 1, "plain") local r = region.create(1, 1, "plain")
local f1 = faction.create("test@example.com", "human", "de") local f1 = faction.create("test@example.com", "human", "de")
local f2 = faction.create("test@example.com", "human", "de") local f2 = faction.create("test@example.com", "human", "de")

View File

@ -191,6 +191,7 @@ set(TESTS_SRC
${ATTRIBUTES_TESTS} ${ATTRIBUTES_TESTS}
${UTIL_TESTS} ${UTIL_TESTS}
${KERNEL_TESTS} ${KERNEL_TESTS}
${ITEMS_TESTS}
) )
add_executable(test_eressea ${TESTS_SRC}) add_executable(test_eressea ${TESTS_SRC})

View File

@ -1,4 +1,9 @@
PROJECT(items C) PROJECT(items C)
SET(_TEST_FILES
xerewards.test.c
)
SET(_FILES SET(_FILES
artrewards.c artrewards.c
demonseye.c demonseye.c
@ -14,4 +19,8 @@ FOREACH(_FILE ${_FILES})
ENDFOREACH(_FILE) ENDFOREACH(_FILE)
SET(ITEMS_SRC ${_SOURCES} PARENT_SCOPE) SET(ITEMS_SRC ${_SOURCES} PARENT_SCOPE)
FOREACH(_FILE ${_TEST_FILES})
LIST(APPEND _TESTS ${PROJECT_NAME}/${_FILE})
ENDFOREACH(_FILE)
SET(ITEMS_TESTS ${_TESTS} PARENT_SCOPE)

View File

@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
static int int
use_skillpotion(struct unit *u, const struct item_type *itype, int amount, use_skillpotion(struct unit *u, const struct item_type *itype, int amount,
struct order *ord) struct order *ord)
{ {
@ -59,12 +59,10 @@ struct order *ord)
} }
} }
ADDMSG(&u->faction->msgs, msg_message("skillpotion_use", "unit", u)); ADDMSG(&u->faction->msgs, msg_message("skillpotion_use", "unit", u));
return amount;
change_resource(u, itype->rtype, -amount);
return 0;
} }
static int int
use_manacrystal(struct unit *u, const struct item_type *itype, int amount, use_manacrystal(struct unit *u, const struct item_type *itype, int amount,
struct order *ord) struct order *ord)
{ {
@ -82,8 +80,7 @@ struct order *ord)
ADDMSG(&u->faction->msgs, msg_message("manacrystal_use", "unit aura", u, sp)); ADDMSG(&u->faction->msgs, msg_message("manacrystal_use", "unit aura", u, sp));
change_resource(u, itype->rtype, -amount); return amount;
return 0;
} }
void register_xerewards(void) void register_xerewards(void)

View File

@ -22,7 +22,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern void register_xerewards(void); struct unit;
struct item_type;
struct order;
void register_xerewards(void);
int use_skillpotion(struct unit *u, const struct item_type *itype, int amount, struct order *ord);
int use_manacrystal(struct unit *u, const struct item_type *itype, int amount, struct order *ord);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -0,0 +1,39 @@
#include <platform.h>
#include "xerewards.h"
#include <kernel/unit.h>
#include <kernel/item.h>
#include <kernel/pool.h>
#include <kernel/region.h>
#include <tests.h>
#include <CuTest.h>
static void test_manacrystal(CuTest *tc) {
test_cleanup();
test_create_world();
test_cleanup();
}
static void test_skillpotion(CuTest *tc) {
unit *u;
const struct item_type *itype;
test_cleanup();
test_create_world();
u = test_create_unit(test_create_faction(NULL), findregion(0, 0));
itype = test_create_itemtype("skillpotion");
change_resource(u, itype->rtype, 2);
CuAssertIntEquals(tc, 1, use_skillpotion(u, itype, 1, NULL));
test_cleanup();
}
CuSuite *get_xerewards_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_manacrystal);
SUITE_ADD_TEST(suite, test_skillpotion);
return suite;
}

View File

@ -3499,8 +3499,7 @@ void update_long_order(unit * u)
} }
} }
static int static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
use_item(unit * u, const item_type * itype, int amount, struct order *ord)
{ {
int i; int i;
int target = read_unitid(u->faction, u->region); int target = read_unitid(u->faction, u->region);
@ -3508,6 +3507,7 @@ use_item(unit * u, const item_type * itype, int amount, struct order *ord)
i = get_pooled(u, itype->rtype, GET_DEFAULT, amount); i = get_pooled(u, itype->rtype, GET_DEFAULT, amount);
if (amount > i) { if (amount > i) {
/* TODO: message? eg. "not enough %, using only %" */
amount = i; amount = i;
} }
if (amount == 0) { if (amount == 0) {
@ -3515,10 +3515,15 @@ use_item(unit * u, const item_type * itype, int amount, struct order *ord)
} }
if (target == -1) { if (target == -1) {
int result;
if (itype->use == NULL) { if (itype->use == NULL) {
return EUNUSABLE; return EUNUSABLE;
} }
return itype->use(u, itype, amount, ord); result = itype->use ? itype->use(u, itype, amount, ord) : EUNUSABLE;
if (result>0) {
use_pooled(u, itype->rtype, GET_DEFAULT, result);
}
return result;
} }
else { else {
if (itype->useonother == NULL) { if (itype->useonother == NULL) {
@ -3787,10 +3792,6 @@ int use_cmd(unit * u, struct order *ord)
if (itype != NULL) { if (itype != NULL) {
err = use_item(u, itype, n, ord); err = use_item(u, itype, n, ord);
assert(err <= 0 || !"use_item should not return positive values.");
if (err > 0) {
log_error("use_item returned a value>0 for %s\n", resourcename(itype->rtype, 0));
}
} }
switch (err) { switch (err) {
case ENOITEM: case ENOITEM:
@ -3802,6 +3803,9 @@ int use_cmd(unit * u, struct order *ord)
case ENOSKILL: case ENOSKILL:
cmistake(u, ord, 50, MSG_PRODUCE); cmistake(u, ord, 50, MSG_PRODUCE);
break; break;
default:
// no error
break;
} }
return err; return err;
} }

View File

@ -54,6 +54,8 @@ int RunAllTests(void)
RUN_TESTS(suite, unicode); RUN_TESTS(suite, unicode);
RUN_TESTS(suite, strings); RUN_TESTS(suite, strings);
RUN_TESTS(suite, rng); RUN_TESTS(suite, rng);
/* items */
RUN_TESTS(suite, xerewards);
/* kernel */ /* kernel */
RUN_TESTS(suite, alliance); RUN_TESTS(suite, alliance);
RUN_TESTS(suite, unit); RUN_TESTS(suite, unit);