예제 #1
0
        public void DropTeam()
        {
            // Find exit spot.
            IntVec3 exitSpot        = IntVec3.Invalid;
            bool    exitSpotIsValid = Expedition.TryFindRandomExitSpot(this.Map, this.Position, out exitSpot);

            if (exitSpotIsValid)
            {
                // Spawn expedition pawns.
                List <Pawn> stayingAboardPawns = new List <Pawn>();
                List <Pawn> droppedPawns       = new List <Pawn>();
                foreach (Pawn pawn in this.pawnsAboard)
                {
                    if (pawn.kindDef == Util_PawnKindDefOf.Pilot)
                    {
                        stayingAboardPawns.Add(pawn);
                    }
                    else
                    {
                        droppedPawns.Add(pawn);
                        GenSpawn.Spawn(pawn, this.Position + IntVec3Utility.RandomHorizontalOffset(3f), this.Map);
                    }
                }
                this.pawnsAboard = stayingAboardPawns;
                // Make lord.
                LordMaker.MakeNewLord(Util_Faction.MiningCoFaction, new LordJob_ExitMap(exitSpot), this.Map, droppedPawns);
                // Spawn payment.
                SpawnPayment(droppedPawns.Count);
                Util_Faction.AffectGoodwillWith(Util_Faction.MiningCoFaction, Faction.OfPlayer, droppedPawns.Count);
            }
        }
예제 #2
0
        // Return the primary landing pad if available and reaching map edge
        //     else a random one
        //     else null.
        public static Building_LandingPad GetBestAvailableLandingPadReachingMapEdge(Map map)
        {
            IntVec3 exitSpot = IntVec3.Invalid;
            // Check pawns can reach map edge from best landing pad.
            Building_LandingPad bestLandingPad = GetBestAvailableLandingPad(map);

            if (bestLandingPad != null)
            {
                if (Expedition.TryFindRandomExitSpot(map, bestLandingPad.Position, out exitSpot))
                {
                    return(bestLandingPad);
                }
            }
            // Check pawns can exit map from any landing pad.
            List <Building_LandingPad> allAvailableLandingPads = Util_LandingPad.GetAllFreeAndPoweredLandingPads(map);

            if (allAvailableLandingPads != null)
            {
                foreach (Building_LandingPad landingPad in allAvailableLandingPads.InRandomOrder())
                {
                    if (Expedition.TryFindRandomExitSpot(map, landingPad.Position, out exitSpot))
                    {
                        return(landingPad);
                    }
                }
            }
            return(null);
        }
 public override bool ActivateOn(Lord lord, TriggerSignal signal)
 {
     if ((signal.type == TriggerSignalType.Tick) &&
         (Find.TickManager.TicksGame % checkInterval == 0))
     {
         IntVec3 targetDestination = (lord.LordJob as LordJob_MiningCoBase).targetDestination;
         // Look for a reachable unreserved downed pawn.
         if (lord.ownedPawns.NullOrEmpty())
         {
             lord.Cleanup();
             return(false);
         }
         Pawn pawnToRescue = Util_DownedPawn.GetRandomReachableDownedPawn(lord.ownedPawns.RandomElement());
         if (pawnToRescue == null)
         {
             return(false);
         }
         // Check all lord pawns can reach downed pawn.
         foreach (Pawn pawn in lord.ownedPawns)
         {
             if (pawn.CanReserveAndReach(pawnToRescue, PathEndMode.OnCell, Danger.Some) == false)
             {
                 return(false);
             }
         }
         // Check all lord pawns can reach target destination.
         bool targetDestinationIsReachable = true;
         foreach (Pawn pawn in lord.ownedPawns)
         {
             if (pawn.CanReach(targetDestination, PathEndMode.OnCell, Danger.Some) == false)
             {
                 targetDestinationIsReachable = false;
                 break;
             }
         }
         if (targetDestinationIsReachable)
         {
             return(true);
         }
         // Try to find a new exit spot.
         IntVec3 exitSpot        = IntVec3.Invalid;
         bool    exitSpotIsValid = Expedition.TryFindRandomExitSpot(lord.Map, lord.ownedPawns.RandomElement().Position, out exitSpot);
         if (exitSpotIsValid)
         {
             targetDestinationIsReachable = true;
             foreach (Pawn pawn in lord.ownedPawns)
             {
                 if (pawn.CanReach(exitSpot, PathEndMode.OnCell, Danger.Some) == false)
                 {
                     targetDestinationIsReachable = false;
                     break;
                 }
             }
         }
         return(targetDestinationIsReachable);
     }
     return(false);
 }
        public override void DoAction(Transition trans)
        {
            Lord    lord = trans.target.lord;
            IntVec3 targetDestination = (lord.LordJob as LordJob_MiningCoBase).targetDestination;
            bool    needNewExitSpot   = false;
            bool    isEdgeCell        = targetDestination.InBounds(lord.Map) &&
                                        ((targetDestination.x == 0) ||
                                         (targetDestination.x == lord.Map.Size.x - 1) ||
                                         (targetDestination.z == 0) ||
                                         (targetDestination.z == lord.Map.Size.z - 1));

            if (isEdgeCell == false)
            {
                needNewExitSpot = true;
            }
            else
            {
                foreach (Pawn pawn in lord.ownedPawns)
                {
                    if (pawn.CanReach(targetDestination, PathEndMode.OnCell, Danger.Some) == false)
                    {
                        needNewExitSpot = true;
                        break;
                    }
                }
            }

            IntVec3 newTargetDestination = targetDestination;

            if (needNewExitSpot)
            {
                if (Expedition.TryFindRandomExitSpot(lord.Map, lord.ownedPawns.RandomElement().Position, out newTargetDestination) == false)
                {
                    newTargetDestination = CellFinder.RandomEdgeCell(lord.Map);
                }
            }
            (lord.LordJob as LordJob_MiningCoBase).targetDestination = newTargetDestination;
            // Refresh lord toil destination anyway as it may have been initialized with an invalid vector (case of a fallback).
            LordToil_Travel travelToil = trans.target as LordToil_Travel;

            if (travelToil != null)
            {
                travelToil.SetDestination(newTargetDestination);
            }
            LordToil_EscortDownedPawn escortToil = trans.target as LordToil_EscortDownedPawn;

            if (escortToil != null)
            {
                escortToil.SetDestination(newTargetDestination);
            }
        }
예제 #5
0
        public bool SpawnTeamOnMapEdge(IntVec3 targetDestination, Map map, List <Pawn> teamPawns)
        {
            // Find entry cell.
            IntVec3 entryCell        = IntVec3.Invalid;
            bool    entryCellIsValid = Expedition.TryFindRandomExitSpot(map, targetDestination, out entryCell);

            if (entryCellIsValid)
            {
                // Spawn expedition pawns.
                foreach (Pawn pawn in teamPawns)
                {
                    IntVec3 cell = CellFinder.RandomSpawnCellForPawnNear(entryCell, map, 5);
                    GenSpawn.Spawn(pawn, cell, map);
                }
                // Make lord.
                Lord lord = LordMaker.MakeNewLord(Util_Faction.MiningCoFaction, new LordJob_BoardSpaceship(targetDestination), map, teamPawns);
            }
            return(entryCellIsValid);
        }