Ticket #779 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Villagers stuck on construction sites

Reported by: Jubal Owned by: philip
Priority: Should Have Milestone: Alpha 5
Component: UI & Simulation Keywords:
Cc:

Description

Essentially, pre-tasked villagers or troops can get trapped on construction sites if they walk onto them between placement and construction starting; they carry on trying to walk across them, and get stuck. The building remains on 0HP, and they remain stationary. Subsequent troops will also get stuck, and for an AI player this can cause economic wreckage.

Change History

comment:1 Changed 2 years ago by historic_bruno

Does this ever happen for human players? (my units seem to get cleared off the construction site)

comment:2 follow-up: ↓ 5 Changed 2 years ago by Philip

There was a similar-sounding problem in the past (particularly in multiplayer games with long turn lengths), but r9035 (before Alpha 4) fixed it so I'm not sure in what situations this would still be an issue.

comment:3 Changed 2 years ago by michael

Confirmed this can happen for human players as well.

comment:4 Changed 2 years ago by k776

  • Priority changed from Should Have to Release Blocker
  • Milestone changed from Backlog to Alpha 5

comment:5 in reply to: ↑ 2 Changed 2 years ago by historic_bruno

Replying to Philip:

There was a similar-sounding problem in the past (particularly in multiplayer games with long turn lengths), but r9035 (before Alpha 4) fixed it so I'm not sure in what situations this would still be an issue.

I've seen it happen with AIs, I think you need a lot of units trying to build at once and a few in the foundation moving elsewhere. At first I thought perhaps the orders can conflict so they become deadlocked, but I'm not sure if that's possible.

comment:6 Changed 2 years ago by k776

  • Owner set to philip

comment:7 Changed 2 years ago by k776

  • Milestone changed from Alpha 5 to Alpha 6

comment:8 Changed 2 years ago by philip

(In [9510]) Fix units in formation blocking construction and not moving out of the way (see #779). Make non-movement-blocking buildings (e.g. farms) not require units to move out of the way.

comment:9 follow-up: ↓ 10 Changed 2 years ago by Philip

  • Priority changed from Release Blocker to Should Have

I don't know if this is a complete fix, since I assume AI doesn't put units into non-default formations so maybe it's hitting a different problem (but I can't imagine what). Need to either have some precise steps to reproduce if it's still a problem for AI, or just assume that it's okay.

(Not a release blocker in any case since it's seemingly pretty rare and not terribly harmful, though if it's still a problem it should get fixed.)

comment:10 in reply to: ↑ 9 Changed 2 years ago by Badmadblacksad

Replying to Philip:

I don't know if this is a complete fix, since I assume AI doesn't put units into non-default formations so maybe it's hitting a different problem (but I can't imagine what). Need to either have some precise steps to reproduce if it's still a problem for AI, or just assume that it's okay. (Not a release blocker in any case since it's seemingly pretty rare and not terribly harmful, though if it's still a problem it should get fixed.)

I am able to reproduce this bug most of the time.

You just need to place a foundation (e.g Agora, since your patch prevent the bug to happen with farms), with 4+ builders, on top of 5+ units moving individually (i.e. in INDIVIDUAL.WALKING state).

Each builder will ask every moving units to leaveFormation, resulting in 4*5 calls to pushOrderFront(leaveFormation) / finishOrder / "Order.Walk" / moveToPoint / .. per turn. I read that the call to moveTo* functions are quite time consuming, so I think that's the problem.

comment:11 Changed 2 years ago by Badmadblacksad

  • Status changed from new to closed
  • Resolution set to fixed

(In [9525]) units are not stuck on construction sites anymore. fixes #779

comment:12 Changed 2 years ago by k776

  • Milestone changed from Alpha 6 to Alpha 5

comment:13 Changed 2 years ago by Philip

  • Status changed from closed to reopened
  • Resolution fixed deleted

Ah, indeed. MoveToPoint causes the unit to stop while it computes a new path, which is currently delayed by 2 turns. If you have enough builders to trigger LeaveFormation every single turn (which I think means 4 builders in single-player, if their timings sync up unluckily), the unit will never get a chance to finish pathing and start moving.

I think DiscardOrder interacts badly with promotional cheering, though. Say orderQueue = [Cheering, Walk] and the state is INDIVIDUAL.CHEERING, then someone calls LeaveFoundation(), which results in orderQueue = [Cheering, LeaveFoundation, Walk]. The cheering hits its timer, calls FinishOrder, then orderQueue = [LeaveFoundation, Walk] and it processes Order.LeaveFoundation in the state INDIVIDUAL.CHEERING, which calls DiscardOrder. Now orderQueue = [Walk] but it's still INDIVIDUAL.CHEERING. Eventually the cheering will hit its timer a second time, call FinishOrder again, and probably lose that Walk order, and it'll be broken since DiscardOrder left it in an inconsistent state.

r9527 makes this easier to test - buildings built on top of cheering units do seem to trigger multiple cheerings in practice, so I think a better solution is needed (though I'm not sure exactly what yet).

comment:14 Changed 2 years ago by philip

  • Status changed from reopened to closed
  • Resolution set to fixed

(In [9528]) Fix #779 differently, to avoid problems with building on top of cheering units

comment:15 Changed 2 years ago by Philip

I think this works, though I'm not absolutely sure it's perfect. The idea is to effectively do DiscardOrder if the LeaveFoundation order is being processed via PushOrderFront (since in that case it's safe to carry on with the previously-front order since we're already in the right state for it); but in FinishOrder (and PushOrder) it's equivalent to calling FinishOrder again, so the next order in the queue is processed anew.

comment:16 Changed 2 years ago by Badmadblacksad

ack. sorry I missed this bug. :)

Note: See TracTickets for help on using tickets.