Beispiel #1
0
    protected void AnalyzePrey()
    {
        // when eating, dont try to hunt anyone
        if (this.State == STATE.EATING)
        {
            return;
        }

        if (size == SIZE.GOD)
        {
            // God fish has special logic, it will sense energies and chase them no matter how far away
            EnergyBall eBall = checkForEnergy();
            if (eBall)
            {
                this.PhysicalTarget = eBall;
                Hunt();
            }
            else
            {
                Idle();
            }

            return;
        }

        FishTarget orbTarget = this.PhysicalTarget as FishTarget;

        if (orbTarget)
        {
            // light orb presents, ignore all else
            return;
        }

        BoidsFish predatee = this.PhysicalTarget as BoidsFish;

        // if the target is out of sight, stop hunting
        if (predatee && !checkIfVisible(predatee))
        {
            predatee = null;
        }

        if (predatee != null)
        {
            foreach (BoidsFish potentialSwitch in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(potentialSwitch))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Don't switch if the predatee is A.U.L.I.V.
                    if (predatee == GameManager.Instance.Player)
                    {
                        break;
                    }

                    // Switch to A.U.L.I.V. if within prey
                    if (potentialSwitch == GameManager.Instance.Player)
                    {
                        predatee = potentialSwitch;
                        break;
                    }
                }

                // Skip if potential switch is smaller in size or the same fish as already being hunted
                if (potentialSwitch == predatee || potentialSwitch.Size < predatee.Size)
                {
                    continue;
                }

                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    // Skip small fish that aren't in a big enough flock
                    SmallBoidsFish potentialSmall = potentialSwitch as SmallBoidsFish;
                    SmallBoidsFish predateeSmall  = predatee as SmallBoidsFish;
                    if ((predateeSmall != null && potentialSmall != null) && (potentialSmall.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToCurrent   = (this.transform.position - predatee.transform.position).sqrMagnitude;
                float sqrDistToPotential = (this.transform.position - potentialSwitch.transform.position).sqrMagnitude;
                if (sqrDistToPotential < sqrDistToCurrent)
                {
                    predatee = potentialSwitch;
                }
            }

            this.PhysicalTarget = predatee;
        }
        else
        {
            float     closestSqrDist = float.PositiveInfinity;
            BoidsFish closestFish    = null;
            foreach (BoidsFish fish in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(fish))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Set A.U.L.I.V. as prey immediately if present
                    if (fish == GameManager.Instance.Player)
                    {
                        closestFish = fish;
                        break;
                    }
                }

                // Large fish skip small fish that aren't in a big enough flock
                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    SmallBoidsFish small = fish as SmallBoidsFish;
                    if (fish == GameManager.Instance.Player && (small != null) && (small.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToFish = (this.transform.position - fish.transform.position).sqrMagnitude;
                if (sqrDistToFish < closestSqrDist)
                {
                    closestSqrDist = sqrDistToFish;
                    closestFish    = fish;
                }
            }

            if (closestFish != null)
            {
                this.PhysicalTarget = predatee = closestFish;
                this.Hunt();
            }
            else
            {
                this.PhysicalTarget = null;
                this.Idle();
            }
        }

        // Only medium fish are scared of approaching flocks
        if (this.Size == SIZE.MEDIUM)
        {
            SmallBoidsFish smallPredatee = predatee as SmallBoidsFish;
            if (smallPredatee != null)
            {
                if (smallPredatee.FlockSize > BoidsSettings.Instance.MinFlockSizeToScareMediumFish)
                {
                    this.PhysicalTarget = predatee = null;
                    this.Idle();
                }
            }
        }

        // if (this.Size != SIZE.SMALL)
        // {
        //     if (predatee != null)
        //         this.Hunt ();
        //     else
        //     {
        //         this.Idle ();
        //     }
        // }
    }
Beispiel #2
0
    protected void AnalyzePrey()
    {
        // when eating, dont try to hunt anyone
        if (this.State == STATE.EATING)
        {
            return;
        }

        BoidsFish predatee = this.PhysicalTarget as BoidsFish;

        if (predatee != null)
        {
            foreach (BoidsFish potentialSwitch in this.Predatees)
            {
                if (potentialSwitch == predatee || potentialSwitch.Size < predatee.Size)
                {
                    continue;
                }

                if (this.Size >= SIZE.LARGE)
                {
                    // Skip small fish that aren't in a big enough flock
                    SmallBoidsFish potentialSmall = potentialSwitch as SmallBoidsFish;
                    SmallBoidsFish predateeSmall  = predatee as SmallBoidsFish;
                    if ((predateeSmall != null && potentialSmall != null) && (potentialSmall.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToCurrent   = (this.transform.position - predatee.transform.position).sqrMagnitude;
                float sqrDistToPotential = (this.transform.position - potentialSwitch.transform.position).sqrMagnitude;
                if (sqrDistToPotential < sqrDistToCurrent)
                {
                    predatee = potentialSwitch;
                }
            }

            this.PhysicalTarget = predatee;
        }
        else
        {
            float     closestSqrDist = float.PositiveInfinity;
            BoidsFish closestFish    = null;
            foreach (BoidsFish fish in this.Predatees)
            {
                // Skip small fish that aren't in a big enough flock
                SmallBoidsFish small = fish as SmallBoidsFish;
                if ((small != null) && (small.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                {
                    continue;
                }

                float sqrDistToFish = (this.transform.position - fish.transform.position).sqrMagnitude;
                if (sqrDistToFish < closestSqrDist)
                {
                    closestSqrDist = sqrDistToFish;
                    closestFish    = fish;
                }
            }

            if (closestFish != null)
            {
                this.PhysicalTarget = predatee = closestFish;
            }
        }

        // Only medium fish are scared of approaching flocks
        if (this.Size == SIZE.MEDIUM)
        {
            SmallBoidsFish smallPredatee = predatee as SmallBoidsFish;
            if (smallPredatee != null)
            {
                if (smallPredatee.FlockSize > BoidsSettings.Instance.MinFlockSizeToScareMediumFish)
                {
                    this.PhysicalTarget = null;
                }
            }
        }

        if (this.Size != SIZE.SMALL)
        {
            if (predatee != null)
            {
                this.Hunt();
            }
            else
            {
                this.Idle();
            }
        }
    }