Ejemplo n.º 1
0
        // ==================================

        /// <summary>
        ///
        /// </summary>
        public override void Tick()
        {
            if (!instantiated)
            {
                //foreach (Thing thing in GetContainer())
                //{
                //    thing.holder.owner = this;
                //}

                currentDriverSpeed = VehicleSpeed;
                instantiated       = true;
            }

            base.Tick();

            #region Headlights
#if Headlights
            {
                if (Find.GlowGrid.GameGlowAt(Position - Rotation.FacingCell - Rotation.FacingCell) < 0.4f)
                {
                    // TODO Add headlights to xml & move the flooder initialization to mountableComp
                    if (mountableComp.Driver != null && !compVehicles.AnimalsCanDrive() && flooder == null)
                    {
                        flooder = new HeadLights(Position, Rotation, this);
                        CustomGlowFloodManager.RegisterFlooder(flooder);
                        CustomGlowFloodManager.RefreshGlowFlooders();
                    }
                    if (mountableComp.Driver == null && flooder != null)
                    {
                        flooder.Clear();
                        CustomGlowFloodManager.DeRegisterGlower(flooder);
                        CustomGlowFloodManager.RefreshGlowFlooders();
                        flooder = null;
                    }
                    // TODO optimized performance, lights only at night and when driver is mounted => light switch gizmo?
                    if (flooder != null)
                    {
                        flooder.Position    = Position + Rotation.FacingCell + Rotation.FacingCell;
                        flooder.Orientation = Rotation;
                        flooder.Clear();
                        flooder.CalculateGlowFlood();
                    }
                }
                if (mountableComp.Driver == null && flooder != null || flooder != null)
                {
                    CustomGlowFloodManager.DeRegisterGlower(flooder);
                    CustomGlowFloodManager.RefreshGlowFlooders();
                    flooder = null;
                }
            }
#endif
            #endregion

            if (mountableComp.IsMounted)
            {
                if (refuelableComp != null)
                {
                    if (mountableComp.Driver.Faction != Faction.OfPlayer)
                    {
                        if (!fueledByAI)
                        {
                            if (refuelableComp.FuelPercent < 0.550000011920929)
                            {
                                refuelableComp.Refuel(
                                    ThingMaker.MakeThing(refuelableComp.Props.fuelFilter.AllowedThingDefs.FirstOrDefault()));
                            }
                            else
                            {
                                fueledByAI = true;
                            }
                        }
                    }
                }

                if (mountableComp.Driver.pather.Moving) // || mountableComp.Driver.drafter.pawn.pather.Moving)
                {
                    if (!mountableComp.Driver.stances.FullBodyBusy && axlesComp.HasAxles())
                    {
                        wheelRotation += currentDriverSpeed / 3f;
                        tick_time     += 0.01f * currentDriverSpeed / 5f;
                    }

                    if (mountableComp.Driver.Position.AdjacentTo8WayOrInside(mountableComp.Driver.pather.Destination.Cell) && axlesComp.HasAxles())
                    {
                        // Make the breaks sound once and throw some dust if Driver comes to his destination
                        if (!soundPlayed)
                        {
                            SoundDef.Named("VehicleATV_Ambience_Break").PlayOneShot(mountableComp.Driver.Position);
                            MoteMaker.ThrowDustPuff(DrawPos, 0.8f);
                            soundPlayed = true;
                        }
                    }
                    else
                    {
                        soundPlayed = false;
                    }

                    // TODO  move all variables like smoke amount and break sound to xml etc.
                    if (Find.TerrainGrid.TerrainAt(DrawPos.ToIntVec3()).takeFootprints || Find.SnowGrid.GetDepth(DrawPos.ToIntVec3()) > 0.2f)
                    {
                        if (vehicleComp.LeaveTrail())
                        {
                            Vector3 normalized = (DrawPos - _lastFootprintPlacePos).normalized;
                            float   rot        = normalized.AngleFlat();
                            Vector3 loc        = DrawPos + TrailOffset;

                            if ((loc - _lastFootprintPlacePos).MagnitudeHorizontalSquared() > FootprintIntervalDist)
                            {
                                if (loc.ShouldSpawnMotesAt() && !MoteCounter.SaturatedLowPriority)
                                {
                                    MoteThrown moteThrown =
                                        (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("Mote_Trail_ATV"));
                                    moteThrown.exactRotation = rot;
                                    moteThrown.exactPosition = loc;
                                    GenSpawn.Spawn(moteThrown, loc.ToIntVec3());
                                    _lastFootprintPlacePos = DrawPos;
                                }
                            }
                        }
                        if (axlesComp.HasAxles())
                        {
                            MoteMaker.ThrowDustPuff(DrawPos + DustOffset, 0.15f + Mathf.InverseLerp(0, 50, currentDriverSpeed) * 0.6f);
                        }
                        else
                        {
                            MoteMaker.ThrowDustPuff(DrawPos + DustOffset, 0.15f + Mathf.InverseLerp(0, 50, VehicleSpeed) * 0.6f);
                        }
                    }
                }



                //Exhaustion fumes - basic
                // only fumes on vehicles with combustion and no animals driving
                if (!vehicleComp.MotorizedWithoutFuel() && !vehicleComp.AnimalsCanDrive())
                {
                    MoteMaker.ThrowSmoke(DrawPos + FumesOffset, 0.05f + currentDriverSpeed * 0.01f);
                }

                if (Find.TickManager.TicksGame - tickCheck >= tickCooldown)
                {
                    if (mountableComp.Driver.pather.Moving)
                    {
                        if (!mountableComp.Driver.stances.FullBodyBusy)
                        {
                            if (refuelableComp != null)
                            {
                                refuelableComp.Notify_UsedThisTick();
                            }
                            damagetick -= 1;

                            if (axlesComp.HasAxles())
                            {
                                currentDriverSpeed = ToolsForHaulUtility.GetMoveSpeed(mountableComp.Driver);
                            }
                        }
                        if (breakdownableComp != null && breakdownableComp.BrokenDown ||
                            refuelableComp != null && !refuelableComp.HasFuel)
                        {
                            VehicleSpeed = 0.75f;
                        }
                        else
                        {
                            VehicleSpeed = DesiredSpeed;
                        }
                        tickCheck = Find.TickManager.TicksGame;
                    }

                    if (Position.InNoBuildEdgeArea() && despawnAtEdge && Spawned && (mountableComp.Driver.Faction != Faction.OfPlayer || mountableComp.Driver.MentalState.def == MentalStateDefOf.PanicFlee))
                    {
                        DeSpawn();
                    }
                }
            }

            //if (Find.TickManager.TicksGame >= damagetick)
            //{
            //    TakeDamage(new DamageInfo(DamageDefOf.Deterioration, 1, null, null, null));
            //    damagetick = Find.TickManager.TicksGame + 3600;
            //}

            if (vehicleComp.tankLeaking)
            {
                if (Find.TickManager.TicksGame > _tankSpillTick)
                {
                    if (refuelableComp.FuelPercent > _tankHitPos)
                    {
                        refuelableComp.ConsumeFuel(0.15f);

                        FilthMaker.MakeFilth(Position, fuelDefName, LabelCap);
                        _tankSpillTick = Find.TickManager.TicksGame + 15;
                    }
                }
            }
        }