protected Agent RequestCurrentLeader(int leadershipSpan, int minStartAge, int maxStartAge, int offset) { // Profiler.BeginSample ("RequestCurrentLeader - GeneratePastSpawnDate"); long spawnDate = CoreGroup.GeneratePastSpawnDate(CoreGroup.LastUpdateDate, leadershipSpan, offset++); // Profiler.EndSample (); if ((LastLeader != null) && (spawnDate < LeaderStartDate)) { return(LastLeader); } // Profiler.BeginSample ("RequestCurrentLeader - GetLocalRandomInt"); // Generate a birthdate from the leader spawnDate (when the leader takes over) int startAge = minStartAge + CoreGroup.GetLocalRandomInt(spawnDate, offset++, maxStartAge - minStartAge); // Profiler.EndSample (); Profiler.BeginSample("RequestCurrentLeader - new Agent"); LastLeader = new Agent(CoreGroup, spawnDate - startAge, Id); LeaderStartDate = spawnDate; Profiler.EndSample(); return(LastLeader); }