From 1e0afdc96125f60a91fc7a09323756e5a28ca9bb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 8 Oct 2019 20:56:14 +0200 Subject: [PATCH] spells can only be cast on single ships. --- res/translations/messages.de.po | 8 ++++- res/translations/messages.en.po | 12 +++++++ scripts/tests/e2/ships.lua | 63 ++++++++++++++++++++++++++++++++- src/give.c | 14 ++++++-- src/items.c | 4 +++ src/kernel/ship.c | 1 - src/spells.c | 8 +++++ 7 files changed, 105 insertions(+), 5 deletions(-) diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po index 759f41ed1..1ea230c8c 100644 --- a/res/translations/messages.de.po +++ b/res/translations/messages.de.po @@ -2768,12 +2768,18 @@ msgstr "\"$unit($unit) verspeiste $int($amount) Bauern.\"" msgid "error320" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit kann nicht bewachen, da sie versucht zu fliehen.\"" -msgid "error321" +msgid "error325" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Zauber kann nur auf ein einzelnes Schiff gewirkt werden.\"" + +msgid "error324" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit gehört nicht zu unserer Partei.\"" msgid "error322" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist bereits auf einem Schiff.\"" +msgid "error323" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff ist verzaubert.\"" + 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\").\"" diff --git a/res/translations/messages.en.po b/res/translations/messages.en.po index 7724fdc07..e6bc922f2 100644 --- a/res/translations/messages.en.po +++ b/res/translations/messages.en.po @@ -2768,6 +2768,18 @@ msgstr "\"$unit($unit) ate $int($amount) peasants.\"" msgid "error320" msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit cannot guard the region because it is trying to flee.\"" +msgid "error325" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Spells can only be cast on a single ship.\"" + +msgid "error324" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is not one of ours.\"" + +msgid "error322" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is already on a ship.\"" + +msgid "error323" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - The ship is under a spell.\"" + msgid "dissolve_units_2" msgstr "\"$unit($unit) in $region($region): $int($number) $race($race,$number) turned into $if($eq($number,1),\"a tree\", \"trees\").\"" diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index c71cf9eb3..5cd723f8e 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -177,6 +177,22 @@ function test_give_ship() assert_equal(1, u2.ship.number) 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) + u2.ship = ship.create(r, 'boat') + u3.ship = u2.ship + u1.ship = ship.create(r, 'boat') + u1.ship.number = 2 + 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_merge() local r = region.create(1, 0, 'ocean') local f = faction.create("human") @@ -227,15 +243,17 @@ end function test_give_ship_all_ships() local r = region.create(1, 0, 'plain') - local f = faction.create("human") + 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.damage = 2 u1.ship.number = 2 u2.ship = ship.create(r, 'boat') u2.ship.number = 1 u1:add_order("GIB " .. itoa36(u2.id) .. " 2 SCHIFF") process_orders() + write_reports() assert_equal(3, u2.ship.number) assert_equal(u2.ship, u1.ship) end @@ -254,3 +272,46 @@ function test_give_ship_self_only() assert_equal(2, u1.ship.number) assert_equal(nil, u2.ship) end + +function test_give_ship_not_cursed() + local r = region.create(1, 0, 'plain') + 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') + u.ship = sh + u:add_item("speedsail", 1) + u:add_order("BENUTZE 1 Sonnensegel") + process_orders() + u:clear_orders() + assert_equal(1, sh:get_curse('shipspeedup')) + + u:add_order("GIB " .. itoa36(u2.id) .. " 1 SCHIFF") + process_orders() + assert_equal(nil, u2.ship) +end + +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') + u.ship = sh + u:add_item("speedsail", 1) + u:add_order("BENUTZE 1 Sonnensegel") + process_orders() + assert_equal(1, sh:get_curse('shipspeedup')) +end + +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') + u.ship = sh + sh.number = 2 + u:add_item("speedsail", 2) + u:add_order("BENUTZE 2 Sonnensegel") + process_orders() + assert_equal(nil, sh:get_curse('shipspeedup')) +end diff --git a/src/give.c b/src/give.c index 582532fe1..71c9bab7d 100644 --- a/src/give.c +++ b/src/give.c @@ -314,15 +314,24 @@ static void transfer_units(ship *s1, ship *s2) } } +static bool ship_cursed(const ship *sh) { + return a_find(sh->attribs, &at_curse) != NULL; +} + 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, 321); + return msg_error(u1, ord, 324); + } + if (ship_cursed(u1->ship)) { + return msg_error(u1, ord, 323); } - /* TODO: when transferring all ships, unit must hop on the target ship */ if (u2->ship) { + if (ship_cursed(u2->ship)) { + return msg_error(u1, ord, 323); + } if (n < u1->ship->number) { if (u2->ship->type != u1->ship->type) { return msg_error(u1, ord, 322); @@ -892,6 +901,7 @@ void give_cmd(unit * u, order * ord) else { cmistake(u, ord, 144, MSG_COMMERCE); } + return; } else if (p == P_PERSON) { if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { diff --git a/src/items.c b/src/items.c index c99fc2cdf..7912ff350 100644 --- a/src/items.c +++ b/src/items.c @@ -101,6 +101,10 @@ struct order *ord) cmistake(u, ord, 20, MSG_MOVE); return -1; } + if (sh->number > 1) { + cmistake(u, ord, 325, MSG_MAGIC); + return -1; + } effect = SPEEDSAIL_EFFECT; create_curse(u, &sh->attribs, &ct_shipspeedup, 20, INT_MAX, effect, 0); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 1e38257d9..601c36d82 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -314,7 +314,6 @@ int shipspeed(const ship * sh, const unit * u) if (!ship_finished(sh)) { return 0; } - if (sh->attribs) { if (curse_active(get_curse(sh->attribs, &ct_stormwind))) { k *= 2; diff --git a/src/spells.c b/src/spells.c index 486a62b71..200e87f62 100644 --- a/src/spells.c +++ b/src/spells.c @@ -808,6 +808,10 @@ static int sp_goodwinds(castorder * co) return 0; sh = pa->param[0]->data.sh; + if (sh->number > 1) { + cmistake(caster, co->order, 325, MSG_MAGIC); + return 0; + } /* keine Probleme mit C_SHIP_SPEEDUP und C_SHIP_FLYING */ /* NODRIFT bewirkt auch +1 Geschwindigkeit */ @@ -2231,6 +2235,10 @@ static int sp_stormwinds(castorder * co) sh = pa->param[n]->data.sh; + if (sh->number > 1) { + cmistake(caster, co->order, 325, MSG_MAGIC); + continue; + } if (is_cursed(sh->attribs, &ct_flyingship)) { ADDMSG(&caster->faction->msgs, msg_feedback(caster, co->order, "error_spell_on_flying_ship", "ship", sh))