Пример #1
0
    //this is called whenever an ant enters a nest
    public void EnteredNest(NestManager nest)
    {
        currentNest = nest;
        inNest      = true;

        /* // this part isn't in gregs? may be from somewhere else
         * if (state == BehaviourState.Recruiting)
         * {
         *  if (nest == oldNest)
         *  {
         *      recruitmentStage = RecruitmentStage.GoingToNewNest;
         *      return;
         *  }
         *  else if (nest == myNest && !IsQuorumReached()) // don't wait if quorum reached
         *  {
         *      recruitmentStage = RecruitmentStage.WaitingInNewNest;
         *      _recruitmentWaitStartSeconds = simulation.TickManager.TotalElapsedSimulatedSeconds;
         *      return;
         *  }
         * } */

        //? I think this case would be covered by the block below
        //ignore ants that have just been dropped here
        if (nest == myNest && state == BehaviourState.Inactive)
        {
            return;
        }

        //ignore ants that are carrying or are being carried
        //? transform.parent.tag == Naming.Ants.CarryPosition is being used for carried ants - could just move isBeingCarried into antmanager
        if (carryPosition.childCount > 0 || transform.parent.tag == Naming.Ants.CarryPosition)
        {
            return;
        }

        //if this ant has been lead to this nest then tell leader that it's done its job
        if (state == BehaviourState.Following && leader != null)
        {
            if (leader.state == BehaviourState.Recruiting && nest != leader.oldNest)
            {
                leader.StopLeading();
                StopFollowing();
                if (passive)    //? i don't think passive ants can be tandem followers
                {
                    myNest = nest;
                    ChangeState(BehaviourState.Inactive);
                    return;
                }
                else
                {
                    nestToAssess = nest;
                    ChangeState(BehaviourState.Assessing);
                }
            }
            else if (leader.state == BehaviourState.Reversing && nest == leader.oldNest)
            {
                myNest  = leader.myNest;
                oldNest = leader.oldNest;
                leader.StopLeading();
                StopFollowing();
                RecruitToNest(myNest);
            }
        }

        // Behaviour for recruiters entering their new nest
        if (state == BehaviourState.Recruiting && nest == myNest)
        {
            if (finishedRecruiting == true)
            {
                ChangeState(BehaviourState.Inactive);
                finishedRecruiting = false;
                droppedRecently    = 0; // Allows this ant to be reverse lead if the emigration is still continuing (this ant was recruited from the other potential nest)
                return;
            }
            else
            {
                // If the quorum is not yet reached, there is a chance that a recruiter will reassess their new nest
                if (follower == null && RandomGenerator.Instance.Range(0f, 1f) < Other.v[Other.RecAssessNewProb] && !IsQuorumReached())
                {
                    nestToAssess = nest;
                    ChangeState(BehaviourState.Assessing);
                }
                else if (waitNewNestTime == 0)                                                                         // If the recruiter needs to now wait in the new nest, set the wait counter
                {
                    waitNewNestTime = Mathf.RoundToInt(quorumThreshold * simulation.Settings.WaitNewNestFactor.Value); // Recruiters wait in the new nest for time dependent on the quorum threshold
                }
            }
        }

        if (state == BehaviourState.Recruiting && nest == oldNest)
        {
            //if no passive ants left in old nest then turn around and return home
            if (finishedRecruiting == true || nest.GetPassive() == 0)
            {
                recruitmentStage   = RecruitmentStage.GoingToNewNest;
                finishedRecruiting = true;
                return;
            }
            //if recruiting and this is old nest then assess with probability pRecAssessOld
            else if (follower == null && RandomGenerator.Instance.Range(0f, 1f) < Other.v[Other.RecAssessOldProb])
            {
                nestToAssess = nest;
                ChangeState(BehaviourState.Assessing);
                return;
            }
        }

        if (state == BehaviourState.Reversing && nest == oldNest)
        {
            if (nest.GetPassive() == 0)
            {
                recruitmentStage = RecruitmentStage.GoingToNewNest;
                ChangeState(BehaviourState.Recruiting);
                finishedRecruiting = true;
                return;
            }
        }


        //if either ant is following or this isn't one of the ants known nests then assess it
        if (((state == BehaviourState.Scouting || state == BehaviourState.Recruiting) && nest != oldNest && nest != myNest) || state == BehaviourState.Following && leader.state != BehaviourState.Reversing && nest != leader.oldNest)
        {
            if (follower != null)
            {
                follower.FailedTandemFollowerBehaviour();
                StopLeading();//? Obscure bugfix
            }
            nestToAssess = nest;
            ChangeState(BehaviourState.Assessing);
        }
        else
        {
            /* //? This bit is commented out
             * int id = simulation.GetNestID(nest);
             * //if this nest is my old nest and there's nothing to recruit from it then stop coming here
             * if (nest == oldNest && GameObject.Find("P" + id).transform.childCount == 0)     //? could have a better way to check passive ants left in nest
             *  //oldNest = null;
             */
            /* //? Don't think this is needed
             * //if recruiting and this is your nest then go back to looking around for ants to recruit
             * if (state == BehaviourState.Recruiting && nest == myNest && follower == null)
             * {
             *  RecruitToNest(myNest);
             * }*/
        }

        /* //? not sure what this is for
         * // Assessing ant has entered a nest, make sure it updates the assement bit
         * if (state == BehaviourState.Assessing)
         * {
         *  //? move.AssessingDirectionChange();
         * }*/
    }