check compatible costs

This commit is contained in:
Enno Rehling 2019-10-10 16:12:25 +02:00
parent 24978a5b80
commit 78e44e0fe3
2 changed files with 71 additions and 18 deletions

View File

@ -193,6 +193,49 @@ function test_give_ship_only_to_captain()
assert_equal(1, u2.ship.number)
end
function test_give_ship_compatible_coasts()
local r = region.create(1, 0, 'plain')
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1.ship = ship.create(r, 'boat')
u1.ship.number = 4
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
u2.ship = ship.create(r, 'boat')
-- cannot give a ship with different coast:
u1.ship.coast = 1
u2.ship.coast = 2
process_orders()
assert_equal(4, u1.ship.number)
assert_equal(1, u2.ship.number)
-- can give a ship with no coast:
u1.ship.coast = -1
u2.ship.coast = 2
process_orders()
assert_equal(3, u1.ship.number)
assert_equal(2, u2.ship.number)
assert_equal(2, u2.ship.coast)
-- can give a ship with same coast:
u1.ship.coast = 2
u2.ship.coast = 2
process_orders()
assert_equal(2, u1.ship.number)
assert_equal(3, u2.ship.number)
assert_equal(2, u2.ship.coast)
-- giving to a ship with no coast:
u1.ship.coast = 2
u2.ship.coast = -1
process_orders()
assert_equal(1, u1.ship.number)
assert_equal(4, u2.ship.number)
assert_equal(2, u2.ship.coast)
end
function test_give_ship_only_from_captain()
local r = region.create(1, 0, 'ocean')
local f = faction.create("human")

View File

@ -331,26 +331,36 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
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);
}
if (n < u1->ship->number) {
if (fval(u_race(u2), RCF_CANSAIL)) {
if (u2->ship) {
if (u2 != ship_owner(u2->ship)) {
return msg_error(u1, ord, 146);
}
if (u2->ship->type != u1->ship->type) {
return msg_error(u1, ord, 322);
}
transfer_ships(u1->ship, u2->ship, n);
if (ship_cursed(u2->ship)) {
return msg_error(u1, ord, 323);
}
if (u1->ship->coast != u2->ship->coast) {
if (u1->ship->coast != NODIRECTION) {
if (u2->ship->coast == NODIRECTION) {
u2->ship->coast = u1->ship->coast;
}
else {
return msg_error(u1, ord, 182);
}
}
}
if (n < u1->ship->number) {
transfer_ships(u1->ship, u2->ship, n);
}
else {
transfer_ships(u1->ship, u2->ship, n);
transfer_units(u1->ship, u2->ship);
}
}
else {
transfer_ships(u1->ship, u2->ship, n);
transfer_units(u1->ship, u2->ship);
}
}
else {
if (fval(u_race(u2), RCF_CANSAIL)) {
if (n < u1->ship->number) {
ship * sh = new_ship(u1->ship->type, u1->region, u1->faction->locale);
scale_ship(sh, 0);
@ -362,9 +372,9 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
ship_set_owner(u2);
}
}
else {
return msg_error(u1, ord, 233);
}
}
else {
return msg_error(u1, ord, 233);
}
return NULL;
}