Skip to content

feat: goal-driven task generation system#115

Draft
kcjonson wants to merge 2 commits into
mainfrom
feature/goal-driven-task-generation
Draft

feat: goal-driven task generation system#115
kcjonson wants to merge 2 commits into
mainfrom
feature/goal-driven-task-generation

Conversation

@kcjonson
Copy link
Copy Markdown
Owner

@kcjonson kcjonson commented Jan 6, 2026

Summary

Implements centralized goal-driven task generation as specified in /docs/design/goal-driven-task-generation.md.

New Components:

  • GoalTaskRegistry - Central singleton for goal storage with indices for fast lookup by destination, type, and parent-child relationships
  • CraftingGoalSystem - Creates Craft + Harvest + Haul goal hierarchies when recipes are queued
  • StorageGoalSystem - Creates Haul goals for storage containers wanting items
  • BuildGoalSystem - Creates PlacePackaged goals for furniture placement

Key Changes:

  • AIDecisionSystem now evaluates goals from registry instead of ad-hoc world scanning
  • ActionSystem updates goal progress (deliveredAmount) on task completion
  • Task component extended with goal IDs for reservation tracking
  • GlobalTaskAdapter displays goal hierarchy in task list UI

Known Issues

⚠️ WIP - Bug under investigation: Goals are being removed unexpectedly, causing CraftingGoalSystem to recreate goal hierarchies every tick. This leads to infinite goal accumulation.

Debug logging has been added to trace the removal path.

Test Plan

  • Queue craft job → verify single goal hierarchy created
  • Complete harvest → verify haul goal becomes available
  • Complete haul → verify materials delivered to station
  • Cancel craft → verify all child goals removed
  • Verify goal count stabilizes (not growing infinitely)

Adds centralized GoalTaskRegistry for managing crafting, hauling, and
harvesting goals with parent-child relationships and dependency tracking.

New systems:
- GoalTaskRegistry: Central goal storage with indices for fast lookup
- CraftingGoalSystem: Creates Craft + Harvest + Haul goal hierarchies
- StorageGoalSystem: Creates Haul goals for storage containers
- BuildGoalSystem: Creates PlacePackaged goals for furniture placement

Changes:
- AIDecisionSystem: Evaluates goals from registry instead of ad-hoc scanning
- ActionSystem: Updates goal progress on task completion
- Task component: Added goal IDs for tracking reservations
- GlobalTaskAdapter: Displays goal hierarchy in task list UI

Known issue: Goals are being removed unexpectedly, causing infinite
regeneration. Debug logging added to investigate.
Bug Fix:
- StorageGoalSystem was removing Craft goals owned by CraftingGoalSystem
- Root cause: getGoalsByType(Haul) returned ALL Haul goals, including
  child Haul goals from CraftingGoalSystem's material delivery
- StorageGoalSystem would then call removeGoalByDestination() on entities
  it didn't recognize, inadvertently removing Craft goals

Goal Ownership System:
- Added GoalOwner enum (StorageGoalSystem, CraftingGoalSystem, BuildGoalSystem)
- Added owner field to GoalTask struct
- Added ownerToGoals index for efficient ownership-based queries
- Systems now query getGoalsByOwner() instead of getGoalsOfType()
- Each goal explicitly tracks which system created it

Test Infrastructure:
- Added CraftingGoalSystem.test.cpp with 7 tests
- Tests reproduce the bug and verify the fix
- Added registerTestRecipe() to RecipeRegistry for test support

All 330 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant