sow no longer needs grain + add crop zone paint tools
Bug: pawns weren't replanting. _find_sow required a TYPE_GRAIN item as seed, but Millstone's flour bill (FOREVER) consumed all grain before sow could claim it. With CookingProvider now priority 6, grain contention is fatal — TILLED crops sit forever. Fix: removed the grain requirement. Sow is now Rimworld-style — the designation triggers work; no input is consumed. _find_sow returns a 2-toil job (walk → interact). Crop.on_sow_tick just flips stage to SOWN. Feature: 4 new paint tools in BuildDrawer's new "Farm" section column — TOOL_PAINT_CROP_WHEAT/POTATO/CORN/STRAWBERRY. Painting a grass tile spawns a TILLED Crop entity that pawns then sow. World rejects non-grass tiles, occupied tiles, and non-walkable terrain. 9 new string keys, kind-specific thumbnail draws (gold/tan/yellow/red). MCP verified: 12 forced-TILLED crops fully cycled TILLED → SOWN → growth → READY within ~3000 ticks. Paint tool spawned wheat crop at (35, 30); wall tile at (44, 23) correctly rejected. Followup smell: cancelling a designation on a player-painted crop will queue_free even if grown — Crop has no can_complete. Future guard could skip crops past TILLED. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
87a7beb22b
commit
c6c88acc47
6 changed files with 107 additions and 54 deletions
|
|
@ -183,6 +183,7 @@ const TABLE: Dictionary = {
|
|||
&"ui.build_drawer.section.structures": "Structures",
|
||||
&"ui.build_drawer.section.furniture": "Furniture",
|
||||
&"ui.build_drawer.section.production": "Production",
|
||||
&"ui.build_drawer.section.farm": "Farm",
|
||||
&"tool.chop": "Chop trees",
|
||||
&"tool.mine": "Mine rocks",
|
||||
&"tool.dig_grave": "Dig grave",
|
||||
|
|
@ -330,6 +331,15 @@ const TABLE: Dictionary = {
|
|||
&"tooltip.tool.paint_quarry": "Paint a quarry on a stone outcrop",
|
||||
&"tooltip.tool.paint_stockpile": "Paint a stockpile zone",
|
||||
&"tooltip.tool.graveyard": "Paint a graveyard zone",
|
||||
# Crop zone paint tools (no seed cost — pawns sow when free).
|
||||
&"tool.paint_crop_wheat": "Wheat field",
|
||||
&"tool.paint_crop_potato": "Potato field",
|
||||
&"tool.paint_crop_corn": "Corn field",
|
||||
&"tool.paint_crop_strawberry": "Berry patch",
|
||||
&"tooltip.tool.paint_crop_wheat": "Paint a wheat field. Pawns will sow when free.",
|
||||
&"tooltip.tool.paint_crop_potato": "Paint a potato field. Pawns will sow when free.",
|
||||
&"tooltip.tool.paint_crop_corn": "Paint a corn field. Pawns will sow when free.",
|
||||
&"tooltip.tool.paint_crop_strawberry": "Paint a strawberry patch. Pawns will sow when free.",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,17 +12,10 @@ class_name PlantProvider extends WorkProvider
|
|||
## Harvest Job (two toils):
|
||||
## walk_to(crop.tile) → interact(crop.get_path(), "on_harvest_tick")
|
||||
##
|
||||
## Sow Job (four toils):
|
||||
## walk_to(grain_item.tile) → pickup → walk_to(crop.tile)
|
||||
## → interact(crop.get_path(), "on_sow_tick")
|
||||
## The grain item is consumed by the INTERACT completion (on_sow_tick does
|
||||
## the stage transition; the pawn's carried item is cleared by the provider
|
||||
## by queuing a DROP toil after interact, or — simpler — on_sow_tick itself
|
||||
## does not free the item, so we add a consume step here).
|
||||
##
|
||||
## Seed item: Item.TYPE_GRAIN (&"grain") — universal MVP seed for all crop kinds.
|
||||
## Wheat/corn already produce grain on harvest. Potato/strawberry accept grain
|
||||
## as seed in the same way (MVP simplification noted in design.md).
|
||||
## Sow Job (two toils — no seed cost, Rimworld-style):
|
||||
## walk_to(crop.tile) → interact(crop.get_path(), "on_sow_tick")
|
||||
## The designation alone triggers work; no grain is consumed. on_sow_tick()
|
||||
## flips the crop from TILLED → SOWN so growth begins on the next sim tick.
|
||||
##
|
||||
## The INTERACT toil calls the action method once per sim tick. Both actions
|
||||
## complete in a single tick; the done-check in JobRunner._tick_interact fires
|
||||
|
|
@ -54,9 +47,6 @@ func find_best_for(pawn) -> Job:
|
|||
return j
|
||||
|
||||
# ── 2. Sow pass — only if no harvest work exists ─────────────────────────
|
||||
# Pawn must not already be carrying something (no double-carry).
|
||||
if pawn.carried_item != null:
|
||||
return null
|
||||
return _find_sow(pawn)
|
||||
|
||||
|
||||
|
|
@ -89,11 +79,10 @@ func _find_harvest(pawn) -> Job:
|
|||
return j
|
||||
|
||||
|
||||
## Scan World.crops for the nearest sowable (TILLED) crop, find a reachable
|
||||
## grain item to use as seed, and build a 4-toil sow job.
|
||||
## Returns null when no sowable tile or no grain exists.
|
||||
## Scan World.crops for the nearest sowable (TILLED) crop and build a 2-toil
|
||||
## sow job. No seed item is consumed — sow is a free designation (Rimworld-style).
|
||||
## Returns null when no sowable crop is reachable.
|
||||
func _find_sow(pawn) -> Job:
|
||||
# Find the nearest sowable crop the pawn can reach.
|
||||
var best_crop = null
|
||||
var best_crop_dist: int = 999999
|
||||
|
||||
|
|
@ -114,45 +103,9 @@ func _find_sow(pawn) -> Job:
|
|||
if best_crop == null:
|
||||
return null
|
||||
|
||||
# Find the nearest free grain item in the world.
|
||||
var best_grain = null
|
||||
var best_grain_dist: int = 999999
|
||||
|
||||
for it in World.items:
|
||||
if it.item_type != Item.TYPE_GRAIN:
|
||||
continue
|
||||
if it.being_carried:
|
||||
continue
|
||||
# Reachability pre-check for the grain item too.
|
||||
if pawn.tile != it.tile and World.pathfinder != null:
|
||||
if World.pathfinder.find_path(pawn.tile, it.tile).is_empty():
|
||||
continue
|
||||
var d: int = abs(it.tile.x - pawn.tile.x) + abs(it.tile.y - pawn.tile.y)
|
||||
if d < best_grain_dist:
|
||||
best_grain_dist = d
|
||||
best_grain = it
|
||||
|
||||
if best_grain == null:
|
||||
return null
|
||||
|
||||
var j := Job.new()
|
||||
j.label = "Sow %s at %s" % [best_crop.crop_kind, best_crop.tile]
|
||||
j.target_node = best_crop
|
||||
# Walk to the grain, pick it up, walk to the crop tile, sow.
|
||||
# on_sow_tick() transitions the crop TILLED → SOWN; after the interact toil
|
||||
# the pawn still carries the consumed grain. A trailing DROP toil deposits
|
||||
# it at the pawn's current tile (which is the crop tile); the item simply
|
||||
# falls on the ground and HaulingProvider re-hauls it. This is intentional
|
||||
# MVP behaviour — the player sees the seed "planted" and any excess grain is
|
||||
# returned to the floor for hauling. A future refinement can consume it
|
||||
# outright by adding a CONSUME toil kind to JobRunner.
|
||||
j.toils.append(Toil.walk_to(best_grain.tile))
|
||||
j.toils.append(Toil.pickup())
|
||||
j.toils.append(Toil.walk_to(best_crop.tile))
|
||||
j.toils.append(Toil.interact(best_crop.get_path(), &"on_sow_tick"))
|
||||
# Deposit the consumed grain at the crop tile so HaulingProvider can route
|
||||
# it back to a stockpile. MVP simplification: the seed is not destroyed on
|
||||
# sow — it becomes a floor item. A future CONSUME toil kind in JobRunner
|
||||
# would burn the item in-place without spawning a floor stack.
|
||||
j.toils.append(Toil.deposit())
|
||||
return j
|
||||
|
|
|
|||
|
|
@ -254,6 +254,28 @@ func _build_build_tab() -> Control:
|
|||
func() -> void: _activate(&"paint_quarry", &"", Strings.t(&"tool.paint_quarry")),
|
||||
Strings.t(&"tooltip.tool.paint_quarry"))
|
||||
row.add_child(pr)
|
||||
row.add_child(VSeparator.new())
|
||||
|
||||
# Farm — crop zone paint (one per kind; no seed cost).
|
||||
var fa := _make_section_column(Strings.t(&"ui.build_drawer.section.farm"))
|
||||
var fa_grid := fa.get_child(1) as GridContainer
|
||||
_add_tool_btn(fa_grid, Strings.t(&"tool.paint_crop_wheat"),
|
||||
&"paint_crop_wheat",
|
||||
func() -> void: _activate(&"paint_crop_wheat", &"", Strings.t(&"tool.paint_crop_wheat")),
|
||||
Strings.t(&"tooltip.tool.paint_crop_wheat"))
|
||||
_add_tool_btn(fa_grid, Strings.t(&"tool.paint_crop_potato"),
|
||||
&"paint_crop_potato",
|
||||
func() -> void: _activate(&"paint_crop_potato", &"", Strings.t(&"tool.paint_crop_potato")),
|
||||
Strings.t(&"tooltip.tool.paint_crop_potato"))
|
||||
_add_tool_btn(fa_grid, Strings.t(&"tool.paint_crop_corn"),
|
||||
&"paint_crop_corn",
|
||||
func() -> void: _activate(&"paint_crop_corn", &"", Strings.t(&"tool.paint_crop_corn")),
|
||||
Strings.t(&"tooltip.tool.paint_crop_corn"))
|
||||
_add_tool_btn(fa_grid, Strings.t(&"tool.paint_crop_strawberry"),
|
||||
&"paint_crop_strawberry",
|
||||
func() -> void: _activate(&"paint_crop_strawberry", &"", Strings.t(&"tool.paint_crop_strawberry")),
|
||||
Strings.t(&"tooltip.tool.paint_crop_strawberry"))
|
||||
row.add_child(fa)
|
||||
|
||||
return row
|
||||
|
||||
|
|
|
|||
|
|
@ -372,6 +372,28 @@ func _draw() -> void:
|
|||
draw_circle(Vector2(c.x, c.y - 10), 4.0, leaf_a)
|
||||
draw_circle(Vector2(c.x - 5, c.y - 6), 3.0, leaf_b)
|
||||
draw_circle(Vector2(c.x + 5, c.y - 5), 3.0, leaf_b)
|
||||
&"paint_crop_wheat", &"paint_crop_potato", &"paint_crop_corn", &"paint_crop_strawberry":
|
||||
# Tilled-soil patch with a small sprout — represents a crop zone designation.
|
||||
# Kind-specific accent colour on the sprout top distinguishes the four tools.
|
||||
var soil := Color(0.32, 0.20, 0.10)
|
||||
var soil_hi := Color(0.48, 0.30, 0.14)
|
||||
var stem_col := Color(0.35, 0.55, 0.20)
|
||||
var sprout_col: Color
|
||||
match tool_id:
|
||||
&"paint_crop_wheat": sprout_col = Color(0.90, 0.80, 0.25) # golden wheat
|
||||
&"paint_crop_potato": sprout_col = Color(0.80, 0.72, 0.40) # pale tan
|
||||
&"paint_crop_corn": sprout_col = Color(0.95, 0.90, 0.30) # bright yellow
|
||||
&"paint_crop_strawberry": sprout_col = Color(0.90, 0.25, 0.25) # red berry
|
||||
_: sprout_col = Color(0.40, 0.75, 0.30)
|
||||
# Soil patch.
|
||||
draw_rect(Rect2(c.x - 14, c.y + 0, 28, 16), soil)
|
||||
draw_rect(Rect2(c.x - 14, c.y + 0, 28, 3), soil_hi)
|
||||
draw_rect(Rect2(c.x - 14, c.y + 0, 28, 16), outline, false, 1.0)
|
||||
# Three small sprouts evenly spaced across the patch.
|
||||
var xs: Array[float] = [c.x - 6.0, c.x, c.x + 6.0]
|
||||
for sx in xs:
|
||||
draw_line(Vector2(sx, c.y + 0), Vector2(sx, c.y - 10), stem_col, 1.5)
|
||||
draw_circle(Vector2(sx, c.y - 12), 3.0, sprout_col)
|
||||
_:
|
||||
# Unknown tool — small grey placeholder.
|
||||
draw_rect(Rect2(c.x - 12, c.y - 12, 24, 24), Color(0.50, 0.50, 0.50))
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ const TOOL_PAINT_STOCKPILE: StringName = &"paint_stockpile"
|
|||
const TOOL_PLANT_TREE: StringName = &"plant_tree"
|
||||
# Quarry — must paint on a BigRockNode tile; spawns a QuarryWorkbench ghost.
|
||||
const TOOL_PAINT_QUARRY: StringName = &"paint_quarry"
|
||||
# Crop zone paint (one tool per kind) — spawns a Crop entity at Stage.TILLED
|
||||
# so PlantProvider will assign a sow job with no seed cost.
|
||||
const TOOL_PAINT_CROP_WHEAT: StringName = &"paint_crop_wheat"
|
||||
const TOOL_PAINT_CROP_POTATO: StringName = &"paint_crop_potato"
|
||||
const TOOL_PAINT_CROP_CORN: StringName = &"paint_crop_corn"
|
||||
const TOOL_PAINT_CROP_STRAWBERRY: StringName = &"paint_crop_strawberry"
|
||||
|
||||
# ── tool → material override ─────────────────────────────────────────────────
|
||||
# For build_wall and build_floor the tool is shared but the material differs.
|
||||
|
|
@ -79,6 +85,10 @@ const _ATLAS_BY_TOOL: Dictionary = {
|
|||
&"paint_stockpile": Vector2i(0, 0),
|
||||
&"plant_tree": Vector2i(0, 0), # grass ghost — tinted green
|
||||
&"paint_quarry": Vector2i(2, 0), # stone-grey ghost
|
||||
&"paint_crop_wheat": Vector2i(1, 0), # dirt-brown ghost (tilled soil)
|
||||
&"paint_crop_potato": Vector2i(1, 0),
|
||||
&"paint_crop_corn": Vector2i(1, 0),
|
||||
&"paint_crop_strawberry": Vector2i(1, 0),
|
||||
}
|
||||
|
||||
# Placeholder source ID — mirrors World.PLACEHOLDER_SOURCE_ID.
|
||||
|
|
@ -128,6 +138,8 @@ func set_active_tool(tool: StringName) -> void:
|
|||
TOOL_PAINT_STOCKPILE,
|
||||
TOOL_PLANT_TREE,
|
||||
TOOL_PAINT_QUARRY,
|
||||
TOOL_PAINT_CROP_WHEAT, TOOL_PAINT_CROP_POTATO,
|
||||
TOOL_PAINT_CROP_CORN, TOOL_PAINT_CROP_STRAWBERRY,
|
||||
],
|
||||
"Designation.set_active_tool: unknown tool '%s'" % tool
|
||||
)
|
||||
|
|
|
|||
|
|
@ -866,6 +866,40 @@ func _on_designation_added(cell: Vector2i, tool: StringName) -> void:
|
|||
# Register as a build site so ConstructionProvider can assign a pawn.
|
||||
World.register_build_site(pt)
|
||||
entity = pt
|
||||
# Crop zone paint — spawns a Crop at Stage.TILLED (no seed cost).
|
||||
# Validity: grass terrain + walkable + no existing crop or tree at this tile.
|
||||
&"paint_crop_wheat", &"paint_crop_potato", &"paint_crop_corn", &"paint_crop_strawberry":
|
||||
# Grass + walkable check (mirrors _wild_growth_tile_eligible).
|
||||
if terrain_layer != null:
|
||||
var src_id: int = terrain_layer.get_cell_source_id(cell)
|
||||
var atlas: Vector2i = terrain_layer.get_cell_atlas_coords(cell)
|
||||
if src_id != PLACEHOLDER_SOURCE_ID or atlas != TILE_GRASS:
|
||||
Audit.log("world", "%s: tile %s is not grass — skipped" % [tool, cell])
|
||||
return
|
||||
if pathfinder != null and not pathfinder.is_walkable(cell):
|
||||
Audit.log("world", "%s: tile %s is not walkable — skipped" % [tool, cell])
|
||||
return
|
||||
# No existing crop at this tile.
|
||||
for existing_c in World.crops:
|
||||
if is_instance_valid(existing_c) and existing_c.tile == cell:
|
||||
Audit.log("world", "%s: tile %s already has a crop — skipped" % [tool, cell])
|
||||
return
|
||||
# No tree at this tile (trees block planting).
|
||||
for existing_t in World.trees:
|
||||
if is_instance_valid(existing_t) and existing_t.tile == cell:
|
||||
Audit.log("world", "%s: tile %s has a tree — skipped" % [tool, cell])
|
||||
return
|
||||
# Map tool → Crop kind.
|
||||
var kind: StringName
|
||||
match tool:
|
||||
&"paint_crop_wheat": kind = Crop.KIND_WHEAT
|
||||
&"paint_crop_potato": kind = Crop.KIND_POTATO
|
||||
&"paint_crop_corn": kind = Crop.KIND_CORN
|
||||
&"paint_crop_strawberry": kind = Crop.KIND_STRAWBERRY
|
||||
var crop_entity: Crop = CROP_SCENE.instantiate()
|
||||
add_child(crop_entity)
|
||||
crop_entity.setup(cell, kind, Crop.Stage.TILLED)
|
||||
entity = crop_entity
|
||||
_:
|
||||
Audit.log("world", "unknown designation tool: %s" % tool)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue