private void DecrementCounters() { if (state == BehaviourState.Recruiting) { if (currentNest == oldNest && recruitmentStage == RecruitmentStage.GoingToOldNest) { if (waitOldNestTime > 0) { waitOldNestTime -= 1; } else { recruitmentStage = RecruitmentStage.GoingToNewNest; } } else if (currentNest == myNest && recruitmentStage == RecruitmentStage.GoingToNewNest) { if (waitNewNestTime > 0) { waitNewNestTime -= 1; } else { RecruitToNest(myNest); } } } //Only try reverse tandem runs for a certain amount of time if (state == BehaviourState.Reversing && currentNest == myNest && follower == null) { if (reverseTime < 1) { RecruitToNest(myNest); } else { reverseTime -= 1; } } if (droppedRecently > 0) { droppedRecently -= 1; } if (state == BehaviourState.Assessing && assessTime > 0) { assessTime -= 1; } else if (state == BehaviourState.Assessing && assessmentStage == NestAssessmentStage.Assessing) { NestAssessmentVisit(); } }
// //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); }
public void DeleteRecriutmentStage(RecruitmentStage rs) { try { using (var db = new DatabaseContainer()) { db.Entry(db.RecruitmentStages.Where(x => x.Id == rs.Id).First()).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } catch (Exception e) { throw; } }
public void ReverseLead(AntManager follower) { // Reset the leader giving up time leaderGiveUpTime = 2; // 2 is roughly the lowest LGUT possible (LGUT when tandem duration is 0s cannot be calculated since Log(0) = -inf // Set the tandem variables (for recording tandem run data) tandemStartTime = simulation.TotalElapsedSimulatedTime("s"); tandemDistance = 0f; forwardRun = false; // Reverse run prevLeaderPosition = transform.position; //let following ant know that you're leading it this.follower = follower; this.follower.Follow(this); recruitmentStage = RecruitmentStage.GoingToOldNest; }
public long SaveRecriutmentStage(RecruitmentStage rs) { try { using (var db = new DatabaseContainer()) { rs.Stage = db.Stage.Where(x => x.Name == rs.Stage.Name).First(); db.Entry(rs).State = rs.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } catch (Exception e) { } return(rs.Id); }
// failed tandem leader behaviour private void FailedTandemLeaderBehaviour() { // reset tandem variables leaderWaits = false; followerWait = true; follower = null; // behaviour after failed tandem run ChangeState(BehaviourState.Recruiting); //? After a failed run the leader continues in the same direction if (previousState == BehaviourState.Reversing) // failed reverse run - head to old nest { AddTandemRunRecord(success: false); recruitmentStage = RecruitmentStage.GoingToOldNest; } else // failed forward run - head to new nest { AddTandemRunRecord(success: false); recruitmentStage = RecruitmentStage.GoingToNewNest; } }
public static RecruitmentStageDetailsModel Create(RecruitmentStage recruitmentStage) { return(Projection.Compile().Invoke(recruitmentStage)); }
public void Tick() { PerceivedTicks++; // Decrement Counters only if 1 second of simulated time has elapsed if (Mathf.Approximately(simulation.TotalElapsedSimulatedTime("ms") % 1000, 0)) { DecrementCounters(); } /* //? This part has been added new. Some may be useful (recruitmentStage) * if (state == BehaviourState.Recruiting && recruitmentStage == RecruitmentStage.WaitingInNewNest) * { * //CheckQuorum(myNest); //? * * // Check if ant is giving up recruiting * if (simulation.TickManager.TotalElapsedSimulatedSeconds - _recruitmentWaitStartSeconds >= AntScales.Times.RecruiterWaitSeconds) * { * recruitmentStage = RecruitmentStage.GoingToOldNest; * } * }*/ /*//? Test removing this, I changed the triggerExit code and nest wall thickness & movement code so hopefully it's fixed * //BUGFIX: sometimes assessors leave nest without triggering OnExit in NestManager * if (state == BehaviourState.Assessing && Vector3.Distance(nestToAssess.transform.position, transform.position) > * Mathf.Sqrt(Mathf.Pow(nestToAssess.transform.localScale.x, 2) + Mathf.Pow(nestToAssess.transform.localScale.z, 2))) * LeftNest();*/ //BUGFIX: occasionally when followers enter a nest there EnteredNest function doesn't get called, this forces that if (state == BehaviourState.Following && Vector3.Distance(LeadersNest().transform.position, transform.position) < LeadersNest().transform.localScale.x / 2f) { EnteredNest(LeadersNest().NestManager()); } //makes Inactive and !passive ants assess nest that they are in every so often if (!passive && state == BehaviourState.Inactive && nextAssessment > 0 && simulation.TotalElapsedSimulatedTime("s") >= nextAssessment) { AssessNest(myNest); nextAssessment = simulation.TotalElapsedSimulatedTime("s") + RandomGenerator.Instance.Range(0.5f, 1f) * Times.v[Times.MaxAssessmentWait]; } //if an ant is carrying another and is within x distance of their nest's centre then drop the ant if (carryPosition.childCount > 0 && Vector3.Distance(myNest.transform.position, transform.position) < Length.v[Length.RecruitingNestMiddle]) { AntManager carriedAnt = carryPosition.Find(Naming.Ants.Tag).GetComponent <AntManager>(); carriedAnt.Dropped(myNest); /*//? This if will always equate to true? * // drop social carry "follower" calculate total timesteps for social carry * if (socialCarrying == true) * { * carryingTimeSteps = -1 * (carryingTimeSteps - timeStep); * } * // get end position of social carry * Vector3 endPos = transform.position; * // calculate total distance and speed of social carry * float TRDistance = Vector3.Distance(endPos, startPos); //? These seem to no longer be used * float TRSpeed = TRDistance / carryingTimeSteps; * // update history with social carry and social carry speed //? This no longer happens * if (socialCarrying == true) * { * socialCarrying = false; * }*/ // If RTRs are enabled attempt to find an ant to lead, else just continue to recruit as normal if (simulation.Settings.AntsReverseTandemRun.Value) { Reverse(myNest); } else { RecruitToNest(myNest); } } //BUGFIX: Sometimes new to old is incorrectly set for recruiters - unclear why as of yet. if (state == BehaviourState.Recruiting && follower != null && currentNest == oldNest) { recruitmentStage = RecruitmentStage.GoingToNewNest; } move.Tick(); //? Moved this to the end }
//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(); * }*/ }
//makes this ant pick up 'otherAnt' and carry them back to preffered nest public void PickUp(AntManager otherAnt) { otherAnt.PickedUp(transform); recruitmentStage = RecruitmentStage.GoingToNewNest; }