protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => PrisonerFoodReservation.isReserved(TargetA.Thing));
            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else if (usingNutrientPasteDispenser)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)
                             .FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, pawn));
            }
            else
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)
                             .FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, Deliveree));
            }
            var toil = new Toil();

            toil.initAction = delegate
            {
                var actor  = toil.actor;
                var curJob = actor.jobs.curJob;
                actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            toil.AddFailCondition(delegate
            {
                var pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                return(!pawn.IsPrisonerOfColony || !pawn.guest.CanBeBroughtFood);
            });
            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing thing;
                    pawn.carryTracker.TryDropCarriedThing(toil.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct,
                                                          out thing, null);
                    PrisonerFoodReservation.reserve(thing, (Pawn)toil.actor.jobs.curJob.targetB.Thing);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
Exemplo n.º 2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.B);
            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else if (usingNutrientPasteDispenser)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, pawn));
            }
            else
            {
                yield return(Toils_Ingest.ReserveFoodFromStackForIngesting(TargetIndex.A, Deliveree));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, Deliveree));
            }
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            toil.AddFailCondition(delegate
            {
                Pawn pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                if (!pawn.IsPrisonerOfColony)
                {
                    return(true);
                }
                return((!pawn.guest.CanBeBroughtFood) ? true : false);
            });
            yield return(toil);

            Toil toil2 = new Toil();

            toil2.initAction = delegate
            {
                pawn.carryTracker.TryDropCarriedThing(toil2.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out Thing _);
            };
            toil2.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil2);
        }
Exemplo n.º 3
0
        public static Toil LayDown(TargetIndex bedOrRestSpotIndex)
        {
            Log.Message("Started Laying down job");
            Toil layDown = new Toil();

            layDown.initAction = delegate
            {
                layDown.actor.pather.StopDead();
                JobDriver curDriver = layDown.actor.jobs.curDriver;
                curDriver.layingDown = true;
                curDriver.asleep     = false;
            };
            layDown.tickAction = delegate
            {
                Pawn      actor     = layDown.actor;
                Job       curJob    = actor.CurJob;
                JobDriver curDriver = actor.jobs.curDriver;
                if (actor.Downed)
                {
                    actor.Position = CellFinder.RandomClosewalkCellNear(actor.Position, 1);
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                }
                return;
            };
            layDown.defaultDuration = 360;
            if (CultUtility.remainingDuration != 0)
            {
                layDown.defaultDuration = CultUtility.remainingDuration;
            }
            layDown.defaultCompleteMode = ToilCompleteMode.Delay;
            layDown.FailOnDestroyedNullOrForbidden(bedOrRestSpotIndex);

            layDown.AddFinishAction(delegate
            {
                Pawn actor              = layDown.actor;
                JobDriver curDriver     = actor.jobs.curDriver;
                curDriver.layingDown    = false;
                curDriver.layingDownBed = null;
                curDriver.asleep        = false;
            });
            return(layDown);
        }
Exemplo n.º 4
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                Toil toil;

                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedOrNull(TargetIndex.B);
                    if (this.eatingFromInventory)
                    {
                        this.$current = Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    if (this.usingNutrientPasteDispenser)
                    {
                        this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 2;
                        }
                        return(true);
                    }
                    this.$current = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 1u:
                    break;

                case 2u:
                    this.$current = Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    break;

                case 4u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                    this.$current = Toils_Ingest.PickupIngestible(TargetIndex.A, base.Deliveree);
                    if (!this.$disposing)
                    {
                        this.$PC = 6;
                    }
                    return(true);

                case 6u:
                    break;

                case 7u:
                {
                    Toil toil = new Toil();
                    toil.initAction = delegate()
                    {
                        Thing thing;
                        this.pawn.carryTracker.TryDropCarriedThing(toil.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out thing, null);
                    };
                    toil.defaultCompleteMode = ToilCompleteMode.Instant;
                    this.$current            = toil;
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);
                }

                case 8u:
                    this.$PC = -1;
                    return(false);

                default:
                    return(false);
                }
                toil            = new Toil();
                toil.initAction = delegate()
                {
                    Pawn actor  = toil.actor;
                    Job  curJob = actor.jobs.curJob;
                    actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
                };
                toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
                toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
                toil.AddFailCondition(delegate
                {
                    Pawn pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                    return(!pawn.IsPrisonerOfColony || !pawn.guest.CanBeBroughtFood);
                });
                this.$current = toil;
                if (!this.$disposing)
                {
                    this.$PC = 7;
                }
                return(true);
            }
Exemplo n.º 5
0
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodDeliver obj)
        {
            var foodThing = obj.TargetThing(FoodInd);
            var deliveree = (Pawn)obj.TargetThing(DelivereeInd);
            var dropCell  = obj.TargetCell(DeliverToInd);

            yield return(Toils_Reserve.Reserve(DelivereeInd, 1));

            if (foodThing is Building)
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.InteractionCell).FailOnForbidden(FoodInd));

                if (foodThing is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(FoodInd, obj.pawn));
                }
                else if (foodThing is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(FoodInd, obj.pawn));
                }
                else // Unknown building
                {
                    throw new Exception("Food target for JobDriver_FoodDeliver is a building but not Building_NutrientPasteDispenser or Building_AutomatedFactory!");
                }
            }
            else if (
                (obj.pawn.inventory != null) &&
                (obj.pawn.inventory.Contains(foodThing))
                )
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(obj.pawn, FoodInd));
            }
            else
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.ClosestTouch));

                yield return(Toils_Ingest.PickupIngestible(FoodInd, deliveree));
            }

            var pathToTarget = new Toil();

            pathToTarget.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            pathToTarget.initAction          = new Action(() =>
            {
                var pawn = obj.pawn;
                var job  = pawn.jobs.curJob;
                pawn.pather.StartPath(job.targetC, PathEndMode.OnCell);
            }
                                                          );
            pathToTarget.FailOnDestroyedNullOrForbidden(DelivereeInd);
            pathToTarget.AddFailCondition(() =>
            {
                return
                ((deliveree.Downed) ||
                 (!deliveree.IsPrisonerOfColony) ||
                 (!deliveree.guest.ShouldBeBroughtFood));
            });
            yield return(pathToTarget);

            var dropFoodAtTarget = new Toil();

            dropFoodAtTarget.initAction = new Action(() =>
            {
                Thing resultingThing;
                obj.pawn.carrier.TryDropCarriedThing(dropCell, ThingPlaceMode.Direct, out resultingThing);
            }
                                                     );
            dropFoodAtTarget.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(dropFoodAtTarget);
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            var foodThing = this.TargetThing( FoodInd );
            var deliveree = (Pawn) this.TargetThing( DelivereeInd );
            var dropCell = this.TargetCell( DeliverToInd );

            yield return Toils_Reserve.Reserve( DelivereeInd, 1 );

            if( foodThing is Building )
            {
                yield return Toils_Goto.GotoThing( FoodInd, PathEndMode.InteractionCell ).FailOnForbidden( FoodInd );

                if( foodThing is Building_NutrientPasteDispenser )
                {
                    yield return Toils_Ingest.TakeMealFromDispenser( FoodInd, this.pawn );
                }
                else if( foodThing is Building_AutomatedFactory )
                {
                    yield return Toils_FoodSynthesizer.TakeMealFromSynthesizer( FoodInd, this.pawn );
                }
                else // Unknown building
                {
                    throw new Exception( "Food target for JobDriver_FoodDeliver is a building but not Building_NutrientPasteDispenser or Building_AutomatedFactory!" );
                }
            }
            else if(
                ( this.pawn.inventory != null )&&
                ( this.pawn.inventory.Contains( foodThing ) )
            )
            {
                yield return Toils_Misc.TakeItemFromInventoryToCarrier( this.pawn, FoodInd );
            }
            else
            {
                yield return Toils_Reserve.Reserve( FoodInd, 1 );
                yield return Toils_Goto.GotoThing( FoodInd, PathEndMode.ClosestTouch );
                yield return Toils_Ingest.PickupIngestible( FoodInd, deliveree );
            }

            var pathToTarget = new Toil();
            pathToTarget.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            pathToTarget.initAction = new Action( () =>
                {
                    var pawn = this.pawn;
                    var job = pawn.jobs.curJob;
                    pawn.pather.StartPath( job.targetC, PathEndMode.OnCell );
                }
            );
            pathToTarget.FailOnDestroyedNullOrForbidden( DelivereeInd );
            pathToTarget.AddFailCondition( () =>
            {
                if( deliveree.Downed )
                {
                    return false;
                }
                if( deliveree.IsPrisonerOfColony )
                {
                    return !deliveree.guest.ShouldBeBroughtFood;
                }
                var compPrisoner = deliveree.TryGetComp<CompPrisoner>();
                if( compPrisoner != null )
                {
                    return !compPrisoner.wasArrested;
                }
                return false;
            } );
            yield return pathToTarget;

            var dropFoodAtTarget = new Toil();
            dropFoodAtTarget.initAction = new Action( () =>
                {
                    Thing resultingThing;
                    this.pawn.carrier.TryDropCarriedThing( dropCell, ThingPlaceMode.Direct, out resultingThing );
                }
            );
            dropFoodAtTarget.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return dropFoodAtTarget;
        }
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodDeliver obj)
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));

            var targetThingA = obj.TargetThingA();

            if (targetThingA is Building)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

                if (targetThingA is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, obj.pawn));
                }
                if (targetThingA is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(TargetIndex.A, obj.pawn));
                }
            }
            else
            {
                var deliveree = (Pawn)obj.pawn.CurJob.targetB.Thing;
                yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, deliveree));
            }

            var pathToTarget = new Toil();

            pathToTarget.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            pathToTarget.initAction          = new Action(() =>
            {
                Pawn pawn = obj.pawn;
                Job job   = pawn.jobs.curJob;
                pawn.pather.StartPath(job.targetC, PathEndMode.OnCell);
            }
                                                          );
            pathToTarget.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            pathToTarget.AddFailCondition(() =>
            {
                Pawn pawn = (Pawn)obj.pawn.jobs.curJob.targetB.Thing;
                return
                ((pawn.Downed) ||
                 (!pawn.IsPrisonerOfColony) ||
                 (!pawn.guest.ShouldBeBroughtFood));
            });
            yield return(pathToTarget);

            var dropFoodAtTarget = new Toil();

            dropFoodAtTarget.initAction = new Action(() =>
            {
                Thing resultingThing;
                obj.pawn.carrier.TryDropCarriedThing(obj.pawn.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out resultingThing);
            }
                                                     );
            dropFoodAtTarget.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(dropFoodAtTarget);
        }