Skip to content

Commit e1b2551

Browse files
committed
lastorder support
1 parent c6f60bd commit e1b2551

4 files changed

Lines changed: 80 additions & 5 deletions

File tree

Copilot/openra_ai/OpenRA_Copilot_Library/game_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def update_actor(self, actor: Actor) -> bool:
666666
raise GameAPIError("UPDATE_ACTOR_ERROR", "更新Actor信息时发生错误: {0}".format(str(e)))
667667

668668
def deploy_units(self, actors: List[Actor]) -> None:
669-
'''部署/展开 Actor
669+
'''部署/展开 Actor (如展开基地车)
670670
671671
Args:
672672
actors (List[Actor]): 要部署/展开的Actor列表

OpenRA.Mods.Common/ServerCommands.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,8 @@ public static JObject ActorQueryCommand(JObject json, World world)
10731073
{
10741074
var hashealth = actor.Info.HasTraitInfo<HealthInfo>();
10751075
var health = actor.TraitOrDefault<Health>();
1076+
var activity = actor.CurrentActivity;
1077+
var lastOrder = actor.TraitOrDefault<TrackLastResolvedOrder>();
10761078
return new JObject
10771079
{
10781080
["id"] = actor.ActorID,
@@ -1082,6 +1084,10 @@ public static JObject ActorQueryCommand(JObject json, World world)
10821084
["hp"] = hashealth ? health.HP : -1,
10831085
["maxHp"] = hashealth ? health.MaxHP : -1,
10841086
["isDead"] = hashealth && health.IsDead,
1087+
// 与调试红字 RenderDebugState 一致:Activity.DebugLabelComponents().JoinWith(".")
1088+
["activity"] = activity != null ? activity.DebugLabelComponents().JoinWith(".") : "",
1089+
// OpenRA 默认不提供“当前 order”的直接读取,这里返回最近一次 ResolveOrder 记录到 trait 的值
1090+
["order"] = lastOrder?.LastOrderLabel ?? "",
10851091
["position"] = new JObject
10861092
{
10871093
["x"] = actor.Location.X,
@@ -1215,8 +1221,8 @@ public static JObject FogQueryCommand(JObject json, World world)
12151221
public static JObject MapQueryCommand(JObject json, World world)
12161222
{
12171223
var map = world.Map;
1218-
var width = map.MapSize.X;
1219-
var height = map.MapSize.Y;
1224+
var width = map.MapSize.X - 2;
1225+
var height = map.MapSize.Y - 2;
12201226

12211227
// 初始化二维数组
12221228
var heightArray = new JArray();
@@ -1226,7 +1232,7 @@ public static JObject MapQueryCommand(JObject json, World world)
12261232
var resourcesTypeArray = new JArray();
12271233
var resourcesArray = new JArray();
12281234

1229-
for (var x = 0; x < width; x++)
1235+
for (var x = 1; x <= width; x++)
12301236
{
12311237
var heightRow = new JArray();
12321238
var isVisibleRow = new JArray();
@@ -1235,7 +1241,7 @@ public static JObject MapQueryCommand(JObject json, World world)
12351241
var resourcesTypeRow = new JArray();
12361242
var resourcesRow = new JArray();
12371243

1238-
for (var y = 0; y < height; y++)
1244+
for (var y = 1; y <= height; y++)
12391245
{
12401246
var pos = new CPos(x, y);
12411247
heightRow.Add(map.Height[pos]);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#region Copyright & License Information
2+
/*
3+
* Copyright (c) The OpenRA Developers and Contributors
4+
* This file is part of OpenRA, which is free software. It is made
5+
* available to you under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, either version 3 of
7+
* the License, or (at your option) any later version. For more
8+
* information, see COPYING.
9+
*/
10+
#endregion
11+
12+
using OpenRA.Network;
13+
using OpenRA.Traits;
14+
15+
namespace OpenRA.Mods.Common.Traits
16+
{
17+
/// <summary>
18+
/// 记录 actor 最近一次被执行(Resolve)的 Order,用于调试/查询接口。
19+
/// 注意:OpenRA 默认不会把“当前正在执行的 Order”保存在 Actor 上;
20+
/// Order 会被分发到 Actor.ResolveOrder(...) 然后由各 trait 处理。
21+
/// </summary>
22+
[Desc("Records the last resolved Order for debugging/queries.")]
23+
public sealed class TrackLastResolvedOrderInfo : TraitInfo
24+
{
25+
public override object Create(ActorInitializer init) { return new TrackLastResolvedOrder(); }
26+
}
27+
28+
public sealed class TrackLastResolvedOrder : IResolveOrder
29+
{
30+
/// <summary>最近一次 order 的 id(OrderString)。</summary>
31+
public string LastOrderString { get; private set; } = "";
32+
33+
/// <summary>最近一次 order 的 TargetString(如果有)。</summary>
34+
public string LastOrderTargetString { get; private set; } = "";
35+
36+
/// <summary>最近一次 order 是否 queued。</summary>
37+
public bool LastOrderQueued { get; private set; }
38+
39+
/// <summary>
40+
/// 给外部(如 ServerCommands)直接用的展示字符串。
41+
/// </summary>
42+
public string LastOrderLabel
43+
{
44+
get
45+
{
46+
if (string.IsNullOrEmpty(LastOrderString))
47+
return "";
48+
49+
// 例:Move, Attack, Harvest...;若 TargetString 有值则拼上,方便调试
50+
if (string.IsNullOrEmpty(LastOrderTargetString))
51+
return LastOrderQueued ? $"{LastOrderString} (Queued)" : LastOrderString;
52+
53+
return LastOrderQueued
54+
? $"{LastOrderString} -> {LastOrderTargetString} (Queued)"
55+
: $"{LastOrderString} -> {LastOrderTargetString}";
56+
}
57+
}
58+
59+
void IResolveOrder.ResolveOrder(Actor self, Order order)
60+
{
61+
// 仅记录信息,不影响逻辑与同步
62+
LastOrderString = order?.OrderString ?? "";
63+
LastOrderTargetString = order?.TargetString ?? "";
64+
LastOrderQueued = order != null && order.Queued;
65+
}
66+
}
67+
}
68+
69+

start.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)