GIB 0 n SCHIFFE

Keine Boote erlauben
Übergabe an eigene Besatzung.
This commit is contained in:
Enno Rehling 2019-10-10 20:17:25 +02:00
parent 78e44e0fe3
commit 1d405e2ef8
4 changed files with 171 additions and 70 deletions

View File

@ -2780,6 +2780,12 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist
msgid "error323"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff ist verzaubert.\""
msgid "error327"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - So viele Schiffe kann die Einheit nicht übergeben.\""
msgid "error326"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Diese Schiffe können keinen Konvoi bilden.\""
msgid "dissolve_units_2"
msgstr "\"$unit($unit) in $region($region): $int($number) $race($race,$number) $if($eq($number,1),\"wurde zum Baum\", \"wurden zu Bäumen\").\""

View File

@ -2771,6 +2771,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit cannot
msgid "error325"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Spells can only be cast on a single ship.\""
msgid "error326"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - These ships cannot form a convoy.\""
msgid "error324"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is not one of ours.\""

View File

@ -83,9 +83,9 @@ function test_ship_convoy_capacity()
local u = unit.create(f, r1, 1)
u:add_order('NACH O')
u:set_skill('sailing', 2, true)
u:add_item('jewel', 40)
u.ship = ship.create(r1, 'boat')
u:set_skill('sailing', 10, true)
u:add_item('jewel', 490)
u.ship = ship.create(r1, 'longboat')
assert_equal(1, u.ship.number)
process_orders()
u:clear_orders()
@ -99,19 +99,17 @@ function test_ship_convoy_capacity()
assert_equal(r2, u.region) -- too heavy
u:add_order('NACH W')
u:add_item('jewel', 39)
u:add_item('jewel', 489)
u.ship.number = 2
u.number = 2
u:set_skill('sailing', 2, true)
u:set_skill('sailing', 10, true)
process_orders()
u:clear_orders()
assert_equal(r1, u.region) -- double capacity
u:add_order('NACH O')
u.ship.number = 2
u.name = 'Bolgrim'
u:add_item('jewel', 1) -- too heavy again
u:set_skill('sailing', 2, true)
process_orders()
u:clear_orders()
assert_equal(r1, u.region)
@ -122,17 +120,17 @@ function test_ship_convoy_crew()
local r2 = region.create(2, 0, 'ocean')
local f = faction.create("human")
local u = unit.create(f, r1, 1)
u.ship = ship.create(r1, 'boat')
u.ship = ship.create(r1, 'longboat')
u.ship.number = 2
u:set_skill('sailing', 4, true)
u.number = 2
u:set_skill('sailing', 5, true)
u:add_order('NACH O')
process_orders()
u:clear_orders()
assert_equal(r1, u.region) -- not enough captains
u.number = 2
u:set_skill('sailing', 2, true)
u:set_skill('sailing', 10, true)
u:add_order('NACH O')
process_orders()
u:clear_orders()
@ -146,20 +144,20 @@ function test_ship_convoy_skill()
local f = faction.create("human")
local u = unit.create(f, r1, 1)
u:set_skill('sailing', 2, true)
u.ship = ship.create(r1, 'boat')
u:set_skill('sailing', 10, true)
u.ship = ship.create(r1, 'longboat')
assert_equal(1, u.ship.number)
u:add_order('NACH O')
process_orders()
assert_equal(r2, u.region)
u.ship.number = 2
u:set_skill('sailing', 4, true)
u:set_skill('sailing', 20, true)
process_orders()
assert_equal(r2, u.region) -- not enough captains
u.number = 2
u:set_skill('sailing', 2, true)
u:set_skill('sailing', 10, true)
process_orders()
assert_equal(r3, u.region)
end
@ -169,7 +167,7 @@ function test_give_ship()
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 = ship.create(r, 'longboat')
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
@ -177,15 +175,84 @@ function test_give_ship()
assert_equal(1, u2.ship.number)
end
function test_give_ship_new_unit()
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)
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
assert_equal(1, u1.ship.number)
assert_equal(1, u2.ship.number)
end
function test_give_ship_same_ship()
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)
u1.ship = ship.create(r, 'longboat')
u2.ship = u1.ship
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
assert_equal(1, u1.ship.number)
assert_equal(1, u2.ship.number)
assert_not_equal(u1.ship, u2.ship)
end
function test_give_ship_dont_give_all()
local r = region.create(1, 0, 'ocean')
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u1:add_order("GIB 0 2 SCHIFF")
process_orders()
assert_equal(2, u1.ship.number)
end
function test_give_ship_no_boat()
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)
u1.ship = ship.create(r, 'boat')
u1.ship.number = 1
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
assert_equal(1, u1.ship.number)
assert_equal(nil, u2.ship)
end
function test_give_ship_away()
local r = region.create(1, 0, 'ocean')
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u1:add_order("GIB 0 1 SCHIFF")
process_orders()
assert_equal(1, u1.ship.number)
local count = 0
for sh in r.ships do
assert_equal(1, sh.number)
count = count + 1
end
assert_equal(2, count)
end
function test_give_ship_only_to_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)
u1.ship = ship.create(r, 'boat')
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u2.ship = ship.create(r, 'boat')
u2.ship = ship.create(r, 'longboat')
u3.ship = u2.ship
u1:add_order("GIB " .. itoa36(u3.id) .. " 1 SCHIFF")
process_orders()
@ -198,10 +265,10 @@ function test_give_ship_compatible_coasts()
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 = ship.create(r, 'longboat')
u1.ship.number = 4
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
u2.ship = ship.create(r, 'boat')
u2.ship = ship.create(r, 'longboat')
-- cannot give a ship with different coast:
u1.ship.coast = 1
@ -242,8 +309,8 @@ function test_give_ship_only_from_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')
u1.ship = ship.create(r, 'boat')
u2.ship = ship.create(r, 'longboat')
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u3.ship = u1.ship
u3:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
@ -257,8 +324,8 @@ function test_give_ship_merge()
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u2.ship = ship.create(r, 'boat')
u1.ship = ship.create(r, 'boat')
u2.ship = ship.create(r, 'longboat')
u1.ship = ship.create(r, 'longboat')
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
@ -271,8 +338,8 @@ function test_give_ship_only_same()
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u2.ship = ship.create(r, 'boat')
u1.ship = ship.create(r, 'longboat')
u2.ship = ship.create(r, 'longboat')
u1.ship = ship.create(r, 'caravel')
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
@ -285,7 +352,7 @@ function test_give_ship_scale()
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
local sh = ship.create(r, 'boat')
local sh = ship.create(r, 'longboat')
sh.number = 3
sh.damage = 9
sh.size = 12
@ -305,10 +372,10 @@ function test_give_ship_all_ships()
local f = faction.create("human", 'noreply@vg.no')
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1.ship = ship.create(r, 'boat')
u1.ship = ship.create(r, 'longboat')
u1.ship.damage = 2
u1.ship.number = 2
u2.ship = ship.create(r, 'boat')
u2.ship = ship.create(r, 'longboat')
u2.ship.number = 1
u1:add_order("GIB " .. itoa36(u2.id) .. " 2 SCHIFF")
process_orders()
@ -323,7 +390,7 @@ function test_give_ship_self_only()
local f2 = faction.create("human")
local u1 = unit.create(f1, r, 1)
local u2 = unit.create(f2, r, 1)
local sh = ship.create(r, 'boat')
local sh = ship.create(r, 'longboat')
sh.number = 2
u1.ship = sh
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
@ -337,7 +404,7 @@ function test_give_ship_not_cursed()
local f = faction.create("human")
local u = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
local sh = ship.create(r, 'boat')
local sh = ship.create(r, 'longboat')
u.ship = sh
u:add_item("speedsail", 1)
u:add_order("BENUTZE 1 Sonnensegel")
@ -354,7 +421,7 @@ function test_speedsail_on_ship()
local r = region.create(1, 0, 'plain')
local f = faction.create("human")
local u = unit.create(f, r, 1)
local sh = ship.create(r, 'boat')
local sh = ship.create(r, 'longboat')
u.ship = sh
u:add_item("speedsail", 1)
u:add_order("BENUTZE 1 Sonnensegel")
@ -366,7 +433,7 @@ function test_no_speedsail_on_convoy()
local r = region.create(1, 0, 'plain')
local f = faction.create("human")
local u = unit.create(f, r, 1)
local sh = ship.create(r, 'boat')
local sh = ship.create(r, 'longboat')
u.ship = sh
sh.number = 2
u:add_item("speedsail", 2)

View File

@ -299,6 +299,9 @@ static void transfer_ships(ship *s1, ship *s2, int n)
s2->damage += s1->damage * n / s1->number;
s2->size += s1->size * n / s1->number;
s2->number += n;
if (s1->coast != NODIRECTION) {
s2->coast = s1->coast;
}
scale_ship(s1, s1->number - n);
}
@ -322,8 +325,9 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
{
assert(u1->ship);
assert(n > 0 && n <= u1->ship->number);
if (u1->faction != u2->faction) {
return msg_error(u1, ord, 324);
if (u1->ship->type->range < 3) {
/* Keine Boote und anderes Kleinzeug erlaubt */
return msg_error(u1, ord, 326);
}
if (ship_cursed(u1->ship)) {
return msg_error(u1, ord, 323);
@ -331,8 +335,27 @@ 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 == NULL) {
if (n < u1->ship->number) {
ship * sh = new_ship(u1->ship->type, u1->region, u1->faction->locale);
scale_ship(sh, 0);
transfer_ships(u1->ship, sh, n);
}
else {
return msg_error(u1, ord, 327);
}
} else {
if (u1->faction != u2->faction) {
return msg_error(u1, ord, 324);
}
if (fval(u_race(u2), RCF_CANSAIL)) {
if (u2->ship) {
if (u2->ship == u1->ship) {
ship * sh = new_ship(u1->ship->type, u1->region, u1->faction->locale);
scale_ship(sh, 0);
leave_ship(u2);
u_set_ship(u2, sh);
} else {
if (u2 != ship_owner(u2->ship)) {
return msg_error(u1, ord, 146);
}
@ -352,6 +375,7 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
}
}
}
}
if (n < u1->ship->number) {
transfer_ships(u1->ship, u2->ship, n);
}
@ -376,6 +400,7 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
else {
return msg_error(u1, ord, 233);
}
}
return NULL;
}