本文整理汇总了C#中OpenRA.Mods.Common.AI.Squad类的典型用法代码示例。如果您正苦于以下问题:C# Squad类的具体用法?C# Squad怎么用?C# Squad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Squad类属于OpenRA.Mods.Common.AI命名空间,在下文中一共展示了Squad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tick
public void Tick(Squad owner)
{
if (!owner.IsValid)
return;
if (!owner.IsTargetValid)
{
var t = owner.Bot.FindClosestEnemy(owner.Units.FirstOrDefault().CenterPosition);
if (t == null) return;
owner.TargetActor = t;
}
var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(10))
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
if (enemyUnits.Any())
{
if (owner.AttackOrFleeFuzzy.CanAttack(owner.Units, enemyUnits))
{
foreach (var u in owner.Units)
owner.Bot.QueueOrder(new Order("AttackMove", u, false) { TargetLocation = owner.TargetActor.Location });
// We have gathered sufficient units. Attack the nearest enemy unit.
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsAttackMoveState(), true);
return;
}
else
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsFleeState(), true);
}
}
示例2: RandomBuildingLocation
protected static CPos RandomBuildingLocation(Squad squad)
{
var location = squad.Bot.GetRandomBaseCenter();
var buildings = squad.World.ActorsWithTrait<Building>()
.Where(a => a.Actor.Owner == squad.Bot.Player).Select(a => a.Actor).ToList();
if (buildings.Count > 0)
location = buildings.Random(squad.Random).Location;
return location;
}
示例3: Tick
public void Tick(Squad owner)
{
if (!owner.IsValid)
return;
if (!owner.IsTargetValid)
{
var closestEnemy = owner.Bot.FindClosestEnemy(owner.Units.Random(owner.Random).CenterPosition);
if (closestEnemy != null)
owner.TargetActor = closestEnemy;
else
{
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsFleeState(), true);
return;
}
}
var leader = owner.Units.ClosestTo(owner.TargetActor.CenterPosition);
if (leader == null)
return;
var ownUnits = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(owner.Units.Count) / 3)
.Where(a => a.Owner == owner.Units.FirstOrDefault().Owner && owner.Units.Contains(a)).ToHashSet();
if (ownUnits.Count < owner.Units.Count)
{
owner.World.IssueOrder(new Order("Stop", leader, false));
foreach (var unit in owner.Units.Where(a => !ownUnits.Contains(a)))
owner.World.IssueOrder(new Order("AttackMove", unit, false) { TargetLocation = leader.Location });
}
else
{
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(12))
.Where(a1 => !a1.Disposed && !a1.IsDead);
var enemynearby = enemies.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy);
var target = enemynearby.ClosestTo(leader.CenterPosition);
if (target != null)
{
owner.TargetActor = target;
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsAttackState(), true);
return;
}
else
foreach (var a in owner.Units)
owner.World.IssueOrder(new Order("AttackMove", a, false) { TargetLocation = owner.TargetActor.Location });
}
if (ShouldFlee(owner))
{
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsFleeState(), true);
return;
}
}
示例4: Tick
public void Tick(Squad owner)
{
if (!owner.IsValid)
return;
if (!owner.TargetIsValid)
{
var a = owner.Units.Random(owner.Random);
var closestEnemy = owner.Bot.FindClosestEnemy(a.CenterPosition);
if (closestEnemy != null)
owner.TargetActor = closestEnemy;
else
{
owner.FuzzyStateMachine.ChangeState(owner, new AirFleeState(), true);
return;
}
}
if (!NearToPosSafely(owner, owner.TargetActor.CenterPosition))
{
owner.FuzzyStateMachine.ChangeState(owner, new AirFleeState(), true);
return;
}
foreach (var a in owner.Units)
{
if (BusyAttack(a))
continue;
if (!ReloadsAutomatically(a))
{
if (!HasAmmo(a))
{
if (IsRearm(a))
continue;
owner.World.IssueOrder(new Order("ReturnToBase", a, false));
continue;
}
if (IsRearm(a))
continue;
}
if (owner.TargetActor.HasTrait<ITargetable>() && CanAttackTarget(a, owner.TargetActor))
owner.World.IssueOrder(new Order("Attack", a, false) { TargetActor = owner.TargetActor });
}
}
示例5: ShouldFlee
protected virtual bool ShouldFlee(Squad squad, Func<IEnumerable<Actor>, bool> flee)
{
if (!squad.IsValid)
return false;
var u = squad.Units.Random(squad.Random);
var units = squad.World.FindActorsInCircle(u.CenterPosition, WDist.FromCells(DangerRadius)).ToList();
var ownBaseBuildingAround = units.Where(unit => unit.Owner == squad.Bot.Player && unit.Info.HasTraitInfo<BuildingInfo>());
if (ownBaseBuildingAround.Any())
return false;
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>());
if (!enemyAroundUnit.Any())
return false;
return flee(enemyAroundUnit);
}
示例6: FindSafePlace
protected static CPos? FindSafePlace(Squad owner, out Actor detectedEnemyTarget, bool needTarget)
{
var map = owner.World.Map;
detectedEnemyTarget = null;
var x = (map.MapSize.X % DangerRadius) == 0 ? map.MapSize.X : map.MapSize.X + DangerRadius;
var y = (map.MapSize.Y % DangerRadius) == 0 ? map.MapSize.Y : map.MapSize.Y + DangerRadius;
for (var i = 0; i < x; i += DangerRadius * 2)
{
for (var j = 0; j < y; j += DangerRadius * 2)
{
var pos = new CPos(i, j);
if (NearToPosSafely(owner, map.CenterOfCell(pos), out detectedEnemyTarget))
{
if (needTarget && detectedEnemyTarget == null)
continue;
return pos;
}
}
}
return null;
}
示例7: Activate
public void Activate(Squad owner)
{
}
示例8: NearToPosSafely
protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget)
{
detectedEnemyTarget = null;
var unitsAroundPos = owner.World.FindActorsInCircle(loc, WRange.FromCells(DangerRadius))
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
if (!unitsAroundPos.Any())
return true;
if (CountAntiAirUnits(unitsAroundPos) * MissileUnitMultiplier < owner.Units.Count)
{
detectedEnemyTarget = unitsAroundPos.Random(owner.Random);
return true;
}
return false;
}
示例9: ShouldFlee
// Checks the number of anti air enemies around units
protected virtual bool ShouldFlee(Squad owner)
{
return base.ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * MissileUnitMultiplier > owner.Units.Count);
}
示例10: FindDefenselessTarget
protected static Actor FindDefenselessTarget(Squad owner)
{
Actor target = null;
FindSafePlace(owner, out target, true);
return target;
}
示例11: Deactivate
public void Deactivate(Squad owner)
{
}
示例12: GoToRandomOwnBuilding
protected static void GoToRandomOwnBuilding(Squad squad)
{
var loc = RandomBuildingLocation(squad);
foreach (var a in squad.Units)
squad.Bot.QueueOrder(new Order("Move", a, false) { TargetLocation = loc });
}
示例13: Deactivate
public void Deactivate(Squad owner)
{
owner.Units.Clear();
}
示例14: ShouldFlee
protected virtual bool ShouldFlee(Squad owner)
{
return base.ShouldFlee(owner, enemies => !owner.AttackOrFleeFuzzy.CanAttack(owner.Units, enemies));
}
示例15: RegisterNewSquad
Squad RegisterNewSquad(SquadType type, Actor target = null)
{
var ret = new Squad(this, type, target);
squads.Add(ret);
return ret;
}