Example #1
0
        private Toil FindNextWanderSpot(int waitTicks)
        {
            return(new Toil
            {
                initAction = delegate
                {
                    pawn.pather.StopDead();

                    var rect = CellRect.CenteredOn(pawn.Position, 4);
                    var dest = rect.Cells
                               .Where(c => c != pawn.Position && pawn.CanReach(c, PathEndMode.OnCell, Danger.None))
                               .RandomElement();
                    if (dest.IsValid)
                    {
                        CurJob.SetTarget(TargetIndex.A, dest);
                    }
                    else
                    {
                        EndJobWith(JobCondition.Succeeded);
                    }
                },
                socialMode = RandomSocialMode.SuperActive,
                defaultCompleteMode = ToilCompleteMode.Delay,
                defaultDuration = waitTicks
            });
        }
 private Toil FindTrashSpot()
 {
     // Doubting that this needs to be done this way.
     // Only use case is if this step needs to ever be jumped back to.
     return(new Toil
     {
         initAction = delegate
         {
             var target = Info.GetNextTrashCellFor(this.ThingToHaul, this.pawn);
             if (!target.IsValid)
             {
                 base.EndJobWith(JobCondition.Errored);
             }
             CurJob.SetTarget(TargetIndex.B, target);
         }
     });
 }
Example #3
0
        private Toil FindTicketTaker()
        {
            return(new Toil
            {
                initAction = delegate
                {
                    var ticketTaker = Info.GetBestEntertainer(false);

                    if (ticketTaker == null)
                    {
                        Log.Error("[Carnivale] Found no ticket taker to give silver to.");
                        base.EndJobWith(JobCondition.Errored);
                    }

                    DutyUtility.HitchToSpot(ticketTaker, ticketTaker.Position);

                    CurJob.SetTarget(TargetIndex.B, ticketTaker);
                }
            });
        }
Example #4
0
        private Toil Collect()
        {
            Toil toil = new Toil();

            toil.initAction = delegate {
                // Increment the record for how many cells this pawn has mined since this counts as mining
                pawn.records.Increment(RecordDefOf.CellsMined);

                // Start with None to act as a fallback. Rubble will be returned with this parameter
                ResourceRequest req = ResourceRequest.None;

                // Use the mineModeToggle to determine the request
                req = (Quarry.mineModeToggle ? ResourceRequest.Resources : ResourceRequest.Blocks);

                MoteType mote = MoteType.None;

                // Get the resource from the quarry
                Thing haulableResult = Quarry.GiveResources(req, out mote);
                // Place the resource near the pawn
                GenPlace.TryPlaceThing(haulableResult, pawn.Position, Map, ThingPlaceMode.Near);

                // If the resource had a mote, throw it
                if (mote == MoteType.LargeVein)
                {
                    MoteMaker.ThrowText(haulableResult.DrawPos, Map, Static.TextMote_LargeVein, Color.green, 3f);
                }
                else if (mote == MoteType.Failure)
                {
                    MoteMaker.ThrowText(haulableResult.DrawPos, Map, Static.TextMote_MiningFailed, Color.red, 3f);
                }

                // Prevent the colonists from trying to haul rubble, which just makes them visit the platform
                if (haulableResult.def == ThingDefOf.RockRubble)
                {
                    EndJobWith(JobCondition.Succeeded);
                }

                // If this is a chunk or slag, mark it as haulable if allowed to
                if (haulableResult.def.designateHaulable && Quarry.autoHaul)
                {
                    Map.designationManager.AddDesignation(new Designation(haulableResult, DesignationDefOf.Haul));
                }

                // Setup IntVec for assigning
                IntVec3 c;

                // Try to find a suitable storage spot for the resource, removing it from the quarry
                // If there are no platforms, hauling will be done by haulers
                if (Quarry.autoHaul && Quarry.TryFindBestStoreCellFor(haulableResult, pawn, Map, pawn.Faction, out c))
                {
                    CurJob.SetTarget(TargetIndex.B, haulableResult);
                    CurJob.count = haulableResult.stackCount;
                    CurJob.SetTarget(TargetIndex.C, c);
                }
                // If there is no spot to store the resource, end this job
                else
                {
                    EndJobWith(JobCondition.Succeeded);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;

            return(toil);
        }