Exemple #1
0
        /// <summary>
        /// Choose a random path. More likely to choose a race path than a general path
        /// </summary>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        public static OpponentPath GetNextPath(OpponentPathNode currentNode)
        {
            if (currentNode.Paths.Count == 0)
            {
                return(null);
            }

            int choosenPath = Engine.Random.Next(currentNode.Paths.Count);

            if (currentNode.Paths[choosenPath].Type == PathType.Race)
            {
                return(currentNode.Paths[choosenPath]);
            }

            // 1/3 times, we re-choose the race path
            if (Engine.Random.Next() % 3 == 0)
            {
                foreach (OpponentPath path in currentNode.Paths)
                {
                    if (path.Type == PathType.Race)
                    {
                        return(path);
                    }
                }
            }

            // if we cant find a race path, go with our first choice
            return(currentNode.Paths[choosenPath]);
        }
Exemple #2
0
 public void TargetNode(OpponentPathNode node)
 {
     _targetNode = node;
     SetState(CpuDriverState.Racing);
     _lastTargetChangeTime = GameEngine.TotalSeconds;
     GetNextPath();
 }
Exemple #3
0
        private void Teleport(OpponentPathNode node)
        {
            TargetNode(node);
            Vehicle.Teleport(_targetNode.Position);
            Vehicle.Chassis.Reset();

            if (_nextPath != null)
            {
                Matrix m = Vehicle.Chassis.Actor.GlobalOrientation;
                m.Forward = _nextPath.End.Position - _nextPath.Start.Position;
                m.Forward = Vector3.Normalize(m.Forward);
                Vehicle.Chassis.Actor.GlobalOrientation *= Matrix.CreateRotationY(Helpers.GetSignedAngleBetweenVectors(Vehicle.Chassis.Actor.GlobalOrientation.Forward, _nextPath.End.Position - _nextPath.Start.Position, true));
            }
        }
Exemple #4
0
        private void TargetClosestNode(Vector3 pos)
        {
            OpponentPathNode curNode = _targetNode;

            TargetNode(OpponentController.GetClosestNode(pos));
            _currentPath = null;

            if (curNode == _targetNode) //if the closest node is the one we've failed to get to
            {
                // if we've failed to get to the target twice we're really stuck, teleport straight to node :)
                Teleport(_targetNode);
                return;
            }
            GameConsole.WriteEvent("ClosestNode");
            _nbrFails++;
        }
Exemple #5
0
        public static OpponentPathNode GetClosestNode(Vector3 currentPosition)
        {
            float            leastDistance    = int.MaxValue;
            OpponentPathNode leastDistantNode = null;

            foreach (OpponentPathNode node in Nodes)
            {
                float distance;
                Vector3.Distance(ref currentPosition, ref node.Position, out distance);
                if (distance < leastDistance)
                {
                    leastDistance    = distance;
                    leastDistantNode = node;
                }
            }

            return(leastDistantNode);
        }
        /// <summary>
        /// Choose a random path. More likely to choose a race path than a general path
        /// </summary>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        public static OpponentPath GetNextPath(OpponentPathNode currentNode)
        {
            if (currentNode.Paths.Count == 0) return null;

            int choosenPath = Engine.Random.Next(currentNode.Paths.Count);
            if (currentNode.Paths[choosenPath].Type == PathType.Race)
                return currentNode.Paths[choosenPath];

            // 1/3 times, we re-choose the race path
            if (Engine.Random.Next() % 3 == 0)
            {
                foreach (OpponentPath path in currentNode.Paths)
                {
                    if (path.Type == PathType.Race)
                        return path;
                }
            }

            // if we cant find a race path, go with our first choice
            return currentNode.Paths[choosenPath];
        }
Exemple #7
0
 public void TargetNode(OpponentPathNode node)
 {
     _targetNode = node;
     SetState(CpuDriverState.Racing);
     _lastTargetChangeTime = Engine.TotalSeconds;
     GetNextPath();
 }
Exemple #8
0
        private void Teleport(OpponentPathNode node)
        {
            TargetNode(node);
            Vehicle.Teleport(_targetNode.Position);
            Vehicle.Chassis.Reset();

            if (_nextPath != null)
            {
                Matrix m = Vehicle.Chassis.Actor.GlobalOrientation;
                m.Forward = _nextPath.End.Position - _nextPath.Start.Position;
                m.Forward = Vector3.Normalize(m.Forward);
                Vehicle.Chassis.Actor.GlobalOrientation *= Matrix.CreateRotationY(Helpers.GetSignedAngleBetweenVectors(Vehicle.Chassis.Actor.GlobalOrientation.Forward, _nextPath.End.Position - _nextPath.Start.Position, true));
            }
        }