diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 5cd723f8e..b038553b8 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -183,16 +183,32 @@ function test_give_ship_only_to_captain() local u1 = unit.create(f, r, 1) local u2 = unit.create(f, r, 1) local u3 = unit.create(f, r, 1) - u2.ship = ship.create(r, 'boat') - u3.ship = u2.ship u1.ship = ship.create(r, 'boat') u1.ship.number = 2 + u2.ship = ship.create(r, 'boat') + u3.ship = u2.ship u1:add_order("GIB " .. itoa36(u3.id) .. " 1 SCHIFF") process_orders() assert_equal(2, u1.ship.number) assert_equal(1, u2.ship.number) end +function test_give_ship_only_from_captain() + local r = region.create(1, 0, 'ocean') + local f = faction.create("human") + local u1 = unit.create(f, r, 1) + local u2 = unit.create(f, r, 1) + local u3 = unit.create(f, r, 1) + u2.ship = ship.create(r, 'boat') + u1.ship = ship.create(r, 'boat') + u1.ship.number = 2 + u3.ship = u1.ship + u3:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF") + process_orders() + assert_equal(2, u1.ship.number) + assert_equal(1, u2.ship.number) +end + function test_give_ship_merge() local r = region.create(1, 0, 'ocean') local f = faction.create("human") diff --git a/src/give.c b/src/give.c index 71c9bab7d..cc9f54987 100644 --- a/src/give.c +++ b/src/give.c @@ -328,7 +328,13 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord) if (ship_cursed(u1->ship)) { return msg_error(u1, ord, 323); } + if (u1 != ship_owner(u1->ship)) { + return msg_error(u1, ord, 146); + } if (u2->ship) { + if (u2 != ship_owner(u2->ship)) { + return msg_error(u1, ord, 146); + } if (ship_cursed(u2->ship)) { return msg_error(u1, ord, 323); }