public static float GetDistanceScore(float baseDiscoveryRange, TowerPositionData towerPos) { float distanceInDistanceUnits = (towerPos.Distance / baseDiscoveryRange); float DistanceScore = distanceInDistanceUnits + ((towerPos.DiscoveryRangeCycleNumber * baseDiscoveryRange) * StaticObjects.Instance.DistanceScoreMultiplier); return(DistanceScore); }
public static Dictionary <Vector2, TowerPositionData> CardinalTowersNoAnglesLoopOver(GameObject self, Dictionary <Vector2, TowerSlotController> allTowers, CardinalSet cardinalSet, int rangeCheckCyclesAmount) { Dictionary <Vector2, TowerPositionData> dict = new Dictionary <Vector2, TowerPositionData>(); Vector2 selfPosition = self.transform.position; float towerDiscoveryRange = StaticObjects.Instance.TowerSize; for (int i = 0; i < cardinalSet.length; i++) { dict.Add(cardinalSet.directionsClockwise[i], new TowerPositionData(null, 999f, 99)); foreach (var tower in allTowers) { if (tower.Value.name == self.name || tower.Value == null) { continue; } for (int ii = 1; ii < rangeCheckCyclesAmount; ii++) { float newDiscoveryRange = (towerDiscoveryRange * (float)ii); TowerPositionQuery tq = new TowerPositionQuery(selfPosition, tower.Key, towerDiscoveryRange, newDiscoveryRange); if (tower.Value.name == dict[cardinalSet.directionsClockwise[i]].TowerSlotGo?.name) { continue; } if (cardinalSet.discoveryConditionsClockwise[i](tq)) { float d = Vector2.Distance(selfPosition, tower.Key); TowerPositionData tempTowerPos = new TowerPositionData(tower.Value.gameObject, tower.Value, d, ii); float currentDistanceScore = GetDistanceScore(towerDiscoveryRange, dict[cardinalSet.directionsClockwise[i]]); float candidateDistanceScore = GetDistanceScore(towerDiscoveryRange, tempTowerPos); if (candidateDistanceScore < currentDistanceScore) { dict[cardinalSet.directionsClockwise[i]] = tempTowerPos; } } } } } return(dict); }
public static Dictionary <Vector2, TowerPositionData> CardinalTowersNoAngles(GameObject self, Dictionary <Vector2, GameObject> allTowers, CardinalSet cardinalSet, float towerDiscoveryRange) { Dictionary <Vector2, TowerPositionData> dict = new Dictionary <Vector2, TowerPositionData>(); Vector2 selfPosition = self.transform.position; Vector2 towerDiscoveryRangeY = new Vector2(0, towerDiscoveryRange); Vector2 towerDiscoveryRangeX = new Vector2(towerDiscoveryRange, 0); for (int i = 0; i < cardinalSet.length; i++) { dict.Add(cardinalSet.directionsClockwise[i], new TowerPositionData(null, 999f, i)); } foreach (var item in allTowers) { if (item.Value.name == self.name || item.Value == null) { continue; } //Get UP tower if (item.Key.y >= selfPosition.y + towerDiscoveryRange) { if (FindIfTowerInStraightPositionRangeXorY(selfPosition.x, item.Key.x, towerDiscoveryRange)) { if (dict[DirectionsClockwise4[0]].Distance > Vector2.Distance(item.Key, selfPosition)) { dict[DirectionsClockwise4[0]] = new TowerPositionData(item.Value, Vector2.Distance(item.Key, selfPosition + towerDiscoveryRangeY), 0); } } } //Get RIGHT tower if (item.Key.x >= selfPosition.x + towerDiscoveryRange) { if (FindIfTowerInStraightPositionRangeXorY(selfPosition.y, item.Key.y, towerDiscoveryRange)) { if (dict[DirectionsClockwise4[1]].Distance > Vector2.Distance(item.Key, selfPosition + towerDiscoveryRangeX)) { dict[DirectionsClockwise4[1]] = new TowerPositionData(item.Value, Vector2.Distance(item.Key, selfPosition + towerDiscoveryRangeX), 1); } } } //get DOWN tower if (item.Key.y <= selfPosition.y - towerDiscoveryRange) { if (FindIfTowerInStraightPositionRangeXorY(selfPosition.x, item.Key.x, towerDiscoveryRange)) { if (dict[DirectionsClockwise4[2]].Distance > Vector2.Distance(item.Key, selfPosition)) { dict[DirectionsClockwise4[2]] = new TowerPositionData(item.Value, Vector2.Distance(item.Key, selfPosition - towerDiscoveryRangeY), 2); } } } //Get LEFT tower if (item.Key.x <= selfPosition.x - towerDiscoveryRange) { if (FindIfTowerInStraightPositionRangeXorY(selfPosition.y, item.Key.y, towerDiscoveryRange)) { if (dict[DirectionsClockwise4[3]].Distance > Vector2.Distance(item.Key, selfPosition)) { dict[DirectionsClockwise4[3]] = new TowerPositionData(item.Value, Vector2.Distance(item.Key, selfPosition - towerDiscoveryRangeX), 3); } } } } return(dict); }