diff --git a/docs/usr/modules/tactics.md b/docs/usr/modules/tactics.md index 02532e2b..b57d2a38 100644 --- a/docs/usr/modules/tactics.md +++ b/docs/usr/modules/tactics.md @@ -27,6 +27,10 @@ local moved = battle.move("00000000-0000-0000-0000-000000001002", 1, 0, 0); 代理内部只保存带 module epoch 的 generation handle;`release()` 或模块卸载后,后续写操作返回 `StaleHandle`。脚本不会接触 ECS handle 或跨帧裸指针。 +`Tactics.getName()` 返回模块名;`battleCount()`、`sideCount()` 和 `unitCount()` 返回当前存活的 +战局、阵营与单位数量。战局代理的 `ownership()` 返回 `"owned"`,`isStale()` 用于在调用其他 +战局方法前显式检查代理是否已因 `release()` 或模块 epoch 变化而失效。 + 可用的战局操作包括 `setTopology/addCell/addSide/addUnit/start/advance/move/face/wait/defeatUnit`,查询包括 `status/phase/activeUnit/unitCell/revision/eventCount/eventAt`。所有可能失败的写操作都返回统一 `{ok, code, status, diagnostics, value}` 结构。 diff --git a/src/modules/tactics/TacticsPersistence.cpp b/src/modules/tactics/TacticsPersistence.cpp index 2ea297de..4989f17f 100644 --- a/src/modules/tactics/TacticsPersistence.cpp +++ b/src/modules/tactics/TacticsPersistence.cpp @@ -92,7 +92,7 @@ Result parseCell(const Value& value, std::string path) { if (candidate.value()->size() != 3) return fail(DiagnosticCode::ParseError, "cell has unknown or missing fields", std::move(path)); Cell result; - for (const auto [name, target] : {std::pair{"x", &result.x}, {"y", &result.y}, {"layer", &result.layer}}) { + for (const auto& [name, target] : {std::pair{"x", &result.x}, {"y", &result.y}, {"layer", &result.layer}}) { auto member = field(*candidate.value(), name, path); if (!member) return Result::failure(member.status()); auto parsed = integer(*member.value(), path + "." + name); @@ -755,7 +755,7 @@ Result parseCandidate(Battle& battle, const Value& payload, Revision definition = *parsedDefinition; } TacticalUnit::TurnResources turn; - for (const auto [name, target] : + for (const auto& [name, target] : {std::pair{"actionPoints", &turn.actionPoints}, {"movePoints", &turn.movePoints}, {"reactionPoints", &turn.reactionPoints}, {"roundActionPoints", &turn.roundActionPoints}, {"roundMovePoints", &turn.roundMovePoints}, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 421f6de0..47befb01 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -353,6 +353,15 @@ file(GLOB all_test_cpp tensor.cpp tensor_llm.cpp tensor_quant.cpp + tactics_action.cpp + tactics_board.cpp + tactics_objective.cpp + tactics_path.cpp + tactics_reaction.cpp + tactics_replay.cpp + tactics_rpg_integration.cpp + tactics_script.cpp + tactics_turn.cpp callgraph.cpp renderflow.cpp resource_lifetime.cpp