Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Abernethy committed Jul 19, 2017
2 parents dfa3ef5 + ba2cf9f commit 8da1cb4
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 4 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>Autarky</name>
<author>Chais</author>
<targetVersion>0.17.0</targetVersion>
<description>V1.6
<description>V1.7
This mod adds crafting recipes for Neutroamine, Luciferium and glitterworld medicine, granting you more independence from traders. It makes Boomalopes and Boomrats more useful and requires to build a production line of drugs if you want Luciferium. Luciferium and glitterworld medicine require a lot of research.
</description>
</ModMetaData>
Binary file modified Assemblies/Autarky.dll
Binary file not shown.
12 changes: 9 additions & 3 deletions Defs/ThingDefs/Items_Resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<defName>Autarky_VolatileChemicals</defName>
<label>volatile chemicals</label>
<description>A volatile cocktail of chemicals harvested from Boomalopes or Boomrats. Required, amongst other things, to synthesise Neutroamine. Highly flammable!</description>
<tickerType>Normal</tickerType>
<graphicData>
<texPath>Things/Item/Resource/Chemicals</texPath>
<graphicClass>Graphic_Single</graphicClass>
Expand All @@ -20,13 +21,18 @@
<li>ResourcesRaw</li>
</thingCategories>
<comps>
<li Class="Autarky.CompProperties_Explosive">
<li Class="Autarky.CompProperties_TempExplosive">
<explosiveRadius>1.1</explosiveRadius>
<explosiveDamageType>Flame</explosiveDamageType>
<explosiveExpandPerStackcount>0.173</explosiveExpandPerStackcount>
<startWickOnDamageTaken>Flame</startWickOnDamageTaken>
<startWickHitPointsPercent>0.2</startWickHitPointsPercent>
<chanceNeverExplodeFromDamage>0.5</chanceNeverExplodeFromDamage>
<maxSafeTemperature>45</maxSafeTemperature>
<maxSafeTempFactor>0.00001</maxSafeTempFactor>
<wickTicks>
<min>1</min>
<max>3</max>
<min>110</min>
<max>250</max>
</wickTicks>
</li>
</comps>
Expand Down
1 change: 1 addition & 0 deletions Languages/English/Keyed/Misc_Gameplay.xml
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>
1 change: 1 addition & 0 deletions Languages/German/Keyed/Misc_Gameplay.xml
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>
55 changes: 55 additions & 0 deletions Source/CompProperties_TempExplosive.cs
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);
}
}
}
216 changes: 216 additions & 0 deletions Source/CompTempExplosive.cs
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;
}
}
}

0 comments on commit 8da1cb4

Please sign in to comment.