BUG 2408: acceptance test for TARNE PARTEI

This commit is contained in:
Enno Rehling 2018-01-10 18:38:38 +01:00
parent 5587e209a2
commit d2cbed3042
2 changed files with 54 additions and 8 deletions

View File

@ -403,3 +403,45 @@ function test_give_to_other_okay()
assert_equal(1, u1.number)
assert_equal(2, u2.number)
end
local function get_name(x)
return x.name .. " (" .. itoa36(x.id) .. ")"
end
function test_faction_stealth()
local f = faction.create('human')
local f2 = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
local u2 = unit.create(f2, r)
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
u:add_order("TARNE PARTEI NUMMER " .. itoa36(f2.id))
process_orders()
assert_equal(get_name(u) .. ", " .. get_name(f2) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f2) .. ", 1 Mensch.", u:show(f2))
u:clear_orders()
u:add_order("TARNE PARTEI NUMMER")
process_orders()
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
end
function test_faction_anonymous()
local f = faction.create('human')
local f2 = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
local u2 = unit.create(f2, r)
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
u:add_order("TARNE PARTEI")
process_orders()
assert_equal(get_name(u) .. ", anonym, 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", anonym, 1 Mensch.", u:show(f2))
u:clear_orders()
u:add_order("TARNE PARTEI NICHT")
process_orders()
assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f))
assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2))
end

View File

@ -49,14 +49,18 @@
#include <limits.h>
static int tolua_bufunit(lua_State * L) {
unit *u = (unit *)tolua_tousertype(L, 1, 0);
if (u) {
faction *f = (faction *)tolua_tousertype(L, 2, u->faction);
if (f) {
char buf[8192];
unit *self = (unit *)tolua_tousertype(L, 1, 0);
int mode = (int)tolua_tonumber(L, 2, (int)seen_unit);
if (!self) return 0;
bufunit(self->faction, self, 0, mode, buf, sizeof(buf));
int mode = (int)tolua_tonumber(L, 3, (int)seen_unit);
bufunit(f, u, 0, mode, buf, sizeof(buf));
tolua_pushstring(L, buf);
return 1;
}
}
return 0;
}