Skip to content

Commit

Permalink
Merge pull request CorsixTH#2578 from tobylane/newgoals3
Browse files Browse the repository at this point in the history
End condtions and progress report dialog improvements
  • Loading branch information
TheCycoONE authored Oct 26, 2024
2 parents b29f486 + 9c2c5ef commit 9ecc4ed
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CorsixTH/Lua/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local runDebugger = corsixth.require("run_debugger")
-- and add compatibility code in afterLoad functions
-- Recommended: Also replace/Update the summary comment

local SAVEGAME_VERSION = 205 -- Prevent staff grab spamming fix
local SAVEGAME_VERSION = 206 -- Add support for new win and lose criteria

class "App"

Expand Down
41 changes: 25 additions & 16 deletions CorsixTH/Lua/dialogs/fullscreen/progress_report.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ function UIProgressReport:UIProgressReport(ui)
self.red_font = gfx:loadFont("QData", "Font101V", false, palette)
self.normal_font = gfx:loadFont("QData", "Font100V", false, palette)
self.small_font = gfx:loadFont("QData", "Font106V")
self.panel_sprites = gfx:loadSpriteTable("QData", "Rep02V", true, palette)
-- Load all sprite tables needed for all goal icons
self.panel_sprites_table = {
MPointer = gfx:loadSpriteTable("Data", "MPointer"),
Rep02V = gfx:loadSpriteTable("QData", "Rep02V", true, palette)
}
self.panel_sprites = self.panel_sprites_table.Rep02V -- The default goals icons
end) then
ui:addWindow(UIInformation(ui, {_S.errors.dialog_missing_graphics}))
self:close()
Expand Down Expand Up @@ -66,12 +71,23 @@ function UIProgressReport:UIProgressReport(ui)
-- FIXME: res_value and cure_value are depersisted as floating points, using
-- string.format("%.0f", x) is not suitable due to %d (num) param in _S string
local tooltip
if crit_table.two_tooltips then
local direction = crit_table.win_value and "over" or "under"
tooltip = _S.tooltip.status[direction][crit_name]
else
tooltip = _S.tooltip.status[crit_name]
end
if crit_table.formats == 2 then
tooltip = _S.tooltip.status[crit_name]:format(math.floor(res_value), math.floor(cur_value))
tooltip = tooltip:format(math.floor(res_value), math.floor(cur_value))
elseif crit_table.formats == 3 then
tooltip = tooltip:format(math.floor(res_value) / 1000,
math.floor(cur_value) / 1000)
else
tooltip = _S.tooltip.status[crit_name]:format(math.floor(res_value))
tooltip = tooltip:format(math.floor(res_value))
end
if not crit_table.icon_file then -- Icons from QData/Rep02V
self:addPanel(crit_table.icon, x, 240)
end
self:addPanel(crit_table.icon, x, 240)
self:makeTooltip(tooltip, x, 180, x + 30, 180 + 90)
x = x + 30
end
Expand Down Expand Up @@ -194,6 +210,10 @@ function UIProgressReport:draw(canvas, x, y)
result_y = result_y + 1
end
self.panel_sprites:draw(canvas, 2 + sprite_offset, x + lx, y + 237 - result_y)
if crit_table.icon_file then -- Icons not from QData/Rep02V
local icon_sprites = self.panel_sprites_table[crit_table.icon_file]
icon_sprites:draw(canvas, crit_table.icon, x + lx, y + 240)
end
lx = lx + 30
end
end
Expand All @@ -208,18 +228,7 @@ function UIProgressReport:draw(canvas, x, y)
end

function UIProgressReport:afterLoad(old, new)
if old < 179 then
local gfx = TheApp.gfx

local palette = gfx:loadPalette("QData", "Rep01V.pal", true)
self.background = gfx:loadRaw("Rep01V", 640, 480, "QData", "QData", "Rep01V.pal", true)
self.red_font = gfx:loadFont("QData", "Font101V", false, palette)
self.normal_font = gfx:loadFont("QData", "Font100V", false, palette)
self.small_font = gfx:loadFont("QData", "Font106V")
self.panel_sprites = gfx:loadSpriteTable("QData", "Rep02V", true, palette)
end

if old < 188 then
if old < 206 then
self:close()
end

Expand Down
30 changes: 19 additions & 11 deletions CorsixTH/Lua/endconditions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. --]]

-- The "Winning and Losing Conditions" section of level files uses Criteria
-- numbers from the order of this table.
-- Icon and formats are used in the progress report dialog.
-- numbers from the order of this table. Any Criteria numbers higher than
-- the size of this table will be silently ignored.
-- Icon, icon_file, formats and two_tooltips are used in the progress report dialog.
local local_criteria_variable = {
{name = "reputation", icon = 10, formats = 2},
{name = "balance", icon = 11, formats = 2},
Expand All @@ -31,7 +32,7 @@ local local_criteria_variable = {
}

-- A table of functions for fetching criteria values that cannot be measured
-- directly from a hospital attribute of the same name.
-- directly from a hospital attribute of the same name.
local get_custom_criteria = {
balance = function(hospital) return hospital.balance - hospital.loan end,
}
Expand Down Expand Up @@ -72,7 +73,7 @@ end
--!param win (boolean) If the win goals are being filled this time
function EndConditions:_loadGoals(criteria_tbl, goals, start, win)
for _, values in pairs(criteria_tbl) do
if values.Criteria ~= 0 then
if local_criteria_variable[values.Criteria] then
local crit_name = local_criteria_variable[values.Criteria].name
if not goals[values.Group] then goals[values.Group] = {} end
goals[values.Group][crit_name] = {
Expand All @@ -81,7 +82,9 @@ function EndConditions:_loadGoals(criteria_tbl, goals, start, win)
criterion = values.Criteria,
max_min = values.MaxMin,
icon = local_criteria_variable[values.Criteria].icon,
icon_file = local_criteria_variable[values.Criteria].icon_file,
formats = local_criteria_variable[values.Criteria].formats,
two_tooltips = local_criteria_variable[values.Criteria].two_tooltips,
start = start[crit_name] or 0,
}
if win then
Expand Down Expand Up @@ -124,7 +127,7 @@ end
-- lose criteria with the smallest gap between current value and boundary,
-- then fill up to five with win criteria in the best group.
function EndConditions:generateReportTable(hospital)
local count, lose_table, report_table, tmp_table = 0, {}, {}, {}
local count, lose_table, key_lose_goals_table, report_table, unique_criteria_set = 0, {}, {}, {}, {}
local win_group = self.win_goals[self:_findBestWinGroup(hospital)] or {}

-- Collect lose criteria over the boundary
Expand All @@ -134,25 +137,30 @@ function EndConditions:generateReportTable(hospital)
-- Get the most relevant of each criterion in all groups
for _, group_table in pairs(lose_table) do
for crit_name, crit_table in pairs(group_table) do
if not tmp_table[crit_name] or tmp_table[crit_name].gap > crit_table.gap then
tmp_table[crit_name] = crit_table
if not key_lose_goals_table[crit_name] or key_lose_goals_table[crit_name].gap > crit_table.gap then
key_lose_goals_table[crit_name] = crit_table
end
end
end
-- Move into a numbered table
for _, crit_table in pairs(tmp_table) do
for _, crit_table in pairs(key_lose_goals_table) do
table.insert(report_table, crit_table)
count = count + 1
if count == 5 then break end
end
-- If there are more than five, keep the five criteria closest to meeting lose conditions
if count > 5 then
table.sort(report_table, function(a,b) return a.gap > b.gap end)
for n = 6, #report_table do report_table[n] = nil end
end

-- Fill up the report table with win criteria not already present as lose criteria
for _, crit in pairs(report_table) do unique_criteria_set[crit.name] = true end
for i = 1, #local_criteria_variable do
if count == 5 then break end
local name = local_criteria_variable[i].name
if win_group[name] and not tmp_table[name] then
if win_group[name] and not unique_criteria_set[name] then
count = count + 1
report_table[count] = win_group[name]
if count == 5 then break end
end
end

Expand Down

0 comments on commit 9ecc4ed

Please sign in to comment.