// ************************ Methods ********************************************* /// <summary> /// Compare this instance of this class to another instance. The second /// instance is less than this one if it is applied earlier. /// </summary> /// <param name="obj">The second instance of this class</param> /// <returns> /// -1 if this instance is applied earlier, 0 if both instances are applied at /// the same time, 1 if this instance is applied later. /// </returns> public int CompareTo(Object obj) { cStrategy Other = (cStrategy)obj; if (mvarYear < Other.Year) { return(-1); } else if (mvarYear == Other.Year) { if (mvarWeek < Other.Week) { return(-1); } else if (mvarWeek > Other.Week) { return(1); } else { return(0); } } else { return(1); } }
// ************************ Methods ********************************************** /// <summary> /// Add a strategy to the strategy list. /// </summary> /// <param name="item"> /// The strategy to add to the list. If item is null, an ArgumentNullException /// exception is raised. /// </param> public virtual void Add(cStrategy item) { Values.Add(item); }
// *********************** private members **************************************** // private function for the actual weekly calls private bool WeeklyCalls(bool IncrementTime) { //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls()"); //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls() Animals.Count = " + Animals.Count); cWeeklyActivityThread ActivityThread = new cWeeklyActivityThread(0, Animals.Count - 1, Animals, Years.CurrentYear.CurrentWeek, PreventIncest); ActivityThread.RunWeeklyActivities(); // add babies to master list, attaching the event handler in each case //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls() add babies"); Animals.AddBabiesToList(new AnimalInfectedEventHandler(this.Animal_AnimalInfected)); // apply any strategies applicable to this year and week if (StrategyCounter < Strategies.Count) { for (; ;) { cStrategy CurrentStrategy = Strategies[StrategyCounter]; // if the most current strategy should be applied later, exit now if (CurrentStrategy.Year > Years.CurrentYearNum || CurrentStrategy.Week > Years.CurrentYear.CurrentWeek) { break; } // if the most current strategy should be applied now, apply it!! else if (CurrentStrategy.Year == Years.CurrentYearNum && CurrentStrategy.Week == Years.CurrentYear.CurrentWeek) { CurrentStrategy.ApplyStrategy(); } // increment the StrategyCounter StrategyCounter++; // make sure we have not just run the last strategy if (StrategyCounter >= Strategies.Count) { break; } } } // indicate that weekly events have been run //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls() indicate that weekly events have been run"); mvarHaveRunWeeklyEvents = true; // raise the WeeklyUpdate event before the dead are removed //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls(): raise weekly event before dead are removed"); cWeeklyUpdateEventArgs e = new cWeeklyUpdateEventArgs(this); onWeeklyUpdate(e, false); //if (e.Abort) return false; //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls(): e.Abort = " + e.Abort); if (e.Abort) { return(false); } // remove dead animals from main list Animals.RemoveDeceased(); // raise weekly event after dead are removed //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls(): raise weekly event AFTER dead are removed"); onWeeklyUpdate(e, true); if (e.Abort) { return(false); } // scramble the animals if (ScrambleList) { Animals.ScrambleOrder(); } // increment time if (IncrementTime) { Years.IncrementTime(); // indicate that weekly events have not been run mvarHaveRunWeeklyEvents = false; } //System.Diagnostics.Debug.WriteLine("cBackground.cs: WeeklyCalls() END"); return(true); }