Stellaris開發(fā)日志#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的開發(fā)日志!今天,我要給大伙說說即將到來的3.1版本號補(bǔ)丁里一些新的腳本語言特性。
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.
我們之前已經(jīng)說過,在新系統(tǒng)中傳統(tǒng)Traditions對Mod的適應(yīng)性更強(qiáng),不再需要對gui和loc文件進(jìn)行艱難的修改了。我也可以確認(rèn)其他一些事,舉例來說,你可以編寫腳本創(chuàng)造那種你必須在游戲內(nèi)做出某些決定才能用的傳統(tǒng)樹。不過今天,主要內(nèi)容還是變量。

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.
上次我說過,我們一直在試圖更多地利用一下變量。上一個(gè)補(bǔ)丁中加入了幾個(gè)在游戲中保存各種各樣的信息片段的方法,但是最大的缺失是一個(gè)輕松獲取觸發(fā)器數(shù)值的方法,比如一個(gè)行星上的人口數(shù)。你能使用變量的地方仍然相當(dāng)有限,特別是相對于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版本號中,我們已經(jīng)極大地增強(qiáng)了變量的能力。首先是格式:之前,如果你想獲取一個(gè)變量的值,你就得參考……變量本身,這就是所有能做的事了?,F(xiàn)在,你可以做點(diǎn)新東西了。
value = my_var
#gets the value of my_var variable set on the current scope
#獲取當(dāng)前作用域內(nèi)my_var變量的值
value = from.capital_scope.my_var
#gets the value of the my_var variable set on from’s capital
#從當(dāng)前帝國的首都獲取my_var變量的值
value = trigger:num_pops
#gets the number of pops in the current scope
#獲取當(dāng)前作用域內(nèi)的人口數(shù)
value = from.capital_scope.trigger:num_pops
#gets the number of pops in from’s capital
#從當(dāng)前帝國的首都獲取人口數(shù)
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 { }.
現(xiàn)在你可以設(shè)定點(diǎn)作用域,省去了許多麻煩,算是不折不扣的重大改進(jìn)。如你所見,你也可以用trigger:<trigger>指向觸發(fā)器。這能讓任何觸發(fā)器檢定一個(gè)數(shù)字,也只有一個(gè)數(shù)字,沒有{}。
(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 }")
(注意:之前那種非常麻煩的在不同作用域內(nèi)復(fù)制變量的格式已經(jīng)被移除了。就是這種你需要聲明“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版本號已經(jīng)有了一個(gè)效果,比如export_trigger_to_variable,但是那只能和fleet_power一起生效。這就是原型了,現(xiàn)在這一功能已經(jīng)擴(kuò)展至所有這類觸發(fā)器。重要的是,該效果允許你從稍微復(fù)雜一點(diǎn)的觸發(fā)器中獲取數(shù)值,帶有{}的那種,且依然只比較一個(gè)數(shù)值。
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版本號吧,它也加入了許多從游戲中的數(shù)值——比如修正項(xiàng)數(shù)值和資源儲(chǔ)量中,獲取變量數(shù)值的方法。它也增加了一些你能使用的幾個(gè)新地方:比如add_resource 和 add_modifier中的乘子。在3.1版本號中,我們已經(jīng)增加了更多的你可以使用變量做的東西:
? As values in triggers checking single numbers, e.g. "num_pops > my_variable", "intel = { who = from value < trigger:num_pops }"
? 在觸發(fā)器中作為數(shù)值檢定單個(gè)數(shù)字,例如“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".
? 在使用單個(gè)數(shù)字的效果中作為數(shù)值使用,例如“add_experience = my_variable”
? As a multiplier parameter in triggered resource tables (e.g. in a building)
? 作為已觸發(fā)的資源表中的乘子參數(shù)(例如在某個(gè)建筑中):
resources = {
category = planet_buildings
cost = {
trigger = { <triggers> }
minerals = 100
}
multiplier = my_var/owner.trigger:num_pops
}
? In MTTH/AI Chance modifiers:
? 在MTTH或AI幾率的修正項(xiàng)中:
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 現(xiàn)在有了一個(gè) time_multiplier,以及一個(gè)乘子參數(shù),你可以在那里使用它。例如,對于死亡教團(tuán)來說,這被用于施加一個(gè)修正,持續(xù)(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中:一個(gè)從我們比較新的游戲中搞來的特性。我會(huì)用觸發(fā)器文檔記錄來說明。ordered_owned_fleet – 在國家擁有的每個(gè)艦隊(duì)中迭代 – 在限制觸發(fā)器返回值為真的其中一支艦隊(duì)中,執(zhí)行封閉效果。以特定的順序選取特定對象(position 0, order_by = trigger:num_pops 會(huì)在擁有最多人口的X中執(zhí)行效果)。
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.
? 如果你的變量作為數(shù)字的話太過精確,你現(xiàn)在可以用round_variable_to_nearest將其數(shù)值取整,例如取整至最接近的10的倍數(shù)。
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.:
一份關(guān)于這些功能的概述已添加至events文件夾下的一個(gè)信息文件中(本文后也有附件)。另外,我也可以設(shè)想進(jìn)一步拓展變量的使用范圍,所以未來拓展這些說明也是很有可能的。這些改動(dòng)對我們來說已經(jīng)被證明是非常有用的,例如:
? 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!
? 改進(jìn)死亡教團(tuán)回報(bào):節(jié)省了大約1000行代碼,但是新版本仍然考慮了更多因素,以確定對你而言合適的回報(bào)
? 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.
? 確定黃金律(譯注:聯(lián)邦主席繼位決斗法的一種)需要付款的數(shù)額:之前的解決方案回避了數(shù)值問題,只會(huì)給你一個(gè)和真正的預(yù)付款沒多大關(guān)系的數(shù)額。以后就沒必要這么做了。
? Improving Federation Science Leadership Challenge: adding the actual number of techs and repeatable techs you have researched as a factor
? 改進(jìn)聯(lián)邦科研繼任挑戰(zhàn)(譯注:應(yīng)該指的是繼位決斗法里“論文答辯”這個(gè)選項(xiàng)):增加了你已經(jīng)研究的科技和可重復(fù)科技作為一個(gè)因素
? And more.
? 以及更多。

Sprite Sheet Changes
精靈表單改動(dòng)
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.
上邊已經(jīng)說了不少了,不過我還是想多強(qiáng)調(diào)幾件事。首先,游戲里一些比較老的元素在它們的圖標(biāo)中使用了“精靈表單”——一種在一個(gè)圖片文件內(nèi)放一排圖標(biāo)的系統(tǒng),然后我們聲明我們想用哪一個(gè),比方說表里的第五個(gè)。我們在這些內(nèi)部開發(fā)的東西上遇到過一些問題(我突然想到了殖民地自動(dòng)化按鈕意外成了一個(gè)機(jī)械奶牛的事情),Mod制作人們也指出它們是改寫時(shí)的一個(gè)比較麻煩的瓶頸,因?yàn)橐粋€(gè)Mod一次只能改寫一個(gè)精靈表單,所以一次只能增加一個(gè)額外的對象來添加進(jìn)新的圖像。
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.
我們找到了一種將精靈表單中圖標(biāo)的索引引用更改為普通的鍵引用的方式,這意味著我們可以將游戲的這些元素轉(zhuǎn)換為使用普通系統(tǒng)(不再需要在精靈表單中添加新圖標(biāo))。這可以被推廣運(yùn)用到陸軍類型、殖民地自動(dòng)開發(fā)類型、轟炸姿態(tài),甚至是艦船規(guī)模(這很困難?。?。
An example:
給帶伙整個(gè)活:
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
在艦船規(guī)模這方面有點(diǎn)棘手,因?yàn)閳D標(biāo)框架索引編號指定了它在多個(gè)精靈表單上使用的圖標(biāo)。最后我們?yōu)樾行腔乇A袅诉@個(gè)系統(tǒng)(因?yàn)楹苌儆腥藝L試新增一個(gè)全新類型的行星基地)并使“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!
因?yàn)榕f的格式不再有效,所以一些對象受到影響的Mod需要進(jìn)行更新,但長期來看這將很有希望能夠解決很多兼容性問題。

Randomness
隨機(jī)性
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).
有的朋友可能已經(jīng)注意到,在某些特定情況下,腳本函數(shù)比如random_list的隨機(jī)性并不是那么的隨機(jī)。特別是由on_game_start觸發(fā)的事件有這個(gè)問題(還有很多on_action,但是這個(gè)問題最大)。這很不對勁,因?yàn)槊勘P游戲應(yīng)該觸發(fā)不同的內(nèi)容……但實(shí)際上不是這樣。相關(guān)地,我們還同時(shí)回顧了一些長期存在的問題,比如說如果使用while循環(huán)或是every_x循環(huán),每一次在循環(huán)中觸發(fā)效果時(shí),它的結(jié)果都是一樣的。(比如在25x random_list中,會(huì)把一個(gè)相同的結(jié)果重復(fù)25次,而不是25個(gè)隨機(jī)結(jié)果)。
We fixed this quite exhaustively:
我們非常徹底地解決了這個(gè)問題:
- 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.
- 在游戲開始時(shí),游戲開始時(shí)的on_actions缺乏隨機(jī)性已經(jīng)被修復(fù)。如果未來我們觸發(fā)了這個(gè)錯(cuò)誤,游戲?qū)⒕嫖覀?,所以希望這個(gè)問題最好已經(jīng)被解決了。
- While loops and every_x loops have improved randomness
- While循環(huán)和每個(gè)_x循環(huán)都改善了隨機(jī)性。
- For good measure, we added a reroll_random effect
- 作為一個(gè)好的方法,我們添加了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.
在其他方面,我們現(xiàn)在可以添加被觸發(fā)的人口特質(zhì)修正,比如,你可以添加一個(gè)在一種行星類型上有加成、同時(shí)在另一種行星類型上有懲罰的特質(zhì)。這能開發(fā)出極其可觀的潛力——比如,這將讓我們停止使用不直觀(同時(shí)不起眼)的權(quán)宜之計(jì)來給虛空居者安排兩個(gè)特質(zhì),而是給他們一個(gè)可以根據(jù)所居住的行星類型提供不同效果的特質(zhì)。
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:
正如一些人所注意到的,克隆之軍的起源做了一些我們在游戲中沒有真正探索過的很酷的新事情。我們?yōu)樗砑拥暮芏鄸|西將來可能會(huì)有更酷的用途,例如:
? You can now gender-lock species
? 現(xiàn)在可以鎖定性別
? You can set an empire limit on how many instances of a building you can build. (And alter it during the game).
? 可以設(shè)置建筑的數(shù)量限制(并在游戲中更改它)。
? 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.
? 增加了一條游戲規(guī)則,“強(qiáng)制減少物種”。它將使一個(gè)物種在一個(gè)星球上真正衰退,并根據(jù)游戲規(guī)則中指定的任何提示欄觸發(fā)警報(bào)。它同時(shí)可以阻止人口遷移或被重新安置之類到一個(gè)它們會(huì)立即開始下降的地方。
Finally, we added a bunch of new effects, triggers and modifiers, as usual. A couple to highlight are:
最后,我們像往常一樣添加了一系列新的效果、觸發(fā)器和修改器。需要強(qiáng)調(diào)一些亮點(diǎn)是:
? set_visited = <system> - reveals a system to you, without you having surveyed it
? set_visted=<system> - 向你顯示一個(gè)星系,而你沒有完成對它的調(diào)查。
? 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 - 用于保存特定日期(將來實(shí)現(xiàn)),以便在本地化文本中使用,類似于變量:[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
? 從技術(shù)上講,最后一個(gè)效果實(shí)際上是添加了一個(gè)<scope>_flag,因此標(biāo)準(zhǔn)flag效果和觸發(fā)器已移植到所有作用域。
? You can now use [loc] commands in button effects, which apparently will be very useful for dynamic modded UIs
? 你現(xiàn)在可以在按鈕效果中使用[loc]命令,這顯然對動(dòng)態(tài)修改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 } }定義地區(qū)、建筑、崗位和特殊項(xiàng)目的描述文本。它們現(xiàn)在也可使用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作者們,私密馬賽,麻煩做個(gè)搜索替代。
? Every scope that lacked script flags (e.g. country_flag) now has them. Also, variables work in all scopes now too.
? 每個(gè)缺少腳本flag(例如國家/地區(qū)標(biāo)志)的作用域現(xiàn)在都有腳本flag。此外,變量現(xiàn)在也可以在所有作用域內(nèi)工作。
? 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的注意事項(xiàng):count_diplo_ties現(xiàn)在是count_relation,count_army是count_owned_army或count_planet_army(視情況而定)。任何/每一個(gè)/隨機(jī)的采礦站/研究站也被移除,因?yàn)樗鼈兒翢o意義。改用簡單的采礦站/研究站/軌道站范圍變更。此外,觀察哨站不再接受“l(fā)imit”,但你可以用“exists = observation_outpost”作為補(bǔ)償。
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!
添加這些全新的功能對我們守護(hù)者團(tuán)隊(duì)來說是一個(gè)大好事,我們正在逐步將這些改動(dòng)推廣到游戲的更早部分,使其從這些新功能中獲益。這是我希望可以在未來可以更多地去做的事情,同樣我很激動(dòng)(同時(shí)我承認(rèn)有那么億點(diǎn)點(diǎn)害怕)看到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現(xiàn)在已經(jīng)被棄用,取而代之的是,我們現(xiàn)在有了一個(gè)更易使用、更全面的script_documentation文件夾,其內(nèi)容附在本文之后。
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更新的搶先體驗(yàn)。在這個(gè)擴(kuò)展包發(fā)布日當(dāng)天,約10個(gè)mod進(jìn)行了更新,為約160萬訂閱用戶提供了服務(wù),總體而言,我們對結(jié)果和社區(qū)反應(yīng)非常滿意,如果進(jìn)展順利,我們希望將此實(shí)驗(yàn)逐步擴(kuò)展到更多的mod社區(qū)。對于萊姆Lem更新,我們希望在搶先體驗(yàn)中再增加10個(gè)左右的mod作者名額。如果您感興趣,可以在Modder Early Access Request論壇中填寫申報(bào)。
翻譯:AntiAccess 枸杞泡闊落
校對:一水戰(zhàn)阿部熊 三等文官猹中堂
歡迎關(guān)注UP主和主播小牧Phenix!
歡迎關(guān)注牧游社微信公眾號和知乎專欄!微信公眾號改版為信息流,歡迎【置頂訂閱】不迷路,即時(shí)獲得推送消息!
B站在關(guān)注分組中設(shè)置為【特別關(guān)注】,將會(huì)在私信內(nèi)及時(shí)收到視頻和專欄投稿的推送!
歡迎加入牧有漢化,致力于為玩家社群提供優(yōu)質(zhì)內(nèi)容!組員急切募集中!測試群組822400145!? ?