public override void CompTick()
        {
            base.CompTick();
            if (IsMounted)
            {
                if (!Driver.Spawned)
                {
                    parent.DeSpawn();
                    return;
                }

                if (Driver.Dead || Driver.Downed || Driver.health.InPainShock ||
                    Driver.MentalStateDef == MentalStateDefOf.WanderPsychotic ||
                    (parent.IsForbidden(Faction.OfPlayer) && Driver.Faction == Faction.OfPlayer))
                {
                    if (!Driver.Position.InBounds())
                    {
                        DismountAt(Driver.Position);
                        return;
                    }

                    DismountAt(Driver.Position - parent.def.interactionCellOffset.RotatedBy(Driver.Rotation));
                    Driver.Position = Driver.Position.RandomAdjacentCell8Way();
                    return;
                }


                if (Find.TickManager.TicksGame - tickCheck >= tickCooldown)
                {
                    if (Driver.Faction == Faction.OfPlayer && Driver.CurJob != null)
                    {
                        if (Driver.CurJob.def.playerInterruptible && (
                                Driver.CurJob.def == JobDefOf.GotoWander ||
                                Driver.CurJob.def == JobDefOf.Open ||
                                Driver.CurJob.def == JobDefOf.ManTurret ||
                                Driver.CurJob.def == JobDefOf.EnterCryptosleepCasket ||
                                Driver.CurJob.def == JobDefOf.UseNeurotrainer ||
                                Driver.CurJob.def == JobDefOf.UseArtifact ||
                                Driver.CurJob.def == JobDefOf.DoBill ||
                                Driver.CurJob.def == JobDefOf.Research ||
                                Driver.CurJob.def == JobDefOf.OperateDeepDrill ||
                                Driver.CurJob.def == JobDefOf.Repair ||
                                Driver.CurJob.def == JobDefOf.FixBrokenDownBuilding ||
                                Driver.CurJob.def == JobDefOf.UseCommsConsole ||
                                Driver.CurJob.def == JobDefOf.BuryCorpse ||
                                Driver.CurJob.def == JobDefOf.TradeWithPawn ||
                                Driver.CurJob.def == JobDefOf.Lovin ||
                                Driver.CurJob.def == JobDefOf.SocialFight ||
                                Driver.CurJob.def == JobDefOf.Maintain ||
                                Driver.CurJob.def == JobDefOf.MarryAdjacentPawn ||
                                Driver.CurJob.def == JobDefOf.SpectateCeremony ||
                                Driver.CurJob.def == JobDefOf.StandAndBeSociallyActive ||
                                Driver.CurJob.def == JobDefOf.LayDown ||
                                Driver.CurJob.def == JobDefOf.Ingest ||
                                Driver.CurJob.def == JobDefOf.SocialRelax ||
                                Driver.CurJob.def == JobDefOf.Refuel ||
                                Driver.CurJob.def == JobDefOf.FillFermentingBarrel ||
                                Driver.CurJob.def == JobDefOf.TakeBeerOutOfFermentingBarrel ||
                                Driver.CurJob.def == JobDefOf.TakeWoundedPrisonerToBed ||
                                Driver.CurJob.def == JobDefOf.TakeToBedToOperate ||
                                Driver.CurJob.def == JobDefOf.EscortPrisonerToBed ||
                                Driver.CurJob.def == JobDefOf.CarryToCryptosleepCasket ||
                                Driver.CurJob.def == JobDefOf.ReleasePrisoner ||
                                Driver.CurJob.def == JobDefOf.PrisonerAttemptRecruit ||
                                Driver.CurJob.def == JobDefOf.PrisonerFriendlyChat ||
                                Driver.CurJob.def == JobDefOf.PrisonerExecution ||
                                Driver.CurJob.def == JobDefOf.FeedPatient ||
                                Driver.CurJob.def == JobDefOf.TendPatient ||
                                Driver.CurJob.def == JobDefOf.VisitSickPawn ||
                                Driver.CurJob.def == JobDefOf.Slaughter ||
                                Driver.CurJob.def == JobDefOf.Milk ||
                                Driver.CurJob.def == JobDefOf.Shear ||
                                Driver.CurJob.def == JobDefOf.Train ||
                                Driver.CurJob.def == JobDefOf.Mate ||
                                Driver.health.NeedsMedicalRest ||
                                Driver.health.PrefersMedicalRest
                                ) && Driver.Position.Roofed())
                        {
                            parent.Position = Position.ToIntVec3();
                            parent.Rotation = Driver.Rotation;
                            if (!Driver.Position.InBounds())
                            {
                                DismountAt(Driver.Position);
                                return;
                            }
                            DismountAt(Driver.Position - InteractionOffset.ToIntVec3());
                            Driver.Position = Driver.Position.RandomAdjacentCell8Way();
                            return;
                        }
                    }
                    tickCheck    = Find.TickManager.TicksGame;
                    tickCooldown = Rand.RangeInclusive(60, 180);

                    CompVehicle vehicleComp = parent.TryGetComp <CompVehicle>();

                    if (!vehicleComp.MotorizedWithoutFuel())
                    {
                        CompRefuelable refuelableComp = parent.TryGetComp <CompRefuelable>();
                        Job            jobNew         = ToolsForHaulUtility.DismountInBase(Driver, MapComponent_ToolsForHaul.currentVehicle[Driver]);

                        if (Driver.Faction == Faction.OfPlayer)
                        {
                            if (!GenAI.EnemyIsNear(Driver, 40f))
                            {
                                if (parent.HitPoints / parent.MaxHitPoints < 0.65f ||
                                    (Driver.CurJob != null && Driver.jobs.curDriver.asleep) ||
                                    vehicleComp.tankLeaking ||
                                    !refuelableComp.HasFuel)
                                {
                                    Driver.jobs.StartJob(jobNew, JobCondition.InterruptForced);
                                }
                            }
                        }

                        else if (!refuelableComp.HasFuel)
                        {
                            Dismount();
                            FireUtility.TryStartFireIn(Position.ToIntVec3(), 0.1f);
                        }
                    }
                }
                if (Find.TickManager.TicksGame - tickLastDoorCheck >= 96 &&
                    (Driver.Position.GetEdifice() is Building_Door || parent.Position.GetEdifice() is Building_Door))
                {
                    lastPassedDoor =
                        (Driver.Position.GetEdifice() is Building_Door
                            ? Driver.Position.GetEdifice()
                            : parent.Position.GetEdifice()) as Building_Door;
                    lastPassedDoor.StartManualOpenBy(Driver);
                    tickLastDoorCheck = Find.TickManager.TicksGame;
                }
                else if (Find.TickManager.TicksGame - tickLastDoorCheck >= 96 && lastPassedDoor != null)
                {
                    lastPassedDoor.StartManualCloseBy(Driver);
                    lastPassedDoor = null;
                }
                if (Driver.pather.Moving && Driver.Position != (Driver.pather.Destination.Cell))
                {
                    lastDrawAsAngle = Driver.Rotation.AsAngle;
                    parent.Position = (Position.ToIntVec3());
                    parent.Rotation = (Driver.Rotation);
                }
            }
        }
Beispiel #2
0
        public override Job JobOnThing(Pawn pawn, Thing t)
        {
            Vehicle_Cart cart = null;

            if (!HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t))
            {
                return(null);
            }

            // Vehicle selection

            if (ToolsForHaulUtility.IsDriver(pawn))
            {
                cart = ToolsForHaulUtility.GetCartByDriver(pawn);

                if (cart == null)
                {
                    //  JobFailReason.Is("Can't haul with military vehicle");
                    return(ToolsForHaulUtility.DismountInBase(pawn, MapComponent_ToolsForHaul.currentVehicle[pawn]));
                }
            }


            if (cart == null)
            {
                cart = RightTools.GetRightVehicle(pawn, WorkTypeDefOf.Hauling, t) as Vehicle_Cart;

                if (cart == null)
                {
                    return(null);
                }
            }



            if (cart.IsBurning())
            {
                JobFailReason.Is(ToolsForHaulUtility.BurningLowerTrans);
                return(null);
            }

            if (!cart.allowances.Allows(t))
            {
                JobFailReason.Is("Cart does not allow that thing");
                return(null);
            }

            if (ListerHaulables.ThingsPotentiallyNeedingHauling().Count == 0 && cart.storage.Count == 0)
            {
                JobFailReason.Is("NoHaulable".Translate());
                return(null);
            }

            if (Find.SlotGroupManager.AllGroupsListInPriorityOrder.Count == 0)
            {
                JobFailReason.Is(ToolsForHaulUtility.NoEmptyPlaceLowerTrans);
                return(null);
            }

            if (ToolsForHaulUtility.AvailableAnimalCart(cart) || ToolsForHaulUtility.AvailableVehicle(pawn, cart))
            {
                return(ToolsForHaulUtility.HaulWithTools(pawn, cart, t));
            }
            JobFailReason.Is(ToolsForHaulUtility.NoAvailableCart);
            return(null);
        }