コード例 #1
0
        //it gives as the cost of the edge between these two nodes
        public float CostWithInfluences(Node currentNode, Node neighbor)
        {
            float cost = 0;

            //todo revisar esto
            if (currentNode.GridX == neighbor.GridX || currentNode.GridZ == neighbor.GridZ && neighbor.NodeType == Node.ENodeType.Walkable)
            {
                cost += 1f;
            }
            else if (!(currentNode.GridX == neighbor.GridX || currentNode.GridZ == neighbor.GridZ) && neighbor.NodeType == Node.ENodeType.Walkable)
            {
                cost += 1.4f;
            }

            InfluenceMap.Node neigborInfluenceNode = _influenceMapComponent.GetNodeAtLocation(currentNode.WorldPosition);

            cost += neigborInfluenceNode.GetTotalInfluenceAtNodeWithFilter(InfluenceType.Core);

            return(cost);
        }
コード例 #2
0
        private void AnalyzeSurroundingInfluences(List <AITaskCommand> aiTaskCommands,
                                                  StrategicObjective chosenStrategicObjective, Entity analyzedEntity,
                                                  Entity[] playerControlledEntites, LevelController levelController)
        {
            AbstractNPCBrain analyzedNpc = analyzedEntity.GetComponent <AbstractNPCBrain>();

            if (analyzedNpc != null) // es una entidad con brain, es decir, no es un muro
            {
                //get node of the entity in the influence map
                // look in a ring
                InfluenceMap.Node node          = _influenceMapComponent.GetNodeAtLocation(analyzedNpc.transform.position);
                List <Node>       influenceData = _influenceMapComponent.GetKRingsOfNodes(node, chosenStrategicObjective.SampleRadius);

                Entity chosenTarget = chosenStrategicObjective.DecideBasedOnInfluenceData(analyzedNpc, influenceData, playerControlledEntites, levelController);

                if (chosenTarget == null && !(analyzedNpc is Troop))
                {
                    return;
                }
                if (chosenTarget == null && analyzedNpc is Troop) //no hay nadie a quien atacar o mejorar, pues movemos.
                {
                    Debug.Log("trying to move");
                    aiTaskCommands.Add(new MoveAITaskCommand(analyzedNpc));
                }
                else if (chosenTarget.owner == Entity.Owner.AI)
                {
                    //mejorar
                    Debug.Log("trying to upgrade");
                    aiTaskCommands.Add(new UpgradeAITaskCommand(chosenTarget));
                }
                else if (chosenTarget.owner == Entity.Owner.Player)
                {
                    Debug.Log("trying to attack");
                    aiTaskCommands.Add(new AttackAITaskCommand(analyzedNpc, chosenTarget));
                }
            }
            else // es un muro
            {
                return;
            }
        }