Pawn needs to know which task it is walking to #112
Labels
No labels
assets
bug
duplicate
enhancement
help wanted
invalid
question
testing
ui
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
liamjd/UntitledColonyBuilder#112
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of milestone #5. Depends on #70. Could be absorbed into #75 if that is where the work lands — filed separately because it is a change to the
Pawnrecord, alongside #74.Pawns._on_view_arrived()sets every arriving pawn toIDLING. Nothing distinguishes "arrived because it was wandering" from "arrived at the cell it was sent to in order to work", so the work loop has no way to reach theWORKINGstate thatPawn.PawnStatealready declares.The pawn needs to remember what it is walking towards:
Pawn.current_task_id: int = -1, set when the pawn claims a task and cleared when it releases, completes or is cancelled out of one_on_view_arrived()moves the pawn toWORKINGwhencurrent_task_idnames a live task whosetarget_cellmatches the arrival cell, and toIDLINGotherwiseThis also gives #75 two of its acceptance criteria almost for free — "if the task is cancelled mid-work, the pawn stops and returns to idle" becomes a check on
current_task_id, and the debug panel can show what each pawn is doing rather than just its state.AC:
current_task_idon thePawnrecord, defaulting to -1WORKINGorIDLINGdepending on whether the pawn arrived at its task's target cellSpec written on branch
112-pawn-knows-its-task—test/unit/test_pawn_task_arrival.gd, 14 tests, all red for the right reason (the API does not exist). Full suite: 522 passing, the 14 new ones failing, nothing else disturbed.Files that change
entities/pawns/pawn.gd—var current_task_id: int = -1entities/pawns/pawns.gd—tasksinjection,assign_task(),clear_task(), the arrival branch, and the signal handlersentities/tasks/task_manager.gd—get_task()and atask_releasedsignalcommon/game.gd— one line,pawns.tasks = task_manager, beside the existingbuildings.tasks = task_managerDecisions the spec makes, for confirmation
1.
Pawnsgets theTaskManager, not the other way round. MirrorsBuildings.tasks: injected bygame.gd, left null everywhere else. The alternative —TaskManagerholding aPawnsreference so it can clear on cancel — points the dependency the wrong way, since the manager is deliberately ignorant of who is doing the work.2. Clearing is driven by signals, not by callers remembering.
cancel()andcomplete()already emit;release()does not, so the spec addstask_released(task)for symmetry. Thetaskssetter connects all three and clears any pawn holding that id. Without the third signal, the release path has to be cleared by hand from #75's work loop, which is exactly the kind of thing that gets forgotten once and then stays broken quietly.3.
get_task(id)returns null for an unknown id, with nopush_error(). A cancelled task is erased fromtasks, so a pawn arriving with a stale id is the normal case rather than a fault — and GUT fails a test on anypush_error()raised during it, so shouting here would make the honest case untestable.4.
stop()does not clear the task.repath_pawns()is stop-then-move_to, so clearing instop()would drop the task of every pawn a building re-routed — the #56 scenario this issue exists to handle. Two tests pin it.5.
clear_task()idles a WORKING pawn but leaves a MOVING one walking. Whether to turn a now-taskless walker around is #75's call, not this issue's; all that is owed here is that its arrival resolves to IDLING.6. Arriving off-site keeps the task. The pawn goes IDLING but
current_task_idsurvives, so #75 can send it again rather than having to re-claim from scratch.Deliberately out of scope
remove()on a pawn that holds a claimed task leaves that task assigned to a dead id. The fix is arelease()from the removal path, but it needs #111's decision on whetherassigneestays single-valued first — filing separately unless you would rather it rode along here.