Пример #1
0
        public static void AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> source = transferables.Where((TransferableOneWay x) => x.ThingDef.category == ThingCategory.Pawn);

            widget.AddSection("ColonistsSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).IsFreeColonist));
            widget.AddSection("PrisonersSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).IsPrisoner));
            widget.AddSection("CaptureSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).Downed && CaravanUtility.ShouldAutoCapture((Pawn)x.AnyThing, Faction.OfPlayer)));
            widget.AddSection("AnimalsSection".Translate(), source.Where((TransferableOneWay x) => ((Pawn)x.AnyThing).RaceProps.Animal));
        }
Пример #2
0
        static void Postfix(ref TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> mechs = from x in transferables
                                                     where x.ThingDef.category == ThingCategory.Pawn &&
                                                     ((Pawn)x.AnyThing).RaceProps.IsMechanoid &&
                                                     ((Pawn)x.AnyThing).IsHacked()
                                                     select x;

            widget.AddSection("WTH_MechanoidsSection".Translate(), mechs);
            if (mechs != null && mechs.Count() > 0)
            {
                LessonAutoActivator.TeachOpportunity(WTH_DefOf.WTH_Caravanning, OpportunityType.Important);
            }
        }
Пример #3
0
        /// <summary>
        /// Create sections in VehicleCaravan dialog for proper listing
        /// </summary>
        /// <param name="pawnWidget"></param>
        /// <param name="vehicleWidget"></param>
        /// <param name="transferables"></param>
        public static void AddVehicleAndPawnSections(TransferableOneWayWidget pawnWidget, TransferableVehicleWidget vehicleWidget, List <TransferableOneWay> transferables)
        {
            IEnumerable <TransferableOneWay> source = from x in transferables
                                                      where x.ThingDef.category == ThingCategory.Pawn
                                                      select x;

            vehicleWidget.AddSection("VehiclesTab".Translate(), from x in source
                                     where x.AnyThing is VehiclePawn vehicle && vehicle.CanMove
                                     select x);
            pawnWidget.AddSection("ColonistsSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).IsFreeColonist
                                  select x);
            pawnWidget.AddSection("PrisonersSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).IsPrisoner
                                  select x);
            pawnWidget.AddSection("CaptureSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).Downed && CaravanUtility.ShouldAutoCapture((Pawn)x.AnyThing, Faction.OfPlayer)
                                  select x);
            pawnWidget.AddSection("AnimalsSection".Translate(), from x in source
                                  where ((Pawn)x.AnyThing).RaceProps.Animal
                                  select x);
            vehicleWidget.AvailablePawns = source.Where(x => x.AnyThing is Pawn pawn && !(pawn is VehiclePawn) && pawn.IsColonistPlayerControlled).ToList();
        }
Пример #4
0
        public static void Postfix(ref TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            RoadsOfTheRim.DebugLog("DEBUG AddPawnsSection: ");
            List <TransferableOneWay> source = new List <TransferableOneWay>();

            foreach (TransferableOneWay tow in transferables)
            {
                if (tow.ThingDef.IsWithinCategory(ThingCategoryDef.Named("RoadEquipment")))
                {
                    source.Add(tow);
                    RoadsOfTheRim.DebugLog("Found an ISR2G");
                }
            }
            widget.AddSection("RoadsOfTheRim_RoadEquipment".Translate(), source);
        }
Пример #5
0
        private static List <Pawn> PawnsInCurrentSections; // For Giddy-up! Caravan compatibility
        public static bool AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            PawnsInCurrentSections = new List <Pawn>(); // For Giddy-up! Caravan compatibility

            // Get all pawns from the list of transferables
            List <Pawn> pawns = new List <Pawn>();
            Dictionary <Pawn, TransferableOneWay> pawnThing = new Dictionary <Pawn, TransferableOneWay>();

            foreach (TransferableOneWay thing in transferables)
            {
                if (thing.ThingDef.category == ThingCategory.Pawn)
                {
                    Pawn pawn = (Pawn)thing.AnyThing;
                    pawns.Add(pawn);
                    pawnThing[pawn] = thing;
                }
            }

            List <PawnGroup> pawnGroups = TacticUtils.AllPawnGroups;

            pawnGroups.Reverse(); // Reverse the list because it iterates in the wrong direction

            // Create a HashSet to sort out all the ungrouped pawns
            HashSet <Pawn> ungroupedPawns = new HashSet <Pawn>(pawns);

            foreach (PawnGroup pawnGroup in pawnGroups)
            {
                if (pawnGroup.pawns != null && pawnGroup.pawns.Count > 0)
                {
                    // Remove grouped pawns from the ungroupedPawns HashSet
                    ungroupedPawns.ExceptWith(from pawn in pawnGroup.pawns select pawn);

                    // Get only the group's pawns that are in the current list of transferables
                    List <TransferableOneWay> sectionTranferables = new List <TransferableOneWay>();
                    foreach (Pawn pawn in pawnGroup.pawns)
                    {
                        if (pawns.Contains(pawn) && pawnThing.ContainsKey(pawn) && pawn.IsFreeColonist)
                        {
                            sectionTranferables.Add(pawnThing[pawn]);
                            if (!PawnsInCurrentSections.Contains(pawn))
                            {
                                PawnsInCurrentSections.Add(pawn); // For Giddy-up! Caravan compatibility
                            }
                        }
                    }

                    if (sectionTranferables.Count > 0)
                    {
                        // Add a new section containing all pawns within the group
                        widget.AddSection(pawnGroup.curGroupName ?? "", from pawn in sectionTranferables select pawn);
                    }
                }
            }

            if (ungroupedPawns.Count > 0)
            {
                // Create a section containing all the ungrouped pawns
                widget.AddSection("Ungrouped " + "ColonistsSection".Translate().ToLower(), from pawn in ungroupedPawns
                                  where pawn.IsFreeColonist
                                  select pawnThing[pawn]);
                foreach (Pawn pawn in ungroupedPawns)
                {
                    if (pawn.IsFreeColonist && !PawnsInCurrentSections.Contains(pawn))
                    {
                        PawnsInCurrentSections.Add(pawn); // For Giddy-up! Caravan compatibility
                    }
                }
            }

            // We then return to vanilla code (slightly tweaked), commenting out the Colonists section of course

            /*
             * widget.AddSection("ColonistsSection".Translate(), from pawn in pawns
             *                                                where pawn.IsFreeColonist
             *                                                select pawnThing[pawn]);
             */

            widget.AddSection("PrisonersSection".Translate(), from pawn in pawns
                              where pawn.IsPrisoner
                              select pawnThing[pawn]);

            widget.AddSection("CaptureSection".Translate(), from pawn in pawns
                              where pawn.Downed && CaravanUtility.ShouldAutoCapture(pawn, Faction.OfPlayer)
                              select pawnThing[pawn]);

            widget.AddSection("AnimalsSection".Translate(), from pawn in pawns
                              where pawn.RaceProps.Animal
                              select pawnThing[pawn]);
            return(false);
        }
        public static bool AddPawnsSections(TransferableOneWayWidget widget, List <TransferableOneWay> transferables)
        {
            if (ModCompatibility.GiddyUpCaravanIsActive)
            {
                PawnsInCurrentSections = new List <Pawn>();
            }

            // Get all pawns from the list of transferables
            List <Pawn> pawns = new List <Pawn>();
            Dictionary <Pawn, TransferableOneWay> pawnTransferable = new Dictionary <Pawn, TransferableOneWay>();

            foreach (TransferableOneWay transferable in transferables)
            {
                if (transferable.ThingDef.category == ThingCategory.Pawn)
                {
                    Pawn pawn = (Pawn)transferable.AnyThing;
                    pawns.Add(pawn);
                    pawnTransferable[pawn] = transferable;
                }
            }

            List <PawnGroup> pawnGroups = TacticUtils.AllPawnGroups;

            pawnGroups.Reverse(); // Reverse the list because it iterates in the wrong direction

            // Create a HashSet to sort out all the ungrouped pawns
            HashSet <Pawn> ungroupedPawns = new HashSet <Pawn>(pawns);

            foreach (PawnGroup pawnGroup in pawnGroups)
            {
                if (!(pawnGroup.pawns is null) && pawnGroup.pawns.Count > 0)
                {
                    // Remove grouped pawns from the ungroupedPawns HashSet
                    ungroupedPawns.ExceptWith(from pawn in pawnGroup.pawns select pawn);

                    // Get only the group's pawns that are in the current list of transferables
                    List <Pawn> sectionPawns = new List <Pawn>();
                    sectionPawns.AddRange(from pawn in pawnGroup.pawns
                                          where pawns.Contains(pawn)
                                          select pawn);

                    if (ModCompatibility.GiddyUpCaravanIsActive)
                    {
                        PawnsInCurrentSections.AddRange(from pawn in sectionPawns.Except(PawnsInCurrentSections)
                                                        where pawn.IsFreeNonSlaveColonist
                                                        select pawn);
                    }

                    // Add a new section containing all pawns within the group
                    if (sectionPawns.Any(pawn => pawn.IsFreeNonSlaveColonist))
                    {
                        widget.AddSection(pawnGroup.curGroupName, from pawn in sectionPawns
                                          where pawn.IsFreeNonSlaveColonist
                                          select pawnTransferable[pawn]);
                    }

                    // Add a new section containing all slave pawns within the group
                    if (ModsConfig.IdeologyActive && sectionPawns.Any(pawn => pawn.IsSlave))
                    {
                        widget.AddSection("TG.GroupSlavesSection".Translate(pawnGroup.curGroupName), from pawn in sectionPawns
                                          where pawn.IsSlave
                                          select pawnTransferable[pawn]);
                    }
                }
            }

            // Create a section containing all the ungrouped pawns
            if (ungroupedPawns.Any(pawn => pawn.IsFreeNonSlaveColonist))
            {
                widget.AddSection("TG.UngroupedColonistsSection".Translate(), from pawn in ungroupedPawns
                                  where pawn.IsFreeNonSlaveColonist
                                  select pawnTransferable[pawn]);

                if (ModCompatibility.GiddyUpCaravanIsActive)
                {
                    PawnsInCurrentSections.AddRange(from pawn in ungroupedPawns.Except(PawnsInCurrentSections)
                                                    where pawn.IsFreeNonSlaveColonist
                                                    select pawn);
                }
            }

            // Create a section containing all the ungrouped slave pawns
            if (ModsConfig.IdeologyActive && ungroupedPawns.Any(pawn => pawn.IsSlave))
            {
                widget.AddSection("TG.UngroupedSlavesSection".Translate(), from pawn in ungroupedPawns
                                  where pawn.IsSlave
                                  select pawnTransferable[pawn]);
            }


            // We then return to vanilla code

            /*
             * widget.AddSection("ColonistsSection".Translate(), from pawn in pawns
             *                                                where pawn.IsFreeNonSlaveColonist
             *                                                select pawnTransferable[pawn]);
             *
             * if (ModsConfig.IdeologyActive)
             * {
             *  widget.AddSection("SlavesSection".Translate(), from pawn in pawns
             *                                                 where pawn.IsSlave
             *                                                 select pawnTransferable[pawn]);
             * }
             */

            widget.AddSection("PrisonersSection".Translate(), from pawn in pawns
                              where pawn.IsPrisoner
                              select pawnTransferable[pawn]);

            widget.AddSection("CaptureSection".Translate(), from pawn in pawns
                              where pawn.Downed && CaravanUtility.ShouldAutoCapture(pawn, Faction.OfPlayer)
                              select pawnTransferable[pawn]);

            widget.AddSection("AnimalsSection".Translate(), from pawn in pawns
                              where pawn.RaceProps.Animal
                              select pawnTransferable[pawn]);
            return(false);
        }