Example #1
0
        protected bool Execute(IncidentParms parms, Map map)
        {
            IntVec3 spawnSpot = IntVec3.Invalid;

            if (map != null && !CellFinder.TryFindRandomEdgeCellWith(vec => vec.Standable(map) && map.reachability.CanReachColony(vec), map, CellFinder.EdgeRoadChance_Ignore, out spawnSpot) ||
                !WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElementByWeight(animal => map.Biome.CommonalityOfAnimal(animal) / animal.wildGroupSize.Average
                                                                                                           , out PawnKindDef wanderingCaravanDef))
            {
                return(false);
            }
            IEnumerable <Pawn> wanderingCaravans = this.GenerateWanderingCaravans(wanderingCaravanDef);
            Pawn p = null;

            List <Pawn> list = new List <Pawn>();

            foreach (Pawn pawn in wanderingCaravans)
            {
                p = pawn;
                list.Add(p);
                GenSpawn.Spawn(pawn, CellFinder.RandomSpawnCellForPawnNear(spawnSpot, map), map, Rot4.Random);
            }
            //    this.SpawnPawns(wanderingCaravans, map, spawnSpot);

            base.SendStandardLetter(parms, list, wanderingCaravans.First().def.LabelCap);
            return(true);
        }
        protected virtual bool TryResolveParms(IncidentParms parms, out PawnKindDef chasedCaravan)
        {
            Map map = (Map)parms.target;

            chasedCaravan = null;
            return(CellFinder.TryFindRandomEdgeCellWith(c => map.reachability.CanReachColony(c), map, CellFinder.EdgeRoadChance_Neutral, out parms.spawnCenter) &&
                   Find.FactionManager.AllFactions.Where(f => !f.def.hidden && f.HostileTo(Faction.OfPlayer)).TryRandomElement(out parms.faction) &&
                   WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElement(out chasedCaravan));
        }
Example #3
0
        protected bool Execute(IncidentParms parms, Map map)
        {
            IntVec3 spawnSpot = IntVec3.Invalid;

            if (map != null && !CellFinder.TryFindRandomEdgeCellWith(vec => vec.Standable(map) && map.reachability.CanReachColony(vec), map, CellFinder.EdgeRoadChance_Ignore, out spawnSpot) ||
                !WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElementByWeight(animal => map.Biome.CommonalityOfAnimal(animal) / animal.wildGroupSize.Average
                                                                                                           , out PawnKindDef wanderingCaravanDef))
            {
                return(false);
            }
            IEnumerable <Pawn> wanderingCaravans = this.GenerateWanderingCaravans(wanderingCaravanDef);

            this.SpawnPawns(wanderingCaravans, map, spawnSpot);
            Pawn infoPawn = wanderingCaravans.First();

            SendStandardLetter(parms, infoPawn, infoPawn.def.LabelCap);
            return(true);
        }
Example #4
0
        protected bool Execute(Caravan caravan)
        {
            Map map = GetOrGenerateMapUtility.GetOrGenerateMap(caravan.Tile, DefDatabase <WorldObjectDef> .GetNamed("WanderingCaravanEncounter"));

            if (!WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElement(out PawnKindDef wanderingCaravanDef))
            {
                return(false);
            }
            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 caravanSpot, out IntVec3 wanderingCaravansSpot);
            IEnumerable <Pawn> wanderingCaravans = this.GenerateWanderingCaravans(wanderingCaravanDef);
            Pawn    infoPawn = wanderingCaravans.First();
            DiaNode diaNode  = new DiaNode($"A wandering {infoPawn.LabelCap} has been spotted in the distance by {caravan.LabelCap}, with more wandering caravans possible following it.\n\nYou can "
                                           + $"ignore them, or you can tame or kill them to obtain their potentially valuable inventory.")
            {
                options =
                {
                    new DiaOption("Go and claim their inventory")
                    {
                        action = delegate
                        {
                            string plural = wanderingCaravans.Count() > 1 ? "ies" : "y";
                            CaravanEnterMapUtility.Enter(caravan, map, pawn => CellFinder.RandomSpawnCellForPawnNear(caravanSpot, map));
                            Messages.Message($"You have {TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000)} to claim the wandering {infoPawn.LabelCap}s inventor{plural} before the "
                                             + $"caravan is reformed.", infoPawn, MessageTypeDefOf.PositiveEvent);
                            ((WorldObject)map.ParentHolder).GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
                        },
                        resolveTree = true
                    }, new DiaOption("Ignore them and continue")
                    {
                        resolveTree = true
                    }
                }
            };

            Find.WindowStack.Add(new Dialog_NodeTree(diaNode, true, false, $"Wandering {infoPawn.LabelCap} spotted"));
            this.SpawnPawns(wanderingCaravans, map, wanderingCaravansSpot);
            return(true);
        }
        protected bool Execute(Caravan caravan)
        {
            Map map = GetOrGenerateMapUtility.GetOrGenerateMap(caravan.Tile, DefDatabase <WorldObjectDef> .GetNamed("WanderingCaravanEncounter"));

            if (!WanderingCaravansUtility.AllWanderingCaravansSpawnableInMap(map).TryRandomElement(out PawnKindDef wanderingCaravanDef))
            {
                return(false);
            }
            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 caravanSpot, out IntVec3 wanderingCaravansSpot);
            IEnumerable <Pawn> wanderingCaravans = this.GenerateWanderingCaravans(wanderingCaravanDef);
            Pawn    infoPawn = wanderingCaravans.First();
            DiaNode diaNode  = new DiaNode($"WanderingCaravan.WanderingCaravan_Spotted".Translate(infoPawn.LabelCap, caravan.LabelCap))
            {
                options =
                {
                    new DiaOption("WanderingCaravan.WanderingCaravan_Accept")
                    {
                        action = delegate
                        {
                            string plural = wanderingCaravans.Count() > 1 ? "ies" : "y";
                            CaravanEnterMapUtility.Enter(caravan, map, pawn => CellFinder.RandomSpawnCellForPawnNear(caravanSpot, map));
                            Messages.Message($"WanderingCaravan.WanderingCaravan_Accepted".Translate(TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000), infoPawn.LabelCap, plural), infoPawn, MessageTypeDefOf.PositiveEvent);
                            ((WorldObject)map.ParentHolder).GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
                        },
                        resolveTree = true
                    }, new DiaOption("WanderingCaravan.WanderingCaravan_Reject".Translate())
                    {
                        resolveTree = true
                    }
                }
            };

            Find.WindowStack.Add(new Dialog_NodeTree(diaNode, true, false, $"WanderingCaravan.WanderingCaravan_Title".Translate(infoPawn.LabelCap)));
            this.SpawnPawns(wanderingCaravans, map, wanderingCaravansSpot);
            return(true);
        }