Beispiel #1
0
        internal static void UpdateState(
            List <AssignLink> links, List <Pawn> pawns, Policy policy)
        {
            List <AssignLink> mapLinks  = null;
            List <AssignLink> 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 (AssignLink l in zoneLinks)
                {
                    if (l.colonist != null && l.colonist.Equals(p))
                    {
                        l.hostilityResponse =
                            p.playerSettings.hostilityResponse;
                        l.foodPolicy = p.foodRestriction.CurrentFoodRestriction;
                    }
                }
            }

            AssignManager.SetActivePolicy(policy);
        }
 public override void PreClose()
 {
     base.PreClose();
     AssignManager.CleanDeadMaps();
     AssignManager.CleanDeadColonists(this.Pawns.ToList());
     AssignManager.SaveCurrentState(this.Pawns.ToList());
 }
        private static void LoadState(
            List <AssignLink> links, List <Pawn> pawns, Policy policy)
        {
            List <AssignLink> mapLinks  = null;
            List <AssignLink> zoneLinks = null;
            int currentMap = Find.VisibleMap.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 (AssignLink l in zoneLinks)
                {
                    if (l.colonist != null && l.colonist.Equals(p))
                    {
                        p.outfits.CurrentOutfit = OutfitExits(l.outfit) ?
                                                  l.outfit : null;
                        p.drugs.CurrentPolicy = DrugPolicyExits(l.drugPolicy) ?
                                                l.drugPolicy : null;
                        p.playerSettings.hostilityResponse =
                            l.hostilityResponse;
                        if (Widget_CombatExtended.CombatExtendedAvailable)
                        {
                            Widget_CombatExtended.SetLoadoutById(
                                p, l.loadoutId);
                        }
                    }
                }
            }

            AssignManager.SetActivePolicy(policy);
        }
        private static void SaveCurrentState(List <Pawn> pawns)
        {
            int currentMap = Find.VisibleMap.uniqueID;

            //Save current state
            foreach (Pawn p in pawns)
            {
                //find colonist on the current zone in the current map
                AssignLink link = AssignManager.links.Find(
                    x => x.colonist.Equals(p) &&
                    x.zone == AssignManager.GetActivePolicy().id&&
                    x.mapId == currentMap);

                if (link != null)
                {
                    //colonist found! save
                    link.outfit            = p.outfits.CurrentOutfit;
                    link.drugPolicy        = p.drugs.CurrentPolicy;
                    link.hostilityResponse =
                        p.playerSettings.hostilityResponse;
                    if (Widget_CombatExtended.CombatExtendedAvailable)
                    {
                        link.loadoutId = Widget_CombatExtended.GetLoadoutId(p);
                    }
                }
                else
                {
                    //colonist not found. So add it to the AssignLink list
                    int loadoutId = 0;
                    if (Widget_CombatExtended.CombatExtendedAvailable)
                    {
                        loadoutId = Widget_CombatExtended.GetLoadoutId(p);
                    }

                    Outfit outfit = p.outfits.CurrentOutfit;
                    if (p.outfits.CurrentOutfit ==
                        Current.Game.outfitDatabase.AllOutfits[0])
                    {
                        outfit = AssignManager.DefaultOutfit;
                    }

                    AssignManager.links.Add(
                        new AssignLink(
                            AssignManager.GetActivePolicy().id,
                            p,
                            outfit,
                            p.drugs.CurrentPolicy,
                            p.playerSettings.hostilityResponse,
                            loadoutId,
                            currentMap));
                }
            }
        }
        public override void DoWindowContents(Rect fillRect)
        {
            if (AssignManager.DirtyPolicy)
            {
                LoadState(
                    AssignManager.links, this.Pawns.ToList(),
                    AssignManager.GetActivePolicy());
                AssignManager.DirtyPolicy = false;
            }

            float num = 5f;

            base.DoWindowContents(fillRect);
            Rect position = new Rect(0f, 0f, fillRect.width, 65f);

            GUI.BeginGroup(position);
            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.LowerCenter;
            Rect rect1 =
                new Rect(num, -8f, 165f, Mathf.Round(position.height / 3f));

            Widgets.Label(rect1, "BPC.CurrentAssignPolicy".Translate());
            GUI.EndGroup();

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;
            Rect rect2 = new Rect(
                num, Mathf.Round(position.height / 4f) - 4f,
                rect1.width, Mathf.Round(position.height / 4f) + 4f);

            if (Widgets.ButtonText(
                    rect2, AssignManager.GetActivePolicy().label,
                    true, false, true))
            {
                //CleanDeadColonists(this.pawns);
                SaveCurrentState(this.Pawns.ToList());
                OpenAssignPolicySelectMenu(
                    AssignManager.links, this.Pawns.ToList());
            }
            num += rect1.width;
            Rect rect3 = new Rect(
                num, 0f, 20f, Mathf.Round(position.height / 2f));

            if (Widgets.ButtonText(rect3, "", true, false, true))
            {
                Find.WindowStack.Add(
                    new Dialog_ManagePolicies(Find.VisibleMap));
            }
            Rect rect4 = new Rect(num + 3f, rect3.height / 4f, 14f, 14f);

            GUI.DrawTexture(rect4, Resources.Settings);
            TooltipHandler.TipRegion(rect4, "BPC.Settings".Translate());
        }
 private static void CleanDeadMaps()
 {
     for (int i = 0; i < AssignManager.activePolicies.Count; i++)
     {
         MapActivePolicy map = AssignManager.activePolicies[i];
         if (!Find.Maps.Any(x => x.uniqueID == map.mapId))
         {
             AssignManager.DeleteLinksInMap(map.mapId);
             AssignManager.DeleteMap(map);
         }
     }
 }
        public override void PreOpen()
        {
            base.PreOpen();

            AssignManager.CleanDeadMaps();

            AssignManager.UpdateState(
                AssignManager.links, this.Pawns.ToList(),
                AssignManager.GetActivePolicy());

            AssignManager.LoadState(
                AssignManager.links, this.Pawns.ToList(),
                AssignManager.GetActivePolicy());

            AssignManager.CleanDeadColonists(this.Pawns.ToList());
        }
        private static void DoColumn(
            Rect rect, Policy policy, Resources.Type type)
        {
            GUI.BeginGroup(rect);
            WidgetRow widgetRow =
                new WidgetRow(0f, 0f, UIDirection.RightThenUp, 99999f, 4f);

            widgetRow.Gap(4f);
            if (policy != null)
            {
                widgetRow.Label(policy.label, 138f);
                if (widgetRow.ButtonText(
                        "BPC.Rename".Translate(), null, true, false))
                {
                    Find.WindowStack.Add(new Dialog_RenamePolicy(policy, type));
                }
                if (policy.id > 0 &&
                    widgetRow.ButtonIcon(
                        ContentFinder <Texture2D> .Get(
                            "UI/Buttons/Delete", true), null))
                {
                    switch (type)
                    {
                    case Resources.Type.assign:
                        AssignManager.DeletePolicy(policy);
                        break;

                    case Resources.Type.animal:
                        AnimalManager.DeletePolicy(policy);
                        break;

                    case Resources.Type.restrict:
                        RestrictManager.DeletePolicy(policy);
                        break;

                    case Resources.Type.work:
                        WorkManager.DeletePolicy(policy);
                        break;
                    }
                }
            }
            GUI.EndGroup();
        }
        private static void OpenAssignPolicySelectMenu(
            List <AssignLink> links, List <Pawn> pawns)
        {
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (Policy assignPolicy in AssignManager.policies)
            {
                list.Add(
                    new FloatMenuOption(
                        assignPolicy.label,
                        delegate
                {
                    AssignManager.LoadState(
                        links,
                        pawns,
                        assignPolicy);
                },
                        MenuOptionPriority.Default, null, null, 0f, null));
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Beispiel #10
0
 internal static void CleanDeadMaps()
 {
     for (int i = 0; i < AssignManager.activePolicies.Count; i++)
     {
         MapActivePolicy map = AssignManager.activePolicies[i];
         if (!Find.Maps.Any(x => x.uniqueID == map.mapId))
         {
             if (Find.Maps.Count == 1 && !AssignManager.ActivePoliciesContainsValidMap())
             {
                 //this means the player was on the move without any base
                 //and just re-settled. So, let's move the settings to
                 //the new map
                 int mapid = Find.CurrentMap.uniqueID;
                 AssignManager.MoveLinksToMap(mapid);
                 map.mapId = mapid;
             }
             else
             {
                 AssignManager.DeleteLinksInMap(map.mapId);
                 AssignManager.DeleteMap(map);
             }
         }
     }
 }
Beispiel #11
0
        internal static void SaveCurrentState(List <Pawn> pawns)
        {
            int currentMap = Find.CurrentMap.uniqueID;

            //Save current state
            foreach (Pawn p in pawns)
            {
                //find colonist on the current zone in the current map
                AssignLink link = AssignManager.links.Find(
                    x => p.Equals(x.colonist) &&
                    x.zone == AssignManager.GetActivePolicy().id&&
                    x.mapId == currentMap);

                if (link != null)
                {
                    //colonist found! save
                    link.outfit            = p.outfits.CurrentOutfit;
                    link.drugPolicy        = p.drugs.CurrentPolicy;
                    link.hostilityResponse =
                        p.playerSettings.hostilityResponse;
                    link.foodPolicy = p.foodRestriction.CurrentFoodRestriction;
                    if (Widget_CombatExtended.CombatExtendedAvailable)
                    {
                        link.loadoutId = Widget_CombatExtended.GetLoadoutId(p);
                    }
                }
                else
                {
                    //colonist not found. So add it to the AssignLink list
                    int loadoutId = 0;
                    if (Widget_CombatExtended.CombatExtendedAvailable)
                    {
                        loadoutId = Widget_CombatExtended.GetLoadoutId(p);
                    }

                    Outfit outfit = p.outfits.CurrentOutfit;
                    if (outfit ==
                        Current.Game.outfitDatabase.DefaultOutfit())
                    {
                        outfit = AssignManager.DefaultOutfit;
                    }

                    DrugPolicy drug = p.drugs.CurrentPolicy;
                    if (drug ==
                        Current.Game.drugPolicyDatabase.DefaultDrugPolicy())
                    {
                        drug = AssignManager.DefaultDrugPolicy;
                    }

                    FoodRestriction food = p.foodRestriction.CurrentFoodRestriction;
                    if (food ==
                        Current.Game.foodRestrictionDatabase.DefaultFoodRestriction())
                    {
                        food = AssignManager.DefaultFoodPolicy;
                    }

                    AssignManager.links.Add(
                        new AssignLink(
                            AssignManager.GetActivePolicy().id,
                            p,
                            outfit,
                            food,
                            drug,
                            p.playerSettings.hostilityResponse,
                            loadoutId,
                            currentMap));
                }
            }
        }
            public override void ExposeData()
            {
                base.ExposeData();

                if (Scribe.mode == LoadSaveMode.LoadingVars ||
                    Scribe.mode == LoadSaveMode.Saving)
                {
                    Scribe_References.Look <Outfit>(
                        ref AssignManager._defaultOutfit,
                        "DefaultOutfit");

                    Scribe_References.Look <DrugPolicy>(
                        ref AssignManager._defaultDrugPolicy,
                        "DefaultDrugPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultFoodPolicy,
                        "DefaultFoodPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultPrisonerFoodPolicy,
                        "DefaultPrisonerFoodPolicy");

                    Scribe_Collections.Look <Policy>(
                        ref AssignManager.policies,
                        "AssignPolicies", LookMode.Deep);

                    Scribe_Collections.Look <AssignLink>(
                        ref AssignManager.links,
                        "AssignLinks", LookMode.Deep);

                    if (AssignManager.links == null)
                    {
                        //this is only required if the save file contains
                        //empty links
                        AssignManager.InstantiateLinks();
                    }

                    Scribe_Collections.Look <string>(
                        ref AssignManager.Prisoners,
                        "Prisoners", LookMode.Value);

                    if (AssignManager.Prisoners == null)
                    {
                        //this is only required if the save file contains
                        //empty prisoners
                        AssignManager.InstantiatePrisoners();
                    }

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref AssignManager.activePolicies,
                        "AssignActivePolicies", LookMode.Deep);

                    Scribe_Collections.Look <Policy>(
                        ref AnimalManager.policies,
                        "AnimalPolicies", LookMode.Deep);

                    Scribe_Collections.Look <AnimalLink>(
                        ref AnimalManager.links,
                        "AnimalLinks", LookMode.Deep);

                    if (AnimalManager.links == null)
                    {
                        //this is only required if the save file contains
                        //empty links. Not sure how this can happen though :(
                        AnimalManager.InstantiateLinks();
                    }

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref AnimalManager.activePolicies,
                        "AnimalActivePolicies", LookMode.Deep);

                    Scribe_Collections.Look <Policy>(
                        ref RestrictManager.policies,
                        "RestrictPolicies", LookMode.Deep);

                    Scribe_Collections.Look <RestrictLink>(
                        ref RestrictManager.links,
                        "RestrictLinks", LookMode.Deep);

                    if (RestrictManager.links == null)
                    {
                        //this is only required if the save file contains
                        //empty links. Not sure how this can happen though :(
                        RestrictManager.InstantiateLinks();
                    }

                    Scribe_Collections.Look <Policy>(
                        ref WorkManager.policies,
                        "WorkPolicies", LookMode.Deep);

                    Scribe_Collections.Look <WorkLink>(
                        ref WorkManager.links,
                        "WorkLinks", LookMode.Deep);

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref WorkManager.activePolicies,
                        "WorkActivePolicies", LookMode.Deep);

                    if (WorkManager.links == null)
                    {
                        //this is only required if the save file contains
                        //empty links. Not sure how this can happen though :(
                        WorkManager.InstantiateLinks();
                    }

                    if (Scribe.mode == LoadSaveMode.LoadingVars &&
                        WorkManager.activePolicies == null)
                    {
                        //this only happens with existing saves prior. Existing saves
                        //have no WorkPolicy data so let's initialize!
                        WorkManager.ForceInit();
                    }
                }

                if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs)
                {
                    Scribe_References.Look <Outfit>(
                        ref AssignManager._defaultOutfit,
                        "DefaultOutfit");

                    Scribe_References.Look <DrugPolicy>(
                        ref AssignManager._defaultDrugPolicy,
                        "DefaultDrugPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultFoodPolicy,
                        "DefaultFoodPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultPrisonerFoodPolicy,
                        "DefaultPrisonerFoodPolicy");
                }
            }
Beispiel #13
0
            //public class DataStorage : WorldComponent
            //{
            //	public DataStorage(World world) : base(world)
            //	{
            //	}

            public override void ExposeData()
            {
                base.ExposeData();

                if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    //Let's make sure all static variables are cleaned.
                    //This shows there's a fundamental problem with this code
                    //A code refractor is require to remove the Static Managers
                    //and replace it with GameComponents
                    AssignManager.Prisoners                 = null;
                    AssignManager.links                     = null;
                    AssignManager.policies                  = null;
                    AssignManager.activePolicies            = null;
                    AssignManager.DefaultDrugPolicy         = null;
                    AssignManager.DefaultFoodPolicy         = null;
                    AssignManager.DefaultOutfit             = null;
                    AssignManager.DefaultPrisonerFoodPolicy = null;
                    AnimalManager.links                     = null;
                    AnimalManager.policies                  = null;
                    AnimalManager.activePolicies            = null;
                    WorkManager.links              = null;
                    WorkManager.policies           = null;
                    WorkManager.activePolicies     = null;
                    RestrictManager.links          = null;
                    RestrictManager.policies       = null;
                    RestrictManager.activePolicies = null;
                    AlertManager.alertLevelsList   = null;
                    System.GC.Collect();
                }

                if (Scribe.mode == LoadSaveMode.LoadingVars ||
                    Scribe.mode == LoadSaveMode.Saving)
                {
                    Scribe_References.Look <Outfit>(
                        ref AssignManager._defaultOutfit,
                        "DefaultOutfit");

                    Scribe_References.Look <DrugPolicy>(
                        ref AssignManager._defaultDrugPolicy,
                        "DefaultDrugPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultFoodPolicy,
                        "DefaultFoodPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultPrisonerFoodPolicy,
                        "DefaultPrisonerFoodPolicy");

                    Scribe_Collections.Look <Policy>(
                        ref AssignManager.policies,
                        "AssignPolicies", LookMode.Deep);

                    Scribe_Collections.Look <AssignLink>(
                        ref AssignManager.links,
                        "AssignLinks", LookMode.Deep);

                    Scribe_Collections.Look <string>(
                        ref AssignManager.Prisoners,
                        "Prisoners", LookMode.Value);

                    if (AssignManager.Prisoners == null)
                    {
                        //this is only required if the save file contains
                        //empty prisoners
                        AssignManager.InstantiatePrisoners();
                    }

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref AssignManager.activePolicies,
                        "AssignActivePolicies", LookMode.Deep);

                    Scribe_Collections.Look <Policy>(
                        ref AnimalManager.policies,
                        "AnimalPolicies", LookMode.Deep);

                    Scribe_Collections.Look <AnimalLink>(
                        ref AnimalManager.links,
                        "AnimalLinks", LookMode.Deep);

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref AnimalManager.activePolicies,
                        "AnimalActivePolicies", LookMode.Deep);

                    Scribe_Collections.Look <Policy>(
                        ref RestrictManager.policies,
                        "RestrictPolicies", LookMode.Deep);

                    Scribe_Collections.Look <RestrictLink>(
                        ref RestrictManager.links,
                        "RestrictLinks", LookMode.Deep);

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref RestrictManager.activePolicies,
                        "RestrictActivePolicies", LookMode.Deep);

                    Scribe_Collections.Look <Policy>(
                        ref WorkManager.policies,
                        "WorkPolicies", LookMode.Deep);

                    Scribe_Collections.Look <WorkLink>(
                        ref WorkManager.links,
                        "WorkLinks", LookMode.Deep);

                    Scribe_Collections.Look <MapActivePolicy>(
                        ref WorkManager.activePolicies,
                        "WorkActivePolicies", LookMode.Deep);

                    Scribe_Values.Look <int>(
                        ref AlertManager._alertLevel, "ActiveLevel", 0, true);

                    Scribe_Values.Look <bool>(
                        ref AlertManager._automaticPawnsInterrupt, "AutomaticPawnsInterrupt", true, true);

                    Scribe_Collections.Look <AlertLevel>(
                        ref AlertManager.alertLevelsList,
                        "AlertLevelsList", LookMode.Deep);


                    if (Scribe.mode == LoadSaveMode.LoadingVars &&
                        WorkManager.activePolicies == null)
                    {
                        //this only happens with existing saves. Existing saves
                        //have no WorkPolicy data so let's initialize!
                        WorkManager.ForceInit();
                    }

                    if (Scribe.mode == LoadSaveMode.LoadingVars &&
                        RestrictManager.activePolicies == null)
                    {
                        //temporary code to be removed on the next version. To fix saves games without activePolicies
                        RestrictManager.FixActivePolicies();
                    }
                }

                if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs)
                {
                    Scribe_References.Look <Outfit>(
                        ref AssignManager._defaultOutfit,
                        "DefaultOutfit");

                    Scribe_References.Look <DrugPolicy>(
                        ref AssignManager._defaultDrugPolicy,
                        "DefaultDrugPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultFoodPolicy,
                        "DefaultFoodPolicy");

                    Scribe_References.Look <FoodRestriction>(
                        ref AssignManager._defaultPrisonerFoodPolicy,
                        "DefaultPrisonerFoodPolicy");
                }
            }