行为树修改
This commit is contained in:
parent
8009c298ae
commit
1195136563
@ -24,7 +24,7 @@ MonoBehaviour:
|
||||
_version: 3.33
|
||||
_category:
|
||||
_comments:
|
||||
_translation: {x: 504, y: 112}
|
||||
_translation: {x: 667, y: 127}
|
||||
_zoomFactor: 1
|
||||
_haltSerialization: 0
|
||||
_externalSerializationFile: {fileID: 0}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -35,11 +35,7 @@ namespace NodeCanvas.Tasks.Actions
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CalculateTypes[0] == CalculateType.UnitMoveToTargetGrid)
|
||||
{
|
||||
Debug.Log(111);
|
||||
}
|
||||
|
||||
data.value.MaxAiAction = AIActionScoreCalculator.CalculateAIActionScore(data.value, CalculateTypes);
|
||||
if (data.value.MaxAiAction == null)
|
||||
{
|
||||
|
||||
@ -6,11 +6,13 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Logic.Action;
|
||||
using Logic.AI;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using RuntimeData;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
@ -43,7 +45,9 @@ namespace NodeCanvas.Tasks.Actions
|
||||
if (data.value.ForeachUnit.Count == 0 && data.value.ForeachLegion.Count != 0)
|
||||
{
|
||||
var legion = data.value.ForeachLegion[0];
|
||||
foreach (var unit in data.value.Map.UnitMap.UnitList)
|
||||
var selfUnitList = new HashSet<UnitData>();
|
||||
data.value.Map.GetUnitDataListByPlayerId(data.value.Player.Id, selfUnitList);
|
||||
foreach (var unit in selfUnitList)
|
||||
{
|
||||
if (unit.LegionId != legion) continue;
|
||||
data.value.ForeachUnit.Add(unit);
|
||||
|
||||
@ -129,6 +129,8 @@ namespace Logic.AI
|
||||
public Dictionary<uint, GridData> UnitTargetGrid;
|
||||
// 小兵攻击系数
|
||||
public Dictionary<uint, int> UnitAttackRatio;
|
||||
// 军团可达城市
|
||||
public Dictionary<uint, HashSet<uint>> LegionCanMoveCities;
|
||||
|
||||
|
||||
public List<AIActionBase> AIActions;
|
||||
@ -180,6 +182,7 @@ namespace Logic.AI
|
||||
LegionTargetCity = new Dictionary<uint, uint>();
|
||||
UnitTargetGrid = new Dictionary<uint, GridData>();
|
||||
UnitAttackRatio = new Dictionary<uint, int>();
|
||||
LegionCanMoveCities = new Dictionary<uint, HashSet<uint>>();
|
||||
|
||||
IsFinish = false;
|
||||
IsInSight = false;
|
||||
@ -226,6 +229,7 @@ namespace Logic.AI
|
||||
LegionTargetCity.Clear();
|
||||
UnitTargetGrid.Clear();
|
||||
UnitAttackRatio.Clear();
|
||||
LegionCanMoveCities.Clear();
|
||||
|
||||
// 国家策略
|
||||
foreach (var playerData in map.PlayerMap.PlayerDataList)
|
||||
@ -299,6 +303,7 @@ namespace Logic.AI
|
||||
LegionTargetCity.Clear();
|
||||
UnitTargetGrid.Clear();
|
||||
UnitAttackRatio.Clear();
|
||||
LegionCanMoveCities.Clear();
|
||||
var selfUnitList = new List<UnitData>();
|
||||
Map.GetUnitDataListByPlayerId(Player.Id, selfUnitList);
|
||||
foreach (var unit in selfUnitList)
|
||||
@ -339,6 +344,20 @@ namespace Logic.AI
|
||||
if (!Map.GridMap.GetGridDataByPos(center.x, center.y, out var centerGrid)) continue;
|
||||
LegionGrid[kv.Key] = centerGrid;
|
||||
}
|
||||
|
||||
foreach (var kv in LegionUnits)
|
||||
{
|
||||
LegionCanMoveCities[kv.Key] = new HashSet<uint>();
|
||||
foreach (var city in Map.CityMap.CityList)
|
||||
{
|
||||
if (!Map.GetGridDataByCityId(city.Id, out var cityGrid)) continue;
|
||||
var path = PathFinder.FindPath((int)Map.MapConfig.Width, (int)Map.MapConfig.Height,
|
||||
new (cityGrid.Pos.X, cityGrid.Pos.Y),
|
||||
new (LegionGrid[kv.Key].Pos.X, LegionGrid[kv.Key].Pos.Y), Map, Player);
|
||||
if (!path.found) continue;
|
||||
LegionCanMoveCities[kv.Key].Add(city.Id);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in LegionUnits)
|
||||
{
|
||||
@ -350,6 +369,7 @@ namespace Logic.AI
|
||||
}
|
||||
LegionUnstableScore[kv.Key] = sunDis * kv.Value.Count / 5f;
|
||||
}
|
||||
|
||||
|
||||
// 自主战略
|
||||
var selfCity = new HashSet<CityData>();
|
||||
@ -370,6 +390,7 @@ namespace Logic.AI
|
||||
foreach (var cityPair in CityStrategy)
|
||||
{
|
||||
if (cityPair.Value != Strategy.EmergencyDefend) continue;
|
||||
if (!LegionCanMoveCities[kv.Key].Contains(cityPair.Key.Id)) continue;
|
||||
LegionTargetCity[kv.Key] = cityPair.Key.Id;
|
||||
LegionStrategy[kv.Key] = Strategy.Defend;
|
||||
isFinish = true;
|
||||
@ -381,6 +402,8 @@ namespace Logic.AI
|
||||
foreach (var targetCity in citySet)
|
||||
{
|
||||
if (selfCity.Contains(targetCity)) continue;
|
||||
if (!LegionCanMoveCities[kv.Key].Contains(targetCity.Id)) continue;
|
||||
|
||||
var score = LegionScore[kv.Key] - CityDefendScore[targetCity.Id];
|
||||
foreach (var unit in kv.Value)
|
||||
{
|
||||
@ -417,6 +440,7 @@ namespace Logic.AI
|
||||
{
|
||||
foreach (var city in selfCity)
|
||||
{
|
||||
if (!LegionCanMoveCities[legionId].Contains(city.Id)) continue;
|
||||
if (!Map.GetGridDataByCityId(city.Id, out var cityGrid)) continue;
|
||||
var score = (LegionScore[legionId] - CityDangerScore[city.Id]) /
|
||||
(Map.GridMap.CalcDistance(cityGrid, LegionGrid[legionId]) + 1);
|
||||
@ -451,6 +475,7 @@ namespace Logic.AI
|
||||
{
|
||||
foreach (var city in Map.CityMap.CityList)
|
||||
{
|
||||
if (!LegionCanMoveCities[legionId].Contains(city.Id)) continue;
|
||||
if (selfCity.Contains(city)) continue;
|
||||
if (!Map.GetGridDataByCityId(city.Id, out var cityGrid)) continue;
|
||||
var score = (2 * LegionScore[legionId] - CityDefendScore[city.Id] - CityRescueScore[city.Id]) /
|
||||
@ -664,7 +689,7 @@ namespace Logic.AI
|
||||
{
|
||||
if (!Map.GetGridDataByCityId(city.Id, out var cityGrid)) continue;
|
||||
var distance = Map.GridMap.CalcDistance(cityGrid, unitGrid);
|
||||
if (distance >= minDis) continue;
|
||||
if (distance <= 2 || distance >= minDis) continue;
|
||||
minDis = distance;
|
||||
target = city;
|
||||
targetGrid = cityGrid;
|
||||
|
||||
@ -737,8 +737,11 @@ namespace Logic.AI
|
||||
{
|
||||
if (param.UnitData == null || param.TargetGridData == null) return;
|
||||
if (!param.MapData.GetGridDataByUnitId(param.UnitData.Id, out var unitGrid)) return;
|
||||
var distance = param.MapData.GridMap.CalcDistance(param.TargetGridData, unitGrid);
|
||||
result.Score[CalculateType.UnitMoveToTargetGrid] = 1f / (distance + 1);
|
||||
var path = PathFinder.FindPath((int)param.MapData.MapConfig.Width, (int)param.MapData.MapConfig.Height,
|
||||
new (unitGrid.Pos.X, unitGrid.Pos.Y), new (param.TargetGridData.Pos.X, param.TargetGridData.Pos.Y),
|
||||
param.MapData, param.PlayerData);
|
||||
if (!path.found) return;
|
||||
result.Score[CalculateType.UnitMoveToTargetGrid] = 1f / (path.length + 1);
|
||||
}
|
||||
|
||||
private static void CalculateLegionDevelopmentAttackUnit(AICalculatorData data, CommonActionParams param, CalculateResult result)
|
||||
|
||||
@ -79,6 +79,8 @@ namespace Logic.AI
|
||||
_playerData = playerData;
|
||||
_generator.Init(_mapData, _playerData);
|
||||
_data.Refresh(mapData, playerData);
|
||||
_btOwner.StopBehaviour();
|
||||
_btOwner.StartBehaviour();
|
||||
MainEditor.Instance.Data = _data;
|
||||
}
|
||||
|
||||
@ -113,7 +115,12 @@ namespace Logic.AI
|
||||
Debug.Log($"{_generator.ActionType} 耗时:{sw.Elapsed.TotalMilliseconds} ms");
|
||||
MainEditor.Instance.IsGo = false;
|
||||
|
||||
if (index > 20 || _data.IsExcute || _data.IsFinish) break;
|
||||
if (_data.IsExcute || _data.IsFinish) break;
|
||||
if (index > 100)
|
||||
{
|
||||
Debug.LogWarning($"死循环了");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_data.IsExcute)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user