ra: 开局自动托管给传统人机(Bot Takeover)
背景 - OpenRA 的 Player 默认按‘人类’设计:不自动执行建造/展开/生产等,需要玩家输入。 - 为了实现全人机阵营交锋(后续再叠加 LLM 增强),需要在开局就把本地玩家控制权交还给传统人机。 改动 - 新增 BotTakeoverManager(Player trait):WorldLoaded 后自动为本地人类玩家激活传统 ModularBot(normal),并授予 nable-normal-ai,确保传统 AI 全链路模块从开局开始运行。 - 将右下角托管按钮逻辑改为切换 BotTakeoverManager,用于随时取消/恢复托管(避免直接激活 LLM bot 导致双 bot 并行与性能风险)。 - RA UI 增加托管按钮与中文提示文案。 影响 - 开局无需等待/点击即可展开 MCV 并开始传统 AI 运营;同时仍可通过按钮取消托管恢复手动操作。
This commit is contained in:
57
OpenRA.Mods.Common/Widgets/Logic/Ingame/LLMTakeoverLogic.cs
Normal file
57
OpenRA.Mods.Common/Widgets/Logic/Ingame/LLMTakeoverLogic.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class LLMTakeoverLogic : ChromeLogic
|
||||
{
|
||||
readonly World world;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public LLMTakeoverLogic(Widget widget, World world, Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
this.world = world;
|
||||
|
||||
var button = widget.Get<ButtonWidget>("LLM_TAKEOVER");
|
||||
button.GetText = () => IsTakeoverActive() ? "Cancel AI" : "AI";
|
||||
button.IsHighlighted = () => IsTakeoverActive();
|
||||
button.OnClick = OnTakeoverClick;
|
||||
button.IsDisabled = () => world.LocalPlayer == null
|
||||
|| world.LocalPlayer.WinState != WinState.Undefined;
|
||||
}
|
||||
|
||||
bool IsTakeoverActive()
|
||||
{
|
||||
var player = world.LocalPlayer;
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
var takeover = player.PlayerActor.TraitOrDefault<BotTakeoverManager>();
|
||||
return takeover != null && takeover.IsActive;
|
||||
}
|
||||
|
||||
void OnTakeoverClick()
|
||||
{
|
||||
var player = world.LocalPlayer;
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
// Prefer the classic AI takeover manager (uses ModularBot + original bot modules).
|
||||
var takeover = player.PlayerActor.TraitOrDefault<BotTakeoverManager>();
|
||||
if (takeover != null)
|
||||
takeover.Toggle();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user