Skip to content

Commit

Permalink
Added partial TURD reset tech
Browse files Browse the repository at this point in the history
  • Loading branch information
Septiple committed Dec 4, 2023
1 parent 3a7d444 commit f6765df
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 51 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Date: ???
- added a new recipe for cumene+nickel+arthropod blood into organic solvent
- buffed bioprinting by removing primers from the pluripotent stem cells recipes
- fixed that bioprinting stage 2 unlocked both mk1 and mk2 of brain printing. mk1 recipe moved down to bioprinting stage 1
- added T.U.R.D unselect infinite tech to allow the indecisive to revert a single T.U.R.D selection
---------------------------------------------------------------------------------------------------
Version: 2.1.12
Date: 2023-11-22
Expand Down
4 changes: 3 additions & 1 deletion locale/en/techs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ vatbrain-mk02=Vatbrain research boost - Stage 2
vatbrain-mk03=Vatbrain research boost - Stage 3
vatbrain-mk04=Vatbrain research boost - Stage 4
turd-respec=T.U.R.D. reset
turd-partial-respec=T.U.R.D. reselect
biofluid-mk01=Biofluid network - Stage 1
biofluid-mk02=Biofluid network - Stage 2
biofluid-mk03=Biofluid network - Stage 3
Expand Down Expand Up @@ -956,4 +957,5 @@ neutron-bombardment=The process involves placing the Numal in a controlled envir
guarpulse=A nanobot-based technology that can monitor the health of individual guar plants in real-time, detecting diseases or nutrient deficiencies before they become a problem. These nanobots can also deliver targeted nutrients or pesticides directly to the plants, reducing waste and increasing efficiency. The semi-perfect environment allows for the occasional production of zinc nanocomplex as a byproduct.
aquaguar=A genetically engineered strain of guar that is resistant to drought and can grow in saline soil. This strain of guar would require less water and fertilizer to grow, making it more sustainable to cultivate.
hh=A drone-based system that uses advanced sensors and AI algorithms to identify the most productive areas of a guar plantation. The drones can then autonomously harvest the ripe guar pods, maximizing yield and minimizing costs.
turd-respec=Resets all T.U.R.D. selections.
turd-respec=Resets all T.U.R.D. selections.
turd-partial-respec=Allows you to reselect an option for one T.U.R.D.
5 changes: 4 additions & 1 deletion locale/en/tips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ biofluid=You’ve successfully bio-engineered [entity=gobachov], [entity=huzu],

[turd]
font=[img=turd] [font=default-semibold][color=114, 192, 12]__1__[/color][/font]
resets-left=[font=default-semibold][color=255,230,192]T.U.R.D. resets left: [/color][/font]__1__
module=T.U.R.D. module effect
recipe=T.U.R.D. recipe
recipe-removal=T.U.R.D. recipe removal
Expand All @@ -34,13 +35,15 @@ tech=T.U.R.D. technology
tech-2=Unlocks a choice between three upgrades to permanently change the behavior of affected buildings. Make a selection from the pY codex.
select=Select
selected=Selected
unavalible=Unavailable
unavailable=Unavailable
no-research=Needs research
not-selected=Not selected
unselect=Reverse selection
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])
file-failure=Could not create file.
file-success=File created successfully.
visible-all=Visible: All
Expand Down
2 changes: 1 addition & 1 deletion locale/ru/tips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tech=Технология Т.У.Р.Д.
tech-2=Открывает выбор между тремя улучшениями, которые навсегда изменят поведение затронутых зданий. Сделайте выбор в кодексе pY.
select=Выбрать
selected=Выбрано
unavalible=Недоступно
unavailable=Недоступно
no-research=Необходимо исследовать
not-selected=Не выбрано
open-in-tech-tree=Открыть в дереве технологий
Expand Down
2 changes: 1 addition & 1 deletion locale/zh-CN/pyalienlife.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3587,7 +3587,7 @@ tech=T.U.R.D.科技
tech-2=解锁三个升级选项,请从Py宝典中进行选择。
select=选择
selected=已选
unavalible=不可用
unavailable=不可用
no-research=需要研究
not-selected=未选中
open-in-tech-tree=在科技列表中打开
Expand Down
47 changes: 47 additions & 0 deletions prototypes/technologies/turd-respec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,50 @@ TECHNOLOGY {
is_turd = true,
localised_description = {'', {'turd.font', {'turd.tech'}}, '\n', {'technology-description.turd-respec'}}
}

TECHNOLOGY {
type = 'technology',
name = 'turd-partial-respec-1',
icon = '__pyalienlifegraphics3__/graphics/technology/updates/restart.png',
icon_size = 128,
prerequisites = {'chemical-science-pack'},
effects = {},
unit = {
count_formula = '2^(L-1)*5000',
ingredients = {
{'automation-science-pack', 10},
{'py-science-pack-1', 6},
{'logistic-science-pack', 3},
{'py-science-pack-2', 2},
{'chemical-science-pack', 1},
},
time = 1200,
},
max_level = 1,
is_turd = true,
localised_description = {'', {'turd.font', {'turd.tech'}}, '\n', {'technology-description.turd-partial-respec'}}
}

TECHNOLOGY {
type = 'technology',
name = 'turd-partial-respec-2',
icon = '__pyalienlifegraphics3__/graphics/technology/updates/restart.png',
icon_size = 128,
prerequisites = {'turd-partial-respec-1'},
effects = {},
unit = {
count_formula = '2^(L-1)*2500',
ingredients = {
{'automation-science-pack', 20},
{'py-science-pack-1', 10},
{'logistic-science-pack', 6},
{'py-science-pack-2', 3},
{'chemical-science-pack', 2},
{'production-science-pack', 1},
},
time = 1200,
},
max_level = 'infinite',
is_turd = true,
localised_description = {'', {'turd.font', {'turd.tech'}}, '\n', {'technology-description.turd-partial-respec'}}
}
128 changes: 81 additions & 47 deletions scripts/turd/turd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,30 @@ 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
element.style = 'confirm_button_without_tooltip_unhoverable'
element.caption = {'turd.selected'}
if global.turd_reset_remaining > 0 then
element.style = 'confirm_button_without_tooltip'
element.caption = {'turd.unselect'}
else
element.style = 'confirm_button_without_tooltip_unhoverable'
element.caption = {'turd.selected'}
end
else
element.style = 'red_back_button_unhoverable'
element.caption = {'turd.unavalible'}
element.caption = {'turd.unavailable'}
end
end

local function create_turd_page(gui, player)
local textbox_frame = gui.add{type = 'frame', direction = 'vertical'}
local textbox_frame = gui.add{type = 'frame', direction = 'vertical', name = 'textbox_frame'}
textbox_frame.style.horizontally_stretchable = true
local label = textbox_frame.add{type = 'label', caption = {'pywiki-descriptions.turd'}, style = 'label_with_left_padding'}
label.style.single_line = false

if global.turd_reset_remaining ~= 0 then
local reset_label = textbox_frame.add{type = 'label', caption = {'turd.resets-left', global.turd_reset_remaining}, style = 'label_with_left_padding', name = 'py_resets_left'}
reset_label.style.single_line = false
end

local py_select_view = textbox_frame.add{type = 'drop-down', name = 'py_select_view', items = views, selected_index = global.turd_views[player.index] or 1}
py_select_view.style.width = 200
py_select_view.style.top_margin = 10
Expand Down Expand Up @@ -292,30 +302,56 @@ local function find_all_assembling_machines(force)
return assembling_machine_list
end

local function apply_turd_bonus(force, master_tech_name, tech_upgrade, assembling_machine_list)
local turd_bonuses = global.turd_bonuses[force.index] or {}
local selection = turd_bonuses[master_tech_name] or NOT_SELECTED
if selection == NOT_SELECTED then return end
local sub_tech = tech_upgrade.sub_techs[selection]

local recipes = force.recipes
local item_prototypes = game.item_prototypes
for _, effect in pairs(sub_tech.effects) do
if effect.type == 'unlock-recipe' then
recipes[effect.recipe].enabled = true
elseif effect.type == 'recipe-replacement' then
local old, new = recipes[effect.old], recipes[effect.new]
if old.enabled then recipe_replacement(old, new, force, assembling_machine_list) end
elseif effect.type == 'module-effects' then
module_effects(tech_upgrade, sub_tech, assembling_machine_list, force, item_prototypes)
end
end
end

local function reapply_turd_bonuses(force)
global.turd_unlocked_modules[force.index] = {}
local recipes = force.recipes
local turd_bonuses = global.turd_bonuses[force.index] or {}
local assembling_machine_list = find_all_assembling_machines(force)
local item_prototypes = game.item_prototypes

for master_tech_name, tech_upgrade in pairs(tech_upgrades) do
local selection = turd_bonuses[master_tech_name] or NOT_SELECTED
if selection == NOT_SELECTED then goto continue end
local sub_tech = tech_upgrade.sub_techs[selection]

for _, effect in pairs(sub_tech.effects) do
if effect.type == 'unlock-recipe' then
recipes[effect.recipe].enabled = true
elseif effect.type == 'recipe-replacement' then
local old, new = recipes[effect.old], recipes[effect.new]
if old.enabled then recipe_replacement(old, new, force, assembling_machine_list) end
elseif effect.type == 'module-effects' then
module_effects(tech_upgrade, sub_tech, assembling_machine_list, force, item_prototypes)
apply_turd_bonus(force, master_tech_name, tech_upgrade, assembling_machine_list)
end
end

local function unselect_recipes_for_subtech(sub_tech, force, assembling_machine_list)
local recipes = force.recipes
for _, effect in pairs(sub_tech.effects) do
if (effect.type == 'unlock-recipe' or effect.type == 'recipe-replacement') and not effect.also_unlocked_by_techs then
local recipe = recipes[effect.new or effect.recipe]
if recipe and recipe.enabled then
recipe_replacement(recipe, effect.old and recipes[effect.old], force, assembling_machine_list)
end
end
end
end

::continue::
local function destroy_all_hidden_beacons(force)
global.turd_unlocked_modules[force.index] = {}
for unit_number, beacon in pairs(global.turd_beaconed_machines) do
if not beacon.valid then
global.turd_beaconed_machines[unit_number] = nil
elseif beacon.force == force then
global.turd_beaconed_machines[unit_number] = nil
beacon.destroy()
end
end
end

Expand All @@ -337,51 +373,48 @@ gui_events[defines.events.on_gui_click]['py_turd_confirm_button'] = function(eve
local turd_bonuses = global.turd_bonuses[force.index] or {}
global.turd_bonuses[force.index] = turd_bonuses
local selection = turd_bonuses[master_tech_name] or NOT_SELECTED
if selection ~= NOT_SELECTED then return end
turd_bonuses[master_tech_name] = sub_tech_name
force.print{'turd.font', {'turd.selected-alert', {'technology-name.'..master_tech_name}, {'technology-name.'..sub_tech_name}, player.name, player.color.r, player.color.g, player.color.b}}
if selection == NOT_SELECTED then
force.print{'turd.font', {'turd.selected-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] = 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 <= 0 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 = global.turd_reset_remaining - 1
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)

sub_tech_flow.parent.parent.textbox_frame.py_resets_left.caption = {'turd.resets-left', global.turd_reset_remaining}
end

for _, sub_tech in pairs(sub_tech_flow.children) do
local confirm_button = sub_tech.info_flow.py_turd_confirm_button
update_confirm_button(confirm_button, player)
end

reapply_turd_bonuses(force)
end

Turd.events.on_init = function()
global.turd_bonuses = global.turd_bonuses or {}
global.turd_beaconed_machines = global.turd_beaconed_machines or {}
global.turd_unlocked_modules = global.turd_unlocked_modules or {}
global.turd_views = global.turd_views or {}
global.turd_reset_remaining = global.turd_reset_remaining or 0
end

local function respec(force)
local function respec_all(force)
local assembling_machine_list = find_all_assembling_machines(force)
local recipes = force.recipes
for _, tech_upgrade in pairs(tech_upgrades) do
for _, sub_tech in pairs(tech_upgrade.sub_techs) do
for _, effect in pairs(sub_tech.effects) do
if (effect.type == 'unlock-recipe' or effect.type == 'recipe-replacement') and not effect.also_unlocked_by_techs then
local recipe = recipes[effect.new or effect.recipe]
if recipe and recipe.enabled then
recipe_replacement(recipe, effect.old and recipes[effect.old], force, assembling_machine_list)
end
end
end
unselect_recipes_for_subtech(sub_tech, force, assembling_machine_list)
end
end

global.turd_unlocked_modules[force.index] = {}
global.turd_bonuses[force.index] = {}
for unit_number, beacon in pairs(global.turd_beaconed_machines) do
if not beacon.valid then
global.turd_beaconed_machines[unit_number] = nil
elseif beacon.force == force then
global.turd_beaconed_machines[unit_number] = nil
beacon.destroy()
end
end
destroy_all_hidden_beacons(force)
end

local function starts_with(str, start)
Expand All @@ -395,8 +428,11 @@ local function on_researched(event)
if tech_upgrades[technology.name] then
global.turd_bonuses[force.index] = global.turd_bonuses[force.index] or {}
global.turd_bonuses[force.index][technology.name] = NOT_SELECTED
elseif starts_with(technology.name, 'turd-partial-respec') and game.tick ~= 0 then
global.turd_reset_remaining = global.turd_reset_remaining + 1
return
elseif starts_with(technology.name, 'turd-respec') and game.tick ~= 0 then
respec(force)
respec_all(force)
return
end

Expand All @@ -412,8 +448,6 @@ local function on_unresearched(event)
if tech_upgrades[technology.name] then
force.reset_technology_effects()
end

if starts_with(technology.name, 'turd-respec') then on_researched(event) end
end

Turd.events.on_research_finished = on_researched
Expand Down

0 comments on commit f6765df

Please sign in to comment.