Problem
choose_task() in scripts/main.gd (line 1446) has two separate food-sorting branches that do virtually the same thing:
# Branch 1: "gather" kind with low-food bias (lines ~1455-1465)
if String(kind) == "gather" and should_bias_to_food_gathering():
tasks.sort_custom(func(a, b) -> bool:
var a_is_food := String(a.get("resource", "")) == "food"
var b_is_food := String(b.get("resource", "")) == "food"
if a_is_food and not b_is_food: return true
if not a_is_food and b_is_food: return false
return task_distance(worker, a) < task_distance(worker, b)
)
# Branch 2: "gather_food" kind (lines ~1467-1477)
elif String(kind) == "gather_food":
tasks.sort_custom(func(a, b) -> bool:
var a_is_food := ColonyStance.is_food_gather_task(a)
var b_is_food := ColonyStance.is_food_gather_task(b)
if a_is_food and not b_is_food: return true
if not a_is_food and b_is_food: return false
return task_distance(worker, a) < task_distance(worker, b)
)
Both sort food tasks first, then by distance. Branch 1 checks resource == "food" directly. Branch 2 uses ColonyStance.is_food_gather_task() which does the same check via the stance module. The duplication means a change to food prioritization logic must be applied in two places.
Fix
Unify into a single sort comparator. Either:
- Extract a
sort_tasks_by_food_priority(tasks, worker) helper that both branches call
- Or collapse
gather and gather_food into one kind that always checks ColonyStance.is_food_gather_task(), eliminating the need for separate branches
The second option is cleaner — tasks_for_kind() already maps both "gather" and "gather_food" to gather_gather_tasks() (line 1497), so the separate kinds only exist for the sort comparator.
Acceptance criteria
Problem
choose_task()inscripts/main.gd(line 1446) has two separate food-sorting branches that do virtually the same thing:Both sort food tasks first, then by distance. Branch 1 checks
resource == "food"directly. Branch 2 usesColonyStance.is_food_gather_task()which does the same check via the stance module. The duplication means a change to food prioritization logic must be applied in two places.Fix
Unify into a single sort comparator. Either:
sort_tasks_by_food_priority(tasks, worker)helper that both branches callgatherandgather_foodinto one kind that always checksColonyStance.is_food_gather_task(), eliminating the need for separate branchesThe second option is cleaner —
tasks_for_kind()already maps both"gather"and"gather_food"togather_gather_tasks()(line 1497), so the separate kinds only exist for the sort comparator.Acceptance criteria
should_bias_to_food_gathering()returns truegather_foodpriority) still workstests/test_colony_stance.gdpasses