Example #1
0
        public MemoryManager(NestManager nestMan)
        {
            _nestMan = nestMan;

            // Start the watching thread.
            StartMemoryWatch();
        }
Example #2
0
    //lets this ant know that it has been put down, sets it upright and turns senses back on
    public void Dropped(NestManager nest)
    {
        //turn the right way up
        transform.rotation  = Quaternion.identity;
        transform.position  = new Vector3(transform.position.x, GetComponent <CapsuleCollider>().radius * 2, transform.position.z);
        move.isBeingCarried = false;

        if (transform.parent.tag == Naming.Ants.CarryPosition)
        {
            int id = simulation.GetNestID(nest);
            transform.parent = GameObject.Find("P" + id).transform;
        }

        //make ant inactive in this nest
        // oldNest = nest; //? This is commented out in Gregs version
        myNest          = nest;
        droppedRecently = (int)Times.v[Times.DroppedWait];
        //? commented out in both versions?
        nextAssessment = simulation.TotalElapsedSimulatedTime("s") + RandomGenerator.Instance.Range(0.5f, 1f) * Times.v[Times.MaxAssessmentWait];
        ChangeState(BehaviourState.Inactive);

        //turns senses on if non passive ant
        if (passive == false)
        {
            sensesCol.enabled = true;
        }
    }
Example #3
0
        private void CleanUp()
        {
            if (_cleanedUp)
            {
                return;
            }

            int[] nestAllegiance = new int[Simulation.NestInfo.Count];

            foreach (AntManager ant in Simulation.Ants)
            {
                NestManager nest = ant.myNest;
                // If the ant is being carried, it is assigned to the carrier's nest
                if (ant.transform.parent.tag == "CarryPosition")
                {
                    nest = ant.transform.parent.parent.GetComponent <AntManager>().myNest;
                }

                nestAllegiance[Simulation.GetNestID(nest)]++;
            }

            string nestNumbersOutput = "";

            foreach (int nestNumbers in nestAllegiance)
            {
                nestNumbersOutput += "," + nestNumbers;
            }

            Dictionary <string, float> runOutput = CalculateTandemValues();

            WriteLine(nestNumbersOutput.Substring(1));
            WriteLine("Absolute Emigration Accuracy: " + Simulation.emigrationData.emigrationAbsoluteAccuracy);
            WriteLine("Relative Emigration Accuracy: " + Simulation.emigrationData.emigrationRelativeAccuracy);
            WriteLine("Emigration Completion: " + Simulation.emigrationData.emigrationAbsoluteAccuracy);
            WriteLine("FTRs Completed: " + (int)runOutput["forward success"]);
            WriteLine("FTRs Failed: " + (int)runOutput["forward failed"]);
            WriteLine("FTR Mean Duration: " + runOutput["forward mean duration"]);
            WriteLine("FTR Mean Distance: " + runOutput["forward mean distance"]);
            WriteLine("FTR Mean Speed: " + runOutput["forward mean speed"]);
            WriteLine("FTR Failure Rate/min: " + runOutput["forward failures/min"]);
            WriteLine("RTRs Completed: " + (int)runOutput["reverse success"]);
            WriteLine("RTRs Failed: " + (int)runOutput["reverse failed"]);
            WriteLine("RTR Mean Duration: " + runOutput["reverse mean duration"]);
            WriteLine("RTR Mean Distance: " + runOutput["reverse mean distance"]);
            WriteLine("RTR Mean Speed: " + runOutput["reverse mean speed"]);
            WriteLine("RTR Failure Rate/min: " + runOutput["reverse failures/min"]);
            WriteLine("Discovery Time: " + Simulation.emigrationData.discoveryTime);
            WriteLine("First Recruiter Time: " + Simulation.emigrationData.firstRecruiter);
            WriteLine("First Tandem Time: " + Simulation.emigrationData.firstTandem);
            WriteLine("First Carry Time: " + Simulation.emigrationData.firstCarry);
            WriteLine("First Reverse Time: " + Simulation.emigrationData.firstReverse);
            WriteLine("End of Emigration Time: " + Simulation.emigrationData.endOfEmigration);

            _cleanedUp = true;
        }
Example #4
0
        public NestInfo(NestManager nest, int nestId, bool isStartingNest, GameObject assessing, GameObject recruiting, GameObject inactive, GameObject reversing)
        {
            Nest           = nest;
            NestId         = nestId;
            IsStartingNest = isStartingNest;

            AntsAssessing  = assessing;
            AntsRecruiting = recruiting;
            AntsPassive    = inactive;
            AntsReversing  = reversing;
        }
Example #5
0
 private void CheckQuorum(NestManager nest)
 {
     //check the quorum of this nest until quorum is met once.
     if (IsQuorumReached())
     {
         perceivedQuorum = quorumThreshold;
     }
     else
     {
         perceivedQuorum = RandomGenerator.Instance.NormalRandom(nest.GetQuorum(), Other.v[Other.QuorumAssessNoise]);
     }
 }
        public UiSettingManager(NestManager nestMan)
        {
            _nestMan = nestMan;

            // If we aren't a background +1 app opened.
            if(!nestMan.IsBackgroundTask)
            {
                AppOpenedCount++;
            }

            nestMan.OnResuming += BaconMan_OnResuming;
        }
Example #7
0
    //

    //switches ants allegiance to this nest and sends them back to their old one to recruit some more
    private void RecruitToNest(NestManager nest)
    {
        recruitmentStage = RecruitmentStage.GoingToOldNest;
        myNest           = nest;
        CheckQuorum(nest);

        waitOldNestTime = (int)Times.v[Times.RecruitTryTime];

        leader = null; //? BUGFIX == random case where an assessor -> recruiter but still had leader set to something, so caused a null exception

        ChangeState(BehaviourState.Recruiting);
    }
Example #8
0
    private void RecruitingMovement()
    {
        // If recruiter needs to wait for the follower, ant should not move (next turn time is increased so the tandem leader doesn't turn immediately after regaining contact)
        if (ant.IsTandemRunning() && ShouldTandemLeaderWait() == true)
        {
            nextTurnTime += Time.fixedDeltaTime;
            return;
        }

        // Update direction only if the required time has elapsed
        if (simulation.TotalElapsedSimulatedTime("s") >= nextTurnTime)
        {
            // Recruiters leading a tandem run or transporting (social carry) will need to return to their new nest.
            if (ant.IsTandemRunning() || ant.IsTransporting())
            {
                WalkToNest(ant.myNest);
                UpdateTandemDistance();
            }
            // Recruiters not tandem running or carrying move back and forth between the new and old nests.
            else
            {
                // The target nest is either the old or new nest, depending on the current recruiter direction
                NestManager targetNest = (ant.recruitmentStage == RecruitmentStage.GoingToOldNest) ? ant.oldNest : ant.myNest;

                // If the recruiter has reached the target nest, then walk randomly inside while waiting/searching for recruits
                if (ant.currentNest == targetNest)
                {
                    RandomWalk(maxVarBase);
                }
                else // Else walk towards the target nest
                {
                    WalkToNest(targetNest);
                }
            }

            ResetTurnParameters(false);
        }

        // Move forward at the speed based on the ant's current behaviour/activity
        if (ant.IsTandemRunning())
        {
            MoveForward(Speed.v[Speed.TandemRunLead], true);
        }
        else if (ant.IsTransporting())
        {
            MoveForward(Speed.v[Speed.Carrying], true);
        }
        else // If waiting or moving between nests then move at standard speed
        {
            MoveForward(Speed.v[Speed.Scouting], true);
        }
    }
Example #9
0
 //called whenever an ant leaves a nest
 public void LeftNest()
 {
     currentNest = null;
     inNest      = false;
     //when an assessor leaves the nest then make decision about wether to recruit TO that nest
     if (state == BehaviourState.Assessing && assessTime == 0)
     {
         if (assessmentStage == 0)
         {
             NestAssessmentVisit();
         }
     }
 }
Example #10
0
 protected void Start()
 {
     nestManager = GameObject.FindObjectOfType <NestManager>();
     if (CurrentOrder == null)
     {
         NestInstance potentialNest = nestManager.RandomNest();
         if (potentialNest != null)
         {
             CurrentInstruction = new Goto(potentialNest.nestPosition + Vector3.forward, 0, this);
             Instructions.Push(new CreateNest(nestPrefab, potentialNest, protectionTimer, this));
         }
     }
 }
Example #11
0
 private void ConstructNest()
 {
     if (nestConstructionTimer <= 0)
     {
         nestConstructionTimer = nestConstructionTime;
         NestManager.SpawnNest(buildingSiteLocation, nest.Player);
         Map.Refresh();
         MoveToPosition(nest.Position);
         state = "nest";
     }
     else
     {
         nestConstructionTimer -= Time.deltaTime;
     }
 }
Example #12
0
 private void AssignParentFromNest(NestManager nest, string prefix, Color?colour)
 {
     if (nest != null)
     {
         prefix += simulation.GetNestID(nest);
     }
     if (transform.parent.name != prefix)
     {
         transform.parent = GameObject.Find(prefix).transform;
     }
     if (colour.HasValue)
     {
         SetPrimaryColour(colour.Value);
     }
 }
Example #13
0
    // Based on the ant's current location, return the next waypoint to walk to in order to reach the desired nest.
    // Order of waypoints starting from a different nest is as follows:
    // current nest door -> desired nest door -> desired nest centre
    private void WalkToNest(NestManager desiredNestManager)
    {
        GameObject desiredNest     = desiredNestManager.gameObject;
        GameObject desiredNestDoor = desiredNestManager.door;

        if (ant.currentNest != null)
        {
            GameObject currentNest     = ant.currentNest.gameObject;
            GameObject currentNestDoor = ant.currentNest.GetComponent <NestManager>().door;

            // If the ant is in the wrong nest, it must walk towards the nest door and exit the nest
            if (currentNest != desiredNest)
            {
                if (currentNest != desiredNest) //? need to check this equality works properly
                {
                    // If the ant is not close to the door they must walk towards it (prevents getting stuck on walls)
                    if (DoorSearch(Length.v[Length.DoorSenseRange]) == null)
                    {
                        WalkToGameObject(currentNestDoor, false);
                    }
                    // else the ant is close to the door, so they can walk directly out towards their desired nest
                    else
                    {
                        WalkToGameObject(desiredNestDoor, true);
                    }
                }
            }
            // Else the ant is already in the desired nest, so move towards the nest centre
            else
            {
                WalkToGameObject(desiredNest, true);
            }
        }
        // If the ant is not in a nest, walk towards the desired nest.
        else
        {
            //If the ant is close to the desired nest door, walk directly into the nest.
            if (DoorSearch(Length.v[Length.DoorSenseRange]) == desiredNestDoor)
            {
                WalkToGameObject(desiredNest, false);
            }
            // Otherwise move towards the desired nest door.
            else
            {
                WalkToGameObject(desiredNestDoor, true);
            }
        }
    }
Example #14
0
    public bool DEBUG_ANT = false; // Used for debugging

    // Use this for initialization
    void Start()
    {
        oldNest            = GameObject.Find(Naming.World.InitialNest).NestManager();
        carryPosition      = transform.Find(Naming.Ants.CarryPosition);
        sensesCol          = transform.Find(Naming.Ants.SensesArea).GetComponent <Collider>();
        move               = gameObject.AntMovement();
        nestThreshold      = RandomGenerator.Instance.NormalRandom(Other.v[Other.QualityThreshMean], Other.v[Other.QualityThreshNoise]);
        perceivedQuality   = float.MinValue;
        finishedRecruiting = false;
        //make sure the value is within contraints
        if (nestThreshold > 1)
        {
            nestThreshold = 1;
        }
        else if (nestThreshold < 0)
        {
            nestThreshold = 0;
        }
    }
Example #15
0
 //returns the ID of the nest that is passed in
 public int GetNestID(NestManager nest)
 {
     return(nests.IndexOf(nest.transform));
 }
Example #16
0
 public NestExtender(IPlayer player, NestManager nest)
 {
     this.m_player = player;
     this.m_nest   = nest;
 }
Example #17
0
 private void Reverse(NestManager nest)
 {
     ChangeState(BehaviourState.Reversing);
     reverseTime = (int)Times.v[Times.ReverseTryTime];
 }
Example #18
0
 public MessageManager(NestManager nestMan)
 {
     _nestMan = nestMan;
 }
Example #19
0
 public CacheManager(NestManager nestMan)
 {
     _nestMan = nestMan;
 }
            // Checks if the current nest is of type nestType in the current stack!
            // Only BeginNests that have been decompiled will be tested for!
            private NestManager.Nest IsInNest( NestManager.Nest.NestType nestType )
            {
                int i = _NestChain.Count - 1;
                if( i == -1 )
                    return null;

                if( _NestChain[i].Type == nestType )
                {
                    return _NestChain[i];
                }
                return null;
            }
 private NestManager.Nest GetMostRecentEndNest( NestManager.Nest.NestType nestType )
 {
     for( int i = _Nester.Nests.Count - 1; i >= 0; -- i )
     {
         if( _Nester.Nests[i] is NestManager.NestEnd && _Nester.Nests[i].Type == nestType )
         {
             return _Nester.Nests[i];
         }
     }
     return null;
 }
Example #22
0
 public AuthManager(NestManager nestMan)
 {
     _nestMan = nestMan;
 }
Example #23
0
 public UserManager(NestManager nestMan)
 {
     _nestMan = nestMan;
     _mAuthMan = new AuthManager(_nestMan);
 }
Example #24
0
 /// <summary>
 /// Called once the plugin is enabled.
 /// Meaning the start methods will be
 /// called when needed.
 /// </summary>
 public void OnEnabled()
 {
     // Create a new nest each time
     // the plugin is enabled.
     Nest = new NestManager();
 }
Example #25
0
 public TileManager(NestManager nestMan)
 {
     _nestMan = nestMan;
 }
            public void InitDecompile()
            {
                _NestChain.Clear();

                _Nester = new NestManager{Decompiler = this};
                CurrentTokenIndex = -1;
                CodePosition = 0;

                FieldToken.LastField = null;

                // TODO: Corrigate detection and version.
                DefaultParameterToken._NextParamIndex = 0;
                if( Package.Version > 300 )
                {
                    var func = _Container as UFunction;
                    if( func != null && func.Params != null )
                    {
                        DefaultParameterToken._NextParamIndex = func.Params.FindIndex(
                            p => p.HasPropertyFlag( Flags.PropertyFlagsLO.OptionalParm )
                        );
                    }
                }

                // Reset these, in case of a loop in the Decompile function that did not finish due exception errors!
                _IsWithinClassContext = false;
                _CanAddSemicolon = false;
                _MustCommentStatement = false;
                _PostIncrementTabs = 0;
                _PostDecrementTabs = 0;
                _PreIncrementTabs = 0;
                _PreDecrementTabs = 0;
                PreComment = String.Empty;
                PostComment = String.Empty;

                _TempLabels = new List<ULabelEntry>();
                if( _Labels != null )
                {
                    for( int i = 0; i < _Labels.Count; ++ i )
                    {
                        // No duplicates, caused by having multiple goto's with the same destination
                        if( !_TempLabels.Exists( p => p.Position == _Labels[i].Position ) )
                        {
                            _TempLabels.Add( _Labels[i] );
                        }
                    }
                }
            }
Example #27
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();
         * }*/
    }
 // Checks if we're currently within a nest of type nestType in any stack!
 private NestManager.Nest IsWithinNest( NestManager.Nest.NestType nestType )
 {
     for( int i = _NestChain.Count - 1; i >= 0; -- i )
     {
         if( _NestChain[i].Type == nestType )
         {
             return _NestChain[i];
         }
     }
     return null;
 }
Example #29
0
    /*//?private void StoreAssessmentHistory()
     * {
     *  if (nestAssessmentVisitNumber != 2)
     *  {
     *      return;
     *  }
     *
     *  if (move.intersectionNumber != 0f)
     *  {
     *      float area = (2.0f * assessmentFirstLengthHistory * assessmentSecondLengthHistory) / (3.14159265359f * move.intersectionNumber);
     *      currentNestArea = area;
     *  }
     *
     *  // reset values
     *  assessmentFirstLengthHistory = 0f;
     *  assessmentSecondLengthHistory = 0f;
     *  assessmentFirstTimeHistory = 0;
     *  assessmentSecondTimeHistory = 0;
     *  nestAssessmentVisitNumber = 0;
     *  move.intersectionNumber = 0f;
     * }*/

    //assesses nest and takes appropriate action
    private void AssessNest(NestManager nest)
    {
        //reset current nest area
        //?currentNestArea = 0f;

        // Nest quality measurement (not buffon's needle, random value from normal distribution, constrained between 0-1)
        float q = RandomGenerator.Instance.NormalRandom(nest.quality, Other.v[Other.AssessmentNoise]);

        if (q < 0f)
        {
            q = 0f;
        }
        else if (q > 1f)
        {
            q = 1f;
        }


        //if an inactive (& non-passive) ant decides that his current isn't good enough then go look for another
        if (state == BehaviourState.Inactive && nest == myNest)
        {
            perceivedQuality = q;
            if (q < nestThreshold)
            {
                // oldNest = myNest; //? this is commented in greg's version
                ChangeState(BehaviourState.Scouting);
            }
        }
        else
        {
            //if not using comparison then check if this nest is as good or better than threshold
            if (comparisonAssess == false && q >= nestThreshold)
            {
                if (nest != myNest)
                {
                    oldNest = myNest; //? this is commented in greg's version
                }
                if (follower != null)
                {
                    follower.myNest = nest;
                    StopLeading();
                }
                perceivedQuality = q;
                RecruitToNest(nest);
            }
            //if using comparison then check if this reaches threshold and is better than previous nest
            else if (comparisonAssess == true && q >= nestThreshold && (myNest == null || q > perceivedQuality))
            {
                if (nest != myNest)
                {
                    oldNest = myNest; //? this is commented in greg's version
                }

                if (follower != null)
                {
                    follower.myNest = nest;     //? Should the follower do this?
                    StopLeading();
                }
                perceivedQuality = q;
                RecruitToNest(nest);
            }
            else // The new nest failed the assessment, so resume the previous state
            {
                if (previousState == BehaviourState.Scouting)
                {
                    ChangeState(BehaviourState.Scouting);
                }
                else if (previousState == BehaviourState.Recruiting)
                {
                    RecruitToNest(myNest);
                }
            }
        }
    }