add message if implicit leave of building owner fails (see bug #1870)

This commit is contained in:
Steffen Mecke 2012-07-25 23:07:30 +02:00
parent f286c51862
commit 69a51c4b2c
3 changed files with 52 additions and 2 deletions

View File

@ -955,6 +955,7 @@ function setup()
eressea.write_game("free.dat")
eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("rules.move.owner_leave", "0")
end
function test_parser()
@ -1257,3 +1258,44 @@ function test_bug_1879_follow_unit()
assert_equal(u2.region.id, r1.id)
end
function test_bug_1870_leave_enter_e2()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u1, u2 = two_units(r, f, f)
local mine = building.create(r, "mine")
mine.size = 10
u1.building = mine
local b = building.create(r, "castle")
b.size = 10
u2.building = b
u1:clear_orders()
u1:add_order("LERNEN Burgenbau ")
u1:add_order("BETRETEN BURG " .. itoa36(b.id))
eressea.settings.set("rules.move.owner_leave", "0")
process_orders()
assert_equal(u1.building.id, b.id)
end
function test_bug_1870_leave_enter_e3()
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u1, u2 = two_units(r, f, f)
local mine = building.create(r, "mine")
mine.size = 10
u1.building = mine
local b = building.create(r, "castle")
b.size = 10
u2.building = b
u1:clear_orders()
u1:add_order("LERNEN Burgenbau ")
u1:add_order("BETRETEN BURG " .. itoa36(b.id))
eressea.settings.set("rules.move.owner_leave", "1")
process_orders()
assert_equal(u1.building.id, mine.id)
end

View File

@ -1261,9 +1261,11 @@ int enter_ship(unit * u, struct order *ord, int id, int report)
}
}
if (leave(u, 0)) {
if (leave(u, false)) {
u_set_ship(u, sh);
fset(u, UFL_ENTER);
} else if (report) {
cmistake(u, ord, 150, MSG_MOVE);
}
return 1;
}
@ -1310,6 +1312,8 @@ int enter_building(unit * u, order * ord, int id, int report)
fset(u, UFL_ENTER);
u_set_building(u, b);
return 1;
} else if (report) {
cmistake(u, ord, 150, MSG_MOVE);
}
return 0;
}

View File

@ -822,14 +822,18 @@ void leave_building(unit * u)
bool can_leave(unit * u)
{
static int gamecookie = -1;
static int rule_leave = -1;
if (!u->building) {
return true;
}
if (rule_leave < 0) {
if (rule_leave < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
rule_leave = get_param_int(global.parameters, "rules.move.owner_leave", 0);
}
if (rule_leave && u->building && u == building_owner(u->building)) {
return false;
}