You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow mods to set threshold at which shield stops taking damage (#6847)
* Allow mods to set threshold at which shield stops taking damage
FSO logic dictates that shields collisions and any related sound or visuals related to shields are skipped if the shields are under 10%. This is rather unintuitive especially for mods, so this PR creates a game setting value that allows mods to set this value.
Also, this PR fixes a bug where the HUD shield gauge would try and incorporate this feature but did not do it correctly. Specifically, the gauge skips shield segment rendering if the raw shield strength was 0.1 not the percent. Incorrectly using the raw value results in HUD shields being rendered (albeit faintly) even if the damage was skipping the shield and directly damaging the hull. In other words, if the shield segment was 8%, the shield segment would show faintly even the shield is skipping damage.
Tested and works as expected. Also happy to discuss or answer any questions!
* update local variable name for clarity
* rename `ship_quadrant_shield_strength`
* cleanup with updated get percent function
* more cleanup
* wording and safety tuning
* use correct default number
if (optional_string("$Threshold below which shield skips damage:")) {
1544
+
float threshold;
1545
+
stuff_float(&threshold);
1546
+
if ((threshold >= 0.0f) && (threshold <= 1.0f)) {
1547
+
Shield_percent_skips_damage = threshold;
1548
+
} else {
1549
+
mprintf(("Game Settings Table: '$Threshold below which shield skips damage' value of %.2f is not between 0 and 1. Using default value of 0.10.\n", threshold));
1550
+
Shield_percent_skips_damage = 0.1f;
1551
+
}
1552
+
}
1553
+
1542
1554
// end of options ----------------------------------------
1543
1555
1544
1556
// if we've been through once already and are at the same place, force a move
* Return the shield strength of the specified quadrant on hit_objp
17271
-
*
17272
-
* @param hit_objp object pointer to ship getting hit
17273
-
* @param quadrant_num shield quadrant that was hit
17274
-
* @return strength of shields in the quadrant that was hit as a percentage, between 0 and 1.0
17275
-
*/
17276
-
float ship_quadrant_shield_strength(const object *hit_objp, int quadrant_num)
17277
-
{
17278
-
float max_quadrant;
17279
-
17280
-
// If ship doesn't have shield mesh, then return
17281
-
if ( hit_objp->flags[Object::Object_Flags::No_shields] ) {
17282
-
return 0.0f;
17283
-
}
17284
-
17285
-
// If shields weren't hit, return 0
17286
-
if ( quadrant_num < 0 )
17287
-
return 0.0f;
17288
-
17289
-
max_quadrant = shield_get_max_quad(hit_objp);
17290
-
if ( max_quadrant <= 0 ) {
17291
-
return 0.0f;
17292
-
}
17293
-
17294
-
Assertion(quadrant_num < static_cast<int>(hit_objp->shield_quadrant.size()), "ship_quadrant_shield_strength() called with a quadrant of %d on a ship with " SIZE_T_ARG " quadrants; get a coder!\n", quadrant_num, hit_objp->shield_quadrant.size());
0 commit comments