예제 #1
0
        public bool FindPath(Int3 from, Int3 to, ref List <Int3> result, TwGame.Team team)
        {
            PathFindingRequest req = new PathFindingRequest(from, to, navgationGraph, pathPlanner, (int)team);
            //astarEngine.AddRequest(req);
            bool ret = astarEngine.ProcessRequest(req);

            if (ret)
            {
                result.Clear();
                result.AddRange(astarEngine.Context.rawPathPoints);
            }
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// calculate tactical G
        /// </summary>
        private int TacticalCost(NavMeshNode prevNode, NavMeshNode currentNode, AStarContext context)
        {
            int distCost = prevNode.GetConnectionCost(currentNode.id);
            int tacCost  = 0;

            PathFindingRequest request = context.Request as PathFindingRequest;

            // doer's team
            TwGame.Team team = (TwGame.Team)request.extend1;

            switch (team)
            {
            case TwGame.Team.Neutral:
                tacCost = 0;
                break;

            case TwGame.Team.Team_1:
            case TwGame.Team.Team_2:
            {
                int MaxInfluence = TwGame.ComInfluenceMap.MaxTeamStrengthValue;
                int cur          = TwGame.AIUtil.GetTeamStrength(currentNode.position, team);
                int pre          = TwGame.AIUtil.GetTeamStrength(prevNode.position, team);
                // avarage influence between current node's position and previous node's position.
                int infl = (cur + pre) >> 1;
                if (infl > 0)
                {
                    tacCost = System.Math.Max(-distCost + 1, -distCost * infl / MaxInfluence);
                }
                else if (infl < 0)
                {
                    tacCost = -distCost * infl / MaxInfluence * 2;
                }
            }
            break;
            }

            return(distCost + tacCost);
        }