From 354dd5ae9897fbca85ab3e441158ef4f864c7f70 Mon Sep 17 00:00:00 2001 From: dimwit105 Date: Tue, 14 May 2024 15:29:37 -0400 Subject: [PATCH 1/7] Changed the size readout in unit-info-viewer to something a regular person can comprehend. Also added a line to include that particular unit's size compared against its own species --- gui/unit-info-viewer.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index ae230a2235..bb2ce59b7b 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -333,12 +333,43 @@ local function get_size_in_cc(unit) return unit.body.size_info.size_cur * 10 end +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 base_comparison_size = 6000 + if size > base_comparison_size*20 then + return string.format('%.3f average elephants', size/500000) + elseif size > base_comparison_size*0.25 then + return string.format('%.3f average dwarves', size/6000) + else + return string.format('%.3f average cats', size/500) + end + +end + +local function get_size_compared_to_median(unit) + local size_normal = unit.body.size_info.size_base + local size_modifier = unit.appearance.size_modifier + --return size_normal/get_caste_data(unit).misc.adult_size + 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) @@ -451,6 +482,7 @@ function UnitInfo:refresh(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) + 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) From c527e078cd046d59aa5233746d264da78c6fdf07 Mon Sep 17 00:00:00 2001 From: dimwit105 Date: Tue, 14 May 2024 15:37:53 -0400 Subject: [PATCH 2/7] Forgot to remove a comment --- gui/unit-info-viewer.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index bb2ce59b7b..399852e9c4 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -350,7 +350,6 @@ end local function get_size_compared_to_median(unit) local size_normal = unit.body.size_info.size_base local size_modifier = unit.appearance.size_modifier - --return size_normal/get_caste_data(unit).misc.adult_size if size_modifier >= 110 then return "larger than average" elseif size_modifier <= 90 then From 1f7bcbf746fc617d0825663a99185886408bb270 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 02:47:31 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gui/unit-info-viewer.lua | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index 399852e9c4..51e8667118 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -334,29 +334,29 @@ local function get_size_in_cc(unit) end 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 base_comparison_size = 6000 - if size > base_comparison_size*20 then - return string.format('%.3f average elephants', size/500000) - elseif size > base_comparison_size*0.25 then - return string.format('%.3f average dwarves', size/6000) - else - return string.format('%.3f average cats', size/500) - end - -end + --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 base_comparison_size = 6000 + if size > base_comparison_size*20 then + return string.format('%.3f average elephants', size/500000) + elseif size > base_comparison_size*0.25 then + return string.format('%.3f average dwarves', size/6000) + else + return string.format('%.3f average cats', size/500) + end + +end local function get_size_compared_to_median(unit) - local size_normal = unit.body.size_info.size_base - 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 + local size_normal = unit.body.size_info.size_base + 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) @@ -365,8 +365,8 @@ local function get_body_chunk(unit) 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} + 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) @@ -481,7 +481,7 @@ function UnitInfo:refresh(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) - add_chunk(chunks, get_average_size(unit), width) + 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) From b9c36a447d13af3b4eb3975563734e6a3dd0531f Mon Sep 17 00:00:00 2001 From: dimwit105 Date: Wed, 15 May 2024 12:08:35 -0400 Subject: [PATCH 4/7] Adjusted the formatting of comments Dwarves specifically will not display a weight in dwarves. Elephants/cats will still display a weight, but will do so in dwarves instead of 1 cat or elephants. Reduced the percision on meaurements. Cats have 2 decimal places, while dwarves/elephants only have 1. --- gui/unit-info-viewer.lua | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index 399852e9c4..ec40f93cac 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -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), @@ -328,27 +332,24 @@ 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 -end - 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 + --[[ 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 base_comparison_size = 6000 - if size > base_comparison_size*20 then - return string.format('%.3f average elephants', size/500000) - elseif size > base_comparison_size*0.25 then - return string.format('%.3f average dwarves', size/6000) + 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('%.3f average cats', size/500) + return string.format('%.1f average dwarves', size/6000) end end local function get_size_compared_to_median(unit) - local size_normal = unit.body.size_info.size_base local size_modifier = unit.appearance.size_modifier if size_modifier >= 110 then return "larger than average" @@ -365,7 +366,7 @@ local function get_body_chunk(unit) end local function get_average_size(unit) - local blurb = ('%s is %s in size'):format(get_pronoun(unit), get_size_compared_to_median(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 @@ -480,7 +481,9 @@ 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) From a0959b61bc2b3761b1548c627c3f189c6f24782c Mon Sep 17 00:00:00 2001 From: dimwit105 Date: Wed, 15 May 2024 12:18:31 -0400 Subject: [PATCH 5/7] Reformatted long comment Removed unneeded function No longer displays sizes as 1 Dwarf, Elephant, or Cat. Dwarves no longer reported weights, but elephants/cats will report weights in dwarves. Reduced percison, elephants/dwarves to 1 decimal place, while cats are at 2. --- gui/unit-info-viewer.lua | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index 830bcc9d1e..ec40f93cac 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -333,7 +333,6 @@ local function get_dead_chunk(unit) end local function get_conceivable_comparison(unit, comparison_unit) -<<<<<<< HEAD --[[ 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 @@ -359,31 +358,6 @@ local function get_size_compared_to_median(unit) else return "about average" end -======= - --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 base_comparison_size = 6000 - if size > base_comparison_size*20 then - return string.format('%.3f average elephants', size/500000) - elseif size > base_comparison_size*0.25 then - return string.format('%.3f average dwarves', size/6000) - else - return string.format('%.3f average cats', size/500) - end - -end - -local function get_size_compared_to_median(unit) - local size_normal = unit.body.size_info.size_base - 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 ->>>>>>> 1f7bcbf746fc617d0825663a99185886408bb270 end local function get_body_chunk(unit) @@ -392,13 +366,8 @@ local function get_body_chunk(unit) end local function get_average_size(unit) -<<<<<<< HEAD local blurb = ('%s is %s in size.'):format(get_pronoun(unit), get_size_compared_to_median(unit)) return{text=blurb, pen=COLOR_LIGHTCYAN} -======= - local blurb = ('%s is %s in size'):format(get_pronoun(unit), get_size_compared_to_median(unit)) - return{text=blurb, pen=COLOR_LIGHTCYAN} ->>>>>>> 1f7bcbf746fc617d0825663a99185886408bb270 end local function get_grazer_chunk(unit) @@ -512,15 +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) -<<<<<<< HEAD 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_body_chunk(unit), width) - add_chunk(chunks, get_average_size(unit), width) ->>>>>>> 1f7bcbf746fc617d0825663a99185886408bb270 add_chunk(chunks, get_grazer_chunk(unit), width) add_chunk(chunks, get_milkable_chunk(unit), width) add_chunk(chunks, get_shearable_chunk(unit), width) From fc5d3e9f838d2e1a4fbf850a34110da86e4ff985 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 16 May 2024 19:43:01 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gui/unit-info-viewer.lua | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/gui/unit-info-viewer.lua b/gui/unit-info-viewer.lua index ec40f93cac..2dced941ee 100644 --- a/gui/unit-info-viewer.lua +++ b/gui/unit-info-viewer.lua @@ -333,31 +333,31 @@ local function get_dead_chunk(unit) end 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 + --[[ 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 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 + 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) @@ -366,8 +366,8 @@ local function get_body_chunk(unit) 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} + 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) @@ -484,7 +484,7 @@ function UnitInfo:refresh(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_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) From f03e50d8ae0a31e90ded241977f87c4e24f41a83 Mon Sep 17 00:00:00 2001 From: dimwit105 Date: Thu, 16 May 2024 17:51:21 -0400 Subject: [PATCH 7/7] Adjusted the changelog to reflect changes --- changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 4f96a1a304..8e8a5c0e3f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,8 @@ Template for new versions: ## Fixes ## Misc Improvements +- `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