Stellaris开发日志#222 | 9/2 莱姆更新中的模组能力

牧游社 牧有汉化翻译
Stellaris Dev Diary #222 - Moddability Updates in LEM
Caligula Caesar, Stellaris Technical Scripter
Welcome to another Stellaris Modding Dev Diary! Today, I'll be talking you through some of the new scripting language features in the upcoming 3.1 patch.
欢迎来到新一篇Stellaris的开发日志!今天,我要给大伙说说即将到来的3.1版本号补丁里一些新的脚本语言特性。
We have already mentioned that Traditions are considerably more moddable now with the new system, with far less heavy lifting needed in the gui and loc files. I can also confirm that you can, for instance, now script in tradition trees that only become available if you make certain decisions during the game. But today, the main focus will lie on variables.
我们之前已经说过,在新系统中传统Traditions对Mod的适应性更强,不再需要对gui和loc文件进行艰难的修改了。我也可以确认其他一些事,举例来说,你可以编写脚本创造那种你必须在游戏内做出某些决定才能用的传统树。不过今天,主要内容还是变量。

Variables
变量
I mentioned last time that we have been looking to do more with variables. In the last patch, several more ways to save various bits of information in the game were added, but the biggest missing one was an easy way to get trigger values, like for example the number of pops on a planet. You also were still quite limited in where you could use variables, especially compared to PDS' newer games like CK3. Also, the syntax for using them was not quite ideal, in many cases.
上次我说过,我们一直在试图更多地利用一下变量。上一个补丁中加入了几个在游戏中保存各种各样的信息片段的方法,但是最大的缺失是一个轻松获取触发器数值的方法,比如一个行星上的人口数。你能使用变量的地方仍然相当有限,特别是相对于CK3这种PDS旗下比较新的游戏来说。并且,在很多情况下,能使用他们的语法也并非很理想。
With 3.1, we have greatly increased the power of variables. First of all, the format: previously, when you wanted to get the value of a variable, you had to refer to… well, the variable itself, and that was all. Now, you can do a few more things:
在3.1版本号中,我们已经极大地增强了变量的能力。首先是格式:之前,如果你想获取一个变量的值,你就得参考……变量本身,这就是所有能做的事了。现在,你可以做点新东西了。
value = my_var
#gets the value of my_var variable set on the current scope
#获取当前作用域内my_var变量的值
value = from.capital_scope.my_var
#gets the value of the my_var variable set on from’s capital
#从当前帝国的首都获取my_var变量的值
value = trigger:num_pops
#gets the number of pops in the current scope
#获取当前作用域内的人口数
value = from.capital_scope.trigger:num_pops
#gets the number of pops in from’s capital
#从当前帝国的首都获取人口数
So you can do dot scoping, which saves a lot of ugliness, and is a big improvement as it is. And as you can see, you can also refer to triggers, with trigger:<trigger>. This will support any trigger checking a number and just a number, with no { }.
现在你可以设定点作用域,省去了许多麻烦,算是不折不扣的重大改进。如你所见,你也可以用trigger:<trigger>指向触发器。这能让任何触发器检定一个数字,也只有一个数字,没有{}。
(Note: the previous, ugly format for copying variables across different scopes has been removed. The one where you'd specify "value = { scope = x variable = y }")
(注意:之前那种非常麻烦的在不同作用域内复制变量的格式已经被移除了。就是这种你需要声明“value = { scope = x variable = y }”)的格式。)
3.0 already had an effect, export_trigger_to_variable, but it only worked with fleet_power. That was the prototype; the functionality has been expanded to all such triggers. Importantly, that effect lets you get values from triggers that are a bit more complex, with { }, that are still comparing a single number:
3.0版本号已经有了一个效果,比如export_trigger_to_variable,但是那只能和fleet_power一起生效。这就是原型了,现在这一功能已经扩展至所有这类触发器。重要的是,该效果允许你从稍微复杂一点的触发器中获取数值,带有{}的那种,且依然只比较一个数值。
export_trigger_value_to_variable = {
trigger = num_assigned_jobs
parameters = {
job = miner
}
variable = num_miner_jobs
}
3.0 also, to mention it again, added a bunch more ways to get game values such as modifier numbers and resource stockpiles to variables. It also added a few more places where you could use them: multipliers in add_resource and add_modifier, for instance. With 3.1, we have added a lot more things that you can use a variable for:
再提一次3.0版本号吧,它也加入了许多从游戏中的数值——比如修正项数值和资源储量中,获取变量数值的方法。它也增加了一些你能使用的几个新地方:比如add_resource 和 add_modifier中的乘子。在3.1版本号中,我们已经增加了更多的你可以使用变量做的东西:
• As values in triggers checking single numbers, e.g. "num_pops > my_variable", "intel = { who = from value < trigger:num_pops }"
• 在触发器中作为数值检定单个数字,例如“num_pops > my_variable”,“intel = { who = from value < trigger:num_pops }”
• As values in effects using a single number, e.g. "add_experience = my_variable".
• 在使用单个数字的效果中作为数值使用,例如“add_experience = my_variable”
• As a multiplier parameter in triggered resource tables (e.g. in a building)
• 作为已触发的资源表中的乘子参数(例如在某个建筑中):
resources = {
category = planet_buildings
cost = {
trigger = { <triggers> }
minerals = 100
}
multiplier = my_var/owner.trigger:num_pops
}
• In MTTH/AI Chance modifiers:
• 在MTTH或AI几率的修正项中:
ai_chance = {
factor = 1
modifier = {
add/factor = my_var/trigger:num_pops
is_variable_set = my_var
}
}
• add_modifier now has a time_multiplier as well as a multiplier parameter, you can use it there. E.g. for death cults, this is used to apply a modifier for 10 years X edict_length_mult
• add_modifier 现在有了一个 time_multiplier,以及一个乘子参数,你可以在那里使用它。例如,对于死亡教团来说,这被用于施加一个修正,持续(10 X edict_length_mult)。
• In ordered_script_lists: a feature yoinked from our newer games. I’ll let the trigger docs entry explain: ordered_owned_fleet - Iterate through each fleet owned by the country - executes the enclosed effects on one of them for which the limit triggers return true. Picks the specific object according to the order specified (position 0, order_by = trigger:num_pops would run the effects on the X with the most pops)
• 在ordered_script_lists中:一个从我们比较新的游戏中搞来的特性。我会用触发器文档记录来说明。ordered_owned_fleet – 在国家拥有的每个舰队中迭代 – 在限制触发器返回值为真的其中一支舰队中,执行封闭效果。以特定的顺序选取特定对象(position 0, order_by = trigger:num_pops 会在拥有最多人口的X中执行效果)。
ordered_owned_fleet = {
limit = { <triggers> }
position = <integer, starting with 0>
order_by = <variable>/trigger:<trigger>
inverse = yes/no (default: no - if yes, then 0 is lowest rather than highest)
<effects>
}
Supported Scopes: country
• If your variable is too exact a number, you can now use round_variable_to_nearest to round its value to e.g. the nearest multiple of 10.
• 如果你的变量作为数字的话太过精确,你现在可以用round_variable_to_nearest将其数值取整,例如取整至最接近的10的倍数。
A summary of these functionalities have been added to an information file in the events folder (and attached to this post). Also, I could well imagine further expanding on these usages of variables, so it’s quite possible there will be even more coming along these lines in future. The changes have already proven extremely useful to us, e.g.:
一份关于这些功能的概述已添加至events文件夹下的一个信息文件中(本文后也有附件)。另外,我也可以设想进一步拓展变量的使用范围,所以未来拓展这些说明也是很有可能的。这些改动对我们来说已经被证明是非常有用的,例如:
• Improving Death Cult rewards: cut about 1000 lines of script and still ended up with the new version taking more factors into account to determine the adequate reward for you!
• 改进死亡教团回报:节省了大约1000行代码,但是新版本仍然考虑了更多因素,以确定对你而言合适的回报
• Fixing Golden Rule cash payouts: the previous solution was to fudge the numbers and give you an amount with a rather tenuous connection to the actual pay-in. This is no longer necessary.
• 确定黄金律(译注:联邦主席继位决斗法的一种)需要付款的数额:之前的解决方案回避了数值问题,只会给你一个和真正的预付款没多大关系的数额。以后就没必要这么做了。
• Improving Federation Science Leadership Challenge: adding the actual number of techs and repeatable techs you have researched as a factor
• 改进联邦科研继任挑战(译注:应该指的是继位决斗法里“论文答辩”这个选项):增加了你已经研究的科技和可重复科技作为一个因素
• And more.
• 以及更多。

Sprite Sheet Changes
精灵表单改动
That was already quite a lot, but there's a few more things that I'd like to highlight. Firstly, certain older elements of the game used sprite sheets for their icons - a system where a list of icons would all be in a row on one image file, and we'd specify that we'd want to use, say, the 5th icon on the list. We had a few issues with these inhouse (the colony automation button currently accidentally being a robotic cow springs to mind), and modders have pointed out that they are a pretty bad overwriting bottleneck, since only one mod can overwrite the sprite sheet at a time, and therefore only one can add extra types of that object that add new graphics at a time.
上边已经说了不少了,不过我还是想多强调几件事。首先,游戏里一些比较老的元素在它们的图标中使用了“精灵表单”——一种在一个图片文件内放一排图标的系统,然后我们声明我们想用哪一个,比方说表里的第五个。我们在这些内部开发的东西上遇到过一些问题(我突然想到了殖民地自动化按钮意外成了一个机械奶牛的事情),Mod制作人们也指出它们是改写时的一个比较麻烦的瓶颈,因为一个Mod一次只能改写一个精灵表单,所以一次只能增加一个额外的对象来添加进新的图像。
We worked out a way to change index references to icons in sprite sheets into normal key references, which meant that we could convert these elements of the game to use the normal system (with no need for new icons to be inside a sprite sheet). This got rolled out to the likes of army types, colony automation types, bombardment stances, and (with great difficulty!) ship sizes.
我们找到了一种将精灵表单中图标的索引引用更改为普通的键引用的方式,这意味着我们可以将游戏的这些元素转换为使用普通系统(不再需要在精灵表单中添加新图标)。这可以被推广运用到陆军类型、殖民地自动开发类型、轰炸姿态,甚至是舰船规模(这很困难!)。
An example:
给带伙整个活:
spriteType = {
name = "GFX_ship_size_military_1"
sprite_sheet_sprite_type = "GFX_ship_sizes"
default_frame = 2
}
In the case of ship sizes, it was a bit tricky, since the icon_frame index number then specified which icon it would use on multiple sprite sheets. In the end, we left that system in place for starbases (since very few tend to add a new type of starbase) and made the line "icon = ship_size_military_1" tell the game to refer to several sprite keys: GFX_text_ship_size_military_1, GFX_ship_size_military_1, GFX_ship_size_military_1_top, GFX_ship_size_military_1_top_damaged
在舰船规模这方面有点棘手,因为图标框架索引编号指定了它在多个精灵表单上使用的图标。最后我们为行星基地保留了这个系统(因为很少有人尝试新增一个全新类型的行星基地)并使“icon = ship_size_military_1”能够告诉游戏参考这些精灵图表的键值:GFX_text_ship_size_military_1,GFX_ship_size_military_1,GFX_ship_size_military_1_top,GFX_ship_size_military_1_top_damaged。
This will need some updating for mods which change the affected objects, since the old format no longer works, but in the long term it will hopefully solve a lot of compatibility headaches!
因为旧的格式不再有效,所以一些对象受到影响的Mod需要进行更新,但长期来看这将很有希望能够解决很多兼容性问题。

Randomness
随机性
Some have noticed that, in certain cases, the randomness of script functions such as random_list is not very random. Specifically, events fired from on_game_start had this issue (and various other on_actions, but that was the one that hurt the most). This was pretty unfortunate, since this effectively meant that certain things that were meant to be different each game... simply were not. Relatedly, we also revisited some more longstanding issues like where if you used while loops or every_x loops, each time the effect happened within that loop, the random result would be the same. (As in 25x random_list resulting in 25x the same result rather than 25x a random result).
有的朋友可能已经注意到,在某些特定情况下,脚本函数比如random_list的随机性并不是那么的随机。特别是由on_game_start触发的事件有这个问题(还有很多on_action,但是这个问题最大)。这很不对劲,因为每盘游戏应该触发不同的内容……但实际上不是这样。相关地,我们还同时回顾了一些长期存在的问题,比如说如果使用while循环或是every_x循环,每一次在循环中触发效果时,它的结果都是一样的。(比如在25x random_list中,会把一个相同的结果重复25次,而不是25个随机结果)。
We fixed this quite exhaustively:
我们非常彻底地解决了这个问题:
- The lack of randomness in on_actions like on_game_start is fixed. If we in future make the mistake that caused this to happen again, the game will warn us, so hopefully it is banished for good.
- 在游戏开始时,游戏开始时的on_actions缺乏随机性已经被修复。如果未来我们触发了这个错误,游戏将警告我们,所以希望这个问题最好已经被解决了。
- While loops and every_x loops have improved randomness
- While循环和每个_x循环都改善了随机性。
- For good measure, we added a reroll_random effect
- 作为一个好的方法,我们添加了reroll_random效果。

Other Cool Stuff
其他很炫酷的花活
On another note, we can now add triggered pop modifiers to traits, so for instance, you can add a trait that gives a bonus on one planet class and a penalty on another. The potential that this unlocks is quite considerable - for instance, it allowed us to stop using the somewhat unintuitive (and eminently cheeseable) stopgap solution of giving Void Dwellers two traits, and instead giving them one that applies differently depending on what sort of planet they are on.
在其他方面,我们现在可以添加被触发的人口特质修正,比如,你可以添加一个在一种行星类型上有加成、同时在另一种行星类型上有惩罚的特质。这能开发出极其可观的潜力——比如,这将让我们停止使用不直观(同时不起眼)的权宜之计来给虚空居者安排两个特质,而是给他们一个可以根据所居住的行星类型提供不同效果的特质。
As some have noticed, the Clone Army origin does several cool, new things that we haven't really explored in the game before. A lot of what we added for it could have further cool uses in the future, for instance:
正如一些人所注意到的,克隆之军的起源做了一些我们在游戏中没有真正探索过的很酷的新事情。我们为它添加的很多东西将来可能会有更酷的用途,例如:
• You can now gender-lock species
• 现在可以锁定性别
• You can set an empire limit on how many instances of a building you can build. (And alter it during the game).
• 可以设置建筑的数量限制(并在游戏中更改它)。
• A game rule, "should_force_decline_species", has been added. It will make a species for which it returns true decline on a planet, triggering an alert based on whatever tooltip is specified in the game rule. It is also hooked up to stop pops from migrating/being resettled/etc to a place where they would immediately start declining.
• 增加了一条游戏规则,“强制减少物种”。它将使一个物种在一个星球上真正衰退,并根据游戏规则中指定的任何提示栏触发警报。它同时可以阻止人口迁移或被重新安置之类到一个它们会立即开始下降的地方。
Finally, we added a bunch of new effects, triggers and modifiers, as usual. A couple to highlight are:
最后,我们像往常一样添加了一系列新的效果、触发器和修改器。需要强调一些亮点是:
• set_visited = <system> - reveals a system to you, without you having surveyed it
• set_visted=<system> - 向你显示一个星系,而你没有完成对它的调查。
• set_saved_date - lets you save a specific date (can be in the future) so that you can use it in locs, similar to variables: [This.my_saved_date].
• set_saved_date - 用于保存特定日期(将来实现),以便在本地化文本中使用,类似于变量:[This.my_saved_date]。
• Technically, the last effect is actually adding a <scope>_flag, so the standard flag effects and triggers have been ported over to all scopes
• 从技术上讲,最后一个效果实际上是添加了一个<scope>_flag,因此标准flag效果和触发器已移植到所有作用域。
• You can now use [loc] commands in button effects, which apparently will be very useful for dynamic modded UIs
• 你现在可以在按钮效果中使用[loc]命令,这显然对动态修改UI非常有用。
• You can define descriptions for districts, buildings, jobs and special projects through desc = { text = X trigger = { Y } } now. They also now take loc commands.
• 你可以通过desc = { text = X trigger = { Y } }定义地区、建筑、岗位和特殊项目的描述文本。它们现在也可使用loc命令。
• We deleted has_non_swapped_tradition and has_tradition_swap, and consolidated them into has_active_tradition. Modders: do a search-replace!
• 我们删除了has_non_swap_tradition和has_tradition_swap,并将其合并为has_active_tradition。mod作者们,私密马赛,麻烦做个搜索替代。
• Every scope that lacked script flags (e.g. country_flag) now has them. Also, variables work in all scopes now too.
• 每个缺少脚本flag(例如国家/地区标志)的作用域现在都有脚本flag。此外,变量现在也可以在所有作用域内工作。
• Note for updating mods: count_diplo_ties is now count_relation, count_armies is count_owned_army or count_planet_army (depending on the case). any/every/random_mining_station/research_station have also been removed, because they were nonsense. Use simply mining_station/research_station/orbital_station scope change instead. Also, observation_outpost no longer takes a "limit", but you can say "exists = observation_outpost" as compensation.
• 更新mods的注意事项:count_diplo_ties现在是count_relation,count_army是count_owned_army或count_planet_army(视情况而定)。任何/每一个/随机的采矿站/研究站也被移除,因为它们毫无意义。改用简单的采矿站/研究站/轨道站范围变更。此外,观察哨站不再接受“limit”,但你可以用“exists = observation_outpost”作为补偿。
Adding all these new functionalities has been a boon for us in the Custodian team, and we are gradually rolling them out to older parts of the game which can benefit from them. It's something I look forward to doing more of in future, and equally, I am excited (and, I'll admit, a tiny bit afraid) to see what modders will do with them!
添加这些全新的功能对我们守护者团队来说是一个大好事,我们正在逐步将这些改动推广到游戏的更早部分,使其从这些新功能中获益。这是我希望可以在未来可以更多地去做的事情,同样我很激动(同时我承认有那么亿点点害怕)看到mod作者们能够整什么花活。
One last thing: the old trigger_docs.log has now been deprecated, and instead we now have a more wieldy and more comprehensive script_documentation folder, the contents of which are attached to this post.
最后一件事:旧的trigger_docs.log现在已经被弃用,取而代之的是,我们现在有了一个更易使用、更全面的script_documentation文件夹,其内容附在本文之后。
And as some of you are probably aware, we did some early access for Modders for the Nemesis update. We had ~10 mods update on release day, servicing around 1.6 million subscribers, overall we were very happy with the results and the community reaction, and if this continues to go well we're looking to gradually expand this experiment to more of the Modding Community. For Lem, we're looking to add another 10-ish Modders to the early-access experiment. If you're interested you can fill out the Modder Early Access Request form.
正如你们中的一些人可能知道的那样,我们给一些mod作者们提供了涅墨西斯Nemesis更新的抢先体验。在这个扩展包发布日当天,约10个mod进行了更新,为约160万订阅用户提供了服务,总体而言,我们对结果和社区反应非常满意,如果进展顺利,我们希望将此实验逐步扩展到更多的mod社区。对于莱姆Lem更新,我们希望在抢先体验中再增加10个左右的mod作者名额。如果您感兴趣,可以在Modder Early Access Request论坛中填写申报。
翻译:AntiAccess 枸杞泡阔落
校对:一水战阿部熊 三等文官猹中堂
欢迎关注UP主和主播小牧Phenix!
欢迎关注牧游社微信公众号和知乎专栏!微信公众号改版为信息流,欢迎【置顶订阅】不迷路,即时获得推送消息!
B站在关注分组中设置为【特别关注】,将会在私信内及时收到视频和专栏投稿的推送!
欢迎加入牧有汉化,致力于为玩家社群提供优质内容!组员急切募集中!测试群组822400145!