MantisBT - VCMI
View Issue Details
0003065VCMIAI - Battlespublic2019-05-28 20:232022-03-27 18:33
mpech 
 
normalminoralways
resolvedfixed 
Ubuntu 16.04.6 LTS
 
1.next 
0003065: battle hangs if no shot left from ballista
ai attacks defended castle by me
catapult is destroyed, ai does not want to move creature
ai tries to shoot with ballista but ballista has no shots left.
infinite loop
as red, go into castle. end turn
//blue attacks castle
as red, magic arrow to destroy the catapult
then always defend with tower arrow and golems.
ai consumes its ballista shots, then
battle hangs when shots left is O
modules used are hota, preserve, retreat, death valley, whitchiking artifacts
R1
? zzballista.vmap (3,207) 2019-05-28 20:23
https://bugs.vcmi.eu/file_download.php?file_id=3022&type=bug
zip VCMI_Client_log.zip (185,086) 2019-05-28 20:24
https://bugs.vcmi.eu/file_download.php?file_id=3023&type=bug
zip zzbalista2.zip (626,952) 2019-05-30 10:48
https://bugs.vcmi.eu/file_download.php?file_id=3024&type=bug
Issue History
2019-05-28 20:23mpechNew Issue
2019-05-28 20:23mpechFile Added: zzballista.vmap
2019-05-28 20:24mpechFile Added: VCMI_Client_log.zip
2019-05-29 09:27mpechNote Added: 0007802
2019-05-29 09:27mpechNote Edited: 0007802bug_revision_view_page.php?bugnote_id=7802#r3574
2019-05-29 14:33PovelitelNote Added: 0007803
2019-05-30 10:48mpechFile Added: zzbalista2.zip
2019-05-30 10:57mpechNote Added: 0007806
2022-03-22 19:57PovelitelTag Attached: R1
2022-03-27 18:32PovelitelNote Added: 0008205
2022-03-27 18:32PovelitelStatusnew => resolved
2022-03-27 18:32PovelitelFixed in Version => 1.next
2022-03-27 18:32PovelitelResolutionopen => fixed
2022-03-27 18:32PovelitelAssigned To => Povelitel
2022-03-27 18:33PovelitelAssigned ToPovelitel =>

Notes
(0007802)
mpech   
2019-05-29 09:27   
when looping (blue does not end its turn)
```
TRACE network [7f2c45d84700] - Applied on gs: 20BattleSetActiveStack
TRACE global [7f2c45d84700] - Making action: {BattleAction: side '0', stackNumber '0', actionType 'Shoot', actionSubtype '-1', target {3@{BattleHex: x '15', y '5', hex '100'},}}
TRACE global [7f2c45d84700] - CGameHandler::makeBattleAction, shoot type
TRACE global [7f2c45d84700] - CBattleInfoCallback::battleCanShoot 24
TRACE network [7f2c45d84700] - Sending to all clients: 13SystemMessage
TRACE network [7f2c45d84700] - Sending a pack of type 13SystemMessage
==>ERROR global [7f2c45d84700] - Cannot shoot!
TRACE global [7f2c45d84700] - CGameHandler::runBattle, getnextstack
TRACE global [7f2c45d84700] - CGameHandler::runBattle, aim
TRACE network [7f2c45d84700] - Sending to all clients: 20BattleSetActiveStack
TRACE network [7f2c45d84700] - Sending a pack of type 20BattleSetActiveStack
TRACE network [7f2c45d84700] - Applied on gs: 20BattleSetActiveStack
TRACE global [7f2c45d84700] - Making action: {BattleAction: side '0', stackNumber '0', actionType 'Shoot', actionSubtype '-1', target {3@{BattleHex: x '15', y '5', hex '100'},}}
```

when ok (that is round before 23)
```
TRACE global [7f2c45d84700] - Making action: {BattleAction: side '0', stackNumber '0', actionType 'Shoot', actionSubtype '-1', target {3@{BattleHex: x '15', y '5', hex '100'},}}
TRACE global [7f2c45d84700] - CGameHandler::makeBattleAction, shoot type
TRACE global [7f2c45d84700] - CBattleInfoCallback::battleCanShoot 23
TRACE network [7f2c45d84700] - Sending to all clients: 11StartAction
TRACE network [7f2c45d84700] - Sending a pack of type 11StartAction
TRACE network [7f2c45d84700] - Applied on gs: 11StartAction
TRACE network [7f2c45d84700] - Sending to all clients: 12BattleAttack
TRACE network [7f2c45d84700] - Sending a pack of type 12BattleAttack
TRACE network [7f2c45d84700] - Applied on gs: 12BattleAttack
TRACE network [7f2c45d84700] - Sending to all clients: 9EndAction
TRACE network [7f2c45d84700] - Sending a pack of type 9EndAction
```

I guess if canShoot, makeAttack triggers some stuff (in particular StartAction/EndAction) so getNextStack() rolls out to behe.
If !canShoot no action is taken and getNextStack does not move to next stack

by dumbly applying the wrapAction if case of !canShoot, round can end even if ballista does not shoot

```
    case EActionType::SHOOT:
        {
            //...
            auto destination = target.at(0).hexValue;

            const CStack * destinationStack = gs->curB->battleGetStackByPos(destination);
            if (!gs->curB->battleCanShoot(stack, destination))
            {
                logGlobal->trace("CGameHandler::makeBattleAction, cannot shoot bbrrrrr");
                if(stack->creatureIndex() == CreatureID::BALLISTA){
                    logGlobal->trace("CGameHandler::makeBattleAction, isballista");
                    auto wrapper = wrapAction(ba);
                }else{
                    complain("Cannot shoot!");
                }
                break;
            }
```

```
TRACE global [7f1da53bc700] - CGameHandler::makeBattleAction, cannot shoot bbrrrrr
TRACE global [7f1da53bc700] - CGameHandler::makeBattleAction, isballista
TRACE network [7f1da53bc700] - Sending to all clients: 11StartAction
TRACE network [7f1da53bc700] - Sending a pack of type 11StartAction
TRACE network [7f1da53bc700] - Applied on gs: 11StartAction
TRACE network [7f1da53bc700] - Sending to all clients: 9EndAction
TRACE network [7f1da53bc700] - Sending a pack of type 9EndAction
TRACE network [7f1da53bc700] - Applied on gs: 9EndAction
TRACE global [7f1da53bc700] - CGameHandler::makeBattleAction, battlemadeactionistrue
TRACE global [7f1da53bc700] - CGameHandler::runBattle, getnextstack
TRACE global [7f1da53bc700] - Activating blue battle stack [2]: 100 of Behemoths from slot 0 of armyobj=1
```

I don't think this is a proper fix (because what about other complain from EActionType::SHOOT case?)
I am not sure either makeBattleAction purpose is to be only called from automatic ia (and not human)

(0007803)
Povelitel   
2019-05-29 14:33   
2453 2719 2799 related?
(0007806)
mpech   
2019-05-30 10:57   
@polivetel i don't think so, 2453,2799 involves fortress, here we are in castle
2719 is seems to be a strategic "fail" (round can end but no action taken in round, here round does not end)

in added zzbalista2, attacking hero has now artillery.
We can see that _without_ fix, ballista with no ammunition chose to defend.

so bug only occurs if ballista has no ammunition AND hero has no artillery skill
(0008205)
Povelitel   
2022-03-27 18:32   
Don't reproduce in current develop. Probably fixed long time ago