forked from github/server
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:
parent
896681e189
commit
b2b35fd9d0
|
@ -430,7 +430,6 @@ end
|
||||||
|
|
||||||
function test_give_50_percent_of_money()
|
function test_give_50_percent_of_money()
|
||||||
local r = region.create(0, 0, "plain")
|
local r = region.create(0, 0, "plain")
|
||||||
r.name = "50percent"
|
|
||||||
local u1 = unit.create(faction.create("noreply@eressea.de", "human", "de"), r, 1)
|
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)
|
local u2 = unit.create(faction.create("noreply@eressea.de", "orc", "de"), r, 1)
|
||||||
u1.faction.age = 10
|
u1.faction.age = 10
|
||||||
|
|
16
src/give.c
16
src/give.c
|
@ -95,21 +95,19 @@ static bool limited_give(const item_type * type)
|
||||||
int give_quota(const unit * src, const unit * dst, const item_type * type,
|
int give_quota(const unit * src, const unit * dst, const item_type * type,
|
||||||
int n)
|
int n)
|
||||||
{
|
{
|
||||||
static float divisor = -1;
|
float divisor;
|
||||||
|
|
||||||
if (divisor == 0 || !limited_give(type)) {
|
if (!limited_give(type)) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
if (dst && src && src->faction != dst->faction) {
|
if (dst && src && src->faction != dst->faction) {
|
||||||
if (divisor < 0) {
|
|
||||||
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
|
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
|
||||||
assert(divisor == 0 || divisor >= 1);
|
assert(divisor == 0 || divisor >= 1);
|
||||||
}
|
if (divisor >= 1) {
|
||||||
if (divisor >= 1) {
|
/* predictable > correct: */
|
||||||
/* predictable > correct: */
|
int x = (int)(n / divisor);
|
||||||
int x = (int)(n / divisor);
|
return x;
|
||||||
return x;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1214,8 +1214,8 @@ bool has_skill(const unit * u, skill_t sk)
|
||||||
static int item_invis(const unit *u) {
|
static int item_invis(const unit *u) {
|
||||||
const struct resource_type *rring = get_resourcetype(R_RING_OF_INVISIBILITY);
|
const struct resource_type *rring = get_resourcetype(R_RING_OF_INVISIBILITY);
|
||||||
const struct resource_type *rsphere = get_resourcetype(R_SPHERE_OF_INVISIBILITY);
|
const struct resource_type *rsphere = get_resourcetype(R_SPHERE_OF_INVISIBILITY);
|
||||||
return i_get(u->items, rring->itype)
|
return (rring ? i_get(u->items, rring->itype) : 0)
|
||||||
+ i_get(u->items, rsphere->itype) * 100;
|
+ (rsphere ? i_get(u->items, rsphere->itype) * 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int item_modification(const unit * u, skill_t sk, int val)
|
static int item_modification(const unit * u, skill_t sk, int val)
|
||||||
|
|
|
@ -17,7 +17,8 @@ function setup()
|
||||||
},
|
},
|
||||||
"keywords" : {
|
"keywords" : {
|
||||||
"de" : {
|
"de" : {
|
||||||
"give" : "GIB"
|
"give" : "GIB",
|
||||||
|
"contact" : "KONTAKTIERE"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strings" : {
|
"strings" : {
|
||||||
|
@ -56,3 +57,18 @@ function test_give_from_faction()
|
||||||
assert_equal(0, u2:get_item("money"))
|
assert_equal(0, u2:get_item("money"))
|
||||||
assert_equal(100, u3:get_item("money"))
|
assert_equal(100, u3:get_item("money"))
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in New Issue