Skip to content

Commit

Permalink
Merge branch 'DFHack:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bumber64 authored Jul 31, 2024
2 parents 73aea9a + 63801db commit eea9cf7
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 61 deletions.
65 changes: 37 additions & 28 deletions ban-cooking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,29 @@ funcs.seeds = function()
if p.material_defs.type.seed == -1 or p.material_defs.idx.seed == -1 or p.flags.TREE then goto continue end
ban_cooking(p.name .. ' seeds', p.material_defs.type.seed, p.material_defs.idx.seed, df.item_type.SEEDS, -1)
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
local has_drink = false
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
has_drink = has_drink or s.value == "DRINK_MAT"
end
if has_seed and has_drink then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
end
if has_seed then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
end
end
break
end
end
for k, g in ipairs(p.growths) do
local matinfo = dfhack.matinfo.decode(g)
local m = matinfo.material
if m.flags.EDIBLE_COOKED then
local has_drink = false
local has_seed = false
for _, s in ipairs(m.reaction_product.id) do
has_seed = has_seed or s.value == "SEED_MAT"
has_drink = has_drink or s.value == "DRINK_MAT"
end
if has_seed and has_drink then
if has_seed then
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT_GROWTH, k)
end
end
Expand All @@ -174,14 +173,18 @@ funcs.brew = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.type.drink == -1 or p.material_defs.idx.drink == -1 then goto continue end
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "DRINK_MAT" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
end
end
end
-- Stop iterating materials since there is only one STRUCTURAL
break
end
end
for k, g in ipairs(p.growths) do
Expand All @@ -205,9 +208,12 @@ funcs.mill = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.idx.mill ~= -1 then
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
end
break
end
end
end
Expand All @@ -218,14 +224,17 @@ funcs.thread = function()
for _, p in ipairs(df.global.world.raws.plants.all) do
if p.material_defs.idx.thread == -1 then goto continue end
for _, m in ipairs(p.material) do
if m.id == "STRUCTURAL" and m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "THREAD" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
if m.id == "STRUCTURAL" then
if m.flags.EDIBLE_COOKED then
for _, s in ipairs(m.reaction_product.id) do
if s.value == "THREAD" then
local matinfo = dfhack.matinfo.find(p.id, m.id)
ban_cooking(p.name .. ' ' .. m.id, matinfo.type, matinfo.index, df.item_type.PLANT, -1)
break
end
end
end
break
end
end
for k, g in ipairs(p.growths) do
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Template for new versions:
- `clear-smoke`: properly tag smoke flows for garbage collection to avoid memory leak
- `warn-stranded`: don't warn for babies carried by mothers who happen to be gathering fruit from trees
- `prioritize`: also boost priority of already-claimed jobs when boosting priority of a job type so those jobs are not interrupted
- `ban-cooking`: ban all seed producing items from being cooked when 'seeds' is chosen instead of just brewable seed producing items

## Misc Improvements
- `item`: option for ignoring uncollected spider webs when you search for "silk"
Expand Down
2 changes: 1 addition & 1 deletion docs/ban-cooking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Valid types are:
- ``milk``
- ``mill`` (millable plants)
- ``oil``
- ``seeds`` (plantable seeds)
- ``seeds`` (plantable seeds and items producing seeds)
- ``tallow``
- ``thread``

Expand Down
9 changes: 2 additions & 7 deletions gui/companion-order.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ function getxyz() -- this will return pointers x,y and z coordinates.
return x,y,z -- return the coords
end

function GetCaste(race_id,caste_id)
local race=df.creature_raw.find(race_id)
return race.caste[caste_id]
end

function EnumBodyEquipable(race_id,caste_id)
local caste=GetCaste(race_id,caste_id)
local caste=dfhack.units.getCasteRaw(race_id,caste_id)
local bps=caste.body_info.body_parts
local ret={}
for k,v in pairs(bps) do
Expand Down Expand Up @@ -149,7 +144,7 @@ function AddIfFits(body_equip,unit,item)
return false
end
function EnumGrasps(race_id,caste_id)
local caste=GetCaste(race_id,caste_id)
local caste=dfhack.units.getCasteRaw(race_id,caste_id)
local bps=caste.body_info.body_parts
local ret={}
for k,v in pairs(bps) do
Expand Down
16 changes: 6 additions & 10 deletions gui/unit-info-viewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ local function get_death_type(death_cause)
return DEATH_TYPES[death_cause] or ' died of unknown causes'
end

local function get_caste_data(unit)
return df.global.world.raws.creatures.all[unit.race].caste[unit.caste]
end

local function get_creature_data(unit)
return df.global.world.raws.creatures.all[unit.race]
end
Expand All @@ -190,7 +186,7 @@ local function get_translated_name_chunk(unit)
end

local function get_description_chunk(unit)
local desc = get_caste_data(unit).description
local desc = dfhack.units.getCasteRaw(unit).description
if #desc == 0 then return end
return {text=desc, pen=COLOR_WHITE}
end
Expand Down Expand Up @@ -271,7 +267,7 @@ end

local function get_max_age_chunk(unit)
if not dfhack.units.isAlive(unit) then return end
local caste = get_caste_data(unit)
local caste = dfhack.units.getCasteRaw(unit)
local blurb
if caste.misc.maxage_min == -1 then
blurb = ' only die of unnatural causes.'
Expand Down Expand Up @@ -395,15 +391,15 @@ end

local function get_grazer_chunk(unit)
if not dfhack.units.isGrazer(unit) then return end
local caste = get_caste_data(unit)
local caste = dfhack.units.getCasteRaw(unit)
local blurb = 'Grazing satisfies ' .. tostring(caste.misc.grazer) .. ' units of hunger.'
return {text=blurb, pen=COLOR_LIGHTGREEN}
end

local function get_milkable_chunk(unit)
if not dfhack.units.isAlive(unit) or not dfhack.units.isMilkable(unit) then return end
if not dfhack.units.isAnimal(unit) then return end
local caste = get_caste_data(unit)
local caste = dfhack.units.getCasteRaw(unit)
local milk = dfhack.matinfo.decode(caste.extracts.milkable_mat, caste.extracts.milkable_matidx)
if not milk then return end
local days, seconds = math.modf(caste.misc.milkable / TU_PER_DAY)
Expand All @@ -419,7 +415,7 @@ end
local function get_shearable_chunk(unit)
if not dfhack.units.isAlive(unit) then return end
if not dfhack.units.isAnimal(unit) then return end
local caste = get_caste_data(unit)
local caste = dfhack.units.getCasteRaw(unit)
local mat_types = caste.body_info.materials.mat_type
local mat_idxs = caste.body_info.materials.mat_index
for idx, mat_type in ipairs(mat_types) do
Expand All @@ -438,7 +434,7 @@ end

local function get_egg_layer_chunk(unit)
if not dfhack.units.isAlive(unit) or not dfhack.units.isEggLayer(unit) then return end
local caste = get_caste_data(unit)
local caste = dfhack.units.getCasteRaw(unit)
local clutch = (caste.misc.clutch_size_max + caste.misc.clutch_size_min) // 2
local blurb = ('She lays clutches of about %d egg%s.'):format(clutch, clutch == 1 and '' or 's')
return {text=blurb, pen=COLOR_GREEN}
Expand Down
2 changes: 1 addition & 1 deletion gui/unit-syndromes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ local function getLivestock()
local units = {}

for _, unit in pairs(df.global.world.units.active) do
local caste_flags = unit.caste and df.global.world.raws.creatures.all[unit.race].caste[unit.caste].flags
local caste_flags = dfhack.units.getCasteRaw(unit).flags

if dfhack.units.isFortControlled(unit) and caste_flags and (caste_flags.PET or caste_flags.PET_EXOTIC) then
table.insert(units, unit)
Expand Down
4 changes: 2 additions & 2 deletions internal/gm-unit/editor_colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end

function Editor_Colors:random()
local featureChoiceIndex, featureChoice = self.subviews.features:getSelected() -- This is the part / feature that's selected
local caste = df.creature_raw.find(self.target_unit.race).caste[self.target_unit.caste]
local caste = dfhack.units.getCasteRaw(self.target_unit)

-- Nil check in case there are no features
if featureChoiceIndex == nil then
Expand Down Expand Up @@ -136,7 +136,7 @@ function Editor_Colors:featureSelected(index, choice)
end

function Editor_Colors:updateChoices()
local caste = df.creature_raw.find(self.target_unit.race).caste[self.target_unit.caste]
local caste = dfhack.units.getCasteRaw(self.target_unit)
local choices = {}
for index, colorMod in ipairs(caste.color_modifiers) do
table.insert(choices, {text = colorMod.part:gsub("^%l", string.upper), mod = colorMod, index = index})
Expand Down
6 changes: 2 additions & 4 deletions internal/notify/notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ local function for_moody(fn, reverse)
end, fn, reverse)
end

local races = df.global.world.raws.creatures.all

local function is_stealer(unit)
local casteFlags = races[unit.race].caste[unit.caste].flags
local casteFlags = dfhack.units.getCasteRaw(unit).flags
if casteFlags.CURIOUS_BEAST_EATER or
casteFlags.CURIOUS_BEAST_GUZZLER or
casteFlags.CURIOUS_BEAST_ITEM
Expand Down Expand Up @@ -224,7 +222,7 @@ end
local function summarize_units(for_fn)
local counts = {}
for_fn(function(unit)
local names = races[unit.race].caste[unit.caste].caste_name
local names = dfhack.units.getCasteRaw(unit).caste_name
local record = ensure_key(counts, names[0], {count=0, plural=names[1]})
record.count = record.count + 1
end)
Expand Down
2 changes: 1 addition & 1 deletion modtools/set-personality.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ end

-- Gets the range of the unit caste's min, average, and max value for a trait, as defined in the PERSONALITY creature tokens.
function getUnitCasteTraitRange(unit, trait)
local caste = df.creature_raw.find(unit.race).caste[unit.caste]
local caste = dfhack.units.getCasteRaw(unit)
local range = {}

range.min = caste.personality.a[df.personality_facet_type[trait]]
Expand Down
2 changes: 1 addition & 1 deletion set-orientation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function randomiseOrientation(unit, sex)
return
end

local caste = df.creature_raw.find(unit.race).caste[unit.caste]
local caste = dfhack.units.getCasteRaw(unit)

-- Build a weighted table for use in the weighted roll function
local sexname = getSexString(sex)
Expand Down
2 changes: 1 addition & 1 deletion uniform-unstick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end

local function bodyparts_that_can_wear(unit, item)
local bodyparts = {}
local unitparts = df.creature_raw.find(unit.race).caste[unit.caste].body_info.body_parts
local unitparts = dfhack.units.getCasteRaw(unit).body_info.body_parts

if item._type == df.item_helmst then
for index, part in ipairs(unitparts) do
Expand Down
2 changes: 1 addition & 1 deletion unretire-anyone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function showNemesisPrompt(advSetUpScreen)
not histFlags.deity and
not histFlags.force
then
local creature = df.creature_raw.find(histFig.race).caste[histFig.caste]
local creature = dfhack.units.getCasteRaw(histFig.race, histFig.caste)
local name = creature.caste_name[0]
if histFig.info and histFig.info.curse then
local curse = histFig.info.curse
Expand Down
5 changes: 1 addition & 4 deletions workorder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,7 @@ end

-- true/false or nil if no shearable_tissue_layer with length > 0.
local function canShearCreature(u)
local stls = world.raws.creatures
.all[u.race]
.caste[u.caste]
.shearable_tissue_layer
local stls = dfhack.units.getCasteRaw(u).shearable_tissue_layer

local any
for _, stl in ipairs(stls) do
Expand Down

0 comments on commit eea9cf7

Please sign in to comment.