Skip to content

Commit

Permalink
use canonicalized structures and field names
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jun 3, 2024
1 parent 4e5bc7c commit 92d27a3
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build-now.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local function get_jobs(opts)

-- job_items are not items, they're filters that describe the kinds of
-- items that need to be attached.
for _,job_item in ipairs(job.job_items) do
for _,job_item in ipairs(job.job_items.elements) do
-- we have to check for quantity != 0 instead of just the existence
-- of the job_item since buildingplan leaves 0-quantity job_items in
-- place to protect against persistence errors.
Expand Down
4 changes: 2 additions & 2 deletions feature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function list_features()
if feat:isChasm() then
tags = tags .. ' [chasm]'
end
if feat:isLayer() then
tags = tags .. ' [layer]'
if feat:isUnderworld() then
tags = tags .. ' [underworld]'
end
feat:getName(name)
print(('Feature #%i is %s: "%s", type %s%s'):format(
Expand Down
25 changes: 12 additions & 13 deletions gui/advfort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,14 @@ function SetCarveDir(args)
local job=args.job
local pos=args.pos
local from_pos=args.from_pos
local dirs={up=18,down=19,right=20,left=21}
if pos.x>from_pos.x then
job.item_category[dirs.right]=true
job.specflag.carve_track_flags.carve_track_east=true
elseif pos.x<from_pos.x then
job.item_category[dirs.left]=true
job.specflag.carve_track_flags.carve_track_west=true
elseif pos.y>from_pos.y then
job.item_category[dirs.down]=true
job.specflag.carve_track_flags.carve_track_south=true
elseif pos.y<from_pos.y then
job.item_category[dirs.up]=true
job.specflag.carve_track_flags.carve_track_north=true
end
end
function is_grasping_item( item_bp,unit )
Expand Down Expand Up @@ -799,7 +798,7 @@ function putItemsInBuilding(building,job_item_refs)
if not dfhack.items.moveToBuilding(v.item,building,0) then
print("Could not put item:",k,v.item)
end
v.is_fetching=0
v.flags.is_fetching=false
end
end
function putItemsInHauling(unit,job_item_refs)
Expand All @@ -810,7 +809,7 @@ function putItemsInHauling(unit,job_item_refs)
if not dfhack.items.moveToInventory(v.item,unit,0,0) then
print("Could not put item:",k,v.item)
end
v.is_fetching=0
v.flags.is_fetching=false
end
end
function finish_item_assign(args)
Expand All @@ -832,7 +831,7 @@ function finish_item_assign(args)
end
else
job.flags.fetching=true
uncollected[1].is_fetching=1
uncollected[1].flags.is_fetching=true
end
end
function EnumItems_with_settings( args )
Expand All @@ -845,7 +844,7 @@ function EnumItems_with_settings( args )
end
end
function find_suitable_items(job,items,job_items)
job_items=job_items or job.job_items
job_items=job_items or job.job_items.elements

local item_counts={}
for job_id, trg_job_item in ipairs(job_items) do
Expand Down Expand Up @@ -899,7 +898,7 @@ function AssignJobItems(args)
job.items:erase(#job.items-1)
end]]

if settings.gui_item_select and #job.job_items>0 then
if settings.gui_item_select and #job.job_items.elements>0 then
if settings.quick then --TODO not so nice hack. instead of rewriting logic for job item filling i'm using one in gui dialog...
local item_editor=advfort_items.jobitemEditor{
job = job,
Expand All @@ -925,7 +924,7 @@ function AssignJobItems(args)
end
else
if not settings.build_by_items then
for job_id, trg_job_item in ipairs(job.job_items) do
for job_id, trg_job_item in ipairs(job.job_items.elements) do
if item_counts[job_id]>0 then
print("Not enough items for this job")
return false, "Not enough items for this job"
Expand Down Expand Up @@ -1001,7 +1000,7 @@ function ContinueJob(unit)
--reset suspends...
c_job.flags.suspend=false
for k,v in pairs(c_job.items) do --try fetching missing items
if v.is_fetching==1 then
if v.flags.is_fetching then
unit.path.dest:assign(v.item.pos)
return
end
Expand Down Expand Up @@ -1277,7 +1276,7 @@ function setFiltersUp(specific,args)
--printall(v)
local filter=v
filter.new=true
job.job_items:insert("#",filter)
job.job_items.elements:insert("#",filter)
end
return true
end
Expand Down
2 changes: 1 addition & 1 deletion gui/tiletypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ function BoxSelection:init()
guidm.setCursorPos(guidm.Viewport.get():getCenter())

-- Show cursor
df.global.game.main_interface.main_designation_selected = df.main_designation_type.TOGGLE_ENGRAVING -- Alternative: df.main_designation_type.REMOVE_CONSTRUCTION
df.global.game.main_interface.main_designation_selected = df.main_designation_type.TOGGLE_ENGRAVING

if self.screen then
self.dimensions_tooltip = widgets.DimensionsTooltip{
Expand Down
2 changes: 1 addition & 1 deletion gui/workshop-job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function JobDetails:initListChoices()
end

local choices = {}
for i,iobj in ipairs(self.job.job_items) do
for i,iobj in ipairs(self.job.job_items.elements) do
local head = 'Item '..(i+1)..': '..(items[i] or 0)..' of '..iobj.quantity
if iobj.min_dimension > 0 then
head = head .. '(size '..iobj.min_dimension..')'
Expand Down
4 changes: 2 additions & 2 deletions internal/advfort/advfort_items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function update_slot_text(slot)

slot.text=string.format("%02d. Filled(%d/%d):%s",slot.id+1,slot.filled_amount,slot.job_item.quantity,items)
end
--items-> table => key-> id of job.job_items, value-> table => key (num), value => item(ref)
--items-> table => key-> id of job.job_items.elements, value-> table => key (num), value => item(ref)
function jobitemEditor:init(args)
--self.job=args.job
if self.job==nil and self.job_items==nil then qerror("This screen must have job target or job_items list") end
Expand Down Expand Up @@ -156,7 +156,7 @@ function jobitemEditor:fill()
local job_item

if self.job then
job_item=self.job.job_items[k]
job_item=self.job.job_items.elements[k]
else
job_item=self.job_items[k]
end
Expand Down
2 changes: 1 addition & 1 deletion internal/dwarf-op/dorf_tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ professions = {

--Arts & Crafts & Dwarfism
CRAFTSMAN = { skills = {WOODCRAFT=2, STONECRAFT=2, METALCRAFT=2} },
ENGRAVER = { skills = {DETAILSTONE=5} },
ENGRAVER = { skills = {ENGRAVE_STONE=5} },
MECHANIC = { skills = {MECHANICS=5} },

--Plants & Animals
Expand Down
12 changes: 6 additions & 6 deletions internal/quickfort/stockflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ function collect_reactions()
reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {finished_goods = true},
specflag = {encrust_flags={finished_goods=true}},
}, "Encrust Finished Goods With "..rock_name)

reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {furniture = true},
specflag = {encrust_flags={furniture=true}},
}, "Encrust Furniture With "..rock_name)

reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0,
mat_index = rock_id,
item_category = {ammo = true},
specflag = {encrust_flags={ammo=true}},
}, "Encrust Ammo With "..rock_name)
end

Expand Down Expand Up @@ -172,17 +172,17 @@ function collect_reactions()

reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {finished_goods = true},
specflag = {encrust_flags={finished_goods=true}},
}, "Encrust Finished Goods With "..glass_name)

reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {furniture = true},
specflag = {encrust_flags={furniture=true}},
}, "Encrust Furniture With "..glass_name)

reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id,
item_category = {ammo = true},
specflag = {encrust_flags={ammo=true}},
}, "Encrust Ammo With "..glass_name)
end
end
Expand Down
1 change: 0 additions & 1 deletion modtools/create-unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ function enableUnitLabors(unit, default, skilled)
labors.HANDLE_VEHICLES = true
labors.HAUL_TRADE = true
labors.PULL_LEVER = true
labors.REMOVE_CONSTRUCTION = true
labors.HAUL_WATER = true
labors.BUILD_ROAD = true
labors.BUILD_CONSTRUCTION = true
Expand Down
6 changes: 3 additions & 3 deletions sync-windmills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local argparse = require('argparse')
local function process_windmills(rotate_fn, timer_fn)
for _, bld in ipairs(df.global.world.buildings.other.WINDMILL) do
if bld.is_working ~= 0 then
bld.visual_rotated = rotate_fn()
bld.rotation = rotate_fn()
bld.rotate_timer = timer_fn()
end
end
Expand All @@ -24,8 +24,8 @@ end

process_windmills(
(opts.randomize or opts.timing) and
function() return math.random(1, 2) == 1 end or
function() return false end,
function() return math.random(0, 1) end or
function() return 0 end,
opts.randomize and not opts.timing and
function() return math.random(0, 74) end or
function() return 0 end)
Expand Down
25 changes: 11 additions & 14 deletions workorder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ local function orders_match(a, b)
end
end

local subtables = {
"item_category",
"material_category",
}
for key, value in ipairs(a.specflag.encrust_flags) do
if b.specflag.encrust_flags[key] ~= value then
return false
end
end

for _, fieldname in ipairs(subtables) do
local aa = a[fieldname]
local bb = b[fieldname]
for key, value in ipairs(aa) do
if bb[key] ~= value then
return false
end
for key, value in ipairs(a.material_category) do
if b.material_category[key] ~= value then
return false
end
end

Expand Down Expand Up @@ -246,7 +243,7 @@ function create_orders(orders, quiet)
end

if it["item_category"] then
local ok, bad = set_flags_from_list(it["item_category"], order.item_category)
local ok, bad = set_flags_from_list(it["item_category"], order.specflag.encrust_flags)
if not ok then
qerror ("Invalid item_category value for manager order: " .. bad)
end
Expand Down Expand Up @@ -351,7 +348,7 @@ function create_orders(orders, quiet)
break
end
end
condition.inorganic_bearing = idx
condition.metal_ore = idx
or qerror( "Invalid item condition inorganic bearing type for manager order: " .. it2["bearing"] )
end

Expand Down Expand Up @@ -398,7 +395,7 @@ function create_orders(orders, quiet)
end)
end
end
--order.items = vector<job_item*>
--order.items.elements = vector<job_item*>

local amount = it.amount_total
if it.__reduce_amount then
Expand Down

0 comments on commit 92d27a3

Please sign in to comment.