From 75cc07e3b3b1eaf511566b63c4e855b9db628fb6 Mon Sep 17 00:00:00 2001 From: Alex ten Brink Date: Sat, 6 Jan 2024 10:46:19 +0100 Subject: [PATCH] Added TURD migration code. TURD options changed by a new version can now be reset for free the first 10 hours after loading a game with that new version. --- locale/en/tips.cfg | 2 ++ migrations/2.1.13.lua | 3 +++ scripts/turd/turd-migration.lua | 15 +++++++++++++++ scripts/turd/turd.lua | 18 +++++++++++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 migrations/2.1.13.lua create mode 100644 scripts/turd/turd-migration.lua diff --git a/locale/en/tips.cfg b/locale/en/tips.cfg index 31ff7e63..5c88de94 100644 --- a/locale/en/tips.cfg +++ b/locale/en/tips.cfg @@ -39,11 +39,13 @@ unavailable=Unavailable no-research=Needs research not-selected=Not selected unselect=Reverse selection +unselect-migrate=Reverse selection (free for __1__ seconds) open-in-tech-tree=Open in tech tree adjusted-speed=[font=default-semibold][color=255,230,192]Real speed: [/color][/font]__1__% admin-needed=Only a server administrator can select T.U.R.D. options. selected-alert=__1__: __2__ selected! (by: [color=__4__, __5__, __6__]__3__[/color]) unselected-alert=__1__: __2__ unselected! (by: [color=__4__, __5__, __6__]__3__[/color]) +migrated-alert=The path __2__ for TURD tech __1__ was changed in an update. You have selected this path, so you will be able to reset it for free in the next __3__ ingame hours. file-failure=Could not create file. file-success=File created successfully. visible-all=Visible: All diff --git a/migrations/2.1.13.lua b/migrations/2.1.13.lua new file mode 100644 index 00000000..7102bc84 --- /dev/null +++ b/migrations/2.1.13.lua @@ -0,0 +1,3 @@ +local turd_migrate = require('__pyalienlife__/scripts/turd/turd-migration') + +turd_migrate('moondrop-upgrade', 'cu') diff --git a/scripts/turd/turd-migration.lua b/scripts/turd/turd-migration.lua new file mode 100644 index 00000000..9f57bf83 --- /dev/null +++ b/scripts/turd/turd-migration.lua @@ -0,0 +1,15 @@ +return function(master_tech_name, sub_tech_name) + local reset_time_in_hours = 10 + local reset_time_in_ticks = reset_time_in_hours * 3600 * 60 + + global.turd_migrations = global.turd_migrations or {} + + for _, force in pairs(game.forces) do + global.turd_migrations[force.index] = global.turd_migrations[force.index] or {} + local turd_bonuses = global.turd_bonuses[force.index] + if turd_bonuses and turd_bonuses[master_tech_name] == sub_tech_name then + global.turd_migrations[force.index][sub_tech_name] = game.tick + reset_time_in_ticks + force.print{'turd.font', {'turd.migrated-alert', {'technology-name.'..master_tech_name}, {'technology-name.'..sub_tech_name}, reset_time_in_hours}} + end + end +end diff --git a/scripts/turd/turd.lua b/scripts/turd/turd.lua index 49e0ca6a..0e970e36 100644 --- a/scripts/turd/turd.lua +++ b/scripts/turd/turd.lua @@ -49,6 +49,10 @@ local function on_search(search_key, gui, player) end end +local function has_turd_migration(force_index, sub_tech_name) + return game.tick < (global.turd_migrations[force_index][sub_tech_name] or 0) +end + local function update_confirm_button(element, player, researched_technologies) local force_index = player.force_index global.turd_bonuses[force_index] = global.turd_bonuses[force_index] or {} @@ -63,7 +67,12 @@ local function update_confirm_button(element, player, researched_technologies) element.style = 'confirm_button_without_tooltip' element.caption = {'turd.select'} elseif selected_upgrade == element.tags.sub_tech_name then - if (global.turd_reset_remaining[force_index] or 0) > 0 then + if has_turd_migration(force_index, selected_upgrade)then + local ticks_remaining = global.turd_migrations[force_index][selected_upgrade] - game.tick + local seconds_remaining = math.floor(ticks_remaining / 60) + element.style = 'confirm_button_without_tooltip' + element.caption = {'turd.unselect-migrate', seconds_remaining} + elseif (global.turd_reset_remaining[force_index] or 0) > 0 then element.style = 'confirm_button_without_tooltip' element.caption = {'turd.unselect'} else @@ -440,12 +449,15 @@ gui_events[defines.events.on_gui_click]['py_turd_confirm_button'] = function(eve turd_bonuses[master_tech_name] = sub_tech_name apply_turd_bonus(force, master_tech_name, tech_upgrades[master_tech_name], find_all_assembling_machines(force)) else - if (global.turd_reset_remaining[force_index] or 0) <= 0 then + global.turd_reset_remaining[force_index] = global.turd_reset_remaining[force_index] or 0 + if global.turd_reset_remaining[force_index] <= 0 and not has_turd_migration(force_index, sub_tech_name) then return end force.print{'turd.font', {'turd.unselected-alert', {'technology-name.'..master_tech_name}, {'technology-name.'..sub_tech_name}, player.name, player.color.r, player.color.g, player.color.b}} turd_bonuses[master_tech_name] = NOT_SELECTED - global.turd_reset_remaining[force_index] = global.turd_reset_remaining[force_index] - 1 + if not has_turd_migration(force_index, sub_tech_name) then + global.turd_reset_remaining[force_index] = global.turd_reset_remaining[force_index] - 1 + end unselect_recipes_for_subtech(tech_upgrades[master_tech_name].sub_techs[selection], force, find_all_assembling_machines(force)) destroy_all_hidden_beacons(force) reapply_turd_bonuses(force)