Exemple #1
0
        protected void Init_Attack()
        {
            SpiderTarget.AimAtTarget();
            //SpiderTarget.GotoTargetNoPath(0.0f);
            Vector3 dir = (Vector3)(SpiderTarget.TargetPosition - Bot.AgentEntity.PositionComp.GetPosition());

            dir.Normalize();
            //Bot.AgentEntity.Physics.ApplyImpulse(dir, Bot.AgentEntity.PositionComp.GetPosition());
            SpiderTarget.Attack();
        }
Exemple #2
0
        protected MyBehaviorTreeState GetTargetWithPriority([BTParam] float radius, [BTInOut] ref MyBBMemoryTarget outTarget, [BTInOut] ref MyBBMemoryInt priority)
        {
            var             myPosition = Bot.Navigation.PositionAndOrientation.Translation;
            BoundingSphereD bb         = new BoundingSphereD(myPosition, radius);

            if (priority == null)
            {
                priority = new MyBBMemoryInt();
            }
            int bestPriority = priority.IntValue;

            if (bestPriority <= 0)
            {
                bestPriority = int.MaxValue;
            }

            MyBehaviorTreeState retval = IsTargetValid(ref outTarget);

            if (retval == MyBehaviorTreeState.FAILURE)
            {
                bestPriority = 7;
                MyBBMemoryTarget.UnsetTarget(ref outTarget);
            }
            Vector3D?targetPosition = SpiderTarget.GetMemoryTargetPosition(outTarget);

            if (!targetPosition.HasValue || Vector3D.Distance(targetPosition.Value, Bot.AgentEntity.PositionComp.GetPosition()) > 400.0f)
            {
                bestPriority = 7;
                MyBBMemoryTarget.UnsetTarget(ref outTarget);
            }

            var myFaction = MySession.Static.Factions.GetPlayerFaction(Bot.AgentEntity.ControllerInfo.ControllingIdentityId);

            // Priorities are as follows:
            // 1st characters, 3rd turrets, 4th weapons, 5th non-armor blocks, 6th armor blocks
            var entityList = MyEntities.GetTopMostEntitiesInSphere(ref bb);

            entityList.ShuffleList(); // Prevent all spiders going for the same player
            foreach (var entity in entityList)
            {
                if (entity == Bot.AgentEntity)
                {
                    continue;
                }
                if (!SpiderTarget.IsEntityReachable(entity))
                {
                    continue;
                }

                int entityPriority = 6;
                var character      = entity as MyCharacter;
                var grid           = entity as MyCubeGrid;

                if (character != null && character.ControllerInfo != null)
                {
                    var faction = MySession.Static.Factions.GetPlayerFaction(character.ControllerInfo.ControllingIdentityId);
                    if (myFaction != null && faction == myFaction)
                    {
                        continue;
                    }
                    if (character.IsDead)
                    {
                        continue;
                    }

                    //if character fly up exclude him from targets
                    var result = Sandbox.Engine.Physics.MyPhysics.CastRay(character.WorldMatrix.Translation - 3 * character.WorldMatrix.Up, character.WorldMatrix.Translation + 3 * character.WorldMatrix.Up, Sandbox.Engine.Physics.MyPhysics.CollisionLayers.DefaultCollisionLayer);
                    if (result == null || (result as VRage.Game.ModAPI.IHitInfo).HitEntity == character)
                    {
                        continue;
                    }

                    entityPriority = 1;

                    if (entityPriority < bestPriority)
                    {
                        retval       = MyBehaviorTreeState.SUCCESS;
                        bestPriority = entityPriority;
                        MyBBMemoryTarget.SetTargetEntity(ref outTarget, MyAiTargetEnum.CHARACTER, character.EntityId);
                        continue;
                    }
                }
                else if (grid != null && bestPriority > 3)
                {
                    Vector3D    spiderPosInGrid = grid.WorldToGridScaledLocal(myPosition);
                    double      closestDist     = double.MaxValue;
                    MySlimBlock closestBlock    = null;
                    foreach (var block in grid.CubeBlocks)
                    {
                        Vector3D blockLocalPos = new Vector3D(block.Min + block.Max);
                        blockLocalPos = blockLocalPos * 0.5;

                        double dist = Vector3D.RectangularDistance(ref blockLocalPos, ref spiderPosInGrid);
                        if (dist < closestDist)
                        {
                            closestBlock = block;
                            closestDist  = dist;
                        }
                    }

                    if (closestBlock != null)
                    {
                        retval       = MyBehaviorTreeState.SUCCESS;
                        bestPriority = 3;
                        MyBBMemoryTarget.SetTargetCube(ref outTarget, (closestBlock.Min + closestBlock.Max) / 2, grid.EntityId);
                    }
                }
            }
            entityList.Clear();

            /*var players = Sync.Players.GetOnlinePlayers();
             * MyCharacter closestCharacter = null;
             * double closestDistanceSq = float.MaxValue;
             * foreach (var player in players)
             * {
             *  if (player.Id.SerialId != 0)
             *  {
             *      var bot = MyAIComponent.Static.Bots.TryGetBot<MyHumanoidBot>(player.Id.SerialId);
             *      if (bot == null || bot.BotDefinition.BehaviorType == "Barbarian")
             *          continue;
             *  }
             *
             *  if (!(player.Character is MyCharacter) || !AiTargetBase.IsEntityReachable(player.Character))
             *  {
             *      continue;
             *  }
             *
             *  if (player.Character.IsDead)
             *      continue;
             *
             *  var distanceSq = Vector3D.DistanceSquared(player.Character.PositionComp.GetPosition(), myPosition);
             *  if (distanceSq < radius * radius && distanceSq < closestDistanceSq)
             *  {
             *      closestCharacter = player.Character;
             *      closestDistanceSq = distanceSq;
             *  }
             * }*/

            //return closestCharacter;

            priority.IntValue = bestPriority;

            // CH: TODO: This is temporary. Remove it!
            //if (outTarget.TargetType == MyAiTargetEnum.CUBE)
            //{
            //    MyEntity outGrid;
            //    MyEntities.TryGetEntityById(outTarget.EntityId.Value, out outGrid);
            //    Debug.Assert(outGrid != null);
            //    var grid = outGrid as MyCubeGrid;
            //    MySlimBlock block = grid.GetCubeBlock(outTarget.BlockPosition);
            //    Debug.Assert(block != null);

            //    //MyTrace.Send(TraceWindow.Ai, "TARGETTING CUBE: " + grid.ToString() + " " + block.ToString());
            //}

            return(retval);
        }