Skip to content

Commit

Permalink
Added TURD migration code. TURD options changed by a new version can …
Browse files Browse the repository at this point in the history
…now be reset for free the first 10 hours after loading a game with that new version.
  • Loading branch information
Septiple committed Jan 6, 2024
1 parent 71b773b commit 75cc07e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions locale/en/tips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions migrations/2.1.13.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local turd_migrate = require('__pyalienlife__/scripts/turd/turd-migration')

turd_migrate('moondrop-upgrade', 'cu')
15 changes: 15 additions & 0 deletions scripts/turd/turd-migration.lua
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions scripts/turd/turd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 75cc07e

Please sign in to comment.