public static void ThrowSmokeRed(Vector3 loc, float size) { if (!loc.ShouldSpawnMotesAt() || MoteCounter.SaturatedLowPriority) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("Mote_SmokeRed"), null); moteThrown.ScaleUniform = Rand.Range(1.5f, 2.5f) * size; moteThrown.exactRotationRate = Rand.Range(-0.5f, 0.5f); moteThrown.exactPosition = loc; moteThrown.SetVelocityAngleSpeed((float)Rand.Range(30, 40), Rand.Range(0.008f, 0.012f)); GenSpawn.Spawn(moteThrown, loc.ToIntVec3()); }
public static void ThrowLightningGlowGreen(Vector3 loc, float size) { if (!loc.ShouldSpawnMotesAt()) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(DefDatabase<ThingDef>.GetNamed("Mote_LightningGlowGreen", true), null); moteThrown.ScaleUniform = 6f * size; moteThrown.exactRotationRate = 0f; moteThrown.exactPosition = loc; moteThrown.exactPosition += new Vector3(0.5f, 0f, 0.5f); //moteThrown.SetVelocityAngleSpeed((float)Rand.Range(0, 0), Rand.Range(0.0002f, 0.0002f)); GenSpawn.Spawn(moteThrown, loc.ToIntVec3()); }
public static void ThrowMicroSparksRed(Vector3 loc) { if (!loc.ShouldSpawnMotesAt() || MoteCounter.Saturated) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("Mote_MicroSparksRed"), null); moteThrown.ScaleUniform = Rand.Range(0.8f, 1.2f); moteThrown.exactRotationRate = Rand.Range(-0.2f, 0.2f); moteThrown.exactPosition = loc; moteThrown.exactPosition -= new Vector3(0.5f, 0f, 0.5f); moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value); moteThrown.SetVelocityAngleSpeed((float)Rand.Range(35, 45), Rand.Range(0.02f, 0.02f)); GenSpawn.Spawn(moteThrown, loc.ToIntVec3()); }
public static void ThrowDustPuff(Vector3 loc, Map map, float scale, ThingDef def = null, Color?color = null) { if (!loc.ShouldSpawnMotesAt(map)) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(def ?? ThingDefOf.Mote_DustPuff, null); moteThrown.Scale = 1.9f * scale; moteThrown.rotationRate = (float)Rand.Range(-60, 60); moteThrown.exactPosition = loc; moteThrown.SetVelocity((float)Rand.Range(0, 360), Rand.Range(0.6f, 0.75f)); if (color.HasValue) { moteThrown.instanceColor = color.Value; // moteThrown.instanceColor = new Color(0.368f, 0f, 1f); } GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish); }
public void ThrowSparks(Vector3 loc, Map map) { if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority) { return; } for (int i = 0; i < 3; i++) { MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_MicroSparks, null); moteThrown.Scale = Rand.Range(2.5f, 3f); moteThrown.rotationRate = Rand.Range(-12f, 12f); moteThrown.exactPosition = loc; moteThrown.exactPosition -= new Vector3(0.5f, 0f, 0.5f); moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value); moteThrown.SetVelocity((float)Rand.Range(7 * (i + 1), 10 * (i + 1)), 2f); GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish); } MoteMaker.ThrowLightningGlow(this.parent.Position.ToVector3(), this.parent.Map, 6f); }
public static void ThrowPawnEffectMote(Vector3 loc, Map map, ThingDef moteDef, bool rotation = true) { if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef, null); moteThrown.Scale = Rand.Range(0.5f, 1.2f); if (rotation) { moteThrown.rotationRate = Rand.Range(-12f, 36f); } moteThrown.exactPosition = loc; moteThrown.exactPosition -= new Vector3(0.5f, 0f, 0.5f); moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value); moteThrown.SetVelocity(Rand.Range(35, 45), 1.2f); GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map); }
public static void ThrowHeatGlow(IntVec3 c, Map map, float size) { Vector3 vector = c.ToVector3Shifted(); if (!vector.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority) { return; } vector += size * new Vector3(Rand.Value - 0.5f, 0f, Rand.Value - 0.5f); if (!vector.InBounds(map)) { return; } MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_HeatGlow, null); moteThrown.Scale = Rand.Range(4f, 6f) * size; moteThrown.rotationRate = Rand.Range(-3f, 3f); moteThrown.exactPosition = vector; moteThrown.SetVelocity((float)Rand.Range(0, 360), 0.12f); GenSpawn.Spawn(moteThrown, vector.ToIntVec3(), map, WipeMode.Vanish); }
public void Impact(Thing thing, Thing hitThing = null) { Map map = thing.Map; Vector3 pos = thing.DrawPos; if (!pos.ShouldSpawnMotesAt(map)) { return; } if (Impact(thing, map, hitThing)) { return; } if (enabled_CombatExtended) { if (ImpactCE(thing, map, hitThing)) { return; } } }
public override void CompTick() { base.CompTick(); if (Find.TickManager.TicksGame % frequency == 0) { // Only throw motes if the location is rendered and valid if (!pPos.ShouldSpawnMotesAt(pMap) || pMap.moteCounter.SaturatedLowPriority) { return; } // only throw motes if it's powered if (refuelableComp != null && !refuelableComp.HasFuel) { return; } // only throw motes when in use, if requested if (Props.produceSmokeOnlyWhenUsed) { if (!parent.def.hasInteractionCell || !IsBeingUsed()) { return; } } // Assign a new random frequency frequency = Rand.RangeInclusive(Props.frequencyMin, Props.frequencyMax); if (Props.smokeStyle == SmokeStyle.Single) { ThrowSmokeSingle(); } if (Props.smokeStyle == SmokeStyle.Triple) { ThrowSmokeTriple(); } } }
public static Mote MakeStaticMote(Vector3 loc, Map map, ThingDef moteDef, float scale = 1f, Color?color = null, float?exactRotation = null) { if (!loc.ShouldSpawnMotesAt(map)) { return(null); } Mote moteThrown = (Mote)ThingMaker.MakeThing(moteDef, null); moteThrown.exactPosition = loc; moteThrown.Scale = scale; if (color.HasValue) { moteThrown.instanceColor = color.Value; // moteThrown.instanceColor = new Color(0.368f, 0f, 1f); } if (exactRotation.HasValue) { moteThrown.exactRotation += exactRotation.Value; } GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish); return(moteThrown); }
public static void ThrowToxicSmoke(Vector3 loc, Map map, Color?color = null) { if (!loc.ShouldSpawnMotesAt(map)) { return; } //moteThrown.instanceColor = new ColorInt(43, 56, 54).ToColor; // to investigate //moteThrown.Scale = Rand.Range(2.5f, 3.9f); to investigate MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_Smoke, null); moteThrown.Scale = Rand.Range(0.5f, 0.9f); moteThrown.rotationRate = Rand.Range(-30f, 30f); moteThrown.exactPosition = loc; moteThrown.airTimeLeft = Rand.Range(0.1f, 0.4f); moteThrown.Speed = 0.3f; moteThrown.SetVelocity((float)Rand.Range(-20, 20), Rand.Range(0.5f, 0.7f)); if (color.HasValue) { moteThrown.instanceColor = color.Value; // moteThrown.instanceColor = new Color(0f, 0.0862f, 0.094117f); } GenSpawn.Spawn(moteThrown, IntVec3Utility.ToIntVec3(loc), map, WipeMode.Vanish); }
// edited public static void ThrowSmoke(Vector3 loc, float size, Map map, FleckDef def = null, Color?color = null, float?exactRotation = null) { bool flag = !loc.ShouldSpawnMotesAt(map); if (!flag) { FleckCreationData data = AdeptusFleckMaker.GetDataStatic(loc, map, def ?? FleckDefOf.Smoke, Rand.Range(1.5f, 2.5f) * size); data.rotationRate = Rand.Range(-30f, 30f); data.velocityAngle = (float)Rand.Range(30, 40); data.spawnPosition = loc; data.velocitySpeed = Rand.Range(0.5f, 0.7f); if (color.HasValue) { data.instanceColor = color.Value; // moteThrown.instanceColor = new Color(0.368f, 0f, 1f); } if (exactRotation.HasValue) { data.rotation += exactRotation.Value; } map.flecks.CreateFleck(data); } }
protected void MakeMote(TargetInfo A, TargetInfo B) { Vector3 vector = Vector3.zero; switch (def.spawnLocType) { case MoteSpawnLocType.OnSource: vector = A.CenterVector3; break; case MoteSpawnLocType.BetweenPositions: { Vector3 vector2 = A.HasThing ? A.Thing.DrawPos : A.Cell.ToVector3Shifted(); Vector3 vector3 = B.HasThing ? B.Thing.DrawPos : B.Cell.ToVector3Shifted(); vector = ((A.HasThing && !A.Thing.Spawned) ? vector3 : ((!B.HasThing || B.Thing.Spawned) ? (vector2 * def.positionLerpFactor + vector3 * (1f - def.positionLerpFactor)) : vector2)); break; } case MoteSpawnLocType.RandomCellOnTarget: vector = ((!B.HasThing) ? CellRect.CenteredOn(B.Cell, 0) : B.Thing.OccupiedRect()).RandomCell.ToVector3Shifted(); break; case MoteSpawnLocType.BetweenTouchingCells: vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f; break; } if (parent != null) { Rand.PushState(parent.GetHashCode()); if (A.CenterVector3 != B.CenterVector3) { vector += (B.CenterVector3 - A.CenterVector3).normalized * parent.def.offsetTowardsTarget.RandomInRange; } vector += Gen.RandomHorizontalVector(parent.def.positionRadius); Rand.PopState(); } Map map = A.Map ?? B.Map; float num = def.absoluteAngle ? 0f : (B.Cell - A.Cell).AngleFlat; if (map == null || !vector.ShouldSpawnMotesAt(map)) { return; } int randomInRange = def.burstCount.RandomInRange; for (int i = 0; i < randomInRange; i++) { Mote obj = (Mote)ThingMaker.MakeThing(def.moteDef); GenSpawn.Spawn(obj, vector.ToIntVec3(), map); obj.Scale = def.scale.RandomInRange; obj.exactPosition = vector + Gen.RandomHorizontalVector(def.positionRadius); obj.rotationRate = def.rotationRate.RandomInRange; obj.exactRotation = def.rotation.RandomInRange + num; obj.instanceColor = def.color; MoteThrown moteThrown = obj as MoteThrown; if (moteThrown != null) { moteThrown.airTimeLeft = def.airTime.RandomInRange; moteThrown.SetVelocity(def.angle.RandomInRange + num, def.speed.RandomInRange); } } }
protected void MakeMote(TargetInfo A, TargetInfo B) { Vector3 vector = Vector3.zero; switch (this.def.spawnLocType) { case MoteSpawnLocType.OnSource: vector = A.CenterVector3; break; case MoteSpawnLocType.BetweenPositions: { Vector3 vector2 = (!A.HasThing) ? A.Cell.ToVector3Shifted() : A.Thing.DrawPos; Vector3 vector3 = (!B.HasThing) ? B.Cell.ToVector3Shifted() : B.Thing.DrawPos; if (A.HasThing && !A.Thing.Spawned) { vector = vector3; } else if (B.HasThing && !B.Thing.Spawned) { vector = vector2; } else { vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor); } break; } case MoteSpawnLocType.BetweenTouchingCells: vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f; break; case MoteSpawnLocType.RandomCellOnTarget: { CellRect cellRect; if (B.HasThing) { cellRect = B.Thing.OccupiedRect(); } else { cellRect = CellRect.CenteredOn(B.Cell, 0); } vector = cellRect.RandomCell.ToVector3Shifted(); break; } } if (this.parent != null) { Rand.PushState(this.parent.GetHashCode()); if (A.CenterVector3 != B.CenterVector3) { vector += (B.CenterVector3 - A.CenterVector3).normalized * this.parent.def.offsetTowardsTarget.RandomInRange; } vector += Gen.RandomHorizontalVector(this.parent.def.positionRadius); Rand.PopState(); } Map map = A.Map ?? B.Map; float num = (!this.def.absoluteAngle) ? (B.Cell - A.Cell).AngleFlat : 0f; if (map != null && vector.ShouldSpawnMotesAt(map)) { int randomInRange = this.def.burstCount.RandomInRange; for (int i = 0; i < randomInRange; i++) { Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null); GenSpawn.Spawn(mote, vector.ToIntVec3(), map, WipeMode.Vanish); mote.Scale = this.def.scale.RandomInRange; mote.exactPosition = vector + Gen.RandomHorizontalVector(this.def.positionRadius); mote.rotationRate = this.def.rotationRate.RandomInRange; mote.exactRotation = this.def.rotation.RandomInRange + num; MoteThrown moteThrown = mote as MoteThrown; if (moteThrown != null) { moteThrown.airTimeLeft = this.def.airTime.RandomInRange; moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange); } } } }
// ================================== /// <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; } } } }
public void ThrowMote(Vector3 loc, Map map, ThingDef explosionMoteDef, Color color, SoundDef sound, Thing hitThing = null) { ThingDef explosionmoteDef = explosionMoteDef; ThingDef ImpactMoteDef = DefDatabase <ThingDef> .GetNamedSilentFail(this.ImpactMoteDef) ?? null; ThingDef ImpactGlowMoteDef = DefDatabase <ThingDef> .GetNamedSilentFail(this.ImpactGlowMoteDef) ?? null; float explosionSize = this.explosionMoteSize; float ImpactMoteSize = this.ImpactMoteSizeRange?.RandomInRange ?? this.ImpactMoteSize; float ImpactGlowMoteSize = this.ImpactGlowMoteSizeRange?.RandomInRange ?? this.ImpactGlowMoteSize; if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority) { return; } Rand.PushState(); float rotationRate = Rand.Range(-30f, 30f); float VelocityAngel = (float)Rand.Range(0, 360); float VelocitySpeed = Rand.Range(0.48f, 0.72f); Rand.PopState(); if (ImpactGlowMoteDef != null) { MoteMaker.MakeStaticMote(loc, map, ImpactGlowMoteDef, ImpactGlowMoteSize); } if (explosionMote) { if (!this.explosionMoteDef.NullOrEmpty()) { ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(this.explosionMoteDef); if (def != null) { explosionmoteDef = def; } } if (explosionmoteDef != null) { MoteThrown moteThrown; moteThrown = (MoteThrown)ThingMaker.MakeThing(explosionmoteDef, null); moteThrown.Scale = explosionSize; Rand.PushState(); moteThrown.rotationRate = Rand.Range(-30f, 30f); Rand.PopState(); moteThrown.exactPosition = loc; moteThrown.instanceColor = color; moteThrown.SetVelocity(VelocityAngel, VelocitySpeed); GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish); } } if (ImpactMoteDef != null) { if (hitThing != null && hitThing is Pawn pawn) { ImpactMoteDef = ThingDef.Named("Mote_BloodPuff"); if (sound != null) { sound.PlayOneShot(new TargetInfo(loc.ToIntVec3(), map, false)); } MoteThrown moteThrown; moteThrown = (MoteThrown)ThingMaker.MakeThing(ImpactMoteDef, null); moteThrown.Scale = ImpactMoteSize; Rand.PushState(); moteThrown.rotationRate = Rand.Range(-30f, 30f); Rand.PopState(); moteThrown.exactPosition = loc; moteThrown.instanceColor = pawn.RaceProps.BloodDef.graphic.color; moteThrown.SetVelocity(VelocityAngel, VelocitySpeed); GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish); if (explosionEffecter != null) { TriggerEffect(explosionEffecter, loc, map, hitThing); } } else { if (explosionEffecter != null) { TriggerEffect(explosionEffecter, loc, map); } MoteMaker.MakeStaticMote(loc, map, ImpactMoteDef, ImpactMoteSize); } } }