Fractal Softworks Forum

Starsector => Mods => Modding => Topic started by: xenoargh on September 05, 2017, 12:45:51 AM

Title: [0.81a] EZ Damage 2a
Post by: xenoargh on September 05, 2017, 12:45:51 AM
Download Linky (http://www.wolfegames.com/TA_Section/xeno_mod_pack.zip)

This mod is part of my Mod Pack.

One of this mod's components requires LazyLib (http://fractalsoftworks.com/forum/index.php?topic=5444.0) to operate.  If you don't have LazyLib installed, do so before running this mod.

This is a "utility" mod.  It does not interfere with the base game in any significant way.  It requires LazyLib.

What this does:  

For modders, applying custom damage events that can't be interfered with by others' code can be hard.  

This code simplifies that task, by using a method that completely follows the game's core rules, rather than using CombatEngineAPI.applyDamage(), which does not properly interact with "exotic" ship defensive systems, etc., because it does not have a callback in any mod-accessible code (at this time).  

This can mean that one mod's "special defense" interferes with another mod's "special weapon".  Naturally, this isn't ideal.

While this code doesn't address the one major case of the Starsector engine's hard-coded use of applyDamage()- to wit, the "flak" weapons that use an AOE hit-detector as well as applyDamage() under the hood, it will address these problems for any mod that wishes to implement their own AOE system (see Vacuum's source, SpecialShotBehaviors.java, for a good example of how to do this cheaply).  The next version of the Rebalance Mod series will have a working example to replace the engine's AOE system entirely and an "opt-in", reasonably efficient AOE system available.

To use this code in your mods to address these problems, simply include the JAR in your project like any other JAR and call:

EZ_Damage.DamageThis(ShipAPI owner, WeaponAPI weapon, CombatEntityAPI target, CombatEngineAPI engine, DamageType damageType, Vector2f point, float damage, float emp);

You don't need to worry about angles, etc., but you need to provide a point, no further than 200 SU from the object you'd like to damage.  A simple example can now be found in Explorer Society's PlasmaOnHitEffect.java, showing how to do randomized points around the target.

Performance Note:  Because of some weird limitations of the engine at this time, EMP requires a separate DamagingProjectileAPI to get created for every 50 points of damage you want to inflict.  Generally speaking, you don't want to use this for huge amounts of EMP damage, although the performance hit is relatively modest, as the projectiles last only a couple of gameframes.
Title: Re: [0.81a] EZ Damage 1a
Post by: Nicke535 on September 06, 2017, 08:28:51 AM
Ok, an immediate question: since a WeaponAPI is passed in, is "damage" automatically modified by any effects that reduce the damage of the controlling weapon? Or do you have to manually add a modifier to the "damage" variable in order to handle this?
Title: Re: [0.81a] EZ Damage 1a
Post by: xenoargh on September 06, 2017, 09:56:53 AM
Yes, the damage passed in will get modified by any buffs the target ShipAPI may have due to having a Captain.  But since you're passing in a WeaponAPI, any buffs the attacking ShipAPI has due to its Captain will be present, as well.
Title: Re: [0.81a] EZ Damage 2a
Post by: xenoargh on September 21, 2017, 08:37:32 AM
Alpha 2 is now available.

Cleans up a couple of minor details of the implementation, mainly visuals.  Modders, you're still calling the same old code, don't worry about it.