#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 logicArgs) { this.world = world; var button = widget.Get("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(); 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(); if (takeover != null) takeover.Toggle(); } } }