forked from github/server
Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
e954b210d4
|
@ -1,5 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT=$(pwd)
|
||||
|
|
|
@ -14,7 +14,7 @@ function pkg.update()
|
|||
local o = f.options
|
||||
local bit = (math.floor(o / 8) % 2)
|
||||
if bit==0 then
|
||||
eressea.log.warning("enable JSON report for " .. tostring(f))
|
||||
eressea.log.info("enable JSON report for " .. tostring(f))
|
||||
f.options = o + 8
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
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
|
||||
local man = unit.create(u.faction, u.region)
|
||||
man.race = "snowman"
|
||||
man.number = amount
|
||||
if u:add_item("snowman", -amount)~= nil then
|
||||
return -1
|
||||
end
|
||||
return 0
|
||||
return amount
|
||||
end
|
||||
return -4
|
||||
end
|
||||
|
|
|
@ -11,8 +11,7 @@ function use_stardust(u, amount)
|
|||
u.region:set_resource("peasant", p)
|
||||
local msg = usepotion_message(u, "stardust")
|
||||
msg:send_region(u.region)
|
||||
u:use_pooled("stardust", amount)
|
||||
return 0
|
||||
return amount
|
||||
end
|
||||
|
||||
local self = {}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
function use_xmastree(u, amount)
|
||||
u.region:set_key("xm06", true)
|
||||
u:use_pooled("xmastree", amount)
|
||||
local msg = message.create("usepotion")
|
||||
msg:set_unit("unit", u)
|
||||
msg:set_resource("potion", "xmastree")
|
||||
msg:send_region(u.region)
|
||||
return 0
|
||||
return amount
|
||||
end
|
||||
|
||||
local self = {}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
function use_xmastree(u, amount)
|
||||
if u.region.herb~=nil then
|
||||
-- TODO: else?
|
||||
local trees = u.region:get_resource("tree")
|
||||
u.region:set_resource("tree", 10+trees)
|
||||
u:use_pooled("xmastree", amount)
|
||||
local msg = message.create("usepotion")
|
||||
msg:set_unit("unit", u)
|
||||
msg:set_resource("potion", "xmastree")
|
||||
msg:send_region(u.region)
|
||||
return 0
|
||||
return amount
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local xmas = {}
|
||||
|
|
|
@ -61,6 +61,7 @@ end
|
|||
|
||||
function test_give_divisor()
|
||||
eressea.settings.set("rules.items.give_divisor", 2)
|
||||
eressea.settings.set("GiveRestriction", 0)
|
||||
local r = region.create(1, 1, "plain")
|
||||
local f1 = faction.create("test@example.com", "human", "de")
|
||||
local f2 = faction.create("test@example.com", "human", "de")
|
||||
|
|
|
@ -191,6 +191,7 @@ set(TESTS_SRC
|
|||
${ATTRIBUTES_TESTS}
|
||||
${UTIL_TESTS}
|
||||
${KERNEL_TESTS}
|
||||
${ITEMS_TESTS}
|
||||
)
|
||||
|
||||
add_executable(test_eressea ${TESTS_SRC})
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 5
|
||||
#define VERSION_MINOR 6
|
||||
#define VERSION_BUILD 0
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
PROJECT(items C)
|
||||
|
||||
SET(_TEST_FILES
|
||||
xerewards.test.c
|
||||
)
|
||||
|
||||
SET(_FILES
|
||||
artrewards.c
|
||||
demonseye.c
|
||||
|
@ -14,4 +19,8 @@ FOREACH(_FILE ${_FILES})
|
|||
ENDFOREACH(_FILE)
|
||||
SET(ITEMS_SRC ${_SOURCES} PARENT_SCOPE)
|
||||
|
||||
FOREACH(_FILE ${_TEST_FILES})
|
||||
LIST(APPEND _TESTS ${PROJECT_NAME}/${_FILE})
|
||||
ENDFOREACH(_FILE)
|
||||
SET(ITEMS_TESTS ${_TESTS} PARENT_SCOPE)
|
||||
|
|
@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int
|
||||
int
|
||||
use_skillpotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
|
@ -59,12 +59,10 @@ struct order *ord)
|
|||
}
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_message("skillpotion_use", "unit", u));
|
||||
|
||||
change_resource(u, itype->rtype, -amount);
|
||||
return 0;
|
||||
return amount;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
use_manacrystal(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
|
@ -82,8 +80,7 @@ struct order *ord)
|
|||
|
||||
ADDMSG(&u->faction->msgs, msg_message("manacrystal_use", "unit aura", u, sp));
|
||||
|
||||
change_resource(u, itype->rtype, -amount);
|
||||
return 0;
|
||||
return amount;
|
||||
}
|
||||
|
||||
void register_xerewards(void)
|
||||
|
|
|
@ -22,7 +22,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
18
src/laws.c
18
src/laws.c
|
@ -3499,8 +3499,7 @@ void update_long_order(unit * u)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
||||
static int use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
||||
{
|
||||
int i;
|
||||
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);
|
||||
|
||||
if (amount > i) {
|
||||
/* TODO: message? eg. "not enough %, using only %" */
|
||||
amount = i;
|
||||
}
|
||||
if (amount == 0) {
|
||||
|
@ -3515,10 +3515,15 @@ use_item(unit * u, const item_type * itype, int amount, struct order *ord)
|
|||
}
|
||||
|
||||
if (target == -1) {
|
||||
int result;
|
||||
if (itype->use == NULL) {
|
||||
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 {
|
||||
if (itype->useonother == NULL) {
|
||||
|
@ -3787,10 +3792,6 @@ int use_cmd(unit * u, struct order *ord)
|
|||
|
||||
if (itype != NULL) {
|
||||
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) {
|
||||
case ENOITEM:
|
||||
|
@ -3802,6 +3803,9 @@ int use_cmd(unit * u, struct order *ord)
|
|||
case ENOSKILL:
|
||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||
break;
|
||||
default:
|
||||
// no error
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ int RunAllTests(void)
|
|||
RUN_TESTS(suite, unicode);
|
||||
RUN_TESTS(suite, strings);
|
||||
RUN_TESTS(suite, rng);
|
||||
/* items */
|
||||
RUN_TESTS(suite, xerewards);
|
||||
/* kernel */
|
||||
RUN_TESTS(suite, alliance);
|
||||
RUN_TESTS(suite, unit);
|
||||
|
|
Loading…
Reference in New Issue