Skip to content

Commit

Permalink
Merge pull request #1119 from dimwit105/conceivable-sizes
Browse files Browse the repository at this point in the history
Conceivable sizes
  • Loading branch information
myk002 authored May 16, 2024
2 parents 2f664e7 + f9a2aba commit c0daef1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Template for new versions:

## Misc Improvements
- `gui/gm-unit`: correctly display skill levels above Legendary+5
- `gui/unit-info-viewer`: now displays a unit's weight, relative to either dwarves, elephants or cats
- `gui/unit-info-viewer`: shows a unit's relative size to its race's average.

## Removed

Expand Down
46 changes: 40 additions & 6 deletions gui/unit-info-viewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ 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

local function get_name_chunk(unit)
return {
text=dfhack.units.getReadableName(unit),
Expand Down Expand Up @@ -328,17 +332,44 @@ local function get_dead_chunk(unit)
return {text=dfhack.units.getReadableName(unit)..str, pen=pen}
end

local function get_size_in_cc(unit)
-- internal measure is cubic centimeters divided by 10
return unit.body.size_info.size_cur * 10
local function get_conceivable_comparison(unit, comparison_unit)
--[[ the objective here is to get a (resaonably) small number to help concieve
how large a thing is. "83 dwarves" doesn't really help convey the size of an
elephant much better than 5m cc, so at certain breakpoints we will use
different animals --]]
local size = unit.body.size_info.size_cur
local dwarf_size = 6000
if size > dwarf_size*20 and get_creature_data(unit).creature_id ~= "ELEPHANT" then
return string.format('%.1f average elephants', size/500000)
elseif size <= dwarf_size*0.25 and get_creature_data(unit).creature_id ~= "CAT" then
return string.format('%.2f average cats', size/500)
else
return string.format('%.1f average dwarves', size/6000)
end

end

local function get_size_compared_to_median(unit)
local size_modifier = unit.appearance.size_modifier
if size_modifier >= 110 then
return "larger than average"
elseif size_modifier <= 90 then
return "smaller than average"
else
return "about average"
end
end

local function get_body_chunk(unit)
local blurb = ('%s appears to be about %d cubic centimeters in size.'):format(
get_pronoun(unit), get_size_in_cc(unit))
local blurb = ('%s weighs about as much as %s'):format(get_pronoun(unit), get_conceivable_comparison(unit, comparison_unit))
return {text=blurb, pen=COLOR_LIGHTBLUE}
end

local function get_average_size(unit)
local blurb = ('%s is %s in size.'):format(get_pronoun(unit), get_size_compared_to_median(unit))
return{text=blurb, pen=COLOR_LIGHTCYAN}
end

local function get_grazer_chunk(unit)
if not dfhack.units.isGrazer(unit) then return end
local caste = get_caste_data(unit)
Expand Down Expand Up @@ -450,7 +481,10 @@ function UnitInfo:refresh(unit, width)
add_chunk(chunks, get_max_age_chunk(unit), width)
add_chunk(chunks, get_ghostly_chunk(unit), width)
add_chunk(chunks, get_dead_chunk(unit), width)
add_chunk(chunks, get_body_chunk(unit), width)
if get_creature_data(unit).creature_id ~= "DWARF" then
add_chunk(chunks, get_body_chunk(unit), width)
end
add_chunk(chunks, get_average_size(unit), width)
add_chunk(chunks, get_grazer_chunk(unit), width)
add_chunk(chunks, get_milkable_chunk(unit), width)
add_chunk(chunks, get_shearable_chunk(unit), width)
Expand Down

0 comments on commit c0daef1

Please sign in to comment.