start implementing give_ship

This commit is contained in:
Enno Rehling 2019-10-06 20:42:47 +02:00
parent 5cf417d16d
commit 39e3001a50
2 changed files with 61 additions and 2 deletions

View File

@ -163,3 +163,30 @@ function test_ship_convoy_skill()
process_orders() process_orders()
assert_equal(r3, u.region) assert_equal(r3, u.region)
end end
function test_give_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, 'boat')
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_merge()
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)
u2.ship = ship.create(r, 'boat')
u1.ship = ship.create(r, 'boat')
u1.ship.number = 2
u1:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF")
process_orders()
assert_equal(1, u1.ship.number)
assert_equal(2, u2.ship.number)
end

View File

@ -293,6 +293,14 @@ bool rule_transfermen(void)
return rule != 0; return rule != 0;
} }
message * give_ship(unit *u, unit *u2, int n, order *ord) {
assert(u->ship);
if (u->ship->number < n) {
n = u->ship->number;
}
return NULL;
}
message * give_men(int n, unit * u, unit * u2, struct order *ord) message * give_men(int n, unit * u, unit * u2, struct order *ord)
{ {
int error = 0; int error = 0;
@ -652,7 +660,19 @@ static void give_all_items(unit *u, unit *u2, order *ord) {
} }
} }
else { else {
if (isparam(s, u->faction->locale, P_PERSON)) { param_t p = findparam(s, u->faction->locale);
if (p == P_SHIP) {
if (u->ship) {
message * msg = give_ship(u, u2, u->ship->number, ord);
if (msg) {
ADDMSG(&u->faction->msgs, msg);
}
}
else {
cmistake(u, ord, 144, MSG_COMMERCE);
}
}
else if (p == P_PERSON) {
if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
@ -815,7 +835,19 @@ void give_cmd(unit * u, order * ord)
return; return;
} }
if (isparam(s, u->faction->locale, P_PERSON)) { p = findparam(s, u->faction->locale);
if (p == P_SHIP) {
if (u->ship) {
message * msg = give_ship(u, u2, n, ord);
if (msg) {
ADDMSG(&u->faction->msgs, msg);
}
}
else {
cmistake(u, ord, 144, MSG_COMMERCE);
}
}
else if (p == P_PERSON) {
if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));