public override CostResult GetAdditionalCostAt(Vector3 location) { var enemyVantages = targeter.GetAllKnownVantages(); TerrainDisparity totalCoverDisparityPenalty = CostCalculatorHelper.CalculateByMostVisibleToTarget( strategizer.InfoGetVantageData(), enemyVantages, location ); CostResult result = new CostResult( new Tuple <float, float, TerrainDisparity>( coverDisparityData.coverDisparityPenalty, coverDisparityData.exposedPenalty, totalCoverDisparityPenalty ), 0, new Tuple <bool, float>( Grid.GetMapNodeAt(location).IsCoverNode(), coverDisparityData.notCoverPenalty ) ); return(result); }
/* * Need to cache the result of this */ public override CostResult GetAdditionalCostAt(Vector3 start, Vector3 end) { var enemyVantages = targeter.GetAllKnownVantages(); float heightDifference = end.y - start.y; float heightPenalty = CostCalculatorHelper.CalculateHeightPenalty( heightDifference, heightData.goingUpPenalty, heightData.climbUpThreshold, heightData.climbUpThreshold, heightData.goingDownPenalty, heightData.climbDownPenalty, heightData.climbDownThreshold ); TerrainDisparity totalCoverDisparityPenalty = CostCalculatorHelper.CalculateByMostVisibleToTarget( strategizer.InfoGetVantageData(), enemyVantages, end/*, * coverDisparityData.exposedPenalty, * coverDisparityData.coverDisparityPenalty*/ ); CostResult result = new CostResult( new Tuple <float, float, TerrainDisparity> ( coverDisparityData.coverDisparityPenalty, coverDisparityData.exposedPenalty, totalCoverDisparityPenalty ) , (int)heightPenalty , new Tuple <bool, float>( Grid.GetMapNodeAt(end).IsCoverNode(), coverDisparityData.notCoverPenalty ) ); //DrawGizmo.AddGizmo(Color.grey, "" + result.CompletelyHidden(), end); return(result); }
public override int Compare(CostResult x, CostResult y) { return(-(x.GetCoverDisparityPenalty() - y.GetCoverDisparityPenalty())); }
public int Extract(CostResult result) { return(0); }
public abstract int Compare(CostResult x, CostResult y);
public void SetStrategyCost( CostResult strategyCost ) { this.strategyCost = strategyCost;; }
public override void ProcessNode( PathfinderNode currentNode, PathfinderNode startNode, PathfinderNode targetNode, PathfindingHeap <PathfinderNode> openSet, HashSet <PathfinderNode> closedSet, Dictionary <Point, PathfinderNode> activeNodes, Grid grid, int maxPathLength ) { Vector3 currentLocation = grid.NodeToWorldCoord(currentNode.GetGridCoord()); List <PathfinderNode> neighbors = PathfinderHelper.GetNeighbors( currentNode, activeNodes, currentNodeCreator ); foreach (PathfinderNode neighbour in neighbors) { Vector3 neighbourLocation = grid.NodeToWorldCoord(neighbour.GetGridCoord()); if (!neighbour.IsWalkable() || closedSet.Contains(neighbour)) { continue; } CostResult newStrategyCost = currentCostStrategy.GetAdditionalCostAt( currentLocation, neighbourLocation ); //neighbour.UpdateAccumulatedStrategyCost(newStrategyCost); int newPhysicalGCost = currentNode.GetPhysicalGCost() + PathfinderHelper.GetDistance(currentNode, neighbour); int newStrategyGCost = currentNode.GetStrategyGCost() + neighbour.GetExtractor().Extract(newStrategyCost); int newMovementCostToNeighbour = newPhysicalGCost + newStrategyGCost; // bool smaller = newStrategyGCost < neighbour.GetStrategyGCost(); //if (smaller) // { //DrawGizmo.AddGizmo(Color.green, newStrategyGCost + " " + neighbour.GetStrategyGCost(), neighbour.GetLocation()); //} //Debug.Log(neighbour.GetGCost()); if (newMovementCostToNeighbour < neighbour.GetGCost() || !openSet.Contains(neighbour)) { //Debug.Log(neighbour.GetGCost()); //DrawGizmo.AddGizmo(Color.green, "" + currentNode.GetExtractor().Extract(newStrategyCost), neighbour.GetLocation()); neighbour.SetStrategyCost( newStrategyCost ); neighbour.SetStrategyGCost( newStrategyGCost ); neighbour.SetPhysicalGCost(newPhysicalGCost); neighbour.SetHCost(GetDistance(neighbour, targetNode)); neighbour.SetParent(currentNode); if (!openSet.Contains(neighbour) && neighbour.WithInRangeOfStart(maxPathLength) ) { openSet.Add(neighbour); PathfinderVisualizer.Visit(neighbour); /*DrawGizmo.AddGizmo(Color.grey, "", grid.NodeToWorldCoord( * neighbour.GetGridCoord()) * );*/ } else { openSet.UpdateItem(neighbour); } } else { } } }
public int Extract(CostResult result) { int penalty = 0; return(penalty + result.GetFlankingPenalty()); }