Beispiel #1
0
        public bool loadBackup(string line, string backup, string inStartYear)
        {
            mLog.Debug("");
            mLog.Debug("");
            mLog.Debug("******************************************************************");
            mLog.Debug("inside load backup");

#if DEBUG
            Console.WriteLine("start loading backup runime is " + DateTime.Now.ToShortTimeString());
#endif
            int i = 0;

            myAnimals.Clear();

            //Set the currNumAnimals to the saved number.
            currNumAnimals = Convert.ToInt32(((line.Split(':'))[1]).Trim());
            mLog.Debug("we are going to load " + currNumAnimals.ToString());
            //Deserialize the list of animals from BackupDir\Animals.xml
            myAnimals = SerializeHelper.DeserializeFromFile(backup + "\\Animals.xml", new List <Animal>()) as List <Animal>;
            mLog.Debug("we loaded " + myAnimals.Count.ToString());
            mLog.Debug("");

            mLog.Debug("******************************************************************");
            mLog.Debug("");
            mLog.Debug("");
            //Finish reconstruction that couldn't be saved to the xml file
            setResidentsTextOutput(this.AnimalAttributes.OutPutDir, inStartYear);
            foreach (Animal a in myAnimals)
            {
                if (a is Resident)
                {
                    Resident r = a as Resident;
                    r.SaySomething("From Backup");
                }
                else
                {
                    ///   this.SetDisperserMapValues(a);
                }


                if (a.TextFileWriter == null)
                {
                    a.ReBuildTextWriter(this.AnimalAttributes.OutPutDir);
                }

                a.rebuildIPointList();
                a.AnimalManager = this;
                i++;
            }

            if (i != currNumAnimals)
            {
                Console.WriteLine("Something is wrong! i={0} cur={1}", i, currNumAnimals);
            }
#if DEBUG
            Console.WriteLine("done loading backup runime is " + DateTime.Now.ToShortTimeString());
#endif
            return(true);
        }
Beispiel #2
0
        public void doTimeStep(HourlyModifier inHM, DailyModifier inDM, DateTime currTime, bool DoTextOutPut, Map currSocialMap)
        {
            //List<Animal> liveAnimals = this.getAllLiveAnimals();
            Animal a;
            string status = "";

            try
            {
                mLog.Debug("inside animal manager do time step with modifiers");
                // foreach (Animal a in myAnimals)
                for (int i = 0; i < myAnimals.Count; i++)
                {
                    a = this.myAnimals[i];
                    mLog.Debug("");
                    mLog.Debug("animal id = " + a.IdNum.ToString());
                    mLog.Debug("animal is type " + a.GetType().ToString());


                    a.doTimeStep(inHM, inDM, currTime, DoTextOutPut, ref status);
                    //check to see if they died if they did remove them from the list
                    if (a.IsDead)
                    {
                        if (a.GetType().ToString().Equals("SEARCH.Resident", StringComparison.CurrentCultureIgnoreCase))
                        {
                            this.AdjustMapForDeadAnimal(currSocialMap, a);
                        }

                        this.changeToDeadAnimal(a);
                    }
                    //check to see if they are changing from disperser to resident

                    if (status == "resident")
                    {
                        mLog.Debug("switching " + a.IdNum.ToString() + " to a resident");
                        Resident r = new Resident();
                        r.Sex               = a.Sex;
                        r.IdNum             = a.IdNum;
                        r.TextFileWriter    = a.TextFileWriter;
                        r.HomeRangeCenter   = a.HomeRangeCenter;
                        r.HomeRangeCriteria = a.HomeRangeCriteria;
                        r.MyAttributes      = this.ResidentAttributes;
                        r.IdNumOrig         = a.IdNum.ToString();
                        this.myAnimals.RemoveAt(i);
                        this.myAnimals.Insert(i, r);
                        status = "";
                        //Sunday, November z08, 2009
                        //update reference to current social map.
                        currSocialMap = MapManager.GetUniqueInstance().SocialMap;
                    }
                }
            }


            catch (System.Exception ex)
            {
                eLog.Debug(ex);
            }
        }
Beispiel #3
0
        public bool makeResidents(InitialAnimalAttributes[] inResAttributes, string currYear)
        {
            bool     success = false;
            Resident r;

            mLog.Debug("inside makeResidents going to make " + inResAttributes.Length.ToString());
            mLog.Debug("total animals now is " + this.myAnimals.Count.ToString());
            try
            {
                for (int i = 0; i < inResAttributes.Length; i++)
                {
                    r = new Resident();
                    r.MyAttributes = new ResidentAttributes();
                    if (inResAttributes[i].Sex.ToString().ToUpper() == "M")
                    {
                        r.Sex = "Male";
                    }
                    else
                    {
                        r.Sex = "Female";
                    }
                    //r.IsDead = false;
                    r.IdNum           = this.currNumAnimals++;
                    r.Location        = inResAttributes[i].Location;
                    r.HomeRangeCenter = r.Location as PointClass;;
                    r.IdNumOrig       = inResAttributes[i].OrginalID;

                    this.myAnimals.Add(r);
                }

                mLog.Debug("after adding residents total animals now is " + this.myAnimals.Count.ToString());
                success = true;
            }
            catch (System.Exception ex)
            {
                eLog.Debug(ex);
#if (DEBUG)
                System.Windows.Forms.MessageBox.Show(ex.Message);
#endif
            }

            return(success);
        }