From e2d2693d3720e5747b34e95866c4898d505e6155 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 1 Sep 2024 13:14:57 -0700 Subject: [PATCH] order roles by room value requirement --- docs/plugins/preserve-rooms.rst | 3 ++- plugins/lua/preserve-rooms.lua | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/plugins/preserve-rooms.rst b/docs/plugins/preserve-rooms.rst index c8cfea98b0..7eb4e064ff 100644 --- a/docs/plugins/preserve-rooms.rst +++ b/docs/plugins/preserve-rooms.rst @@ -73,7 +73,8 @@ Overlay The ``preserve-rooms.reserved`` overlay indicates whether a zone is disabled because it is being reserved for a unit that left the map and is expected to return. For unreserved rooms, it provides widgets to mark the zone as -associated with a specific noble or administrative role. +associated with a specific noble or administrative role. The list of roles is +ordered by how valuable the rooms assigned to that role need to be. Notes ----- diff --git a/plugins/lua/preserve-rooms.lua b/plugins/lua/preserve-rooms.lua index f3a89b2295..a62d8b19cb 100644 --- a/plugins/lua/preserve-rooms.lua +++ b/plugins/lua/preserve-rooms.lua @@ -297,7 +297,12 @@ OVERLAY_WIDGETS = { local function add_positions(positions, entity) if not entity then return end for _,position in ipairs(entity.positions.own) do - positions[position.id] = {id=position.id, code=position.code, replaced_by=position.replaced_by} + positions[position.id] = { + id=position.id, + code=position.code, + replaced_by=position.replaced_by, + required_value=position.required_office + position.required_bedroom + position.required_dining + position.required_tomb, + } end end @@ -317,7 +322,7 @@ local function get_codes(positions) end end - -- add reverse links for promotion chains + -- add reverse links for promotion chains and record whether it has a room requirement for _,group in pairs(grouped) do for _,position in pairs(group) do if position.replaced_by ~= -1 then @@ -327,19 +332,25 @@ local function get_codes(positions) end -- produce combined codes - local codes = {} + local diplay_codes = {} for id,group in pairs(grouped) do local group_codes = {} local position = group[id] while position do table.insert(group_codes, 1, position.code) + group_codes.required_value = math.max(group_codes.required_value or 0, position.required_value) position=group[position.prev] end - table.insert(codes, group_codes) + table.insert(diplay_codes, group_codes) end - table.sort(codes, function(a, b) return a[1] < b[1] end) + table.sort(diplay_codes, function(a, b) + if a.required_value == b.required_value then + return a[1] < b[1] + end + return a.required_value > b.required_value + end) - return codes + return diplay_codes end local function get_api_lookup_table(codes)