public void SetSelected(Creature cr) { if (cr == null && Selected != null) { Selected.Members.SetLayer(0); Selected = null; ClearParamList(); camGUI.enabled = false; slideAnimator.Play("SlidePanelOut"); } else if (Selected != cr) { Selected?.Members.SetLayer(0); Selected = cr; uplockParam = true; //TODO ON/OFF Reproduction repr = Selected.Behaviors.GetBehavior <Reproduction>(); if (repr != null) { if (repr.IsPregnant) { ShowCreatureOnPanel(repr.Baby); uplockParam = true; } else { ShowCreatureOnPanel(Selected); } } } }
/// <summary> /// Process a single generation of the population /// </summary> public void DoGeneration() { Trace.WriteLine("BEGIN: GeneticAlgorithm.DoGeneration():"); Trace.Indent(); List <IChromosome> newPopulation = new List <IChromosome>(); int matingPoolSize = (int)Math.Floor(PopulationSize * CrossoverRate); Trace.WriteLine(String.Format("matingPoolSize = {0}", matingPoolSize)); for (int i = 0; i < matingPoolSize; i++) { // Select and remove the parents from the gene pool IList <IChromosome> parents = Selection.Select(Population, 2); Trace.WriteLine("Selected two parents for crossover."); Trace.WriteLine(String.Format("parents[0] = {0}", parents[0])); Trace.WriteLine(String.Format("parents[1] = {0}", parents[1])); // Reproduce and add children to gene pool IList <IChromosome> children = Reproduction.Reproduce(parents); Trace.WriteLine("Children:"); foreach (IChromosome child in children) { Trace.WriteLine(String.Format("{0}", child)); } Trace.WriteLine("Reproduction complete."); newPopulation.Add(children[0]); } if (newPopulation.Count < PopulationSize) { Trace.WriteLine(String.Format("Re-using {0} individuals from previous generation.", PopulationSize - newPopulation.Count)); Population.Sort(); // Why sort in ascending order?! :( int carry = 1; while (newPopulation.Count < PopulationSize) { newPopulation.Add(Population[Population.Count - carry]); carry++; } } else if (newPopulation.Count > PopulationSize) { Console.WriteLine("Great, Scott! How did we get here?"); Console.WriteLine("In GeneticAlgorithm.DoGeneration(): newPopulation.Count > populationSize"); Environment.Exit(-1); } Population = newPopulation; UpdateFitnessAll(); Trace.Unindent(); Trace.WriteLine("END: GeneticAlgorithm.DoGeneration()"); CurrentGeneration++; }
public bool IsSuitableMate(Reproduction candidate) { if (Sex == Sex.Asexual && candidate.Sex != Sex.Asexual) return false; if (Sex != Sex.Asexual && candidate.Sex == Sex.Asexual) return false; if (Sex == candidate.Sex) return false; if (candidate.Pregnant) return false; return SpeciesMatch(Species, candidate.Species, Fussiness); }
private void Reproduce() { Reproduction.Reproduce(gameObject); Reproduction.Reproduce(gameObject); Reproduction.Reproduce(gameObject); AddEnergy(-500); //reproduced = true; }
public void GiveBirth(Reproduction other, int count) { ChildrenLeft -= count; other.ChildrenLeft -= count; onGiveBirth?.Invoke(this, new GiveBirthData { Count = count }); }
/// <summary> /// /// </summary> /// <param name="message"></param> public string SerializeAs_MountInfos() { var message = new StringBuilder(); message.Append(Id).Append(':'); message.Append(TemplateId).Append(':'); // TODO : ANCESTORS message.Append(string.Empty).Append(':'); // TODO : CAPACITIES message.Append(Capacities).Append(':'); message.Append(Name).Append(':'); message.Append(Sex ? "1" : "0").Append(':'); message.Append(Experience).Append(',') .Append(ExperienceFloorCurrent).Append(',') .Append(ExperienceFloorNext).Append(':'); message.Append(Level).Append(':'); message.Append(Ridable ? "1" : "0").Append(':'); message.Append(MaxPods).Append(':'); message.Append(Wild ? "1" : "0").Append(':'); message.Append(Stamina).Append(',') .Append(MAX_STAMINA).Append(':'); message.Append(Maturity).Append(',') .Append(Template.MaxMaturity).Append(':'); message.Append(Energy).Append(',') .Append(MAX_ENERGY).Append(':'); message.Append(Serenity) .Append(',') .Append(MIN_SERENITY) .Append(',') .Append(MAX_SERENITY).Append(':'); message.Append(Love).Append(',') .Append(MAX_LOVE).Append(':'); message.Append(SerializedPregnancyTime).Append(':'); message.Append(Fecondable ? "1" : "0").Append(':'); message.Append(GetStatistics().ToItemStats()).Append(':'); message.Append(Tired).Append(',') .Append(MAX_TIRED).Append(':'); message.Append(Castrated ? "-1" : Reproduction.ToString()).Append(',') .Append(MAX_REPRODUCTION).Append(':'); return(message.ToString()); }
public void GenComplete() { Reproduction.Asexual(agents); for (int i = 0; i < spawnAmount; i++) { cars[i].ResetCar(); cars[i].transform.position = tb.spawnPos; cars[i].transform.rotation = Quaternion.identity; } uim.UpdateGenCounter(++gen); }
//--------------------------------------------------------------------- public override void Run() { if (SiteLog.Enabled) { SiteLog.TimestepSetUp(); } ProcessInputMap( delegate(Site site, LandUse newLandUse) { LandUse currentLandUse = SiteVars.LandUse[site]; if (newLandUse != currentLandUse) { SiteVars.LandUse[site] = newLandUse; string transition = string.Format("{0} --> {1}", currentLandUse.Name, newLandUse.Name); if (!currentLandUse.AllowEstablishment && newLandUse.AllowEstablishment) { string message = string.Format("Error: The land-use change ({0}) at pixel {1} requires re-enabling establishment, but that's not currently supported", transition, site.Location); throw new System.ApplicationException(message); } else if (currentLandUse.AllowEstablishment && !newLandUse.AllowEstablishment) { Reproduction.PreventEstablishment((ActiveSite)site); } if (isDebugEnabled) { log.DebugFormat(" LU at {0}: {1}", site.Location, transition); } newLandUse.LandCoverChange.ApplyTo((ActiveSite)site); if (SiteLog.Enabled) { SiteLog.WriteTotalsFor((ActiveSite)site); } return(transition); } else { return(null); } }); if (SiteLog.Enabled) { SiteLog.TimestepTearDown(); } }
public void JustSeeding() { // For readability Species.IDataset spp = core.Species; foreach (ActiveSite activeSite in landscape) { expectedSite = activeSite; actualSpecies_SeedingAlg.Clear(); actualSpecies_AddNewCohort.Clear(); if (activeSite.SharesData) { if (activeSite.LocationInBlock == new Location(1, 1)) { SetList(expectedSpecies, spp[0], spp[1], spp[2], spp[3], spp[4], spp[5], spp[6], spp[7], spp[8], spp[9]); SetList(speciesThatReproduce, spp[2], spp[5], spp[7]); } else if (activeSite.LocationInBlock == new Location(1, 2)) { SetList(expectedSpecies, spp[0], spp[1], spp[3], spp[4], spp[6], spp[8], spp[9]); SetList(speciesThatReproduce, spp[0], spp[4]); } else if (activeSite.LocationInBlock == new Location(2, 1)) { SetList(expectedSpecies, spp[1], spp[3], spp[6], spp[8], spp[9]); SetList(speciesThatReproduce, spp[1], spp[6], spp[8]); } else { Assert.AreEqual(new Location(2, 2), activeSite.LocationInBlock); SetList(expectedSpecies, spp[3], spp[9]); SetList(speciesThatReproduce, spp[3]); } } else { // Since planting, serotiny and resprouting aren't enabled, // the seeding algorithm to be called with all species. SetList(expectedSpecies, spp[0], spp[1], spp[2], spp[3], spp[4], spp[5], spp[6], spp[7], spp[8], spp[9]); SetList(speciesThatReproduce, spp[3], spp[6], spp[9]); } Reproduction.Do(activeSite); Assert.AreEqual(expectedSpecies, actualSpecies_SeedingAlg); Assert.AreEqual(speciesThatReproduce, actualSpecies_AddNewCohort); } }
public override void Begin(Brain brain) { brain.MateTime = TimeToMate; brain.Reproduction.Mate(); if (brain.DoGiveBirth) { Reproduction mate = brain.TargetMate.Reproduction; int maxChildren = Mathf.Min(brain.Reproduction.ChildrenLeft, mate.ChildrenLeft); int birthCount = Random.Range(1, maxChildren + 1); brain.Reproduction.GiveBirth(mate, birthCount); } }
public void Planting() { // For readability Species.IDataset spp = core.Species; ISpecies[] speciesToPlant = new ISpecies[] { spp[1], spp[4], spp[8] }; Planting.SpeciesList plantingSpeciesList = new Planting.SpeciesList(speciesToPlant, core.Species); foreach (ActiveSite activeSite in landscape) { Reproduction.ScheduleForPlanting(plantingSpeciesList, activeSite); } // Don't expected seeding algorithm to be called since each active // set will be planted expectedSpecies.Clear(); foreach (ActiveSite activeSite in landscape) { expectedSite = activeSite; actualSpecies_SeedingAlg.Clear(); actualSpecies_AddNewCohort.Clear(); if (activeSite.SharesData) { if (activeSite.LocationInBlock == new Location(1, 1)) { SetList(speciesThatReproduce, speciesToPlant); } else { // At all other active sites in the block, nothing else // should reproduce (because first site in block had // planting occur) SetList(speciesThatReproduce); } } else { SetList(speciesThatReproduce, speciesToPlant); } Reproduction.Do(activeSite); Assert.AreEqual(expectedSpecies, actualSpecies_SeedingAlg); Assert.AreEqual(speciesThatReproduce, actualSpecies_AddNewCohort); } }
static int _CreateReproduction(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 0) { Reproduction obj = new Reproduction(); LuaScriptMgr.PushObject(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: Reproduction.New"); } return(0); }
protected void SimulateOneTimestep() { if (isDebugEnabled) { log.DebugFormat("Starting DemographicSeeding.Algorithm.SimulateOneTimestep() ..."); } foreach (ActiveSite site in Model.Core.Landscape) { int x = site.Location.Column - 1; int y = site.Location.Row - 1; // seedling count high enough to be considered a cohort by the // SimOneTimestep method. int cohortThresholdPlus1 = seedingData.cohort_threshold + 1; foreach (ISpecies species in Model.Core.Species) { int s = species.Index; int a = seedingData.all_species[s].reproductive_age_steps - 1; if (a < 0) { a = 0; } int seedlingCount = 0; if (Reproduction.MaturePresent(species, site)) { // This will cause SimOneTimestep to consider the // species as reproductive at this site. seedlingCount = cohortThresholdPlus1; } seedingData.cohorts[s][x][y][a] = seedlingCount; } } if (isDebugEnabled) { log.DebugFormat(" Calling seedingData.SimOneTimeStep() ..."); } seedingData.SimOneTimeStep(); if (isDebugEnabled) { log.DebugFormat("Exiting SimulateOneTimestep()"); } }
public void AddLittersAndCheckResprouting(object sender, Landis.Library.AgeOnlyCohorts.DeathEventArgs eventArgs) { if (eventArgs.DisturbanceType != null) { ActiveSite site = eventArgs.Site; Disturbed[site] = true; if (eventArgs.DisturbanceType.IsMemberOf("disturbance:fire")) { Reproduction.CheckForPostFireRegen(eventArgs.Cohort, site); } else { Reproduction.CheckForResprouting(eventArgs.Cohort, site); } } }
//--------------------------------------------------------------------- public void DeathEvent(object sender, Landis.Library.PnETCohorts.DeathEventArgs eventArgs) { ExtensionType disturbanceType = eventArgs.DisturbanceType; if (disturbanceType != null) { ActiveSite site = eventArgs.Site; if (disturbanceType.IsMemberOf("disturbance:fire")) { Reproduction.CheckForPostFireRegen(eventArgs.Cohort, site); } else { Reproduction.CheckForResprouting(eventArgs.Cohort, site); } } }
public MockSuccession(PlugIns.ICore modelCore) : base("MockSuccession") { // Initialize the succession library with the core. The other // 3 parameters are passed to Reproduction's Initialize method // but we want to use a mock seeding algorithm. Since the // base class' Initialize method uses an enumerated type to // specify the seeding algorithm, we just pass in an arbitrary // value, and then call Reproduction's Initialize method // directly with the mock seeding algorithm. Initialize(modelCore, null, // establishment probabilities SeedingAlgorithms.NoDispersal, null); // AddNewCohort delegate Reproduction.Initialize(CreateEstablishProbabilities(modelCore), MySeedingAlgorithm, MyAddNewCohort); }
//--------------------------------------------------------------------- public void ApplyTo(ActiveSite site) { if (isDebugEnabled) { log.DebugFormat(" Applying LCC {0} to site {1}", GetType().Name, site.Location); } // For now, we don't do anything with the counts of cohorts cut. CohortCounts cohortCounts = new CohortCounts(); cohortCutter.Cut(site, cohortCounts); if (speciesToPlant != null) { Reproduction.ScheduleForPlanting(speciesToPlant, site); } }
//checks if the found mate is available to mate bool confirmMate(GameObject mateHead) { Reproduction materep = mateHead.GetComponent <Reproduction> (); if (materep != null && !materep.ismating) { ismating = true; //lock self first //set mate and egg to that of the mate if (materep.setMate(this.transform.parent.gameObject)) { mate = mateHead.transform.parent.gameObject; egg = materep.getEgg(); return(true); } } return(false); }
/// <summary> /// Does the actual work of harvesting individual sites /// </summary> public void HarvestSite(ActiveSite site, Stand stand) { // Site selection may have spread to other stands beyond the // original stand. Stand standForCurrentSite = SiteVars.Stand[site]; // Always record the prescription even if nothing harvested; Supports plantOnly prescriptions SiteVars.Prescription[site] = this; SiteVars.PrescriptionName[site] = this.Name; if (isDebugEnabled) { log.DebugFormat(" Cutting cohorts at {0} in stand {1}{2}", site, SiteVars.Stand[site].MapCode, (standForCurrentSite == stand) ? "" : string.Format(" (initial stand {0})", stand.MapCode)); } cohortCutter.Cut(site, cohortCounts); if (cohortCounts.AllSpecies > 0) { SiteVars.CohortsDamaged[site] = cohortCounts.AllSpecies; standForCurrentSite.DamageTable.IncrementCounts(cohortCounts); stand.LastAreaHarvested += Model.Core.CellArea; if (isDebugEnabled) { log.DebugFormat(" # of cohorts damaged = {0}; stand.LastAreaHarvested = {1}", SiteVars.CohortsDamaged[site], stand.LastAreaHarvested); } HarvestExtensionMain.OnSiteHarvest(this, site); } if (speciesToPlant != null) { if (isDebugEnabled) { Model.Core.UI.WriteLine(" {0} {1}", speciesToPlant.ToString(), site.ToString()); } Reproduction.ScheduleForPlanting(speciesToPlant, site); } }
public void CohortDied(object sender, DeathEventArgs eventArgs) { ExtensionType disturbanceType = eventArgs.DisturbanceType; if (disturbanceType != null) { ActiveSite site = eventArgs.Site; Disturbed[site] = true; if (disturbanceType.IsMemberOf("disturbance:fire")) { Reproduction.CheckForPostFireRegen(eventArgs.Cohort, site); } else { Reproduction.CheckForResprouting(eventArgs.Cohort, site); } } }
public override void OnInspectorGUI() { Reproduction reproduction = (Reproduction)target; DrawDefaultInspector(); EditorGUILayout.Space(10); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Draw Debug")) { reproduction.DrawDebug(); } if (GUILayout.Button("Lay Egg")) { reproduction.LayEggButton(); } EditorGUILayout.EndHorizontal(); }
protected async override Task AddAsync(FarmingEntities db, ReproductionViewModel model) { var reproduction = new Reproduction() { CowId = model.CowId, BullId = model.BullId, MethodSluchkiId = model.MethodSluchkiId, DateOsemeneniya = model.DateOsemeneniya.Value, ChisloSuhihDney = model.ChisloSuhihDney.Value, SerPeriod = model.SerPeriod.Value, DateOtela = model.DateOtela.Value, }; db.Reproductions.Add(reproduction); await db.SaveChangesAsync(); model.Id = reproduction.Id; Models.Add(model); }
protected override void GeneUpdate() { Reproduction repr = Own.Behaviors.GetBehavior <Reproduction>(); if (repr == null) { return; } if (repr.IsPregnant) { if (Increase(pregnantTime) == 0) { Own.Behaviors.StartAction <Reproduction>(); } } else if (Amount > 0) { Decrease(pregnantTime); } Bar.sizeDelta = new Vector2(Amount * 100f, Bar.sizeDelta.y); }
/// <summary> ///Used to change the intensity of defoliation parameters across Landis. /// </summary> /// <param name="site"></param> public void ApplyTo(ActiveSite site, bool newLandUse) { if (newLandUse) { CohortDefoliation.Compute = InsectDefoliate; if (!repeat) { harvestTime = Model.Core.CurrentTime; //Model.Core.UI.WriteLine("Setting defoliation harvest time: " + harvestTime); } } else { if (!repeat) //When repeat harvest is off, shut down the delegate if the land use doesn't transition { CohortDefoliation.Compute = DontCompute; } } if (speciesToPlant != null) { Reproduction.ScheduleForPlanting(speciesToPlant, site); } }
//--------------------------------------------------------------------- /// <summary> /// Harvests a stand (and possibly its neighbors) according to the /// prescription's site-selection method. /// </summary> /// <returns> /// The area that was harvested (units: hectares). /// </returns> // This is called by AppliedPrescription public virtual void Harvest(Stand stand) { //set prescription name for stand stand.PrescriptionName = this.Name; stand.HarvestedRank = AppliedPrescription.CurrentRank; stand.LastPrescription = this; stand.MinTimeSinceDamage = this.minTimeSinceDamage; //set current stand currentStand = stand; currentStand.ClearDamageTable(); // SelectSites(stand) is where either complete, complete stand spreading, or partial stand // spreading are activated. // tjs - This is what gets the sites that will be harvested foreach (ActiveSite site in siteSelector.SelectSites(stand)) { currentSite = site; SiteVars.Cohorts[site].RemoveMarkedCohorts(this); if (SiteVars.CohortsDamaged[site] > 0) { stand.LastAreaHarvested += Model.Core.CellArea; SiteVars.Prescription[site] = this; } if (speciesToPlant != null) { Reproduction.ScheduleForPlanting(speciesToPlant, site); } } return; }
//--------------------------------------------------------------------- public override void Run() { if (SiteLog.Enabled) { SiteLog.TimestepSetUp(); } if (pauseFunction != null) { pauseFunction.PauseTimestep(); } ProcessInputMap( delegate(Site site, LandUse newLandUse) { LandUse currentLandUse = SiteVars.LandUse[site]; string siteKey = null; if (newLandUse != currentLandUse) { SiteVars.LandUse[site] = newLandUse; siteKey = string.Format("{0} --> {1}", currentLandUse.Name, newLandUse.Name); if (!currentLandUse.AllowEstablishment && newLandUse.AllowEstablishment) { Reproduction.EnableEstablishment((ActiveSite)site); } else if (currentLandUse.AllowEstablishment && !newLandUse.AllowEstablishment) { Reproduction.PreventEstablishment((ActiveSite)site); } if (isDebugEnabled) { log.DebugFormat(" LU at {0}: {1}", site.Location, siteKey); } for (int i = 0; i < newLandUse.LandCoverChanges.Length; i++) { LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i]; LandCoverChange.ApplyTo((ActiveSite)site, true); } } else { /*if (!currentLandUse.AllowEstablishment) * { * Reproduction.PreventEstablishment((ActiveSite)site); * } * else * { * Reproduction.EnableEstablishment((ActiveSite)site); * }*/ for (int i = 0; i < currentLandUse.LandCoverChanges.Length; i++) { LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i]; LandCoverChange.ApplyTo((ActiveSite)site, false); } } if (SiteLog.Enabled) { SiteLog.WriteTotalsFor((ActiveSite)site); } return(siteKey); }); if (SiteLog.Enabled) { SiteLog.TimestepTearDown(); } }
public new void DoGeneration() { Trace.WriteLine("BEGIN: GeneticAlgorithm.DoGeneration():"); Trace.Indent(); List <IChromosome> newPopulation = new List <IChromosome>(PopulationSize); int matingPoolSize = (int)Math.Floor(PopulationSize * CrossoverRate); Trace.WriteLine(String.Format("matingPoolSize = {0}", matingPoolSize)); UpdateFitnessAll(); ManualResetEvent signal = new ManualResetEvent(false); int threadCount = 0; for (int i = 0; i < matingPoolSize; i++) { int j = i; Interlocked.Increment(ref threadCount); ThreadPool.QueueUserWorkItem(delegate { try { // Select parents from the gene pool IList <IChromosome> parents = Selection.Select(Population, 2); Trace.WriteLine("Selected two parents for crossover."); Trace.WriteLine(String.Format("parents[0] = {0}", parents[0])); Trace.WriteLine(String.Format("parents[1] = {0}", parents[1])); // Reproduce and add children to the new gene pool IList <IChromosome> children = Reproduction.Reproduce(parents); lock (newPopulation) { Trace.WriteLine("Children:"); foreach (IChromosome child in children) { newPopulation.Add(child); Trace.WriteLine(String.Format("{0}", child)); } } Trace.WriteLine("Reproduction complete."); } finally { if (Interlocked.Decrement(ref threadCount) == 0) { signal.Set(); } } }); } signal.WaitOne(); if (newPopulation.Count < PopulationSize) { Trace.WriteLine(String.Format("Re-using {0} individuals from previous generation.", PopulationSize - newPopulation.Count)); Population.Sort(); // Why sort in ascending order?! :( int carry = 1; while (newPopulation.Count < PopulationSize) { newPopulation.Add(Population[Population.Count - carry]); carry++; } } else if (newPopulation.Count > PopulationSize) { Console.WriteLine("Great, Scott! How did we get here?"); Console.WriteLine("In GeneticAlgorithm.DoGeneration(): newPopulation.Count > populationSize"); Environment.Exit(-1); } Population = newPopulation; UpdateFitnessAll(); Trace.Unindent(); Trace.WriteLine("END: GeneticAlgorithm.DoGeneration()"); }
public bool SetParameters(string fileName) { ParameterFiles parameterFiles = ParameterFiles.LoadFromXml(fileName); if (parameterFiles == null) { return(false); } object obj1 = (object)null; object obj2 = (object)Initialization.LoadFromXml(parameterFiles.Initialization); if (obj2 == null) { return(false); } this.Init = (Initialization)obj2; obj1 = (object)null; object obj3 = (object)Mutation.LoadFromXml(parameterFiles.Mutation); if (obj3 == null) { return(false); } this.Mutate = (Mutation)obj3; obj1 = (object)null; object obj4 = (object)Reproduction.LoadFromXml(parameterFiles.Reproduction); if (obj4 == null) { return(false); } this.Reprod = (Reproduction)obj4; obj1 = (object)null; object obj5 = (object)Saving.LoadFromXml(parameterFiles.Saving); if (obj5 == null) { return(false); } this.Saves = (Saving)obj5; obj1 = (object)null; object obj6 = (object)Speciation.LoadFromXml(parameterFiles.Speciation); if (obj6 == null) { return(false); } this.Speciate = (Speciation)obj6; Species.Compatible = this.Speciate; obj1 = (object)null; object obj7 = (object)Testing.LoadFromXml(parameterFiles.Testing); if (obj7 == null) { return(false); } this.Tests = (Testing)obj7; obj1 = (object)null; object obj8 = (object)HyperNEAT.LoadFromXml(parameterFiles.HyperNEAT); if (obj8 == null) { return(false); } Substrates.param = (HyperNEAT)obj8; return(true); }
void Update() { Due = (Pregnant && DueDate > 0 && Time.time > DueDate); if (Pregnant && DueDate == 0) DueDate = Time.time + GestationPeriod + Random.value * 5; InSeason = IsMatingSeason(Time.time) && !Pregnant; if (!InSeason) Mate = null; if (InSeason && !Pregnant) { if (Sex == Sex.Asexual) { GetPregnant(this); } else { if (Mate != null) { if (transform.position.IsCloseTo(Mate.transform.position)) { if (Sex == Sex.Female) { GetPregnant(Mate); } } else { nav.SetDestination(Mate.transform.position, Speed); } } else { LookForMate(); } } } if (Due) { GiveBirth(); } }
static int CaptureScreenshot(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 0); Reproduction.CaptureScreenshot(); return(0); }
public bool IsSameSpecies(Reproduction candidate) { return SpeciesMatch(Species, candidate.Species, Fussiness); }
void GetPregnant(Reproduction father) { Pregnant = true; Father = father; Father.Mate = null; }
void LookForMate() { var mates = senses.Mobiles.FindAll(x => { var r = x.GetComponent<Reproduction>(); return r != null && IsSuitableMate(r); }); mates.Sort((a, b) => { float da = Vector3.Distance(a.transform.position, transform.position), db = Vector3.Distance(b.transform.position, transform.position); return da.CompareTo(db); }); if (mates.Count > 0) Mate = mates[0].GetComponent<Reproduction>(); else Mate = null; }
//--------------------------------------------------------------------- /// <summary> /// Harvests a stand (and possibly its neighbors) according to the /// prescription's site-selection method. /// </summary> /// <returns> /// The area that was harvested (units: hectares). /// </returns> // This is called by AppliedPrescription public virtual void Harvest(Stand stand) { if (isDebugEnabled) { log.DebugFormat(" Harvesting stand {0} by {1} ...", stand.MapCode, Name); } //set prescription name for stand stand.PrescriptionName = this.Name; stand.HarvestedRank = AppliedPrescription.CurrentRank; stand.LastPrescription = this; stand.MinTimeSinceDamage = this.minTimeSinceDamage; //set current stand currentStand = stand; currentStand.ClearDamageTable(); // SelectSites(stand) is where either complete, complete stand spreading, or partial stand // spreading are activated. // tjs - This is what gets the sites that will be harvested foreach (ActiveSite site in siteSelector.SelectSites(stand)) { // Site selection may have spread to other stands beyond the // original stand. Stand standForCurrentSite = SiteVars.Stand[site]; // Always record the prescription even if nothing harvested; Supports plantOnly prescriptions SiteVars.Prescription[site] = this; SiteVars.PrescriptionName[site] = this.Name; if (isDebugEnabled) { log.DebugFormat(" Cutting cohorts at {0} in stand {1}{2}", site, SiteVars.Stand[site].MapCode, (standForCurrentSite == stand) ? "" : string.Format(" (initial stand {0})", stand.MapCode)); } cohortCutter.Cut(site, cohortCounts); if (cohortCounts.AllSpecies > 0) { SiteVars.CohortsDamaged[site] = cohortCounts.AllSpecies; standForCurrentSite.DamageTable.IncrementCounts(cohortCounts); stand.LastAreaHarvested += Model.Core.CellArea; if (isDebugEnabled) { log.DebugFormat(" # of cohorts damaged = {0}; stand.LastAreaHarvested = {1}", SiteVars.CohortsDamaged[site], stand.LastAreaHarvested); } HarvestExtensionMain.OnSiteHarvest(this, site); } if (speciesToPlant != null) { Model.Core.UI.WriteLine(" {0} {1}", speciesToPlant.ToString(), site.ToString()); Reproduction.ScheduleForPlanting(speciesToPlant, site); } } return; }
void GiveBirth() { Pregnant = false; DueDate = 0; Due = false; for (int i = 0; i < LitterSize; i++) { var baby = (GameObject)GameObject.Instantiate(gameObject, transform.position + Random.insideUnitSphere, Random.rotation); var babyRepro = baby.GetComponent<Reproduction>(); if (Father == null) Father = this; babyRepro.Species = MutateSpecies(Species, Father.Species, Fussiness / 2); babyRepro.Mate = null; babyRepro.Father = null; if (Sex != Sex.Asexual) babyRepro.Sex = (Sex)Random.Range(1, 3); var babyBody = baby.GetComponent<Body>(); babyBody.Stomach.Contents = body.Fat.Get(body.Fat.Contents / 2); babyBody.Fat.Contents = 0; var babyReaper = baby.GetComponent<GrimReaper>(); babyReaper.Age = 0; var babyEat = baby.GetComponent<Eat>(); babyEat.Food = null; var babyWalk = baby.GetComponent<RandomWalk>(); babyWalk.Destination = Vector3.zero; } Father = null; }
//--------------------------------------------------------------------- public override void Run() { SiteVars.GetExternalVars(); // ReInitialize(); SiteVars.Prescription.ActiveSiteValues = null; SiteVars.CohortsDamaged.ActiveSiteValues = 0; //harvest each management area in the list foreach (ManagementArea mgmtArea in managementAreas) { totalSites = new int[Prescription.Count]; totalDamagedSites = new int[Prescription.Count]; totalSpeciesCohorts = new int[Prescription.Count, PlugIn.ModelCore.Species.Count]; prescriptionReported = new bool[Prescription.Count]; mgmtArea.HarvestStands(); //and record each stand that's been harvested foreach (Stand stand in mgmtArea) { if (stand.Harvested) { WriteLogEntry(mgmtArea, stand); } } // updating for preventing establishment foreach (Stand stand in mgmtArea) { if (stand.Harvested && stand.LastPrescription.PreventEstablishment) { List <ActiveSite> sitesToDelete = new List <ActiveSite>(); foreach (ActiveSite site in stand) { if (SiteVars.CohortsDamaged[site] > 0) { Reproduction.PreventEstablishment(site); sitesToDelete.Add(site); } } foreach (ActiveSite site in sitesToDelete) { stand.DelistActiveSite(site); } } } // foreach (Stand stand in mgmtArea) foreach (AppliedPrescription aprescription in mgmtArea.Prescriptions) { Prescription prescription = aprescription.Prescription; //string species_string = ""; double[] species_count = new double[modelCore.Species.Count]; foreach (ISpecies species in PlugIn.ModelCore.Species) { species_count[species.Index] += totalSpeciesCohorts[prescription.Number, species.Index]; } if (totalSites[prescription.Number] > 0 && prescriptionReported[prescription.Number] != true) { //summaryLog.WriteLine("{0},{1},{2},{3}{4}", // PlugIn.ModelCore.CurrentTime, // mgmtArea.MapCode, // prescription.Name, // totalDamagedSites[prescription.Number], // species_string); summaryLog.Clear(); SummaryLog sl = new SummaryLog(); sl.Time = modelCore.CurrentTime; sl.ManagementArea = mgmtArea.MapCode; sl.Prescription = prescription.Name; sl.HarvestedSites = totalDamagedSites[prescription.Number]; sl.CohortsHarvested_ = species_count; summaryLog.AddObject(sl); summaryLog.WriteToFile(); prescriptionReported[prescription.Number] = true; } } } prescriptionMaps.WriteMap(PlugIn.ModelCore.CurrentTime); }