private void makeNextGenAnimal(InitialAnimalAttributes inIAA, DateTime currTime) { Animal tmpAnimal = null; mLog.Debug("inside make next gen animal"); try { for (int i = 0; i < inIAA.NumToMake; i++) { if (inIAA.Sex == 'M') { mLog.Debug("makeing a new male"); tmpAnimal = new Male(); tmpAnimal.GenderModifier = this.mMaleModifier; } else { mLog.Debug("makeing a new female"); tmpAnimal = new Female(); tmpAnimal.GenderModifier = this.mFemaleModifier; } tmpAnimal.IdNum = this.currNumAnimals++; mLog.Debug("just made " + tmpAnimal.IdNum.ToString()); tmpAnimal.Location = inIAA.Location; tmpAnimal.AnimalAtributes = this.AnimalAttributes; tmpAnimal.CurrEnergy = this.AnimalAttributes.InitialEnergy; mLog.Debug("now setting the mover"); tmpAnimal.myMover = this.mMover; tmpAnimal.StateModifer = this.SafeSearchMod; tmpAnimal.AnimalManager = this; tmpAnimal.HomeRangeTrigger = this.mHomeRangeTrigger; tmpAnimal.HomeRangeFinder = this.mHomeRangeFinder; tmpAnimal.setInitialSleepTime(currTime); this.SetMapValues(tmpAnimal, currTime); tmpAnimal.BuildTextWriter(currTime.Year.ToString()); tmpAnimal.dump(); this.myAnimals.Add(tmpAnimal); } } catch (System.Exception ex) { #if (DEBUG) System.Windows.Forms.MessageBox.Show(ex.Message); #endif eLog.Debug(ex); } }
public int breedFemales(DateTime currTime) { mLog.Debug("inside breed females"); int numMales = 0; int numFemales = 0; int totalNewAnimals = 0; InitialAnimalAttributes iaa; mLog.Debug("starting the loop"); List <Resident> myBreeders = this.getResidents("female"); foreach (Resident r in myBreeders) { r.breed(out numMales, out numFemales); totalNewAnimals += numFemales + numMales; if (numMales > 0) { iaa = new InitialAnimalAttributes(); iaa.Location = r.HomeRangeCenter; iaa.Sex = 'M'; iaa.NumToMake = numMales; this.makeNextGenAnimal(iaa, currTime); } if (numFemales > 0) { iaa = new InitialAnimalAttributes(); iaa.Location = r.HomeRangeCenter; iaa.Sex = 'F'; iaa.NumToMake = numFemales; this.makeNextGenAnimal(iaa, currTime); } } this.mHomeRangeTrigger.reset(this.myAnimals.Count + 1); setNextGenHomeRange(); return(totalNewAnimals); }
/// <summary> /// When this map is first loaded we need to query the map and build the initial set of animals. /// this will return an array of Initial Animal Attributes. /// </summary> /// public new void GetInitialAnimalAttributes(out InitialAnimalAttributes [] outAttributes) { IPoint tmpPoint = null; IFeature tmpFeature = null; IFeatureClass tmpFeatureClass = null; IFeatureCursor tmpCur = null; IRowBuffer rowBuff; ArrayList tmpArrayList = new ArrayList(); int numToMake = 0; int fieldIndex; InitialAnimalAttributes tempIAA; tmpFeatureClass = base.mySelf; tmpCur = tmpFeatureClass.Search(null, false); tmpFeature = tmpCur.NextFeature(); if (tmpFeature.Shape.GeometryType.ToString() == "esriGeometryPoint") { while (tmpFeature != null) { //make an attribute from the first row in the data base tempIAA = new InitialAnimalAttributes(); //have to have a row buffer to get the value out of the database rowBuff = (IRowBuffer)tmpFeature; tmpPoint = (IPoint)tmpFeature.ShapeCopy; fieldIndex = tmpFeature.Fields.FindField("MALES"); if (fieldIndex >= 0) { numToMake = System.Convert.ToInt32(rowBuff.get_Value(fieldIndex)); } else { numToMake = 0; } tempIAA.setPointValues(tmpPoint); tempIAA.Sex = 'M'; tempIAA.NumToMake = numToMake; tmpArrayList.Add(tempIAA); tempIAA = new InitialAnimalAttributes(); fieldIndex = tmpFeature.Fields.FindField("Fems"); if (fieldIndex >= 0) { numToMake = System.Convert.ToInt32(rowBuff.get_Value(fieldIndex)); } else { numToMake = 0; } tempIAA.setPointValues(tmpPoint); tempIAA.Sex = 'F'; tempIAA.NumToMake = numToMake; tmpArrayList.Add(tempIAA); tmpFeature = tmpCur.NextFeature(); } } outAttributes = new InitialAnimalAttributes[tmpArrayList.Count]; tmpArrayList.CopyTo(outAttributes); }