public Gull.EThreatLevel GetRadialThreatLevel(Vector3 position, float radius, bool player, out List <Gull.Unit> units) { units = new List <Gull.Unit>(); RaycastHit2D[] hits = Physics2D.CircleCastAll(position, radius, Vector2.zero); foreach (RaycastHit2D hit in hits) { if (hit.transform.GetComponent <Gull.Unit>() != null) { Gull.Unit unit = hit.transform.GetComponent <Gull.Unit>(); if (unit.playerOwned != player) { continue; } units.Add(unit); } } //# Check for impossible units in radius if (units.Find(u => u.ThreatLevel_enum == EThreatLevel.Impossible)) { return(EThreatLevel.Impossible); } //# Calculate outcome threat level //# - 1 or more Low units = Low //# - 3 or more Low units OR 1 or more Med unit = Med //# - 2 or more Med units OR 1 or more High unit = High EThreatLevel final = EThreatLevel.None; List <Gull.Unit> low_units = units.FindAll(u => u.ThreatLevel_enum == EThreatLevel.Low); if (low_units.Count >= 1) { final = EThreatLevel.Low; } List <Gull.Unit> med_units = units.FindAll(u => u.ThreatLevel_enum == EThreatLevel.Medium); if (low_units.Count >= 3 || med_units.Count >= 1) { final = EThreatLevel.Medium; } List <Gull.Unit> high_units = units.FindAll(u => u.ThreatLevel_enum == EThreatLevel.High); if (med_units.Count >= 2 || high_units.Count >= 1) { final = EThreatLevel.High; } return(final); }
private void CalculateEnemyThreat() { EThreatLevel playerThreat = LevelManager.instance.GetRadialPlayerThreatLevel(transform.position, RadialThreat_radius); Debug.Log(playerThreat); if (playerThreat >= ThreatLevel_enum && !Fleeing) { Fleeing = true; ThreatLevel_enum = EThreatLevel.None; Vector3 vel = Random.insideUnitCircle.normalized; Vector3 randomFlight = transform.position + (vel * 400); StartMotionCoroutine(new MotionGroup(MoveTowardsTargetPoint(randomFlight))); StartCoroutine(LevelManager.instance.EventPoster.Post(new Pigeon.Flees())); } else if ((playerThreat < ThreatLevel_enum || playerThreat == EThreatLevel.None) && Fleeing) { Fleeing = false; StartMotionCoroutine(new MotionGroup(MoveTowardsTargetPoint(initialPosition))); StartCoroutine(LevelManager.instance.EventPoster.Post(new Pigeon.Returns())); } debugText.text = ThreatLevel_enum.ToString(); }
protected override void UpdateUnit() { ThreatLevel_Real = LevelManager.instance.GetRadialPlayerThreatLevel(transform.position, 60); debugText.text = ThreatLevel_Real.ToString(); }