当前位置: 首页>>代码示例>>C#>>正文


C# AI.Squad类代码示例

本文整理汇总了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);
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:30,代码来源:GroundStates.cs

示例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;
 }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:9,代码来源:StateBase.cs

示例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;
            }
        }
开发者ID:zombie-einstein,项目名称:OpenRA,代码行数:51,代码来源:GroundStates.cs

示例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 });
            }
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:47,代码来源:AirStates.cs

示例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);
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:17,代码来源:StateBase.cs

示例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;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:24,代码来源:AirStates.cs

示例7: Activate

 public void Activate(Squad owner)
 {
 }
开发者ID:ushardul,项目名称:OpenRA,代码行数:3,代码来源:AirStates.cs

示例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;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:17,代码来源:AirStates.cs

示例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);
 }
开发者ID:ushardul,项目名称:OpenRA,代码行数:5,代码来源:AirStates.cs

示例10: FindDefenselessTarget

 protected static Actor FindDefenselessTarget(Squad owner)
 {
     Actor target = null;
     FindSafePlace(owner, out target, true);
     return target;
 }
开发者ID:ushardul,项目名称:OpenRA,代码行数:6,代码来源:AirStates.cs

示例11: Deactivate

 public void Deactivate(Squad owner)
 {
 }
开发者ID:ushardul,项目名称:OpenRA,代码行数:3,代码来源:AirStates.cs

示例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 });
 }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:6,代码来源:StateBase.cs

示例13: Deactivate

 public void Deactivate(Squad owner)
 {
     owner.Units.Clear();
 }
开发者ID:zombie-einstein,项目名称:OpenRA,代码行数:4,代码来源:GroundStates.cs

示例14: ShouldFlee

 protected virtual bool ShouldFlee(Squad owner)
 {
     return base.ShouldFlee(owner, enemies => !owner.AttackOrFleeFuzzy.CanAttack(owner.Units, enemies));
 }
开发者ID:zombie-einstein,项目名称:OpenRA,代码行数:4,代码来源:GroundStates.cs

示例15: RegisterNewSquad

		Squad RegisterNewSquad(SquadType type, Actor target = null)
		{
			var ret = new Squad(this, type, target);
			squads.Add(ret);
			return ret;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:6,代码来源:HackyAI.cs


注:本文中的OpenRA.Mods.Common.AI.Squad类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。