Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: [0.81a] EZ Damage 2a  (Read 3208 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
[0.81a] EZ Damage 2a
« on: September 05, 2017, 12:45:51 AM »


This mod is part of my Mod Pack.

One of this mod's components requires LazyLib 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.
« Last Edit: September 21, 2017, 08:36:39 AM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Nicke535

  • Commander
  • ***
  • Posts: 240
  • Degenerate Core
    • View Profile
Re: [0.81a] EZ Damage 1a
« Reply #1 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?

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: [0.81a] EZ Damage 1a
« Reply #2 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.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: [0.81a] EZ Damage 2a
« Reply #3 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.
Logged
Please check out my SS projects :)
Xeno's Mod Pack