Exemplo n.º 1
0
        public static IntVec3 RandomSpawnCellForPawnNear(IntVec3 root, Map map, int firstTryWithRadius = 4)
        {
            MapExtension mapE = MapExtensionUtility.GetExtensionToMap(map);

            if (GenGridShips.Standable(root, map, mapE) && root.GetFirstPawn(map) is null)
            {
                return(root);
            }
            IntVec3 result;
            int     num = firstTryWithRadius;

            for (int i = 0; i < 3; i++)
            {
                if (CellFinderExtended.TryFindRandomReachableCellNear(root, map, (float)num, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c)
                                                                      => GenGridShips.Standable(c, map, mapE) && (root.Fogged(map) || !c.Fogged(map)) && c.GetFirstPawn(map) is null, out result, null, 999999))
                {
                    return(result);
                }
                num *= 2;
            }
            num = firstTryWithRadius + 1;

            while (!CellFinderExtended.TryRandomClosewalkCellNear(root, map, num, out result, null))
            {
                if (num > map.Size.x / 2 && num > map.Size.z / 2)
                {
                    return(root);
                }
                num *= 2;
            }
            return(result);
        }
Exemplo n.º 2
0
 public static IntVec3 RandomClosewalkCellNear(IntVec3 root, Map map, int radius, Predicate <IntVec3> validator = null)
 {
     if (CellFinderExtended.TryRandomClosewalkCellNear(root, map, radius, out IntVec3 result, validator))
     {
         return(result);
     }
     return(root);
 }
Exemplo n.º 3
0
        private static IntVec3 FindNearEdgeWaterCell(Map map)
        {
            Predicate <IntVec3> validator   = (IntVec3 x) => GenGridShips.Standable(x, map, MapExtensionUtility.GetExtensionToMap(map)) && !x.Fogged(map);
            Faction             hostFaction = map.ParentFaction;
            IntVec3             root;

            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            if (CellFinder.TryFindRandomEdgeCellWith(validator, map, CellFinder.EdgeRoadChance_Ignore, out root))
            {
                return(CellFinderExtended.RandomClosewalkCellNear(root, map, 5, null));
            }
            Log.Warning("Could not find any valid edge cell.", false);
            return(CellFinder.RandomCell(map));
        }
Exemplo n.º 4
0
        public static bool TryFindRandomReachableCellNear(IntVec3 root, Map map, float radius, TraverseParms traverseParms, Predicate <IntVec3> validator, out IntVec3 result,
                                                          Predicate <WaterRegion> regionValidator, int maxRegions = 999999)
        {
            if (map is null)
            {
                Log.ErrorOnce("Tried to find reachable cell using SPExtended in a null map", 61037855, false);
                result = IntVec3.Invalid;
                return(false);
            }
            WaterRegion region = WaterGridsUtility.GetRegion(root, map, RegionType.Set_Passable);

            if (region is null)
            {
                result = IntVec3.Invalid;
                return(false);
            }
            result = CellFinderExtended.RandomEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, (IntVec3 c) => GenGridShips.Standable(c, map, MapExtensionUtility.GetExtensionToMap(map)) && !c.Fogged(map));
            return(true);
        }
Exemplo n.º 5
0
        public static void EnterSpawn(Caravan caravan, Map map, Func <Pawn, IntVec3> spawnCellGetter, CaravanDropInventoryMode caravanDropInventoryMode = CaravanDropInventoryMode.DoNotDrop, bool draftColonists = true)
        {
            List <Pawn>  pawns    = new List <Pawn>(caravan.PawnsListForReading).Where(x => ShipHarmony.IsShip(x)).ToList();
            MapExtension mapE     = MapExtensionUtility.GetExtensionToMap(map);
            Rot4         spawnDir = GetEdgeToSpawnBoatOn(caravan, map);

            for (int i = 0; i < pawns.Count; i++)
            {
                IntVec3 loc = CellFinderExtended.MiddleEdgeCell(spawnDir, map, pawns[i], (IntVec3 c) => GenGridShips.Standable(c, map, mapE) && !c.Fogged(map)); //Change back to spawnCellGetter later

                pawns[i].GetComp <CompShips>().Angle = 0;
                Pawn ship = GenSpawn.Spawn(pawns[i], loc, map, spawnDir.Opposite, WipeMode.Vanish, false) as Pawn;
                ship.drafter.Drafted = draftColonists ? true : false;
            }
            caravan.RemoveAllPawns();
            if (caravan.Spawned)
            {
                Find.WorldObjects.Remove(caravan);
            }
        }
Exemplo n.º 6
0
        public static void Enter(Caravan caravan, Map map, CaravanEnterMode enterMode, CaravanDropInventoryMode dropInventoryMode = CaravanDropInventoryMode.DoNotDrop,
                                 bool draftColonists = true, Predicate <IntVec3> extraValidator = null)
        {
            if (enterMode == CaravanEnterMode.None)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Caravan ", caravan, " tried to enter map ", map, " with no enter mode. Defaulting to edge."
                }), false);
                enterMode = CaravanEnterMode.Edge;
            }
            //Ensure pawns are onboard till a fix for dock settling is done
            if (ShipHarmony.HasShip(caravan) && caravan.PawnsListForReading.Any(x => !ShipHarmony.IsShip(x)))
            {
                ShipHarmony.BoardAllCaravanPawns(caravan);
            }
            IntVec3 enterCell = GetWaterCell(caravan, map, CaravanEnterMode.Edge); //Caravan Enter Mode back to enterMode
            Func <Pawn, IntVec3> spawnCellGetter = (Pawn p) => p.ClampToMap(CellFinderExtended.RandomSpawnCellForPawnNear(enterCell, map, 4), map);

            EnterMapUtilityBoats.EnterSpawn(caravan, map, spawnCellGetter, dropInventoryMode, draftColonists);
        }
Exemplo n.º 7
0
 public static bool TryRandomClosewalkCellNear(IntVec3 root, Map map, int radius, out IntVec3 result, Predicate <IntVec3> validator = null)
 {
     return(CellFinderExtended.TryFindRandomReachableCellNear(root, map, (float)radius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), validator, out result,
                                                              null, 999999));
 }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            return(false); //Disabled for now

            Map map = (Map)parms.target;

            if (!base.TryResolveParms(parms))
            {
                return(false);
            }
            if (parms.faction.HostileTo(Faction.OfPlayer))
            {
                return(false);
            }
            List <Pawn> list = BoatStrategyWorker.GeneratePawnsForBoats(parms, PawnGroupKindDef);

            if (list.Count <= 0)
            {
                return(false);
            }
            foreach (Pawn p in list)
            {
                if (p.needs != null && p.needs.food != null)
                {
                    p.needs.food.CurLevel = p.needs.food.MaxLevel;
                }
            }
            TraderKindDef traderKind = null;

            foreach (Pawn p in list)
            {
                if (p.TraderKind != null)
                {
                    traderKind = p.TraderKind;
                    break;
                }
            }

            List <Pawn> ships = BoatStrategyWorker.GenerateBoatsForIncident(parms, PawnGroupKindDef, ref list);

            if (!ships.Any())
            {
                return(false);
            }
            List <IntVec3>      usedCells  = new List <IntVec3>();
            Predicate <IntVec3> validator  = (IntVec3 c) => GenGridShips.Standable(c, map, MapExtensionUtility.GetExtensionToMap(map)) && !c.Fogged(map);
            IntVec3             root       = CellFinderExtended.MiddleEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, ships.MaxBy(x => x.def.size.z), validator);
            List <Thing>        thingShips = new List <Thing>();

            foreach (Pawn s in ships)
            {
                IntVec3 loc = !usedCells.Any() ? CellFinderExtended.MiddleEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, s, validator) :
                              CellFinderExtended.RandomEdgeCell(Find.World.CoastDirectionAt(map.Tile), map, validator, usedCells, s);
                usedCells.Add(loc);
                Thing shipSpawned = GenSpawn.Spawn(s, loc, map, WipeMode.Vanish);
                shipSpawned.Rotation = Find.World.CoastDirectionAt(map.Tile).Opposite;
                thingShips.Add(shipSpawned);
            }
            List <Pawn> pawnsLeft = list;

            pawnsLeft.SortBy(x => x.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation));
            foreach (Thing t in thingShips)
            {
                for (int i = 0; i < t.TryGetComp <CompShips>().PawnCountToOperate; i++)
                {
                    if (pawnsLeft.Count <= 0)
                    {
                        break;
                    }
                    t.TryGetComp <CompShips>().BoardDirectly(pawnsLeft.Pop(), t.TryGetComp <CompShips>().NextAvailableHandler.handlers);
                }
                if (pawnsLeft.Count <= 0)
                {
                    break;
                }
            }

            int iter = 0;

            for (int i = 0; i < pawnsLeft.Count; i++)
            {
                Thing ship = thingShips[iter];
                Pawn  p    = pawnsLeft.Pop();
                ship.TryGetComp <CompShips>().BoardDirectly(p, ship.TryGetComp <CompShips>().NextAvailableHandler.handlers);
                iter = iter + 1 >= thingShips.Count ? 0 : iter + 1;
            }
            foreach (Thing s in thingShips)
            {
                (s as Pawn).drafter.Drafted = true;
            }

            string label = "LetterLabelTraderCaravanArrival".Translate(parms.faction.Name, traderKind.label).CapitalizeFirst();
            string text  = "LetterTraderCaravanArrival".Translate(parms.faction.Name, traderKind.label).CapitalizeFirst();

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(ships, ref label, ref text, "LetterRelatedPawnsNeutralGroup".Translate(Faction.OfPlayer.def.pawnsPlural), true, true);
            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.PositiveEvent, ships[0], parms.faction, null);

            RCellFinder.TryFindRandomSpotJustOutsideColony(ships[0], out IntVec3 chillSpot);
            LordJob_TradeWithColony lordJob = new LordJob_TradeWithColony(parms.faction, chillSpot);

            foreach (Pawn s in ships)
            {
                Job job = new Job(JobDefOf_Ships.DisembarkLord, FindShoreline(s));
                s.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                s.GetComp <CompShips>().lordJobToAssign = lordJob;
                s.GetComp <CompShips>().lordShipGroup.AddRange(ships);
            }
            return(true);
        }