Skip to content

Commit

Permalink
Merge pull request #1245 from Bumber64/master
Browse files Browse the repository at this point in the history
Make use of dfhack.units.getCasteRaw
  • Loading branch information
myk002 authored Jul 31, 2024
2 parents b8e0af4 + 2a6eeaa commit 0ac7959
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 32 deletions.
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 0ac7959

Please sign in to comment.