private void updatePopulationList(int day) { mHighLight.Points.Clear(); lstPopulations.Items.Clear(); if (day < 0 || day >= mHistory.Count) { return; } int max = 0; DayEvents dayEvent = mHistory[day]; lstPopulations.Items.Add("Day " + day); foreach (KeyValuePair <string, int> s in dayEvent.populations) { max = Math.Max(s.Value, max); lstPopulations.Items.Add(s.Key + " Population: " + s.Value); lstPopulations.Items.Add(s.Key + " Births: " + dayEvent.getBirths(s.Key)); if (dayEvent.deaths.ContainsKey(s.Key)) { foreach (KeyValuePair <char, int> pair in dayEvent.deaths[s.Key]) { lstPopulations.Items.Add(s.Key + " Deaths by " + mDeathNames[pair.Key] + ": " + pair.Value); } } } mHighLight.Points.AddXY((double)day, (double)max); }
private void renderOverlay(int day) { int width = mMapList[0].Length; int height = mMapList.Count; if (mMapOverlay != null) { mMapOverlay.Dispose(); } mMapOverlay = new Bitmap(width, height); if (day < 0) { return; } DayEvents dayEvent = mHistory[day]; foreach (Location location in dayEvent.locations) { int x = location.position.x; int y = location.position.y; mMapOverlay.SetPixel(x, y, mColourList[Animal.Animals[location.id].graphic.fullColour]); } }
void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (cc != null && cc.Length > 0) { bool findState = false; string endState = null; string state = "none"; char tile = '\0'; int mapWidth = -1; Dictionary <string, float> values = new Dictionary <string, float>(); int numAnimals = 0; int oldPercent = -1; for (int i = 0; i < cc.Length; i++) { string line = cc[i]; if (line == "--") { findState = true; continue; } int percent = (int)(((float)i / (float)cc.Length) * 100); if (percent != oldPercent) { oldPercent = percent; worker.ReportProgress(percent); } if (findState) { findState = false; endState = line; } if (state == null || state.Equals("none", StringComparison.CurrentCultureIgnoreCase) || state.Equals("TileData", StringComparison.CurrentCultureIgnoreCase)) { } else if (state.Equals("tiles", StringComparison.CurrentCultureIgnoreCase)) { if (mCharCount < mColors.Length) { if (tile == '\0') { tile = line[0]; } else { int t = int.Parse(line); if (!mColourMap.ContainsKey(tile)) { Console.WriteLine("Adding char {0} with colour {1}", tile, mColors[t].ToKnownColor().ToString()); mColourMap[tile] = mColors[t]; //addColour(mColors[t], tile, true); mCharCount++; tile = '\0'; } } } } else if (state.Equals("options", StringComparison.CurrentCultureIgnoreCase)) { switch (line) { case "current_time": mCurrentTime = float.Parse(cc[++i]); break; case "current_day": mCurrentDay = int.Parse(cc[++i]); break; case "day_length": mDayLength = float.Parse(cc[++i]); break; default: break; } } else if (state.Equals("map", StringComparison.CurrentCultureIgnoreCase)) { if (endState != null) { renderImage(ref mMapTotal); } else { if (mMapList.Count == 0) { mapWidth = line.Length; } mMapList.Add(line); } } else if (state.Equals("entities", StringComparison.CurrentCultureIgnoreCase) || state.Equals("RemovedEntities", StringComparison.CurrentCultureIgnoreCase)) { if (line == "Animal") { i++; Animal a = new Animal(); a.load(ref cc, ref i); i--; string identifier = a.graphic.ToString() + '_' + a.species; if (!mPopulations.ContainsKey(identifier)) { mPopulations[identifier] = new PopulationStat(); } if (a.isDead) { mPopulations[identifier].dead++; } else { mPopulations[identifier].alive++; } } } else if (state.Equals("history", StringComparison.CurrentCultureIgnoreCase)) { if (line.Equals("DayEvent", StringComparison.CurrentCultureIgnoreCase)) { DayEvents day = new DayEvents(); day.load(ref cc, ref i); mHistory.Add(day); } } else { Console.WriteLine("Unknown state {0}", state); } if (endState != null) { state = endState; endState = null; } } mValues = new List <KeyPair>(); foreach (KeyValuePair <string, float> pair in values) { float value = pair.Value / numAnimals; KeyPair p = new KeyPair(pair.Key, value); if (pair.Key.Equals("diet", StringComparison.CurrentCultureIgnoreCase)) { p.max = 1.0f; } mValues.Add(p); } } }
void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (cc != null && cc.Length > 0) { bool findState = false; string endState = null; string state = "none"; char tile = '\0'; int mapWidth = -1; Dictionary<string, float> values = new Dictionary<string, float>(); int numAnimals = 0; int oldPercent = -1; for (int i = 0; i < cc.Length; i++) { string line = cc[i]; if (line == "--") { findState = true; continue; } int percent = (int)(((float)i / (float)cc.Length) * 100); if (percent != oldPercent) { oldPercent = percent; worker.ReportProgress(percent); } if (findState) { findState = false; endState = line; } if (state == null || state.Equals("none", StringComparison.CurrentCultureIgnoreCase) || state.Equals("TileData", StringComparison.CurrentCultureIgnoreCase)) { } else if (state.Equals("tiles", StringComparison.CurrentCultureIgnoreCase)) { if (mCharCount < mColors.Length) { if (tile == '\0') { tile = line[0]; } else { int t = int.Parse(line); if (!mColourMap.ContainsKey(tile)) { Console.WriteLine("Adding char {0} with colour {1}", tile, mColors[t].ToKnownColor().ToString()); mColourMap[tile] = mColors[t]; //addColour(mColors[t], tile, true); mCharCount++; tile = '\0'; } } } } else if (state.Equals("options", StringComparison.CurrentCultureIgnoreCase)) { switch (line) { case "current_time": mCurrentTime = float.Parse(cc[++i]); break; case "current_day": mCurrentDay = int.Parse(cc[++i]); break; case "day_length": mDayLength = float.Parse(cc[++i]); break; default: break; } } else if (state.Equals("map", StringComparison.CurrentCultureIgnoreCase)) { if (endState != null) { renderImage(ref mMapTotal); } else { if (mMapList.Count == 0) { mapWidth = line.Length; } mMapList.Add(line); } } else if (state.Equals("entities", StringComparison.CurrentCultureIgnoreCase) || state.Equals("RemovedEntities", StringComparison.CurrentCultureIgnoreCase)) { if (line == "Animal") { i++; Animal a = new Animal(); a.load(ref cc, ref i); i--; string identifier = a.graphic.ToString() + '_' + a.species; if (!mPopulations.ContainsKey(identifier)) { mPopulations[identifier] = new PopulationStat(); } if (a.isDead) { mPopulations[identifier].dead++; } else { mPopulations[identifier].alive++; } } } else if (state.Equals("history", StringComparison.CurrentCultureIgnoreCase)) { if (line.Equals("DayEvent", StringComparison.CurrentCultureIgnoreCase)) { DayEvents day = new DayEvents(); day.load(ref cc, ref i); mHistory.Add(day); } } else { Console.WriteLine("Unknown state {0}", state); } if (endState != null) { state = endState; endState = null; } } mValues = new List<KeyPair>(); foreach (KeyValuePair<string, float> pair in values) { float value = pair.Value / numAnimals; KeyPair p = new KeyPair(pair.Key, value); if (pair.Key.Equals("diet", StringComparison.CurrentCultureIgnoreCase)) { p.max = 1.0f; } mValues.Add(p); } } }