add-recipe single inserts a duplicate when the civ already knows the recipe
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu với add-recipe.lua và so sánh vòng lặp chèn single với bước kiểm tra addItems bảo vệ các lần chèn hàng loạt. Báo cáo xác định các mục trùng lặp trong historical_entity.resources là lỗi đã được xác nhận; hãy kiểm tra hành vi và bảo đảm rằng hoàn thành có nghĩa là các lệnh single lặp lại không thêm bản sao nào nữa. Định tuyến digger và các kiểm tra nil là những phát hiện bổ sung trong cùng tệp, có thể cần phạm vi riêng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
add-recipe single <TYPE>:<ID> appends to the civ's resource vector without checking whether the subtype is already in there. Run it twice for the same item and you get two copies in historical_entity.resources.<x>_type.
Confirmed in game (DF + DFHack, fortress mode). Running
add-recipe single SHOES:ITEM_SHOES_BOOTS
twice on an item the civ already knew gave me a visible duplicate entry.
The single path in add-recipe.lua is upfront about skipping the check:
local addedItem = nil
--assume the user knows what they're doing, so no need for sanity checks
for _, item in ipairs(all) do
if (item.id == itemId) then
known:insert('#', item.subtype)
addedItem = item
break
end
end
The bulk paths are fine. addItems guards with not checkKnown(known, subtype) before inserting, so this is specific to single.
The duplicates are mostly cosmetic, but they stick around in the save and there's no in-game way to see them or get rid of them.
Adding a checkKnown(known, item.subtype) call in that loop would make it behave like all/native.
Two smaller things in the same file, from reading it rather than playing. Happy to split either out into its own issue.
1. single doesn't route diggers. It looks the category up in the categories table, and there's no digger entry there, so WEAPON:ITEM_WEAPON_PICK ends up in resources.weapon_type. addItems deliberately sends mining weapons to resources.digger_type instead, with the comment "prevents picks from being duplicated, and puts great picks in correct category". Something does read that field: internal/quickfort/stockflow.lua:306 uses resources.digger_type to build MakeWeapon orders for diggers. So the two vectors aren't interchangeable.
Partial in-game note: add-recipe single WEAPON:ITEM_WEAPON_PICK on a civ that already knew picks did not produce a duplicate among the known diggers, which is what you'd expect if the subtype went into weapon_type instead. I did not separately confirm that it appeared under weapons, so treat that half as unverified.
2. Two nil checks that can't fire. Lines 4-12:
local resources = df.historical_entity.find(df.global.plotinfo.civ_id).resources
local civ = df.historical_entity.find(df.global.plotinfo.civ_id).entity_raw
...
if (resources == nil) then
qerror("Could not find entity resources")
elseif (civ == nil) then
If find returns nil, line 4 has already thrown attempt to index a nil value. So running add-recipe with no fortress loaded gets you a Lua traceback instead of either of the qerror messages that were meant to come out.
I checked whether this is a general pattern before bringing it up: of the 439 scripts in DFHack/scripts, 70 sites dereference a find() result in the same expression, and add-recipe.lua is the only one that then nil-tests the result. The rest either guard first or have an argument that can't be nil. So it's one file, not a sweep.
Context: this came out of review on DFHack/scripts#1603, where @chdoc asked for it to be filed rather than worked around in the GUI.
Disclosure: I used AI assistance (Claude) for the code reading and for drafting this write-up. I verified the main bug in game myself, and I'm the one filing it.
- Ngôn ngữ chính
- C++
- Star
- 2.1k
- Fork
- 509
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DFHack/dfhack
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
DFHack/dfhack#5853 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
RemoteFortressReader: GetCreatureRaws sends CP437 (not UTF-8) strings, which breaks protobuf decodingCó thể đã có người làm @dwmuller đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 20/100
DFHack/dfhack#6019 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
reclaim with legends continuityĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Floor-mosaic plannerĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 2 ngày
-
up stair weirdnessĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của DFHack/dfhack
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
qbittorrent/qBittorrent#25121 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
SVT-AV1: Unnecessary size paddingCó thể đã có người làm @pszemus đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
strukturag/libheif#1945 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
v9.6.0: CMake incorrectly enforces presence of libevdevCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
mltframework/shotcut#1943 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Rowan (2017) electron heating gives NaN for beta > beta_max; clip() then sets electrons to kel_minĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
parthenon-hpc-lab/kharma#213 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày