private static string CollectGameState(Settings settings) { //i have NO idea if it is a good idea to do this in a seperate Thread. but so far no trouble TickDataHolder tickData = new TickDataHolder(); GameData gsm = new GameData { tick = GenTicks.TicksGame, worldSeed = Find.World.info.seedString, includesMaps = settings.enableWorld, includesPawns = settings.enablePawns, }; if (settings.enableWorld) { foreach (Map m in knownMaps.Values) { gsm.maps.Add(new MapData(m, settings)); } } if (settings.enablePawns) { foreach (object o in Find.MapUI.selector.SelectedObjectsListForReading) { if (o is Pawn p) { tickData.selectedPawns.Add(p.ThingID); } } foreach (Pawn p in Find.ColonistBar.GetColonistsInOrder()) { if (p != null) { gsm.colonists.Add(new PawnData(p, tickData, settings)); } } } XmlSerializer serializer = new XmlSerializer(typeof(GameData)); StringWriter writer = new StringWriter(); serializer.Serialize(writer, gsm); writer.Close(); return(writer.ToString()); }
public PawnData(Pawn p, TickDataHolder tickData, Settings settings) { id = p.ThingID; fullName = p.Name.ToString(); nickName = p.LabelShort; label = p.Label; includesSkills = settings.enableSkills; includesNeeds = true; includesHealth = true; includesJob = true; includesPortrait = true; if (p.Map != null) { onMap = p.Map.uniqueID; } else { onMap = -1; } colonist = p.IsColonist; //visitor = p.guest != null && p.guest.HostFaction.IsPlayer; prisoner = p.IsPrisonerOfColony; drafted = p.Drafted; selected = tickData.selectedPawns.Contains(id); age = p.ageTracker.AgeBiologicalYearsFloat; currentHealth = p.health.summaryHealth.SummaryHealthPercent; dead = p.Dead; downed = p.Downed; sleeping = p.CurJob != null && p.jobs.curDriver.asleep; idle = p.mindState.IsIdle; medicalRest = p.InBed() && p.CurrentBed().Medical; inAggroMentalState = p.InAggroMentalState; inMentalState = p.InMentalState; location = new Location(p.Position); if (p.story != null && p.story.traits != null) { foreach (Trait t in p.story.traits.allTraits) { traits.Add(t.Label); } } if (includesSkills && p.skills != null) { skillsData = new PawnSkills(p.skills, settings); } if (includesNeeds && p.needs != null) { needData = new PawnNeeds(p.needs, settings); } if (includesHealth && p.health != null) { healthData = new PawnHealth(p, p.health, settings); capacityData = new PawnCapacity(p.health.capacities); } if (includesJob && p.CurJob != null) { job = new JobData(p, p.CurJob); } if (includesPortrait && settings.pawnPortraits.ContainsKey(p.ThingID)) { portrait = settings.pawnPortraits[p.ThingID].EncodeToPNG(); } }