[1.0][1.1] Removing ForcedMissRadius via xml Patch results in error on startup

Started by Currently_Fortifying, March 29, 2020, 01:29:07 PM

Previous topic - Next topic

Currently_Fortifying

Relevant thread:
https://ludeon.com/forums/index.php?topic=51389.0

Basically if you remove forcedMissRadius from explosive weapons via xml patch it creates the following error on startup:
(Config error in Gun_TripleRocket: verb 0: has incorrect forcedMiss settings; explosive projectiles and only explosive projectiles should have forced miss enabled)

Homez found the offending bug in Verse.VerbProperties.ConfigErrors
The relevant code is:
(if (LaunchesProjectile && defaultProjectile != null && forcedMissRadius > 0f != CausesExplosion)
{
yield return "has incorrect forcedMiss settings; explosive projectiles and only explosive projectiles should have forced miss enabled";
})


The issue of course is that forcedMissRadius needs to be greater than 0 if the weapon is an explosive based weapon. Which if you remove FRM from an explosive weapon, this sets FRM to it's default value of 0, float has a default value of 0 in c#.

The solution is to change forcedMissRadius > 0f != CausesExplosion to forcedMissRadius >= 0f != CausesExplosion.

ison

As the error says, explosive projectiles need to have a non-zero forcedMissRadius, so I'm not sure if there's a bug here

Currently_Fortifying

Sorry I didn't get back to you sooner, and I wasn't being clear enough.

It only gives an error on startup, explosive weapons that have FMR removed work perfectly fine in game.
Hence the reason I said it needed to be changed to forcedMissRadius >= 0f != CausesExplosion. Although, this should be changed to forcedMissRadius >=0f, so that FMR can be applied to non Explosive weapons without an error.

Given it doesn't prevent the loading of the mod, and it doesn't prevent weapons from firing without error, the error isn't an error. It's a warning displayed as an error, that's erroneously returned by inappropriate boundary check.

Also, yes I've checked to make sure there's no unintended side effects from adding or removing FMR. The relevant code for FMR calculations is in Verse.Verb_LaunchProjectile.TryCastShot()
In it, it has this check before calculating FMR, if (this.verbProps.forcedMissRadius > 0.5f). Which means erroneous values are already check for, and the check in Verse.VerbProperties.ConfigErrors, is entirely pointless. You could literally have a negative FMR and the relevant code would still function without issue.

It's not something that needs immediate fixing, and I can make a harmony patch for this issue so that people won't complain about my mod giving them an error. Still though, this config error needs to be eventually removed, because it is pointless, or it needs to be changed so that it only throws a warning when FMR is negative.