diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 3a7193ed0..df7fd97ca 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1171,3 +1171,21 @@ function test_bug_1875_use_own_first() assert_equal(99, u:get_potion("peasantblood")) -- unit uses one peasantblood effect assert_equal(99, u2:get_potion("peasantblood")) -- u2 uses its own effect before u's end + + +function test_bug_1879_follow_unit() + local r = region.create(0, 0, "plain") + local r1 = region.create(1, 0, "plain") + local f = faction.create("noreply@eressea.de", "human", "de") + local u1, u2 = two_units(r, f, f) + u1:clear_orders() + u1:set_skill("magic", 10) + u1:add_order("ZAUBERE STUFE 1 Kleine Flüche") + u1:add_order("FOLGEN EINHEIT " .. itoa36(u2.id)) + u2:clear_orders() + u2:add_order("NACH o") + process_orders() + assert_equal(u1.region.id, r1.id) + assert_equal(u2.region.id, r1.id) +end + diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index b79a59233..ac77a3c97 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -3711,7 +3711,7 @@ void update_long_order(unit * u) case K_CAST: /* dient dazu, das neben Zaubern kein weiterer Befehl * ausgeführt werden kann, Zaubern ist ein kurzer Befehl */ - set_order(&u->thisorder, NULL); + set_order(&u->thisorder, copy_order(ord)); break; default: diff --git a/src/kernel/magic.c b/src/kernel/magic.c index 3f388450b..f062549bf 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -2743,13 +2743,15 @@ void magic(void) continue; } - for (ord = u->orders; ord; ord = ord->next) { - if (get_keyword(ord) == K_CAST) { - castorder *co = cast_cmd(u, ord); - fset(u, UFL_LONGACTION | UFL_NOTMOVING); - if (co) { - const spell *sp = co->sp; - add_castorder(&spellranks[sp->rank], co); + if (u->thisorder != NULL) { + for (ord = u->orders; ord; ord = ord->next) { + if (get_keyword(ord) == K_CAST) { + castorder *co = cast_cmd(u, ord); + fset(u, UFL_LONGACTION | UFL_NOTMOVING); + if (co) { + const spell *sp = co->sp; + add_castorder(&spellranks[sp->rank], co); + } } } } diff --git a/src/kernel/move.c b/src/kernel/move.c index 46a1cadfd..9821e92b5 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -2697,12 +2697,13 @@ void follow_unit(unit * u) attrib *a2 = a_find(u2->attribs, &at_follow); if (a2 != NULL) { unit *u3 = a2->data.v; - follow = (u3 && u2->region == u2->region); + follow = (u3 && u2->region == u3->region); } } if (follow) { fset(u, UFL_FOLLOWING); fset(u2, UFL_FOLLOWED); + /* FOLLOW unit on a (potentially) moving unit prevents long orders */ set_order(&u->thisorder, NULL); } }