Replying to odoaker:
Thanks for your remarks, I simplified ShouldPack
which fixed the problem with "Patrol". Not sure about "Garrison" because I can't garrison a siege unit (maybe I don't have the right building).
I will attach the patch right now.
Siege can be garrisoned in a Fortress f.e.
The ShouldPack function looks good now, only it actually returns wheter a unit should UnPack, but that is an easy rename. (And yes naming of the Pack/Unpack function are sometimes a bit confusing but never bad to be clear when we talk about unpacking only.)
Also not all cases are solved still: imagine a unit unpacking and getting an unpack order (is not a very likely situation, but it can occur when using selection), that will now get a cancelUnpack order and directly afterwards an unpack order. Not very efficient...
This can be solved with the following code structure (which also makes the code more readable imo):
(You should correct me if I am messing up here though)
if (IsPacking() && type != "CancelPack" && type != "CancelUnpack")
{
if (ShouldUnpack())
// cancel Pack order, hold unpack order;
else
// cancel unPack order, hold pack order;
// Push new order
}
Some side note: for keeping consistency throughout the code, it would be nice if the lines you add in the code (L3854-6) would look as similar as possible to lines which to almost the same (L3848-50).