[A17b] CompExplosive: parent.Kill(), then check parent.stackCount (always 0)

Started by Alistaire, June 28, 2017, 05:45:08 PM

Previous topic - Next topic

Alistaire

It appears that props.explosiveExpandPerStackcount has no effect on explosion size. This is because of the following lines:

// RimWorld.CompExplosive
///protected void Detonate(Map map)

(..)

if (!this.parent.Destroyed)
{
this.parent.Kill(null);
}

(..)

float num = props.explosiveRadius;
if (this.parent.stackCount > 1 && props.explosiveExpandPerStackcount > 0f)
{
num += Mathf.Sqrt((float)(this.parent.stackCount - 1) * props.explosiveExpandPerStackcount);
}

(..)


Which causes the following to happen. Since this.parent.Kill(null), parent.stackCount = 0. Therefore, regardless of props.explosiveExpandPerStackcount, the explosion radius will be props.explosiveRadius.

Furthermore, there's a check for this.parent further down in the code (which may or may not have problems triggering because of the earlier killed parent).




Suggested solution:

Create Thing instigatorThing = this.instigator ?? this.parent; and num before killing the parent such that these values are not null.

// RimWorld.CompExplosive
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_Explosive 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);
}
Thing instigatorThing = this.instigator ?? this.parent;
if (!this.parent.Destroyed)
{
this.parent.Kill(null);
}
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, instigatorThing, null, null, null, postExplosionSpawnThingDef, postExplosionSpawnChance, postExplosionSpawnThingCount, props.applyDamageToExplosionCellsNeighbors, props.preExplosionSpawnThingDef, props.preExplosionSpawnChance, props.preExplosionSpawnThingCount);
}

ison