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

            dir.Normalize();
            //Bot.AgentEntity.Physics.ApplyImpulse(dir, Bot.AgentEntity.PositionComp.GetPosition());
            WolfTarget.Attack(!WolfLogic.SelfDestructionActivated);
        }
Example #2
0
        protected MyBehaviorTreeState GoToPlayerDefinedTarget()
        {
            if (m_debugTarget != MyAIComponent.Static.DebugTarget)
            {
                m_debugTarget = MyAIComponent.Static.DebugTarget;

                if (MyAIComponent.Static.DebugTarget.HasValue)
                {
                    ;//CyberhoundTarget.SetTargetPosition(MyAIComponent.Static.DebugTarget.Value);
                }
                else
                {
                    return(MyBehaviorTreeState.FAILURE);
                }
            }

            var botPosition = Bot.Player.Character.PositionComp.GetPosition();

            // Distance to target
            if (m_debugTarget != null)
            {
                if (Vector3D.Distance(botPosition, m_debugTarget.Value) <= 1f)
                {
                    return(MyBehaviorTreeState.SUCCESS);
                }

                //var nextPoint = MyAIComponent.Static.PathEngineGetNextPathPoint(botPosition, MyAIComponent.Static.DebugTarget.Value);
                //var nextPoint = MyAIComponent.Static.PathfindingGetNextPathPoint(botPosition, m_debugTarget.Value);
                Vector3D            point      = m_debugTarget.Value;
                MyDestinationSphere destSphere = new MyDestinationSphere(ref point, 1);
                var path = MyAIComponent.Static.Pathfinding.FindPathGlobal(botPosition, destSphere, null);

                Vector3D nextPoint;
                float    targetRadius;
                VRage.ModAPI.IMyEntity entity;
                if (path.GetNextTarget(botPosition, out nextPoint, out targetRadius, out entity))
                {
                    if (WolfTarget.TargetPosition != nextPoint)
                    {
                        //WolfTarget.SetTargetPosition(m_debugTarget.Value/*nextPoint*/);
                        WolfTarget.SetTargetPosition(nextPoint);
                    }
                    WolfTarget.AimAtTarget();
                    WolfTarget.GotoTargetNoPath(0.0f, false);
                }
                else
                {
                    return(MyBehaviorTreeState.FAILURE);
                }
            }
            return(MyBehaviorTreeState.RUNNING);
        }
Example #3
0
        protected MyBehaviorTreeState GetTargetWithPriority([BTParam] float radius, [BTInOut] ref MyBBMemoryTarget outTarget, [BTInOut] ref MyBBMemoryInt priority)
        {
            if (WolfLogic.SelfDestructionActivated) // self destruction activated, do not change target.
            {
                return(MyBehaviorTreeState.SUCCESS);
            }

            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 || Bot.Navigation.Stuck)
            {
                bestPriority = int.MaxValue;
            }

            MyBehaviorTreeState retval = IsTargetValid(ref outTarget);

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

            if (!targetPosition.HasValue ||
                Vector3D.DistanceSquared(targetPosition.Value, Bot.AgentEntity.PositionComp.GetPosition()) > 400.0f * 400.0f)
            {
                bestPriority = 7;
                MyBBMemoryTarget.UnsetTarget(ref outTarget);
            }
            if (targetPosition.HasValue)
            {
                Vector3D targetPositionValue = targetPosition.Value;
                var      planet = MyGamePruningStructure.GetClosestPlanet(targetPositionValue);
                if (planet != null)
                {
                    Vector3D targetPositionProjected = planet.GetClosestSurfacePointGlobal(ref targetPositionValue);
                    if (Vector3D.DistanceSquared(targetPositionProjected, targetPositionValue) > 1.5f * 1.5f &&
                        Vector3D.DistanceSquared(targetPositionProjected, Bot.AgentEntity.PositionComp.GetPosition()) < 5.0f * 5.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 Wolfs going for the same player
            foreach (var entity in entityList)
            {
                if (entity == Bot.AgentEntity ||
                    entity is MyVoxelBase ||
                    !WolfTarget.IsEntityReachable(entity))
                {
                    continue;
                }
                // exclude entities above ground
                Vector3D entityPos = entity.PositionComp.GetPosition();
                var      planet    = MyGamePruningStructure.GetClosestPlanet(entityPos);
                if (planet != null)
                {
                    Vector3D entityPosProjected = planet.GetClosestSurfacePointGlobal(ref entityPos);
                    if (Vector3D.DistanceSquared(entityPosProjected, entityPos) > 1.0f)
                    {
                        continue;
                    }
                }

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

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

                    entityPriority = 1;

                    if (entityPriority < bestPriority)
                    {
                        retval       = MyBehaviorTreeState.SUCCESS;
                        bestPriority = entityPriority;
                        MyBBMemoryTarget.SetTargetEntity(ref outTarget, MyAiTargetEnum.CHARACTER, character.EntityId);
                        m_lastTargetedEntityPosition = character.PositionComp.GetPosition();
                        continue;
                    }
                }
                else if (grid != null && bestPriority > 3)
                {
                    Vector3D    WolfPosInGrid = 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 WolfPosInGrid);
                        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);
                        BoundingBoxD bbBlock;
                        closestBlock.GetWorldBoundingBox(out bbBlock);
                        m_lastTargetedEntityPosition = bbBlock.Center;
                    }
                }
            }
            entityList.Clear();
            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());
            }

            if (outTarget.TargetType == MyAiTargetEnum.NO_TARGET)
            {
                retval = MyBehaviorTreeState.FAILURE;
            }
            return(retval);
        }