Behavior.h
Source/MassBattle/Public/Fragments/Behavior.h
概述Overview
行为系统的 fragment 集合,按配置与状态成对出现:配置 FBehavior 定义九个一次性行为转移点的目标行为,运行时状态 FBehaving 携带当前互斥行为、请求切换的行为、消费标志与瞄准计时;跳跃配置 FJump 定义一次主动跳跃的冲量与冷却,跳跃时钟 FJumping 记录剩余冷却与滞空时间。一次性切换完成后,自然优先级链(Sleep > Patrol,按各自 bEnable)接管。
Behavior fragment collection, arranged in config/state pairs: config FBehavior defines the target behavior at nine one-shot transition points, runtime state FBehaving carries the current mutually-exclusive behavior, the requested switch, the consume flag and the aim clock; jump config FJump defines the impulse and cooldown of one deliberate jump, and the jump clocks FJumping record the remaining cooldown and airborne time. After a one-shot switch, the natural priority chain (Sleep > Patrol, each gated by its own bEnable) takes over.
FBehavior USTRUCT
行为配置 fragment。九个转移点各指定一个 EBehaviorChoice 目标行为(可选值见 MassBattleEnums.h 的 EBehaviorChoice),由策划在 AgentConfig 中配置,运行时不变。其中两条瞄准行决定瞄准行为之后走什么:已对准,或瞄准窗口到期仍未对准。
Behavior config fragment. Each of the nine transition points names an EBehaviorChoice target (the values are listed under EBehaviorChoice in MassBattleEnums.h); designers configure them on the AgentConfig and they stay constant at runtime. The two aim rows decide what follows the Aim behaviour: aligned, or the aim window expiring without alignment.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
OnBirth | EBehaviorChoice | Idle | Agent 出生或激活时选择的行为。Behavior selected when the agent is born or activated. |
OnAppearFinish | EBehaviorChoice | Idle | 出生表现(Appear)结束后选择的行为。Behavior selected when the Appear sequence finishes. |
OnSleepWake | EBehaviorChoice | Idle | 睡眠中受到攻击且 Sleep 的 bWakeOnHit 启用时选择的行为。Behavior selected when Sleep is interrupted by a hit while Sleep's bWakeOnHit is set. |
OnPatrolRoundEnd | EBehaviorChoice | Patrol | 一轮巡逻结束后选择的行为。Behavior selected when a patrol round ends. |
OnLostTarget | EBehaviorChoice | Idle | 追逐或攻击丢失当前目标后选择的行为。Behavior selected when the current target is lost by chase or attack. |
OnReturnFinish | EBehaviorChoice | Idle | 回归结束后选择的行为。Behavior selected when Return finishes. |
OnJumpFinish | EBehaviorChoice | Idle | 跳跃落地后选择的行为。Behavior selected when a jump lands. |
OnAimAligned | EBehaviorChoice | Attack | 瞄准关节已对准目标且达到最短瞄准时间后选择的行为。Behavior selected once the aim joint has aligned with the target and the minimum aim time has elapsed. |
OnAimTimeout | EBehaviorChoice | Attack | 瞄准窗口到期仍未对准时选择的行为。默认 Attack,以便在攻击回合里走完惩罚冷却;改为 Idle 即不惩罚。Behavior selected when the aim window expires without alignment. Defaults to Attack so the penalty cooldown runs inside the attack round; Idle skips the penalty. |
FBehaving USTRUCT
行为运行时状态 fragment。运行时逐帧读取 ActiveBehavior;外部(任务节点、事件)写入 RequestedBehavior + bHasSwitchRequest 请求切换,请求被消费后清除。AimTime 记录本次瞄准行为已经过去多久,进快照与哈希。
Behavior runtime state fragment. The runtime reads ActiveBehavior each frame; external code (task nodes, events) writes RequestedBehavior + bHasSwitchRequest to request a switch, which is consumed and cleared. AimTime records how long the current Aim behaviour has been running; it is snapshotted and hashed.
成员变量Members
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
ActiveBehavior | EBehaviorState | Idle | 当前激活的互斥行为(可选值见 MassBattleEnums.h 的 EBehaviorState)。The currently active mutually-exclusive behavior (values are listed under EBehaviorState in MassBattleEnums.h). |
RequestedBehavior | EBehaviorState | Idle | 请求的行为切换,由行为逻辑消费。Requested behavior switch, consumed by the behavior pass. |
bHasSwitchRequest | bool | false | 本帧是否应消费 RequestedBehavior。Whether RequestedBehavior should be consumed this frame. |
AimTime | float | 0.f | 在 Aim 行为里经过的秒数,进入时清零,与瞄准配置的时间窗口比较。进快照与哈希。Seconds spent in the Aim behaviour, reset on entry and compared against the aim config's time window. Snapshotted and hashed. |
FJump USTRUCT
跳跃配置 fragment。起跳冲量按速度配置,不按高度:模拟积分用的是每个 agent 自己的重力(不同原型可以不同),写死高度就得再按原型反解一遍。滞空时间约为 2 × ZSpeed / |Gravity|。进入跳跃要求接触地面且冷却就绪;落地后触发 Behavior.OnJumpFinish。
Jump config fragment. The takeoff impulse is authored as a speed, not a height: the simulation integrates each agent's own gravity (which can differ between archetypes), so an authored height would have to be re-solved per archetype. Air time is about 2 × ZSpeed / |Gravity|. Entry requires ground contact and a ready cooldown; landing fires Behavior.OnJumpFinish.
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
bEnable | bool | false | 启用跳跃行为。关闭 = 跳跃请求与行为被禁用时一样降级为 Idle。Enable the jump behavior. Off = a jump request degrades to Idle exactly like a disabled behavior. |
ZSpeed | float | 600.f | 起跳的向上速度(cm/s,最小值 0)。滞空时间约为 2 × ZSpeed / |Gravity|。Upward takeoff speed (cm/s, minimum 0). Air time is about 2 × ZSpeed / |Gravity|. |
ForwardSpeed | float | 0.f | 起跳时沿当前朝向叠加的速度(cm/s);0 = 原地跳。Speed added along the current facing at takeoff (cm/s); 0 = jump in place. |
Cooldown | float | 1.f | 下一次跳跃开始前的冷却秒数(最小值 0)。Seconds before another jump can start (minimum 0). |
MaxAirTime | float | 3.f | 滞空阶段的上限(秒,最小值 0.1)。单位一直不报告触地时(例如悬停在空中的飞行单位)靠它退出行为。Upper bound on the airborne phase (seconds, minimum 0.1). Exits the behavior when the agent never reports ground contact (for example a flyer holding altitude). |
FJumping USTRUCT
跳跃运行时时钟 fragment:剩余冷却与起跳冲量以来经过的时间(后者是"永不落地"的保护依据)。与配置分开,和所有 F* / F*ing 对的拆分方式一致。
Jump runtime clocks: the remaining cooldown and the time since the takeoff impulse (the guard against never landing). Split from the config, the same way every F* / F*ing pair is.
| 名称Name | 类型Type | 默认值 | 说明Description |
|---|---|---|---|
CooldownTimer | float | 0.f | 剩余跳跃冷却秒数。Remaining jump cooldown in seconds. |
AirTime | float | 0.f | 起跳冲量以来经过的秒数。Seconds elapsed since the takeoff impulse. |
管线角色Pipeline Role
FBehavior 是行为链的转移表:每个转移点在对应事件发生的时刻被查一次,选出下一个 EBehaviorChoice(再映射为 EBehaviorState)。FBehaving 是这条链的运行时黑板:ActiveBehavior 决定当前持有哪些行为效果,外部请求经 RequestedBehavior 提交、被消费后清除。FJump / FJumping 只管跳跃这一条支线——配置决定冲量与冷却,时钟由模拟推进,落地时回到转移表。动画侧读取 ActiveBehavior、AimTime 与跳跃状态来决定播哪条片段;这些字段都进快照,所以双端看到的是同一套行为状态。
FBehavior is the behavior chain's transition table: each transition point is consulted when its event occurs and selects the next EBehaviorChoice (then mapped to EBehaviorState). FBehaving is the chain's runtime blackboard: ActiveBehavior decides which behavior effects are active, and external requests go through RequestedBehavior and are cleared once consumed. FJump / FJumping own only the jump branch — the config sets the impulse and cooldown, the clocks advance with the simulation, and landing returns to the transition table. The animation side reads ActiveBehavior, AimTime and the jump state to decide which clip plays; these fields are snapshotted, so both peers see the same behavior state.