Skip to content

Commit 8da1cb4

Browse files
author
Philip Abernethy
committed
Merge branch 'master' into release
2 parents dfa3ef5 + ba2cf9f commit 8da1cb4

File tree

7 files changed

+283
-4
lines changed

7 files changed

+283
-4
lines changed

About/About.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<name>Autarky</name>
44
<author>Chais</author>
55
<targetVersion>0.17.0</targetVersion>
6-
<description>V1.6
6+
<description>V1.7
77
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.
88
</description>
99
</ModMetaData>

Assemblies/Autarky.dll

1 KB
Binary file not shown.

Defs/ThingDefs/Items_Resource.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<defName>Autarky_VolatileChemicals</defName>
55
<label>volatile chemicals</label>
66
<description>A volatile cocktail of chemicals harvested from Boomalopes or Boomrats. Required, amongst other things, to synthesise Neutroamine. Highly flammable!</description>
7+
<tickerType>Normal</tickerType>
78
<graphicData>
89
<texPath>Things/Item/Resource/Chemicals</texPath>
910
<graphicClass>Graphic_Single</graphicClass>
@@ -20,13 +21,18 @@
2021
<li>ResourcesRaw</li>
2122
</thingCategories>
2223
<comps>
23-
<li Class="Autarky.CompProperties_Explosive">
24+
<li Class="Autarky.CompProperties_TempExplosive">
2425
<explosiveRadius>1.1</explosiveRadius>
2526
<explosiveDamageType>Flame</explosiveDamageType>
2627
<explosiveExpandPerStackcount>0.173</explosiveExpandPerStackcount>
28+
<startWickOnDamageTaken>Flame</startWickOnDamageTaken>
29+
<startWickHitPointsPercent>0.2</startWickHitPointsPercent>
30+
<chanceNeverExplodeFromDamage>0.5</chanceNeverExplodeFromDamage>
31+
<maxSafeTemperature>45</maxSafeTemperature>
32+
<maxSafeTempFactor>0.00001</maxSafeTempFactor>
2733
<wickTicks>
28-
<min>1</min>
29-
<max>3</max>
34+
<min>110</min>
35+
<max>250</max>
3036
</wickTicks>
3137
</li>
3238
</comps>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<LanguageData>
33
<Autarky_chemicalsFullness>Chemicals fullness</Autarky_chemicalsFullness>
4+
<Autarky_UnsafeStorageTemperature>Unsafe storage temperature!</Autarky_UnsafeStorageTemperature>
45
</LanguageData>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<LanguageData>
33
<Autarky_chemicalsFullness>Chemikalienfüllstand</Autarky_chemicalsFullness>
4+
<Autarky_UnsafeStorageTemperature>Unsichere Lagertemperatur!</Autarky_UnsafeStorageTemperature>
45
</LanguageData>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Verse;
2+
using RimWorld;
3+
4+
namespace Autarky
5+
{
6+
public class CompProperties_TempExplosive : CompProperties
7+
{
8+
//
9+
// Fields
10+
//
11+
public float explosiveRadius = 1.9f;
12+
13+
public float explosiveExpandPerStackcount;
14+
15+
public EffecterDef explosionEffect;
16+
17+
public DamageDef startWickOnDamageTaken;
18+
19+
public float startWickHitPointsPercent = 0.2f;
20+
21+
public IntRange wickTicks = new IntRange (140, 150);
22+
23+
public float wickScale = 1f;
24+
25+
public float chanceNeverExplodeFromDamage;
26+
27+
public int preExplosionSpawnThingCount = 1;
28+
29+
public DamageDef explosiveDamageType = DamageDefOf.Bomb;
30+
31+
public ThingDef postExplosionSpawnThingDef;
32+
33+
public float postExplosionSpawnChance;
34+
35+
public int postExplosionSpawnThingCount = 1;
36+
37+
public bool applyDamageToExplosionCellsNeighbors;
38+
39+
public ThingDef preExplosionSpawnThingDef;
40+
41+
public float preExplosionSpawnChance;
42+
43+
public float maxSafeTemperature = 60f;
44+
45+
public float maxSafeTempFactor = 0.01f;
46+
47+
//
48+
// Constructors
49+
//
50+
public CompProperties_TempExplosive ()
51+
{
52+
this.compClass = typeof(CompTempExplosive);
53+
}
54+
}
55+
}

Source/CompTempExplosive.cs

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
using UnityEngine;
2+
using Verse;
3+
using Verse.Sound;
4+
using RimWorld;
5+
6+
namespace Autarky
7+
{
8+
public class CompTempExplosive : ThingComp
9+
{
10+
//
11+
// Static Fields
12+
//
13+
public const string UnsafeTempSignal = "Autarky_UnsafeStorageTemperature";
14+
15+
//
16+
// Fields
17+
//
18+
public bool wickStarted;
19+
20+
protected Sustainer wickSoundSustainer;
21+
22+
public bool detonated;
23+
24+
private Thing instigator;
25+
26+
protected int wickTicksLeft;
27+
28+
//
29+
// Properties
30+
//
31+
private bool CanEverExplodeFromDamage {
32+
get {
33+
if (this.Props.chanceNeverExplodeFromDamage < 1E-05f) {
34+
return true;
35+
}
36+
Rand.PushState ();
37+
Rand.Seed = this.parent.thingIDNumber.GetHashCode() + (Find.TickManager.TicksGame % 7919);
38+
bool result = Rand.Value < this.Props.chanceNeverExplodeFromDamage;
39+
Rand.PopState ();
40+
return result;
41+
}
42+
}
43+
44+
public CompProperties_TempExplosive Props {
45+
get {
46+
return (CompProperties_TempExplosive)this.props;
47+
}
48+
}
49+
50+
protected int StartWickThreshold {
51+
get {
52+
return Mathf.RoundToInt (this.Props.startWickHitPointsPercent * (float)this.parent.MaxHitPoints);
53+
}
54+
}
55+
56+
//
57+
// Methods
58+
//
59+
public override void CompTick ()
60+
{
61+
if (this.wickStarted)
62+
{
63+
if (this.wickSoundSustainer == null)
64+
{
65+
this.StartWickSustainer();
66+
}
67+
else
68+
{
69+
this.wickSoundSustainer.Maintain();
70+
}
71+
this.wickTicksLeft--;
72+
if (this.wickTicksLeft <= 0)
73+
{
74+
this.Detonate(this.parent.MapHeld);
75+
}
76+
}
77+
else
78+
{
79+
float ambientTemperature = this.parent.AmbientTemperature;
80+
float maxSafeTemperature = this.Props.maxSafeTemperature;
81+
if (ambientTemperature > maxSafeTemperature)
82+
{
83+
Rand.PushState();
84+
Rand.Seed = this.parent.thingIDNumber.GetHashCode() + (Find.TickManager.TicksGame % 7919);
85+
bool selfIgnite = Rand.Value < Mathf.Pow((ambientTemperature - maxSafeTemperature), 2.71828f) *
86+
this.Props.maxSafeTempFactor;
87+
Rand.PopState();
88+
if (selfIgnite)
89+
{
90+
this.StartWick();
91+
}
92+
}
93+
}
94+
}
95+
96+
public override string CompInspectStringExtra()
97+
{
98+
if (this.parent.AmbientTemperature > this.Props.maxSafeTemperature)
99+
{
100+
return UnsafeTempSignal.Translate();
101+
}
102+
return null;
103+
}
104+
105+
protected void Detonate (Map map)
106+
{
107+
if (this.detonated) {
108+
return;
109+
}
110+
this.detonated = true;
111+
if (!this.parent.SpawnedOrAnyParentSpawned) {
112+
return;
113+
}
114+
if (map == null) {
115+
Log.Warning ("Tried to detonate CompExplosive in a null map.");
116+
return;
117+
}
118+
CompProperties_TempExplosive props = this.Props;
119+
float num = props.explosiveRadius;
120+
if (this.parent.stackCount > 1 && props.explosiveExpandPerStackcount > 0f) {
121+
num += Mathf.Sqrt ((float)(this.parent.stackCount - 1) * props.explosiveExpandPerStackcount);
122+
}
123+
if (props.explosionEffect != null) {
124+
Effecter effecter = props.explosionEffect.Spawn ();
125+
effecter.Trigger (new TargetInfo (this.parent.PositionHeld, map, false),
126+
new TargetInfo (this.parent.PositionHeld, map, false));
127+
effecter.Cleanup ();
128+
}
129+
ThingDef postExplosionSpawnThingDef = props.postExplosionSpawnThingDef;
130+
float postExplosionSpawnChance = props.postExplosionSpawnChance;
131+
int postExplosionSpawnThingCount = props.postExplosionSpawnThingCount;
132+
GenExplosion.DoExplosion (this.parent.PositionHeld, map, num, props.explosiveDamageType,
133+
this.instigator ?? this.parent, null, null, null, postExplosionSpawnThingDef,
134+
postExplosionSpawnChance, postExplosionSpawnThingCount,
135+
props.applyDamageToExplosionCellsNeighbors, props.preExplosionSpawnThingDef,
136+
props.preExplosionSpawnChance, props.preExplosionSpawnThingCount);
137+
if (!this.parent.Destroyed)
138+
{
139+
this.parent.Kill(null);
140+
}
141+
}
142+
143+
public override void PostDraw ()
144+
{
145+
if (this.wickStarted) {
146+
this.parent.Map.overlayDrawer.DrawOverlay (this.parent, OverlayTypes.BurningWick);
147+
}
148+
}
149+
150+
public override void PostExposeData ()
151+
{
152+
base.PostExposeData ();
153+
Scribe_References.Look<Thing> (ref this.instigator, "instigator", false);
154+
Scribe_Values.Look<bool> (ref this.wickStarted, "wickStarted", false, false);
155+
Scribe_Values.Look<int> (ref this.wickTicksLeft, "wickTicksLeft", 0, false);
156+
Scribe_Values.Look<bool> (ref this.detonated, "detonated", false, false);
157+
}
158+
159+
public override void PostPostApplyDamage (DamageInfo dinfo, float totalDamageDealt)
160+
{
161+
if (!this.CanEverExplodeFromDamage) {
162+
return;
163+
}
164+
if (!this.parent.Destroyed) {
165+
if (this.wickStarted && dinfo.Def == DamageDefOf.Extinguish) {
166+
this.StopWick ();
167+
}
168+
else if (!this.wickStarted && this.parent.HitPoints <= this.StartWickThreshold) {
169+
this.StartWick (dinfo.Instigator);
170+
}
171+
}
172+
}
173+
174+
public override void PostPreApplyDamage (DamageInfo dinfo, out bool absorbed)
175+
{
176+
absorbed = false;
177+
if (this.CanEverExplodeFromDamage) {
178+
if (dinfo.Def.externalViolence && dinfo.Amount >= this.parent.HitPoints) {
179+
if (this.parent.MapHeld != null) {
180+
this.Detonate (this.parent.MapHeld);
181+
absorbed = true;
182+
}
183+
}
184+
else if (!this.wickStarted && this.Props.startWickOnDamageTaken != null &&
185+
dinfo.Def == this.Props.startWickOnDamageTaken) {
186+
this.StartWick (dinfo.Instigator);
187+
}
188+
}
189+
}
190+
191+
public void StartWick (Thing instigator = null)
192+
{
193+
if (this.wickStarted) {
194+
return;
195+
}
196+
this.instigator = instigator;
197+
this.wickStarted = true;
198+
this.wickTicksLeft = this.Props.wickTicks.RandomInRange;
199+
this.StartWickSustainer ();
200+
GenExplosion.NotifyNearbyPawnsOfDangerousExplosive (this.parent, this.Props.explosiveDamageType, null);
201+
}
202+
203+
private void StartWickSustainer ()
204+
{
205+
SoundDefOf.MetalHitImportant.PlayOneShot (new TargetInfo (this.parent.Position, this.parent.Map, false));
206+
SoundInfo info = SoundInfo.InMap (this.parent, MaintenanceType.PerTick);
207+
this.wickSoundSustainer = SoundDefOf.HissSmall.TrySpawnSustainer (info);
208+
}
209+
210+
public void StopWick ()
211+
{
212+
this.wickStarted = false;
213+
this.instigator = null;
214+
}
215+
}
216+
}

0 commit comments

Comments
 (0)