Opened 8 years ago

Last modified 3 years ago

#4015 closed defect

[PATCH] Stop unpacking siege on stop/move command — at Version 18

Reported by: elexis Owned by: Ágoston Sipos
Priority: Nice to Have Milestone: Alpha 24
Component: Simulation Keywords:
Cc: agoston.sipos.95@… Patch:

Description (last modified by bb)

When siege is unpacking but receives a direct order to move somewhere, there is no reason to wait until the unpacking finished. It should cancel the unpacking immediately and move there.

When the stop command is issued, the packing / unpacking should stop.

Changing UnitAI.js will likely be sufficient. Commands.js is used to pass player commands to the simulation.

Change History (21)

comment:1 by Ágoston Sipos, 7 years ago

Cc: agoston.sipos.95@… added
Owner: set to Ágoston Sipos

by Ágoston Sipos, 7 years ago

Attachment: change4015.patch added

comment:2 by fatherbushido, 7 years ago

Thanks for the patch!

You can add the keyword tag if you want it to be pushed in the (pre)review queue. One should look at that TODO too

TODO: maybe a better way of doing this would be to use priority levels

comment:3 by Ágoston Sipos, 7 years ago

Hi,

This was going to be my first contribution and I don't want to screw things up.

I feel that this TODO is about different things than this ticket's task. The ticket is about fixing a bug, while the comment is a proposal to rework the existing code.

I am also not sure what a 'keyword tag' is.

comment:4 by elexis, 7 years ago

Keywords: rfc added
Milestone: BacklogAlpha 22

@wiki SubmittingPatches Add the rfc and put the milestone to a22 in case you want us to notice ;)

comment:5 by elexis, 7 years ago

Milestone: Alpha 22Work In Progress

Moving to the new WIP milestone.

comment:6 by bb, 7 years ago

Thx for working on this, but the choosen approach doesn't seem to solve the problem in all cases. Because what now if siege is packed and I give an attack order to somewhere out of range (instead of a Walk) during unpacking? I guess the siege will unpack, pack and then walk, thus the problem is not resolved :/.

The good news is that you found the correct part of the code, IMO the else if in L3839 is not doing what it should. Now the current packingorder is just hold in front of the new order, but in some cases the packingorder should simply be overridden. I did make a new function "ShouldPack" to determine if the siege needs to pack or not and use this function here to determine what should happen (cancel packing or not). This function can later also be used in some other places in the UnitAI.

comment:7 by Ágoston Sipos, 7 years ago

Thanks, I checked this and you're right, an attack order does not cancel the unpacking.

Where will I find this ShouldPack function?

comment:8 by bb, 7 years ago

As the function is mostly (if not only) used in UnitAI I did put it there.

Last edited 7 years ago by bb (previous) (diff)

in reply to:  8 ; comment:9 by Ágoston Sipos, 7 years ago

Replying to bb:

As the function is mostly (if not only) used in UnitAI I did put it there.

I'm sorry, but I still can't find a function with that name. How is your patch going? When will it be in the codebase?

in reply to:  9 comment:10 by bb, 7 years ago

Replying to odoaker:

I'm sorry, but I still can't find a function with that name.

I don't think such a function exist in current code (I am rather sure it don't), so you will need to create this function and design it so it solves all cases.

How is your patch going? When will it be in the codebase?

Not sure what patch you mean here?

comment:11 by Ágoston Sipos, 7 years ago

You wrote "I did make a new function "ShouldPack?"". Maybe it was a typo but I understood it literally. I thought that a patch was on its way to be committed that included this function.

in reply to:  11 comment:12 by bb, 7 years ago

Replying to odoaker:

You wrote "I did make a new function "ShouldPack?"". Maybe it was a typo but I understood it literally. I thought that a patch was on its way to be committed that included this function.

I think we just interpreted those words differently (I might be mistaken cuz I am not a native). I meant: "if I would fix this issue then I would make a new function."

by Ágoston Sipos, 7 years ago

Attachment: UnitAI.js.patch added

I believe this solves all the problematic cases.

comment:13 by Vladislav Belov, 7 years ago

This:

UnitAI.prototype.ShouldPack = function(type, data) 
{ 
    if(type == "Walk") 
        return false; 
    if(type == "Attack") 
    {
        // ... 
    }
    return true; 
};

Could be written shorter:

UnitAI.prototype.ShouldPack = function(type, data) 
{ 
    if(type == "Attack") 
    {
        // ... 
    }
    return type != "Walk";
};

comment:14 by Vladislav Belov, 7 years ago

It doesn't work for the "Garrison" and "Patrol" commands.

Also shouldn't we revert the process (status bar of packing animation) instead of just reset w/o waiting? Looks weird, when you have 99% unpacked process, you press walk, and it's immediately packed.

Last edited 7 years ago by Vladislav Belov (previous) (diff)

in reply to:  14 ; comment:15 by bb, 7 years ago

The patch indeed doesn't fix all issues yet and the implementation is not very trivial e.g. hard to understand what exactly happens.

We could start looking to the question: "When should we be unpacked?" AFAIK the answer would be when we get an attack order and we are in range or when we get an unpack order directly. In all other cases we should be packed IMO. So the ShouldPack function should return false in the cases stated above and true in all other cases. (This function can be reduced to a one-liner, but that is not the most important thing.)

We now want to find the correct behaviour using the new function, this can be found by thinking: if we currently pack/unpack and we should be in that state continue pack/unpack, otherwise cancel the pack/unpack. (For finding out wheter we are packing or unpacking we should check something like is done in the CancelPack/Unpack function in unitAI. Maybe make some new UnitAI function doing this check.) One thing we need to look out for is not giving the same order twice when an cancelPack/Unpack order is given.

Also have a look at our Coding Conventions (there were some whitespace issues and a semicolon).

Replying to vladislavbelov:

Also shouldn't we revert the process (status bar of packing animation) instead of just reset w/o waiting? Looks weird, when you have 99% unpacked process, you press walk, and it's immediately packed.

This could be solved in another ticket by altering the cancelPack/UnPack process a bit, but its not the issue for this ticket.

in reply to:  15 comment:16 by Vladislav Belov, 7 years ago

Replying to bb:

This could be solved in another ticket by altering the cancelPack/UnPack process a bit, but its not the issue for this ticket.

Then could you ref it here? It should be depending tickets. I think, if implement the issue with reverting, then the solution of the ticket will be really different.

Last edited 7 years ago by Vladislav Belov (previous) (diff)

comment:17 by Ágoston Sipos, 7 years ago

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.

Replying to vladislavbelov:

Also shouldn't we revert the process (status bar of packing animation) instead of just reset w/o waiting? Looks weird, when you have 99% unpacked process, you press walk, and it's immediately packed.

I think your proposal could be disputed because it changes the strength of siege units. This patch though is just a bugfix. If this is done, I could work on that too, supposed that's decided to be the right way to have siege in the game.

by Ágoston Sipos, 7 years ago

Attachment: UnitAI.js.2.patch added

in reply to:  17 comment:18 by bb, 7 years ago

Description: modified (diff)
Summary: Stop unpacking siege on stop/move command[PATCH] Stop unpacking siege on stop/move command

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).

Note: See TracTickets for help on using tickets.