add a test for the E3 reduced give quota.

foreign units receive only 50% of silver given to them.

Conflicts:
	tests/pool.lua
This commit is contained in:
Enno Rehling 2014-07-07 03:40:58 +02:00
parent 896681e189
commit b2b35fd9d0
4 changed files with 26 additions and 13 deletions

View File

@ -430,7 +430,6 @@ end
function test_give_50_percent_of_money()
local r = region.create(0, 0, "plain")
r.name = "50percent"
local u1 = unit.create(faction.create("noreply@eressea.de", "human", "de"), r, 1)
local u2 = unit.create(faction.create("noreply@eressea.de", "orc", "de"), r, 1)
u1.faction.age = 10

View File

@ -95,16 +95,14 @@ static bool limited_give(const item_type * type)
int give_quota(const unit * src, const unit * dst, const item_type * type,
int n)
{
static float divisor = -1;
float divisor;
if (divisor == 0 || !limited_give(type)) {
if (!limited_give(type)) {
return n;
}
if (dst && src && src->faction != dst->faction) {
if (divisor < 0) {
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
assert(divisor == 0 || divisor >= 1);
}
if (divisor >= 1) {
/* predictable > correct: */
int x = (int)(n / divisor);

View File

@ -1214,8 +1214,8 @@ bool has_skill(const unit * u, skill_t sk)
static int item_invis(const unit *u) {
const struct resource_type *rring = get_resourcetype(R_RING_OF_INVISIBILITY);
const struct resource_type *rsphere = get_resourcetype(R_SPHERE_OF_INVISIBILITY);
return i_get(u->items, rring->itype)
+ i_get(u->items, rsphere->itype) * 100;
return (rring ? i_get(u->items, rring->itype) : 0)
+ (rsphere ? i_get(u->items, rsphere->itype) * 100 : 0);
}
static int item_modification(const unit * u, skill_t sk, int val)

View File

@ -17,7 +17,8 @@ function setup()
},
"keywords" : {
"de" : {
"give" : "GIB"
"give" : "GIB",
"contact" : "KONTAKTIERE"
}
},
"strings" : {
@ -56,3 +57,18 @@ function test_give_from_faction()
assert_equal(0, u2:get_item("money"))
assert_equal(100, u3:get_item("money"))
end
function test_give_divisor()
eressea.settings.set("rules.items.give_divisor", 2)
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")
local u1 = unit.create(f1, r, 1)
local u2 = unit.create(f2, r, 1)
u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
u1:add_item("money", 100)
u1:add_order("GIB " .. itoa36(u2.id) .. " 100 SILBER")
process_orders()
assert_equal(0, u1:get_item("money"))
assert_equal(50, u2:get_item("money"))
end