Mass Battle Frameworkv1.20.0

让 Coding Agent 改源码 Letting a Coding Agent Edit the Source

WORKFLOW

面板是壳,源码是接口 · 2026-11-22The panel is a shell, the source is the interface · 2026-11-22

面板是给没有 agent 的时代造的 Panels Were Built for a World Without Agents

插件作者面对"用户想加一个功能"这种请求,很长一段时间只有两条路:把源码给出去,或者做一个面板。源码不能随便给:用户改完,你下一次更新就冲突,他改的那份也只有他自己看得懂。于是有了面板,把能改的东西收进一个 UI,作者只碰资产、不碰代码,升级时资产还在。

Ask a plugin author for a feature and, for a long time, there were two answers: give away the source, or build a panel. Giving away the source does not scale. The user's edits collide with your next update, and nobody but the user can read what they did. So panels: put the changeable parts in a UI, let authors touch assets instead of code, and assets survive the upgrade.

这笔取舍在当年是成立的,但很少有人把代价算清楚。这篇来算一次,然后说现在多出来的第三条路:让一个能读源码、能改源码、能跑构建的 agent 把功能直接写进去。

That trade made sense at the time; almost nobody stopped to count what it cost. This post counts it, then describes the third option that now exists: an agent that can read the source, edit it, and run the build, writing the feature in directly.

壳的成本 What the Shell Costs

面板不参与运行时。它把控件映射成资产字段,运行时只读资产。所以对于"填数字",这层映射是白送的,甚至比手写强:有校验、有默认值、有搜索、tooltip 里带单位。作者要填一个单位的感知半径、攻击前摇、网格槽位,面板就是最好的工具。

A panel plays no part at runtime. It maps widgets onto asset fields, and the runtime reads the asset. For typing in a number, that mapping costs nothing and beats hand-editing: validation, defaults, search, units in the tooltip. Setting a unit's sight radius, attack wind-up or mesh slot count is exactly what a panel is good for.

换到"写逻辑",代价落在三处:

Switch to writing logic and the cost lands in three places:

第一处是翻译。你得先把意图翻成节点和连线,运行时再把节点一条条解释回去。蓝图虚拟机每调一个函数都要分发一次、开一帧、压参数,编译器没有机会内联。同一段判断写成 C++ 和写成节点图,差一到两个数量级,而且差距随调用次数线性放大。

The first is translation. You turn intent into nodes and wires, and the runtime interprets the nodes back. Every Blueprint function call goes through a dispatch, opens a frame, pushes arguments, and the compiler never gets to inline any of it. The same branch in C++ and as a node graph differs by one to two orders of magnitude, and the gap grows linearly with call count.

第二处是线程。节点图跑在游戏线程上。一次 Mass 并行波里放不进任何一张图:那一波是几千个任务同时跑,每个任务都在裸内存上写字段,而蓝图调用假定单线程、有 UObject 上下文、可以被打断。引擎没有哪里做得不够,只是两种执行模型的形状对不上,优化不掉。

The second is the thread. Node graphs run on the game thread. A Mass parallel wave cannot hold a graph: thousands of tasks run at once, each writing fields in raw memory, while a Blueprint call assumes one thread, a UObject context, and the right to be interrupted. The engine is not missing anything. The two execution models have different shapes, and no amount of optimisation fixes that.

第三处是状态。图能回答"这个对象现在是什么状态",靠的是对象本身。十万个实体没有十万个对象,状态得放进片段,而一张图没法对片段说话。于是可视化方案走到这一步只有两个选择:给每个单位拉回一个 Actor(性能就没了),或者在图外面再造一层影子状态,两边迟早对不上。

The third is state. A graph expresses "what state is this thing in" through the object itself. A hundred thousand entities do not have a hundred thousand objects. Their state lives in fragments, and a graph cannot address a fragment. So visual solutions either drag an Actor back in per unit (there goes the perf) or build a shadow state outside the graph, and the two drift apart eventually.

三处加起来,结论很干脆:在"每帧 × 每个实体"这条路径上,可视化编程是所有选项里最差的一个。它真正擅长的是低频、一次性、需要人看结果的动作:生成、烘焙、摆位、审一张图集。

Add the three up and the answer is blunt: on the "every frame, every entity" path, visual programming is the worst option available. Where it wins is low-frequency, one-shot work whose result a human looks at: spawning, baking, placing, auditing an atlas.

用 Mass 的人已经撞过墙 If You Are on Mass, You Already Hit the Wall

会选择 Mass 的人,多半是被 OOP 逼过来的:单位数量上不去、每帧 GC 尖刺、Actor 开销太大、十万人同屏掉到十几帧。换架构的代价很大,没人会为了赶时髦走这一步。

Most people come to Mass because OOP ran out of room. The unit count would not go up, the GC spiked every frame, Actors were expensive, and a hundred thousand units on screen dropped the frame rate into the teens. Changing architecture costs a lot, and nobody takes that road for fashion.

既然已经为了性能换掉整套数据布局和调度方式,再往关键路径上空降一层解释器,这条路走不通。还有个反身性的证据:我们的 processor 故意切得很粗,一趟并行波覆盖所有单位,这条设计的前提就是"热路径上没有解释层"。塞一张图进去,前面所有取舍都得重算。

Having swapped out the data layout and the scheduler for performance, dropping an interpreter onto the hot path makes no sense. There is also a reflexive piece of evidence: our processors are deliberately coarse, one parallel wave covers every unit, and that design assumes no interpreter on the hot path. Put a graph in there and every earlier trade-off gets recomputed.

所以立场很明确:面板留着用,写逻辑回到源码。分界线是一个乘法:频率 × 数量。配置一个单位是一次;判断一个单位这一帧该干什么,是每帧乘以十万。

So the position is plain: keep the panels for authoring, write the logic in source. The line is a multiplication: frequency times count. Configuring a unit happens once. Deciding what a unit does this frame happens every frame times a hundred thousand.

换一份约定:agent 读的是源码 A Different Contract: The Agent Reads the Source

Coding agent 改变的东西很具体:它能读这个仓库的源码,按已有写法加一段,再跑一遍构建。它不需要"专门给 AI 做的面板",更不需要你把插件包成黑盒。它要的正好反过来:代码可读,构建和闸门能机械执行。

What a coding agent changes is specific: it can read this repository, add a piece in the existing style, and run the build. It does not need a panel made for AI, and it does not need the plugin wrapped as a black box. It needs the opposite: readable code, and a build and gates that run mechanically.

"扩展这个插件"于是从"等作者发下一版"变成"照仓库里已有的两个先例加一份"。这变化只有一个前提:写法本身得明确、可复制。这篇剩下的部分就是把那套写法摊开写,让人和 agent 读同一份。

"Extending the plugin" turns from "wait for the next release" into "add one in the shape of the two precedents already in the repo". That only works on one condition: the shape has to be explicit and copyable. The rest of this post lays that shape out, so a human and an agent read the same page.

顺带说清一件事:给 agent 的说明书不该是"怎么写 ECS 行为"的通用教程。通用教程它读得比你多。它缺的是这个仓库的约定:哪一层、哪个函数、模板里的哪一行。把 FJump/FJumping 和 FDefence 这两个现成先例给它,比十篇论文有用。

One thing to get straight: the brief is not a general tutorial on writing ECS behaviours. It has read more of those than you have. What it lacks is this repository's conventions: which layer, which function, which line in the template. Two working precedents, FJump/FJumping and FDefence, are worth more to it than ten papers.

第一件事:调用已经有的 API First Job: Call the API You Already Have

大部分"我想加个功能"的请求根本不需要动插件。想要一队兵、想要一片区域掉血、想把炮塔挂到车体上,这些都是已有函数,缺的只是那一行调用。

Most "I want a feature" requests do not need the plugin touched at all. A squad of soldiers, damage over an area, a turret mounted on a chassis — those are existing functions; what is missing is the call site.

要做的事调用什么要点
生成 SpawnAgentsByConfigCircular / Rectangular / EQS,以及 SpawnAgentFromTemplate 并行逻辑里要生成,用 *Deferred 版本;所有生成最终都在串行段落地
检索 FMassBattleQuery + SelectAgents;ConvertTraceResultsToEntityArray、ConvertDmgResultsToEntityArray 查询按标志/队伍/类型筛,返回的是句柄数组,之后的遍历是普通循环
伤害 ApplyPointDamageAndDebuff / ApplyRadialDamageAndDebuff / ApplyBeamDamageAndDebuff 伤害写进受击实体的累加器,受击和死亡在同一帧反应
附着 AttachAgentToAgent / AttachActorToAgent / AttachNiagaraToAgent;GetMountParentAgent、GetMountedChildAgents、Detach 子系统自己会建一个跟随用的宿主实体;解开走 Detach,别手动销毁
标志 SetMassFlag / HasMassFlag 蓝图按名字,C++ 用 EAgentFlag;标志是查得动的状态,别用 fragment 里的 bool 代替

这张表有两条性质不那么显眼,值得单独说:

Two properties of that table are worth stating on their own:

一、这些函数和面板用的是同一份实现。面板上的按钮最后也调到这里,命令层返回同一个结构化结果。所以 agent 走 API,拿到的能力和点按钮完全一样,校验和失败码都在。它绕不开什么,也不会少掉什么。

One: these are the same functions the panels call. A panel button ends up here too, and the command layer returns the same structured result. An agent going through the API gets exactly what a click gets, validation and failure codes included. It bypasses nothing, and nothing is lost.

二、生成是唯一必须串行的动作。它也是 agent 最容易踩坏的地方:在并行循环里顺手写一句生成,编译能过,单线程测试也能过,到了十万实体就开始偶发崩溃。brief 里把这条写成硬约束:生成只走 Defer() 或 *Deferred 入口,其余收集完再串行落地。

Two: spawning is the one action that must be serial. It is also the easiest thing for an agent to break: drop a spawn into a parallel loop and the build passes, a single-threaded test passes, then at a hundred thousand entities it starts crashing intermittently. Put that in the brief as a hard rule: spawning goes through Defer() or a *Deferred entry point, everything else is gathered and applied serially.

第二件事之前,先分清三层 Before Extending: Which of the Three Layers

动插件之前,第一个决定是"它属于哪一层"。整条流程里只有这个决定必须由人拍,剩下都是机械劳动。层分错了,代码写得再干净也放错了地方。

Before touching the plugin, the first decision is which layer this belongs to. It is the only decision a human has to make; the rest is mechanical labour. Get the layer wrong and even clean code sits in the wrong place.

层互斥吗答的问题先例
行为(behavior) 互斥,一个单位同一时刻只占一个 这一帧它要往哪走、要做什么 FChase、FPatrol、FJump
并发反应(reaction) 叠加,和行为同时发生 发生了什么,播个什么东西、改一下判定 FBeingHit、FHit、FDefence
数值与计时(debuff / damage) 叠加,只改数 这个单位这一段时间的数字是多少 FDebuff、FTemporalDamage

判据一句话:决定"这一帧往哪走"的放行为;只是"发生了什么、播个东西"的放反应;只改数字的放减益。拿不准就问自己另一个问题:这个能力生效时,单位还能不能继续攻击、继续追?答案如果是"还能",它就不该是行为。行为互斥,占了一个就得让出另一个。

One line of criteria: if it decides where the unit goes this frame, it is a behaviour; if it only says something happened and plays something, it is a reaction; if it only changes numbers, it is a debuff. When unsure, ask another question: while this is happening, can the unit still attack, still chase? If yes, it cannot be a behaviour. Behaviours are exclusive; taking one means yielding another.

放错层的代价很具体。把闪避做进行为链,你要和移动层抢 Moving.Goal,还要在优先级链里插一段,"闪避中能不能攻击"就变成一个全新的状态组合问题。把逃跑做成叠加层,它会和 Chase、Attack 同时持有 Moving.Goal,两个写者一个目标,结果随机。

The cost of the wrong layer is concrete. Make a dodge a behaviour and it fights the movement layer over Moving.Goal, it needs a slot in the priority chain, and "can you attack while dodging" becomes a new state-combination problem. Make an escape an overlay and it holds Moving.Goal at the same time as Chase and Attack: two writers, one target, a random outcome.

加一个行为:Escape 的配方 Adding a Behaviour: the Escape Recipe

拿仓库里已经写好的提案当例子。Docs/Design/EscapeBehavior.md 定义的是一个行为,供两种玩法共用:低血逃命,远程放风筝。敌进我退,敌退我进。它把要改的地方一条条列清楚了,正好是这份配方:

Use the proposal already in the repo as the example. Docs/Design/EscapeBehavior.md defines one behaviour serving two playstyles: flee at low health, and kite at range (back off when the enemy closes, turn and fight when they fall back). It lists every place that has to change, which is exactly the recipe:

一、它进 EBehaviorState,不进 EBehaviorChoice。这是两个枚举,分别在 MassBattleEnums.h:161 和 :173,中间有一个 ToBehaviorState 做映射。Choice 是作者面能看见的选项(出生、睡眠、巡逻、跳跃、攻击、瞄准),State 是运行时占着的状态。逃跑对应的是"血低"或"敌人太近"这个条件,玩家点不出来,所以只拿 State。Chase 是先例,它同样只有 State,没有 Choice。

One: it goes into EBehaviorState, not EBehaviorChoice. Two separate enums at MassBattleEnums.h:161 and :173, with ToBehaviorState mapping between them. Choice is what an author can pick (appear, sleep, patrol, jump, attack, aim); State is what a unit currently occupies. An escape expresses a condition — low health, or the enemy is too close — that no player clicks, so it only takes a State, exactly like Chase, which has no Choice entry either.

二、片段成对:FEscape 管配置,FEscaping 管运行时。仓库里每个行为都是这个形状:FPatrol/FPatrolling、FJump/FJumping、FChase/FChasing、FAttack/FAttacking。配置那一半进 AgentConfig 的作者面,运行时那一半只活在 chunk 里。合成一个会怎样?作者的 Details 面板会被运行期计时器淹掉,改一个不该改的字段也不会报错。

Two: the fragment pair — FEscape for config, FEscaping for runtime. Every behaviour in this repo has that shape: FPatrol/FPatrolling, FJump/FJumping, FChase/FChasing, FAttack/FAttacking. The config half shows up in AgentConfig; the runtime half only lives in chunks. Merge them and the author's Details panel drowns in runtime timers, and editing a field nobody should edit fails silently.

三、一个 bEnable,默认关。关掉以后,行为切换的穷举 switch 会拒绝切进去:MassBattleAgentBehaviorProcessor.cpp:556-582 那段,每个 case 读对应片段的 bEnable。这就是我们的功能开关,作者在 Details 里取消勾选,这个行为对他就不存在,一行代码都不用删。之所以默认关,是因为它一开就会在低血时接管移动,会改变一整局的节奏。

Three: one bEnable, off by default. Turned off, the exhaustive switch refuses to enter it — MassBattleAgentBehaviorProcessor.cpp:556-582, where each case reads the matching fragment's bEnable. That is our feature switch: the author unchecks a box in Details and the behaviour stops existing for them, with no code deleted. Off by default because, once on, it takes over movement at low health, and that changes the tempo of a whole match.

四、转移写在 FBehavior 上,想清楚再加。Fragments/Behavior.h 那一组 OnBirth、OnLostTarget、OnAimTimeout 回答的是"某个事件之后去哪"。给 Escape 加一个 OnEscapeEnd 合理;给每个行为都加一条转移就不合理,表越长,作者越看不出状态机长什么样。

Four: transitions live on FBehavior — add one only when it is needed. The OnBirth, OnLostTarget, OnAimTimeout group in Fragments/Behavior.h answers "where do we go after this event". An OnEscapeEnd is reasonable; a transition per behaviour is not — the longer the table, the harder it is for an author to see the state machine at all.

五、落地有五处,一处都不能漏。枚举加值;两个片段;AgentConfig 里加一行字段(MassBattleAgentConfigDataAsset.h:324 那种,一行一个片段,作者面才看得见);模板构建里加一行 AddFragment_GetRef<FEscape>() = DataAsset->Escape;(MassBattleAgentSubsystem.cpp:1179 附近);最后在启动检查里加 Require(TEXT("FEscape"), Template.HasFragment<FEscape>())(同文件 :164 附近)。

Five: five places to land, and none of them optional. The enum value; the two fragments; one field on the AgentConfig (MassBattleAgentConfigDataAsset.h:324, one line per fragment — that is what makes it visible to the author); one line in the template build, AddFragment_GetRef<FEscape>() = DataAsset->Escape; (around MassBattleAgentSubsystem.cpp:1179); and finally the startup check, Require(TEXT("FEscape"), Template.HasFragment<FEscape>()) (same file, around :164).

最后一条值得多说一句。漏了模板那一行,编译照样过,测试也照样过,症状是几周之后某个查询莫名不命中,或者更糟,读到一个没初始化的片段。有了 Require,第一次构建模板就炸在那里,栈里写着缺哪个片段。这是我们对付"静默失效"的办法:能崩在启动期的东西,别留给运行期。

That last line is worth a sentence. Miss the template line and the build still passes, the tests still pass; the symptom is a query that mysteriously stops matching weeks later, or worse, a fragment read before it was ever written. With the Require, the first template build dies right there with the missing fragment named in the stack. That is how we handle silent failure: anything that can fail at startup should not be left to fail at runtime.

六、处理器里加一节,节序就是优先级。行为处理器是逐节跑的:先处理切换请求,再依次是出生、睡眠、巡逻、追逐、攻击、瞄准、支援、跳跃、回归。一个行为的优先级就是它那一节的位置。Return 放在第 8.5 节,因为它在链上优先级最低,谁都能把它挤掉。逃跑要压过追逐和攻击,判定节就得写在它们前面;同时它不能挡住受击,受击在并发层,不在这条链上。

Six: one more section in the processor, and section order is priority. The behaviour processor runs in sections: switch requests first, then appear, sleep, patrol, chase, attack, aim, reinforce, jump, return. A behaviour's priority is where its section sits. Return is section 8.5 because it is the lowest-priority link on the chain and anything can push it out. An escape that should beat chase and attack needs its check before theirs. It must not block being hit either: that is a concurrent layer, not part of this chain.

不想动插件:把处理器换掉 Without Touching the Plugin: Swap the Processor Out

上面那条配方,最后一步是改 Behavior Processor 本身。对插件作者成立,对使用者不一定:你改的是插件源码,插件一升级,改动要么被覆盖,要么每次都得重新合一遍。把改过的插件绑在项目里走,这个风险一直在。

The recipe above ends inside the Behaviour Processor itself. That works for the plugin's author and less well for a user: you are editing plugin source, so the next plugin update either overwrites your work or forces a fresh merge. Keeping a modified plugin inside a project carries that risk for as long as the project lives.

另一条路是 Processor 注册管线。MassBattle 的每个处理器都有一个稳定节点 ID(Sim.Trace、Sim.Behavior、Sim.Move、Sim.Physics……),世界初始化时按这份名单组装一次;你的游戏模块可以在那个时刻决定留谁、换谁、在谁前面或后面再插一个。想完全接管行为决策,就把 Sim.Behavior 停用,注册自己的处理器;想保留默认行为、只补一段后处理,就在它后面插一个。代码住在你自己的模块里,插件保持原样,升级时没有东西可被覆盖。

The other road is the processor registration pipeline. Every MassBattle processor has a stable node ID (Sim.Trace, Sim.Behavior, Sim.Move, Sim.Physics…), and a world assembles the list once at initialisation; your game module can decide at that moment who stays, who is replaced, and who gets an extra node before or after. To take over behaviour decisions entirely, disable Sim.Behavior and register your own processor; to keep the stock behaviour and add a post-pass, insert one after it. Your code lives in your module, the plugin stays pristine, and an update has nothing to overwrite.

三种操作:InsertBefore / InsertAfter 加一个带全新 ID 的原生处理器;Replace 接管一个内置节点(节点 ID 与调度保留;Move、Physics、Host、Network 这四处的替换必须继承对应的基类);Disable 让节点不创建实例。还有一份保护名单:Sim.Move、Sim.Physics、Sim.Host、Render.Agent、Network.Capture 最终必须有启用实现——可以停用再换上自己的实现,但不能一直空着;Sim.Host 还独占最后一段,不允许往旁边插。

Three operations: InsertBefore / InsertAfter adds a native processor with a new ID; Replace takes over a stock node (the ID and schedule stay; for Move, Physics, Host and Network the replacement must derive from the corresponding base class); Disable stops a node from being instantiated. There is also a protected list: Sim.Move, Sim.Physics, Sim.Host, Render.Agent and Network.Capture must end up with an enabled implementation — you may disable one and supply your own replacement, but it cannot stay empty; Sim.Host also owns the last stage exclusively, so nothing may be inserted beside it.

注册写在你自己模块的 StartupModule(FMassBattleProcessorRegistry::RegisterCodePatch),也可以放进项目设置;没有热替换,新的组成在下一个 World 或 PIE 生效。对 agent 的 brief 因此多一个选项:不是"去改 MassBattle 的 Behavior Processor",而是"在你的模块里写一个 UMassProcessor 子类,在 StartupModule 里注册一个补丁"。它一样写得出来,而且写出来的东西升级不丢。三种操作的字段、节点表与验证规则见 Processor 管线那页。

Registration goes in your module's StartupModule (FMassBattleProcessorRegistry::RegisterCodePatch) or into project settings; there is no hot replacement, and the new composition applies to the next world or PIE session. That gives the agent brief one more option: instead of "edit MassBattle's Behaviour Processor", it is "write a UMassProcessor subclass in your module and register a patch from StartupModule". It writes that just as well, and what it writes survives an update. The fields, node table and validation rules for all three operations are on the processor pipeline page.

片段怎么写才算合格 What Counts as a Correct Fragment

agent 很快就能写出"能跑"的片段,慢的是让它写出"能留在仓库里"的那种。下面几条是审 diff 的检查项,可以直接抄进 brief:

Getting a fragment that runs out of an agent is quick. Getting one that belongs in the repository is the slow part. These are the diff-review checks; copy them into the brief:

配置和运时分家。运行期字段(计时器、当前阶段、上次判定的结果)只在 FXxxing 里,作者面看不到。配置字段把单位写进 tooltip:秒写秒,比例写 0–1,角度写度。别让作者猜。

Config and runtime stay apart. Runtime fields — timers, current phase, last verdict — live only in FXxxing and stay out of the author's face. Config fields carry units in the tooltip: seconds as seconds, ratios as 0–1, angles as degrees. Do not make the author guess.

默认值要"关掉时无害"。概率默认 0,窗口默认 0(表示沿用片段长度),倍率默认 1。这样新片段加进模板、作者还没配的时候,它什么都不做。比"默认就生效,然后所有人被吓一跳"安全得多。

Defaults must be harmless when switched off. Probability 0, window 0 (meaning "use the clip length"), multiplier 1. A freshly added fragment that the author has not configured yet then does nothing — far safer than taking effect by default and surprising everyone.

片段里别塞查询、指针、容器。热路径要读的东西内联在片段里,冷的进 TArray 或共享片段;共享片段里的 TArray 必须声明 MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE 并定义 operator==,否则哈希和比较会给你惊喜。

No queries, pointers or containers in a hot fragment. What the hot path reads lives inline; cold data goes into a TArray or a shared fragment, and a TArray in a shared fragment must declare MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE and define operator==, or hashing and comparison will surprise you.

跨帧的状态要进快照。这个行为或反应里凡是"这帧写、下帧读"的字段,都得在快照注册表里露名并进哈希。漏一个,单机跑一万年都没事,联机时两端会在某一天分叉,而报警的那一帧几乎不是出错的那一帧。这条 agent 最容易忘,因为它测试时只有一份进程。

Cross-frame state has to be snapshotted. Every field this behaviour or reaction writes this frame and reads the next has to be named in the snapshot registry and fed into the hash. Miss one and a single-player build is fine forever, while two peers diverge some day — and the tick that complains is almost never the tick that broke. Agents forget this one most, because their tests run in a single process.

注释、Category、双语 tooltip,一条都不能少。这些都是构建闸门:UPROPERTY 缺 Category,UAT 打包时 UHT 会逐条拒绝;tooltip 两种语言挤在一行,会被 check_bilingual_text.py 拦下。让 agent 自己跑这两个脚本,比在评审里被指出三次便宜。

Comments, Category, bilingual tooltips — all of them. These are build gates: a UPROPERTY without Category is rejected by UHT during UAT packaging, and a tooltip with two languages on one line is caught by check_bilingual_text.py. Have the agent run those two scripts itself; it is cheaper than being told three times in review.

你该交给它什么 What to Hand It

具体写法说完了。剩下的是委托本身:brief 写到什么程度,agent 才能一次做对。下面七行,缺一行就多一轮返工。

The mechanics are done. What is left is the delegation itself: how much a brief has to say before the agent gets it right the first time. Seven lines; miss one and you buy another round of rework.

一、层。行为、并发反应、减益,三选一。不确定就写"我不确定,你先判断该放哪层再动手"。先要结论比先要代码便宜。

One: the layer. Behaviour, concurrent reaction, or debuff. If you are unsure, write "I do not know — decide the layer first, then start"; a conclusion is cheaper than code.

二、触发。什么时候进,什么时候出,用什么量测。"血低于 30%"比"快死的时候"好,"敌人进 8 米就退、拉开到 15 米回头"比"保持距离"好。这两个数字就是玩法,别指望它替你定。

Two: the trigger. When it starts, when it ends, measured how. "Below 30% health" beats "when nearly dead"; "back off inside 8 metres, turn and fight past 15" beats "keep distance". Those two numbers are the gameplay — do not expect it to invent them.

三、数据。字段名、单位、默认值、作者面板上该看见什么。顺便说清哪些字段属于运行期、不该出现在 AgentConfig 里。

Three: the data. Field names, units, defaults, what the author should see in Details. Say which fields are runtime and must stay out of the AgentConfig.

四、链上位置。它压过谁,被谁压过。逃跑压过追逐和攻击、受击不打断攻击,这些是设计决定;写下来,它才知道判定节放哪。

Four: its place on the chain. What it overrides, what overrides it. Escape beats chase and attack; being hit does not interrupt an attack. Those are design decisions; write them and it knows where the check belongs.

五、边界。它能写哪些字段(Moving.Goal?动画片段?),不能碰哪些(别人的片段、原型、查询、模板里别人的那几行)。这一行写清楚最省事:agent 有"顺手统一"的倾向,你不划圈它就不守。

Five: the boundary. Which fields it may write (Moving.Goal? animation clips?) and which it may not touch (other entities' fragments, archetypes, queries, other people's lines in the template). This line saves the most work: agents tend to tidy up along the way, and they respect only the fence you draw.

六、确定性。用不用随机、用哪条流、哪些字段跨帧、要不要进快照。这四句话写清楚,联机失步能少排查一轮。

Six: determinism. Whether it uses randomness, which stream, which fields live across frames, whether they join the snapshot. Four sentences, and one desync hunt saved.

七、验收。一句能观察到的现象,加一张闸门清单:增量构建过、check_pairs.py 与 check_bilingual_text.py 干净、启动 Require 没炸、你打开 PIE 能看到什么。验收写得越像"现象",它越不会用一段自述代替证据。

Seven: acceptance. One observable behaviour, plus a gate list: incremental build green, check_pairs.py and check_bilingual_text.py clean, startup Require not tripped, and what you will see when you open PIE. The more acceptance reads like a phenomenon, the less likely it is to substitute a paragraph of self-report for evidence.

反过来,有几样东西别给:一份"怎么写 ECS 行为"的通用教程;一个"参考一下网上怎么写闪避"的授权;一段"顺便优化一下"的余地。第一样它比你熟,第二样换回来一个和这条链不兼容的教科书答案,第三样把 diff 撑到你读不完。

And a few things not to hand it: a general tutorial on writing ECS behaviours; permission to "look up how dodging is usually done"; and any room to "optimise along the way". It knows the first better than you, the second buys a textbook answer that does not fit this chain, and the third turns the diff into something you cannot finish reading.

它做不到的部分 What It Cannot Do

把话说全:agent 可以写出一个正确、可编译、过了所有闸门的实现,然后它依然是个坏设计。它缺的东西很具体,就三样:

To be complete: an agent can produce a correct implementation that compiles and passes every gate, and it can still be a bad design. What it lacks is specific, and there are only three things:

判断。放哪一层、判定节放在链上什么位置、这个能力值不值得一个片段。它能给出自洽的方案,但"稳定 30 帧比抖动 60 帧值钱"这种取舍它没有立场,因为它没在十万实体下看过帧时间。

Judgement. Which layer, where on the chain, whether the capability deserves a fragment at all. It will give you a coherent proposal, but it has no position on "stable 30 beats jittery 60" — it has never watched frame time at a hundred thousand entities.

手感。阈值、冷却、窗口长度都是玩法,它只能给一个跑得起来的初始值。让它填 30%、8 米、0.2 秒,你自己跑一局再改,这是正常流程。指望它一次给出好玩的数字,等于把设计外包给一个没玩过你游戏的东西。

Feel. Thresholds, cooldowns, window lengths are gameplay, and all it can give you is a working starting value. Let it write 30%, 8 metres, 0.2 seconds, then play a match and change them — that is the normal loop. Expecting good numbers on the first try outsources design to something that has never played your game.

眼睛。它读不到画面。动画叠得顺不顺、逃跑路线在山坡上会不会贴墙、闪避窗口和受击片段对不对得上,这些都得你打开 PIE 看。所有"看起来对不对"的验收它只能自述,而自述不算证据。

Eyes. It cannot see the screen. Whether the animation blends cleanly, whether the flee path grinds along a hillside, whether the dodge window lines up with the hit clip — you have to open PIE. Every "does it look right" check is something it can only describe, and a description is not evidence.

还有一件小事,但它一定会发生:它过度自信。给一个模糊需求,它倾向于把整条链重写一遍来"统一风格"。所以 brief 里"只改这几处"要写死;评审时先看 git diff --stat 的范围,再看内容。

One small thing that will happen: it over-reaches. Given a vague request it tends to rewrite the whole chain "for consistency". So make "touch only these places" explicit in the brief, and read git diff --stat before reading the diff.

一句话 In One Line

面板擅长填数字,源码擅长写逻辑,agent 让第二件事第一次可以外包出去。要付的价钱也从"等作者发下一版"变成了"守住一套写法":分层、成对片段、bEnable 默认关、模板行加启动断言、跨帧字段进快照。这套东西守住了,agent 写的代码和你写的没有区别;守不住,它只会更快地写出你读不懂的东西。

Panels are good at numbers, source is good at logic, and an agent makes the second one outsourceable for the first time. The price moves from "wait for the next release" to "hold one shape": layers, fragment pairs, bEnable off by default, a template line plus a startup assert, cross-frame fields in the snapshot. Hold that shape and agent-written code is indistinguishable from yours. Lose it and the agent just produces unreadable code faster.

Leroy Works · Mass Battle Framework 作者
联系:Discord · QQ 群 916358710 · Fab · 全部联系方式

Leroy Works — author of Mass Battle Framework
Contact: Discord · QQ group 916358710 · Fab · all channels