internal static void PasteToActivePolicy() { Policy policy = GetActivePolicy(); if (!RestrictManager.clipboard.NullOrEmpty() && RestrictManager.clipboard[0].zone != policy.id) { //RestrictManager.links.RemoveAll(x => x.zone == policy.id); foreach (RestrictLink copiedLink in RestrictManager.clipboard) { foreach (RestrictLink link in RestrictManager.links) { if (link.colonist == copiedLink.colonist && link.zone == policy.id) { RestrictManager.CopySchedule(copiedLink.schedule, link.schedule); Log.Message("Copied Schedule"); } } } RestrictManager.LoadState( links, Find.CurrentMap.mapPawns.FreeColonists.ToList(), policy); } }
internal static void SaveCurrentState(List <Pawn> pawns) { int currentMap = Find.CurrentMap.uniqueID; int activePolicyId = RestrictManager.GetActivePolicy().id; //Save current state foreach (Pawn p in pawns) { //find colonist in the current zone in the current map RestrictLink link = RestrictManager.links.Find( x => p.Equals(x.colonist) && x.zone == activePolicyId && x.mapId == currentMap); if (link != null) { //colonist found! save link.area = p.playerSettings.AreaRestriction; RestrictManager.CopySchedule(p.timetable.times, link.schedule); } else { //colonist not found. So add it to the RestrictLink list RestrictManager.links.Add( new RestrictLink( activePolicyId, p, p.playerSettings.AreaRestriction, p.timetable.times, currentMap)); } } }
internal static void LoadState( List <RestrictLink> links, List <Pawn> pawns, Policy policy) { List <RestrictLink> mapLinks = null; List <RestrictLink> zoneLinks = null; int currentMap = Find.CurrentMap.uniqueID; //get all links from the current map mapLinks = links.FindAll(x => x.mapId == currentMap); //get all links from the selected zone zoneLinks = mapLinks.FindAll(x => x.zone == policy.id); foreach (Pawn p in pawns) { foreach (RestrictLink l in zoneLinks) { if (l.colonist != null && l.colonist.Equals(p)) { p.playerSettings.AreaRestriction = l.area; RestrictManager.CopySchedule(l.schedule, p.timetable.times); } } } RestrictManager.SetActivePolicy(policy); }