private Node GetMinInfluenceNode() { InfluenceMapComponent influenceMapComponent = Object.FindObjectOfType <InfluenceMapComponent>(); float minInfluence = int.MaxValue; Node minInfluenceNode = null; List <Node> sameInfluencesNode = new List <Node>(); foreach (var possibleMovement in troopToMove.GetComponent <Troop>().possibleMovements) { float tempInfluence = influenceMapComponent.GetNodeAtLocation(possibleMovement.WorldPosition) .GetTotalInfluenceAtNode(); //intentamos movernos al de menor influencia y que no lo haya elegido otro. if (tempInfluence < minInfluence && !(_levelController.chosenNodesToMoveIA.Contains(possibleMovement))) { minInfluenceNode = possibleMovement; minInfluence = tempInfluence; } else if (tempInfluence == minInfluence && !(_levelController.chosenNodesToMoveIA.Contains(possibleMovement))) { sameInfluencesNode.Add(possibleMovement); } } if (sameInfluencesNode.Count > 0) { return(sameInfluencesNode[Random.Range(0, sameInfluencesNode.Count)]); } return(minInfluenceNode); }
//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); }
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; } }