Esempio n. 1
0
 public override void SpawnSetup(Map map, bool bla)
 {
     compTransporterPawn = this.TryGetComp <CompTransporterPawn>();
     compLaunchablePawn  = this.TryGetComp <CompLaunchablePawn>();
     DecrementMapIndex();
     base.SpawnSetup(map, bla);
 }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t == null)
            {
                return(false);
            }

            Pawn pawn2 = t as Pawn;

            if (pawn2 == null || pawn2 == pawn)
            {
                return(false);
            }
            if (!pawn.CanReserveAndReach(t, PathEndMode.ClosestTouch, Danger.Deadly, 1))
            {
                return(false);
            }

            CompTransporterPawn transporter = t.TryGetComp <CompTransporterPawn>();

            if (transporter == null)
            {
                return(false);
            }
            return(LoadTransportersPawnJobUtility.HasJobOnTransporter(pawn, transporter));
        }
Esempio n. 3
0
        public List <CompTransporterPawn> TransportersInGroup(Map map)
        {
            if (!this.LoadingInProgressOrReadyToLaunch)
            {
                return(null);
            }

            tmpTransportersInGroup.Clear();
            if (this.groupID < 0)
            {
                return(null);
            }
            IEnumerable <Pawn> listSel = from Pawn pawns in map.mapPawns.AllPawnsSpawned
                                         where pawns is PawnFlyer
                                         select pawns;
            List <Pawn> list = new List <Pawn>(listSel);

            for (int i = 0; i < list.Count; i++)
            {
                CompTransporterPawn compTransporter = list[i].TryGetComp <CompTransporterPawn>();
                if (compTransporter.groupID == this.groupID)
                {
                    tmpTransportersInGroup.Add(compTransporter);
                }
            }

            return(CompTransporterPawn.tmpTransportersInGroup);
        }
        // RimWorld.LoadTransportersJobUtility
        private static Thing FindThingToLoad(Pawn p, CompTransporterPawn transporter)
        {
            neededThings.Clear();
            var leftToLoad = transporter.leftToLoad;

            if (leftToLoad != null)
            {
                foreach (var transferableOneWay in leftToLoad)
                {
                    if (transferableOneWay.CountToTransfer <= 0)
                    {
                        continue;
                    }

                    foreach (var item in transferableOneWay.things)
                    {
                        neededThings.Add(item);
                    }
                }
            }

            if (!neededThings.Any())
            {
                return(null);
            }

            bool validator(Thing x)
            {
                return(neededThings.Contains(x) && p.CanReserve(x));
            }

            var thing = GenClosest.ClosestThingReachable(p.Position, p.Map,
                                                         ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch,
                                                         TraverseParms.For(p), 9999f, validator);

            if (thing == null)
            {
                foreach (var current in neededThings)
                {
                    if (current is not Pawn pawn || pawn.IsColonist && !pawn.Downed ||
                        !p.CanReserveAndReach(pawn, PathEndMode.Touch, Danger.Deadly))
                    {
                        continue;
                    }

                    Utility.DebugReport("Pawn to load : " + pawn.Label);
                    return(pawn);
                }
            }

            if (thing != null)
            {
                Utility.DebugReport("Thing to load : " + thing.Label);
            }

            neededThings.Clear();
            return(thing);
        }
Esempio n. 5
0
        // RimWorld.LoadTransportersJobUtility
        public static bool HasJobOnTransporter(Pawn pawn, CompTransporterPawn transporter)
        {
            bool result = !transporter.parent.IsForbidden(pawn) && transporter.AnythingLeftToLoad &&
                          pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) &&
                          pawn.CanReserveAndReach(transporter.parent, PathEndMode.Touch, pawn.NormalMaxDanger(), 1) &&
                          LoadTransportersPawnJobUtility.FindThingToLoad(pawn, transporter) != null;

            Cthulhu.Utility.DebugReport(pawn.Label + " HasJobOnTransporter: " + result.ToString());
            return(result);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            CompTransporterPawn transporter = t.TryGetComp <CompTransporterPawn>();

            if (t == null)
            {
                return(null);
            }
            return(LoadTransportersPawnJobUtility.JobOnTransporter(pawn, transporter));
        }
        private void TryLaunch(GlobalTargetInfo target, PawnsArrivalModeDef arriveMode, bool attackOnArrival)
        {
            Cthulhu.Utility.DebugReport("TryLaunch Called");
            if (!this.parent.Spawned)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's unspawned.");
                return;
            }
            List <CompTransporterPawn> transportersInGroup = this.TransportersInGroup;

            if (transportersInGroup == null)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's not in any group.");
                return;
            }
            if (!this.LoadingInProgressOrReadyToLaunch)
            {
                Cthulhu.Utility.DebugReport("TryLaunch Failed");
                return;
            }
            Map map = this.parent.Map;
            int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, target.Tile);

            if (num > this.MaxLaunchDistance)
            {
                Cthulhu.Utility.DebugReport("TryLaunch Failed #2");
                return;
            }
            this.Transporter.TryRemoveLord(map);
            int groupID = this.Transporter.groupID;

            for (int i = 0; i < transportersInGroup.Count; i++)
            {
                Cthulhu.Utility.DebugReport("Transporter Outspawn Attempt");
                CompTransporterPawn compTransporter = transportersInGroup[i];
                Cthulhu.Utility.DebugReport("Transporter Outspawn " + compTransporter.parent.Label);
                PawnFlyersLeaving pawnFlyerLeaving = (PawnFlyersLeaving)ThingMaker.MakeThing(PawnFlyerDef.leavingDef, null);
                pawnFlyerLeaving.groupID         = groupID;
                pawnFlyerLeaving.pawnFlyer       = this.parent as PawnFlyer;
                pawnFlyerLeaving.destinationTile = target.Tile;
                pawnFlyerLeaving.destinationCell = target.Cell;
                pawnFlyerLeaving.arriveMode      = arriveMode;
                pawnFlyerLeaving.attackOnArrival = attackOnArrival;
                ThingOwner innerContainer = compTransporter.GetDirectlyHeldThings();
                pawnFlyerLeaving.Contents = new ActiveDropPodInfo();
                innerContainer.TryTransferAllToContainer(pawnFlyerLeaving.Contents.innerContainer);
                //pawnFlyerLeaving.Contents.innerContainer. //TryAddMany(innerContainer);
                innerContainer.Clear();
                compTransporter.CleanUpLoadingVars(map);
                compTransporter.parent.DeSpawn();
                pawnFlyerLeaving.Contents.innerContainer.TryAdd(compTransporter.parent);
                GenSpawn.Spawn(pawnFlyerLeaving, compTransporter.parent.Position, map);
            }
        }
Esempio n. 8
0
        public static Job JobOnTransporter(Pawn p, CompTransporterPawn transporter)
        {
            Cthulhu.Utility.DebugReport("JobOnTransporter Called");
            Thing thing = LoadTransportersPawnJobUtility.FindThingToLoad(p, transporter);

            return(new Job(JobDefOf.HaulToContainer, thing, transporter.parent)
            {
                count = Mathf.Min(
                    TransferableUtility.TransferableMatching <TransferableOneWay>(thing, transporter.leftToLoad,
                                                                                  TransferAsOneMode.PodsOrCaravanPacking).CountToTransfer, thing.stackCount),
                ignoreForbidden = true
            });
        }
        //Back to RimWorld.JobGiver_EnterTransporter
        protected override Job TryGiveJob(Pawn pawn)
        {
            Cthulhu.Utility.DebugReport("JobGiver_EnterTransporterPawn Called");
            int transportersGroup = pawn.mindState.duty.transportersGroup;

            JobGiver_EnterTransportersPawn.GetTransportersInGroup(transportersGroup, pawn.Map, JobGiver_EnterTransportersPawn.tmpTransporters);
            CompTransporterPawn compTransporter = this.FindMyTransporter(JobGiver_EnterTransportersPawn.tmpTransporters, pawn);

            if (compTransporter == null || !pawn.CanReserveAndReach(compTransporter.parent, PathEndMode.Touch, Danger.Deadly, 1))
            {
                return(null);
            }
            return(new Job(CultsDefOf.Cults_EnterTransporterPawn, compTransporter.parent));
        }
Esempio n. 10
0
        // RimWorld.LoadTransportersJobUtility
        private static Thing FindThingToLoad(Pawn p, CompTransporterPawn transporter)
        {
            LoadTransportersPawnJobUtility.neededThings.Clear();
            List <TransferableOneWay> leftToLoad = transporter.leftToLoad;

            if (leftToLoad != null)
            {
                for (int i = 0; i < leftToLoad.Count; i++)
                {
                    TransferableOneWay transferableOneWay = leftToLoad[i];
                    if (transferableOneWay.CountToTransfer > 0)
                    {
                        for (int j = 0; j < transferableOneWay.things.Count; j++)
                        {
                            LoadTransportersPawnJobUtility.neededThings.Add(transferableOneWay.things[j]);
                        }
                    }
                }
            }
            if (!LoadTransportersPawnJobUtility.neededThings.Any <Thing>())
            {
                return(null);
            }
            Predicate <Thing> validator = (Thing x) =>
                                          LoadTransportersPawnJobUtility.neededThings.Contains(x) && p.CanReserve(x, 1);
            Thing thing = GenClosest.ClosestThingReachable(p.Position, p.Map,
                                                           ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch,
                                                           TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator);

            if (thing == null)
            {
                foreach (Thing current in LoadTransportersPawnJobUtility.neededThings)
                {
                    Pawn pawn = current as Pawn;
                    if (pawn != null && (!pawn.IsColonist || pawn.Downed) &&
                        p.CanReserveAndReach(pawn, PathEndMode.Touch, Danger.Deadly, 1))
                    {
                        Cthulhu.Utility.DebugReport("Pawn to load : " + pawn.Label);
                        return(pawn);
                    }
                }
            }
            if (thing != null)
            {
                Cthulhu.Utility.DebugReport("Thing to load : " + thing.Label);
            }
            LoadTransportersPawnJobUtility.neededThings.Clear();
            return(thing);
        }
Esempio n. 11
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Cthulhu.Utility.DebugReport("JobGiver_LoadTransportersPawn Called");
            int transportersGroup = pawn.mindState.duty.transportersGroup;

            LoadTransportersPawnJobUtility.GetTransportersInGroup(transportersGroup, pawn.Map, JobGiver_LoadTransportersPawn.tmpTransporters);
            for (int i = 0; i < JobGiver_LoadTransportersPawn.tmpTransporters.Count; i++)
            {
                CompTransporterPawn transporter = JobGiver_LoadTransportersPawn.tmpTransporters[i];
                if (LoadTransportersPawnJobUtility.HasJobOnTransporter(pawn, transporter))
                {
                    return(LoadTransportersPawnJobUtility.JobOnTransporter(pawn, transporter));
                }
            }
            return(null);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(this.TransporterInd);
            yield return(Toils_Reserve.Reserve(this.TransporterInd, 1));

            yield return(Toils_Goto.GotoThing(this.TransporterInd, PathEndMode.Touch));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Cthulhu.Utility.DebugReport("EnterTransporterPawn Called");
                    CompTransporterPawn transporter = this.Transporter;
                    this.pawn.DeSpawn();
                    transporter.GetDirectlyHeldThings().TryAdd(this.pawn, true);
                    transporter.Notify_PawnEnteredTransporterOnHisOwn(this.pawn);
                }
            });

            yield break;
        }
        // I decided to just take one method instead of the entire utility.
        // RimWorld.TransporterUtility
        public static void GetTransportersInGroup(int transportersGroup, Map map, List <CompTransporterPawn> outTransporters)
        {
            outTransporters.Clear();
            if (transportersGroup < 0)
            {
                return;
            }
            IEnumerable <Pawn> listSel = from Pawn pawns in map.mapPawns.AllPawnsSpawned
                                         where pawns is PawnFlyer
                                         select pawns;
            List <Pawn> list = new List <Pawn>(listSel);

            for (int i = 0; i < list.Count; i++)
            {
                CompTransporterPawn compTransporter = list[i].TryGetComp <CompTransporterPawn>();
                if (compTransporter.groupID == transportersGroup)
                {
                    //Cthulhu.Utility.DebugReport("Added Transporter: " + list[i].Label);
                    outTransporters.Add(compTransporter);
                }
            }
        }
        private void CancelLoadingProcess()
        {
            List <Thing> list = this.lord.Map.listerThings.ThingsInGroup(ThingRequestGroup.Pawn);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] != null)
                {
                    if (list[i] is Pawn || list[i] is PawnFlyer)
                    {
                        CompTransporterPawn compTransporter = list[i].TryGetComp <CompTransporterPawn>();
                        if (compTransporter != null)
                        {
                            if (compTransporter.groupID == this.transportersGroup)
                            {
                                compTransporter.CancelLoad();
                                break;
                            }
                        }
                    }
                }
            }
        }