public override void PostPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
 {
     base.PostPostApplyDamage(dinfo, totalDamageDealt);
     if (IsMounted)
     {
         if (parent.TryGetComp <CompExplosive>() != null && parent.TryGetComp <CompExplosive>().wickStarted)
         {
             if (Rand.Value >= 0.1f)
             {
                 DismountAt((Driver.Position - InteractionOffset.ToIntVec3()).RandomAdjacentCell8Way());
             }
         }
         //if (tankLeaking)
         //{
         //    if (hitpointsPercent < 0.2f * Rand.Range(0.5f, 1f))
         //    {
         //        if (!mountableComp.Driver.Position.InBounds())
         //        {
         //            mountableComp.DismountAt(mountableComp.Driver.Position);
         //            FireUtility.TryStartFireIn(Position, 0.1f);
         //            return;
         //        }
         //        mountableComp.DismountAt(mountableComp.Driver.Position - mountableComp.InteractionOffset.ToIntVec3());
         //        mountableComp.Driver.Position = mountableComp.Driver.Position.RandomAdjacentCell8Way();
         //        FireUtility.TryStartFireIn(Position, 0.1f);
         //
         //        return;
         //    }
         //}
     }
 }
        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);
                }
            }
        }