protected override Job TryGiveJob(Pawn pawn)
        {
            //Log.Message("Trying to give job");
            int         transportersGroup = pawn.mindState.duty.transportersGroup;
            List <Pawn> allPawnsSpawned   = pawn.Map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                if (allPawnsSpawned[i] != pawn && allPawnsSpawned[i].CurJobDef == DefDatabase <JobDef> .GetNamed("PD_HaulToPit"))
                {
                    CompPit transporter = ((JobDriver_HaulToPit)allPawnsSpawned[i].jobs.curDriver).Transporter;
                    if (transporter != null && transporter.groupID == transportersGroup)
                    {
                        return(null);
                    }
                }
            }
            PitUtility.GetTransportersInGroup(transportersGroup, pawn.Map, JobGiver_EnterPit.tmpTransporters);
            CompPit compTransporter = JobGiver_EnterPit.FindMyTransporter(JobGiver_EnterPit.tmpTransporters, pawn);

            JobGiver_EnterPit.tmpTransporters.Clear();
            if (compTransporter == null || !pawn.CanReach(compTransporter.parent, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn))
            {
                return(null);
            }
            return(new Job(DefDatabase <JobDef> .GetNamed("PD_EnterPit"), compTransporter.parent));
        }
 public static Job JobOnTransporter(Pawn p, CompPit transporter)
 {
     return(new Job(DefDatabase <JobDef> .GetNamed("PD_HaulToPit"), LocalTargetInfo.Invalid, transporter.parent)
     {
         ignoreForbidden = true
     });
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            int transportersGroup = pawn.mindState.duty.transportersGroup;

            PitUtility.GetTransportersInGroup(transportersGroup, pawn.Map, JobGiver_HaulToPit.tmpTransporters);
            for (int i = 0; i < JobGiver_HaulToPit.tmpTransporters.Count; i++)
            {
                CompPit transporter = JobGiver_HaulToPit.tmpTransporters[i];
                if (LoadPitJobUtility.HasJobOnTransporter(pawn, transporter))
                {
                    return(LoadPitJobUtility.JobOnTransporter(pawn, transporter));
                }
            }
            return(null);
        }
Example #4
0
        public static void GetTransportersInGroup(int transportersGroup, Map map, List <CompPit> outTransporters)
        {
            outTransporters.Clear();
            if (transportersGroup < 0)
            {
                return;
            }
            List <Thing> list = map.listerThings.ThingsOfDef(ThingDef.Named("PD_PitOfDespair"));

            for (int i = 0; i < list.Count; i++)
            {
                CompPit compTransporter = list[i].TryGetComp <CompPit>();
                if (compTransporter.groupID == transportersGroup)
                {
                    outTransporters.Add(compTransporter);
                }
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(this.TransporterInd);
            this.FailOn(() => !this.Transporter.LoadingInProgressOrReadyToLaunch);
            yield return(Toils_Goto.GotoThing(this.TransporterInd, PathEndMode.Touch));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    CompPit transporter = this.Transporter;
                    this.pawn.DeSpawn(DestroyMode.Vanish);
                    transporter.GetDirectlyHeldThings().TryAdd(this.pawn, true);
                }
            });

            yield break;
        }
Example #6
0
        public static bool WasLoadingCanceled(Thing transporter)
        {
            CompPit compTransporter = transporter.TryGetComp <CompPit>();

            return(compTransporter != null && !compTransporter.LoadingInProgressOrReadyToLaunch);
        }
        public static ThingCount FindThingToLoad(Pawn p, CompPit transporter)
        {
            LoadPitJobUtility.neededThings.Clear();
            List <TransferableOneWay> leftToLoad = transporter.leftToLoad;

            LoadPitJobUtility.tmpAlreadyLoading.Clear();
            // Log.Message(leftToLoad.ToString());
            if (leftToLoad != null)
            {
                List <Pawn> allPawnsSpawned = transporter.Map.mapPawns.AllPawnsSpawned;
                for (int i = 0; i < allPawnsSpawned.Count; i++)
                {
                    if (allPawnsSpawned[i] != p)
                    {
                        if (allPawnsSpawned[i].CurJobDef == DefDatabase <JobDef> .GetNamed("PD_HaulToPit"))
                        {
                            JobDriver_HaulToPit jobDriver_HaulToTransporter = (JobDriver_HaulToPit)allPawnsSpawned[i].jobs.curDriver;
                            if (jobDriver_HaulToTransporter.Container == transporter.parent)
                            {
                                TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatchingDesperate(jobDriver_HaulToTransporter.ThingToCarry, leftToLoad, TransferAsOneMode.PodsOrCaravanPacking);
                                if (transferableOneWay != null)
                                {
                                    int num = 0;
                                    if (LoadPitJobUtility.tmpAlreadyLoading.TryGetValue(transferableOneWay, out num))
                                    {
                                        LoadPitJobUtility.tmpAlreadyLoading[transferableOneWay] = num + jobDriver_HaulToTransporter.initialCount;
                                    }
                                    else
                                    {
                                        LoadPitJobUtility.tmpAlreadyLoading.Add(transferableOneWay, jobDriver_HaulToTransporter.initialCount);
                                    }
                                }
                            }
                        }
                    }
                }
                for (int j = 0; j < leftToLoad.Count; j++)
                {
                    TransferableOneWay transferableOneWay2 = leftToLoad[j];
                    int num2;
                    if (!LoadPitJobUtility.tmpAlreadyLoading.TryGetValue(leftToLoad[j], out num2))
                    {
                        num2 = 0;
                    }
                    if (transferableOneWay2.CountToTransfer - num2 > 0)
                    {
                        for (int k = 0; k < transferableOneWay2.things.Count; k++)
                        {
                            LoadPitJobUtility.neededThings.Add(transferableOneWay2.things[k]);
                        }
                    }
                }
            }
            if (!LoadPitJobUtility.neededThings.Any <Thing>())
            {
                LoadPitJobUtility.tmpAlreadyLoading.Clear();
                return(default(ThingCount));
            }
            Thing thing = GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEver), PathEndMode.Touch, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing x) => LoadPitJobUtility.neededThings.Contains(x) && p.CanReserve(x, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false);

            if (thing == null)
            {
                foreach (Thing thing2 in LoadPitJobUtility.neededThings)
                {
                    Pawn pawn = thing2 as Pawn;
                    if (pawn != null && pawn.IsPrisoner && p.CanReserveAndReach(pawn, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false))
                    {
                        LoadPitJobUtility.neededThings.Clear();
                        LoadPitJobUtility.tmpAlreadyLoading.Clear();
                        return(new ThingCount(pawn, 1));
                    }
                }
            }
            LoadPitJobUtility.neededThings.Clear();
            if (thing != null)
            {
                TransferableOneWay transferableOneWay3 = null;
                for (int l = 0; l < leftToLoad.Count; l++)
                {
                    if (leftToLoad[l].things.Contains(thing))
                    {
                        transferableOneWay3 = leftToLoad[l];
                        break;
                    }
                }
                int num3;
                if (!LoadPitJobUtility.tmpAlreadyLoading.TryGetValue(transferableOneWay3, out num3))
                {
                    num3 = 0;
                }
                LoadPitJobUtility.tmpAlreadyLoading.Clear();
                return(new ThingCount(thing, Mathf.Min(transferableOneWay3.CountToTransfer - num3, thing.stackCount)));
            }
            LoadPitJobUtility.tmpAlreadyLoading.Clear();
            return(default(ThingCount));
        }
 public static bool HasJobOnTransporter(Pawn pawn, CompPit transporter)
 {
     return(transporter.AnythingLeftToLoad && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && pawn.CanReach(transporter.parent, PathEndMode.Touch, pawn.NormalMaxDanger(), false, TraverseMode.ByPawn) && LoadPitJobUtility.FindThingToLoad(pawn, transporter).Thing != null);
 }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            CompPit transporter = t.TryGetComp <CompPit>();

            return(LoadPitJobUtility.JobOnTransporter(pawn, transporter));
        }
Example #10
0
        private void DoItemsLists(Rect inRect, ref float curY)
        {
            CompPit transporter = this.Transporter;
            Rect    position    = new Rect(0f, curY, (inRect.width - 10f) / 2f, inRect.height);
            float   a           = 0f;

            /* GUI.BeginGroup(position);
             * Widgets.ListSeparator(ref a, position.width, "ItemsToLoad".Translate());
             * bool flag = false;
             * if (transporter.leftToLoad != null)
             * {
             *   for (int i = 0; i < transporter.leftToLoad.Count; i++)
             *   {
             *       TransferableOneWay t = transporter.leftToLoad[i];
             *       if (t.CountToTransfer > 0 && t.HasAnyThing)
             *       {
             *           flag = true;
             *           this.DoThingRow(t.ThingDef, t.CountToTransfer, t.things, position.width, ref a, delegate (int x)
             *           {
             *               t.ForceTo(t.CountToTransfer - x);
             *               this.EndJobForEveryoneHauling(t);
             *           });
             *       }
             *   }
             * }
             * if (!flag)
             * {
             *   Widgets.NoneLabel(ref a, position.width, null);
             * }
             * GUI.EndGroup();*/
            Rect  position2 = new Rect(0f, curY, (inRect.width - 10f), inRect.height);
            float b         = 0f;

            GUI.BeginGroup(position2);
            Widgets.ListSeparator(ref b, position2.width, "PD_PrisonersInThePit".Translate());
            bool flag2 = false;

            for (int j = 0; j < transporter.innerContainer.Count; j++)
            {
                Thing t = transporter.innerContainer[j];
                flag2 = true;
                ITab_PitContents.tmpSingleThing.Clear();
                ITab_PitContents.tmpSingleThing.Add(t);
                this.DoThingRow(t.def, t.stackCount, ITab_PitContents.tmpSingleThing, position2.width, ref b, delegate(int x)
                {
                    Thing thing;
                    GenDrop.TryDropSpawn(t.SplitOff(x), this.SelThing.Position, this.SelThing.Map, ThingPlaceMode.Near, out thing, null, null);
                    Pawn pawn          = t as Pawn;
                    System.Random rand = new System.Random();
                    if (pawn != null)
                    {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("PD_ThrownIntoPit"), null);
                        HealthUtility.DamageUntilDowned(pawn, false);
                        BodyPartRecord brain = pawn.health.hediffSet.GetBrain();
                        double number        = rand.NextDouble();
                        if (number > 0.75 && number < 0.85)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDefOf.Dementia, pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                        else if (number > 0.85 && number < 0.95)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("PD_Psychosis"), pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                        else if (number > 0.95)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(HediffDef.Named("PD_BrainEatingParasites"), pawn, brain);
                            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                            {
                                pawn.health.AddHediff(hediff, null, null, null);
                            }
                        }
                    }
                });
                ITab_PitContents.tmpSingleThing.Clear();
            }
            if (!flag2)
            {
                Widgets.NoneLabel(ref b, position.width, null);
            }
            GUI.EndGroup();
            curY += Mathf.Max(a, b);
        }