Example #1
0
        protected override void FillTab()
        {
            if (Droid == null)
            {
                Log.Error("Cremation control ITab tried to display on a non droid");
                return;
            }

            Rect mainRect = new Rect(0, 0, size.x, size.y);
            Rect useRect  = mainRect.ContractedBy(borderMargin);

            currentY = 0f;
            CremationWorker        worker  = Droid.work.specialist.GetWorker <CremationWorker>();
            List <CremationTarget> targets = worker.AllTargets.OrderBy((CremationTarget t) => t.NaturalPriority).ThenBy((CremationTarget t) => t.Label).ToList();

            try
            {
                GUI.BeginGroup(useRect);
                foreach (var target in targets)
                {
                    DrawItemRow(target, currentY);
                    currentY += ItemSize.y + itemMargin;
                }
            }
            finally
            {
                GUI.EndGroup();
            }
        }
Example #2
0
        public override bool HasJobOnThing(Pawn pawn, Thing t)
        {
            Droid droid = pawn as Droid;

            if (droid == null)
            {
                return(false);
            }
            CremationWorker   worker     = droid.work.specialist.GetWorker <CremationWorker>();
            Predicate <Thing> predicate1 = (Thing corpse) => !corpse.IsForbidden(Faction.OfColony) && droid.AwareOf(corpse) && droid.CanReserve(corpse);
            bool flag = t is Corpse && droid != null && predicate1(t) && worker.AllTargets.Any((CremationTarget target) => target.Accepts(t));

            return(flag);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid));

            //Reserve the corpse
            yield return(Toils_Reserve.Reserve(CorpseIndex));

            //Go to the corpse
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                //Check if the pawn is set to strip bodies, if yes then strip it, otherwise skip this step
                Droid           droid  = (Droid)pawn;
                CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>();
                if (worker.StripBodies)
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    if (corpse.AnythingToStrip())
                    {
                        corpse.Strip();
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 300;
            toil.WithEffect(() => DefDatabase <EffecterDef> .GetNamed("Cremate"), CorpseIndex);
            toil.WithSustainer(() => DefDatabase <SoundDef> .GetNamed("Recipe_Cremate"));
            toil.AddFinishAction(() => TargetA.Thing.Destroy());
            toil.FailOnBurningImmobile(CorpseIndex);
            toil.FailOnDestroyedOrForbidden(CorpseIndex);
            toil.AddEndCondition(() => this.ticksLeftThisToil <= 0 ? JobCondition.Succeeded : JobCondition.Ongoing);
            yield return(toil);
        }
Example #4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid) || TargetA.Thing.TryGetComp <CompRottable>() != null && TargetA.Thing.TryGetComp <CompRottable>().Stage != RotStage.Fresh);
            Droid           droid  = pawn as Droid;
            CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>();

            //Reserve the corpse
            yield return(Toils_Reserve.Reserve(CorpseIndex));

            //Go to the corpse
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            //If wanting to strip bodies, then strip it.
            if (worker.StripBodies)
            {
                yield return(Toils_General.Wait(80));

                //Strip the body
                Toil t = new Toil();
                t.initAction = () =>
                {
                    Corpse corpse = (Corpse)TargetA.Thing;
                    if (corpse != null && corpse.AnythingToStrip())
                    {
                        corpse.Strip();
                    }
                };
                yield return(t);
            }

            //Wait the time to do the butchering
            Toil effecterWait = Toils_General.Wait(300);

            effecterWait.WithEffect(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <EffecterDef> .GetNamed("ButcherFlesh") : DefDatabase <EffecterDef> .GetNamed("ButcherMechanoid"), CorpseIndex);
            effecterWait.WithSustainer(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseFlesh") : DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseMechanoid"));
            yield return(effecterWait);

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                List <Thing> products;
                Corpse       c = (Corpse)TargetA.Thing;
                if (c != null)
                {
                    float efficiency = Rand.Range(0.9f, 1f);
                    if (c.innerPawn.RaceProps.isFlesh)
                    {
                        products = TargetA.Thing.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList();
                    }
                    else
                    {
                        products = c.innerPawn.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList();
                    }
                    TargetA.Thing.Destroy();
                    foreach (var thing in products)
                    {
                        if (!GenPlace.TryPlaceThing(thing, pawn.Position, ThingPlaceMode.Near))
                        {
                            Log.Error(string.Concat(new object[] {
                                pawn,
                                " could not drop butcher product ",
                                thing,
                                " near ",
                                pawn.Position
                            }));
                        }
                    }
                }
                else
                {
                    Log.Error(string.Concat(new object[] {
                        pawn,
                        " tried to butcher ",
                        TargetA.Thing,
                        " at ",
                        TargetA.Thing.Position,
                        " which is not a corpse."
                    }));
                    return;
                }
            };
            yield return(toil);
        }