Esempio n. 1
0
 public void UsedThisTick()
 {
     if (refuelableComp != null)
     {
         refuelableComp.Notify_UsedThisTick();
     }
 }
        public override void Tick()
        {
            base.Tick();

            if (!Empty && !Finished)
            {
                if (fuelComp.HasFuel)
                {
                    // The smoker has stored food and fuel
                    Progress = Mathf.Min(Progress + ProgressPerTickAtCurrentTemp, 1f);
                    fuelComp.Notify_UsedThisTick();
                    // Throw smoke manually
                    if (this.IsHashIntervalTick(smokeTimer))
                    {
                        smokeTimer = Rand.RangeInclusive(120, 360);
                        smokerComp.ThrowSmokeSingle();
                    }
                }
                else
                {
                    // Simulate rotting from the food being left uncooked
                    Progress = Mathf.Max(Progress - ProgressPerTickAtCurrentTemp, 0.0f);
                    rottingTicks++;
                }
                ticksSinceTending++;
            }
            else
            {
                ticksSinceTending = 0;
            }

            if (this.IsHashIntervalTick(250))
            {
                // Rot the food if it has been left uncooked for too long
                // This prevents players from using the smoker to store food indefinitely until needed
                if (rottingTicks >= GenDate.TicksPerDay)
                {
                    Reset();
                    Messages.Message("MessageRottedAwayInStorage".Translate(Static.Food), this, MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Ticks, a Weighing of Benefits
 ///
 /// When you create one of these, you must pick what Tick
 ///  interval it follows. The vanilla CompRefuelable only
 ///  runs at Tick but any of these Ticks will consume the
 ///  correct amount of fuel. So choose the interval based
 ///  on how you want the machine to behave
 ///
 /// Shorter Tick duration gives you:
 ///  Good view of how much fuel is left (since it goes
 ///    down every tick)
 ///
 /// Longer Tick duration gives you:
 ///  Better performance
 ///  Much better performance if you have a lot of these
 ///
 /// </summary>
 public override void Tick()
 {
     base.Tick();
     if (flick == null || flick.SwitchIsOn)
     {
         if (power == null || power.PowerOn)
         {
             if (fuel != null)
             {
                 fuel.Notify_UsedThisTick();
                 if (fuel.HasFuel)
                 {
                     TryGenerateResource(1);
                 }
             }
             else      //fuel==null
             {
                 TryGenerateResource(1);
             }
         }
     }
 }
        // ==================================

        /// <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;
                    }
                }
            }
        }