Page 1 of 1

Unlocking shortcuts by research

Posted: Sun Jun 19, 2022 10:54 pm
by Pi-C
GCKI used to work with a "car key" item. The recipe for this item would be unlocked when "automobilism" or "cargo-ships" was researched. Now I've changed the prototype of the keys from Prototype/Item to Prototype/Shortcut, and I've got a problem: technology.effects["unlock-recipe"] won't apply anymore, and technology_to_unlock is supposed to be a string value, so the shortcut can be unlocked by one technology only.

I've tried to work around this:

Code: Select all

GCKI.unlock_tech_map = {
  -- Required mod         Technology
  ["base"]              = "automobilism",
  ["cargo-ships"]  = "water_transport",
}

local tech

local unlock = {
  type = "nothing",
  icon = icon,
  icon_size = 64,
  icon_mipmaps = 1,
  effect_description = {"techeffect-description.technology-effect"},
}

for mod_name, tech_name in pairs(GCKI.unlock_tech_map) do
  tech = data.raw.technology[tech_name]
  if mods[mod_name] and tech then
    tech.effects = tech.effects or {}
    table.insert(tech.effects, unlock)
  end
end
However, only "automobilism" (the tech specified in LuaShortcut.technology_to_unlock) will get the effect in the game. Is there really no way to unlock a shortcut by researching any of several techs?

Re: Unlocking shortcuts by research

Posted: Mon Jun 20, 2022 4:29 am
by robot256
It's definitely odd that shortcuts put the technology reference in the shortcut prototype rather than the technology unlock list. That could be a mod interface request.

To get around it, I suppose the answer is to put some code in the on_research_completed and related events, to keep the shortcut unlock state consistent with what technologies are researched.

Re: Unlocking shortcuts by research

Posted: Mon Jun 20, 2022 8:54 am
by Pi-C
robot256 wrote: Mon Jun 20, 2022 4:29 am It's definitely odd that shortcuts put the technology reference in the shortcut prototype rather than the technology unlock list. That could be a mod interface request.
OK, I'll do that. I'd also be content if technology_to_unlock could be either a string or an array of strings.

To get around it, I suppose the answer is to put some code in the on_research_completed and related events, to keep the shortcut unlock state consistent with what technologies are researched.
I don't know what happened yesterday. I'm pretty sure I didn't see the keys' symbol among the effects of the "water_transport" tech, but there it is:
tech.png
tech.png (57.35 KiB) Viewed 1487 times
Still, having to manually add a "nothing" unlock to techs is not really intuitive. :-)

By the way, I was already listening to on_research_completed and on_research_reversed. This way, I can turn off the event handlers for on_player_*selected_area and on_lua_shortcut when they are not needed (i.e., when no force has researched an unlock tech).