diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index a069c7f0a..8e6d66c9f 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -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 diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index ac77a3c97..cf43535d8 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -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; } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 5aee29ab7..16901d34b 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -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; }