-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LanguageData> | ||
<Autarky_chemicalsFullness>Chemicals fullness</Autarky_chemicalsFullness> | ||
<Autarky_UnsafeStorageTemperature>Unsafe storage temperature!</Autarky_UnsafeStorageTemperature> | ||
</LanguageData> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LanguageData> | ||
<Autarky_chemicalsFullness>Chemikalienfüllstand</Autarky_chemicalsFullness> | ||
<Autarky_UnsafeStorageTemperature>Unsichere Lagertemperatur!</Autarky_UnsafeStorageTemperature> | ||
</LanguageData> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Verse; | ||
using RimWorld; | ||
|
||
namespace Autarky | ||
{ | ||
public class CompProperties_TempExplosive : CompProperties | ||
{ | ||
// | ||
// Fields | ||
// | ||
public float explosiveRadius = 1.9f; | ||
|
||
public float explosiveExpandPerStackcount; | ||
|
||
public EffecterDef explosionEffect; | ||
|
||
public DamageDef startWickOnDamageTaken; | ||
|
||
public float startWickHitPointsPercent = 0.2f; | ||
|
||
public IntRange wickTicks = new IntRange (140, 150); | ||
|
||
public float wickScale = 1f; | ||
|
||
public float chanceNeverExplodeFromDamage; | ||
|
||
public int preExplosionSpawnThingCount = 1; | ||
|
||
public DamageDef explosiveDamageType = DamageDefOf.Bomb; | ||
|
||
public ThingDef postExplosionSpawnThingDef; | ||
|
||
public float postExplosionSpawnChance; | ||
|
||
public int postExplosionSpawnThingCount = 1; | ||
|
||
public bool applyDamageToExplosionCellsNeighbors; | ||
|
||
public ThingDef preExplosionSpawnThingDef; | ||
|
||
public float preExplosionSpawnChance; | ||
|
||
public float maxSafeTemperature = 60f; | ||
|
||
public float maxSafeTempFactor = 0.01f; | ||
|
||
// | ||
// Constructors | ||
// | ||
public CompProperties_TempExplosive () | ||
{ | ||
this.compClass = typeof(CompTempExplosive); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
using UnityEngine; | ||
using Verse; | ||
using Verse.Sound; | ||
using RimWorld; | ||
|
||
namespace Autarky | ||
{ | ||
public class CompTempExplosive : ThingComp | ||
{ | ||
// | ||
// Static Fields | ||
// | ||
public const string UnsafeTempSignal = "Autarky_UnsafeStorageTemperature"; | ||
|
||
// | ||
// Fields | ||
// | ||
public bool wickStarted; | ||
|
||
protected Sustainer wickSoundSustainer; | ||
|
||
public bool detonated; | ||
|
||
private Thing instigator; | ||
|
||
protected int wickTicksLeft; | ||
|
||
// | ||
// Properties | ||
// | ||
private bool CanEverExplodeFromDamage { | ||
get { | ||
if (this.Props.chanceNeverExplodeFromDamage < 1E-05f) { | ||
return true; | ||
} | ||
Rand.PushState (); | ||
Rand.Seed = this.parent.thingIDNumber.GetHashCode() + (Find.TickManager.TicksGame % 7919); | ||
bool result = Rand.Value < this.Props.chanceNeverExplodeFromDamage; | ||
Rand.PopState (); | ||
return result; | ||
} | ||
} | ||
|
||
public CompProperties_TempExplosive Props { | ||
get { | ||
return (CompProperties_TempExplosive)this.props; | ||
} | ||
} | ||
|
||
protected int StartWickThreshold { | ||
get { | ||
return Mathf.RoundToInt (this.Props.startWickHitPointsPercent * (float)this.parent.MaxHitPoints); | ||
} | ||
} | ||
|
||
// | ||
// Methods | ||
// | ||
public override void CompTick () | ||
{ | ||
if (this.wickStarted) | ||
{ | ||
if (this.wickSoundSustainer == null) | ||
{ | ||
this.StartWickSustainer(); | ||
} | ||
else | ||
{ | ||
this.wickSoundSustainer.Maintain(); | ||
} | ||
this.wickTicksLeft--; | ||
if (this.wickTicksLeft <= 0) | ||
{ | ||
this.Detonate(this.parent.MapHeld); | ||
} | ||
} | ||
else | ||
{ | ||
float ambientTemperature = this.parent.AmbientTemperature; | ||
float maxSafeTemperature = this.Props.maxSafeTemperature; | ||
if (ambientTemperature > maxSafeTemperature) | ||
{ | ||
Rand.PushState(); | ||
Rand.Seed = this.parent.thingIDNumber.GetHashCode() + (Find.TickManager.TicksGame % 7919); | ||
bool selfIgnite = Rand.Value < Mathf.Pow((ambientTemperature - maxSafeTemperature), 2.71828f) * | ||
this.Props.maxSafeTempFactor; | ||
Rand.PopState(); | ||
if (selfIgnite) | ||
{ | ||
this.StartWick(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public override string CompInspectStringExtra() | ||
{ | ||
if (this.parent.AmbientTemperature > this.Props.maxSafeTemperature) | ||
{ | ||
return UnsafeTempSignal.Translate(); | ||
} | ||
return null; | ||
} | ||
|
||
protected void Detonate (Map map) | ||
{ | ||
if (this.detonated) { | ||
return; | ||
} | ||
this.detonated = true; | ||
if (!this.parent.SpawnedOrAnyParentSpawned) { | ||
return; | ||
} | ||
if (map == null) { | ||
Log.Warning ("Tried to detonate CompExplosive in a null map."); | ||
return; | ||
} | ||
CompProperties_TempExplosive props = this.Props; | ||
float num = props.explosiveRadius; | ||
if (this.parent.stackCount > 1 && props.explosiveExpandPerStackcount > 0f) { | ||
num += Mathf.Sqrt ((float)(this.parent.stackCount - 1) * props.explosiveExpandPerStackcount); | ||
} | ||
if (props.explosionEffect != null) { | ||
Effecter effecter = props.explosionEffect.Spawn (); | ||
effecter.Trigger (new TargetInfo (this.parent.PositionHeld, map, false), | ||
new TargetInfo (this.parent.PositionHeld, map, false)); | ||
effecter.Cleanup (); | ||
} | ||
ThingDef postExplosionSpawnThingDef = props.postExplosionSpawnThingDef; | ||
float postExplosionSpawnChance = props.postExplosionSpawnChance; | ||
int postExplosionSpawnThingCount = props.postExplosionSpawnThingCount; | ||
GenExplosion.DoExplosion (this.parent.PositionHeld, map, num, props.explosiveDamageType, | ||
this.instigator ?? this.parent, null, null, null, postExplosionSpawnThingDef, | ||
postExplosionSpawnChance, postExplosionSpawnThingCount, | ||
props.applyDamageToExplosionCellsNeighbors, props.preExplosionSpawnThingDef, | ||
props.preExplosionSpawnChance, props.preExplosionSpawnThingCount); | ||
if (!this.parent.Destroyed) | ||
{ | ||
this.parent.Kill(null); | ||
} | ||
} | ||
|
||
public override void PostDraw () | ||
{ | ||
if (this.wickStarted) { | ||
this.parent.Map.overlayDrawer.DrawOverlay (this.parent, OverlayTypes.BurningWick); | ||
} | ||
} | ||
|
||
public override void PostExposeData () | ||
{ | ||
base.PostExposeData (); | ||
Scribe_References.Look<Thing> (ref this.instigator, "instigator", false); | ||
Scribe_Values.Look<bool> (ref this.wickStarted, "wickStarted", false, false); | ||
Scribe_Values.Look<int> (ref this.wickTicksLeft, "wickTicksLeft", 0, false); | ||
Scribe_Values.Look<bool> (ref this.detonated, "detonated", false, false); | ||
} | ||
|
||
public override void PostPostApplyDamage (DamageInfo dinfo, float totalDamageDealt) | ||
{ | ||
if (!this.CanEverExplodeFromDamage) { | ||
return; | ||
} | ||
if (!this.parent.Destroyed) { | ||
if (this.wickStarted && dinfo.Def == DamageDefOf.Extinguish) { | ||
this.StopWick (); | ||
} | ||
else if (!this.wickStarted && this.parent.HitPoints <= this.StartWickThreshold) { | ||
this.StartWick (dinfo.Instigator); | ||
} | ||
} | ||
} | ||
|
||
public override void PostPreApplyDamage (DamageInfo dinfo, out bool absorbed) | ||
{ | ||
absorbed = false; | ||
if (this.CanEverExplodeFromDamage) { | ||
if (dinfo.Def.externalViolence && dinfo.Amount >= this.parent.HitPoints) { | ||
if (this.parent.MapHeld != null) { | ||
this.Detonate (this.parent.MapHeld); | ||
absorbed = true; | ||
} | ||
} | ||
else if (!this.wickStarted && this.Props.startWickOnDamageTaken != null && | ||
dinfo.Def == this.Props.startWickOnDamageTaken) { | ||
this.StartWick (dinfo.Instigator); | ||
} | ||
} | ||
} | ||
|
||
public void StartWick (Thing instigator = null) | ||
{ | ||
if (this.wickStarted) { | ||
return; | ||
} | ||
this.instigator = instigator; | ||
this.wickStarted = true; | ||
this.wickTicksLeft = this.Props.wickTicks.RandomInRange; | ||
this.StartWickSustainer (); | ||
GenExplosion.NotifyNearbyPawnsOfDangerousExplosive (this.parent, this.Props.explosiveDamageType, null); | ||
} | ||
|
||
private void StartWickSustainer () | ||
{ | ||
SoundDefOf.MetalHitImportant.PlayOneShot (new TargetInfo (this.parent.Position, this.parent.Map, false)); | ||
SoundInfo info = SoundInfo.InMap (this.parent, MaintenanceType.PerTick); | ||
this.wickSoundSustainer = SoundDefOf.HissSmall.TrySpawnSustainer (info); | ||
} | ||
|
||
public void StopWick () | ||
{ | ||
this.wickStarted = false; | ||
this.instigator = null; | ||
} | ||
} | ||
} |