Skip to content

Weapon launch curves#6732

Merged
BMagnu merged 7 commits into
scp-fs2open:masterfrom
Kestrellius:weapon-launch-curves
May 26, 2025
Merged

Weapon launch curves#6732
BMagnu merged 7 commits into
scp-fs2open:masterfrom
Kestrellius:weapon-launch-curves

Conversation

@Kestrellius

Copy link
Copy Markdown
Contributor

Adds a modular curve set that governs the behavior of weapon creation -- things like fire rate and burst shot count.

This is kind of messy, and if anyone has ideas for how to make it less messy I'm all ears, but I think it's just going to have to be this way -- weapon firing behavior is spread over like five different functions in three separate places, not even counting the edge cases. This messiness means that every input for these curves needs to be passed around a lot, so for now I've kept the inputs limited to the ones that I immediately need for my specific use-cases.

Important limitations of these curves at present:

  • They don't work for beams (because those are a different type of thing that would need its own curveset), subspace missiles (because I couldn't be bothered), or weapons spawned as children or generated by SEXP (because the inputs are undefined). In all those cases except beams, both inputs will always be zero.
  • The outputs include a max velocity multiplier and a lifetime multiplier, both of which may affect when the weapon can be fired and how it is best aimed. The AI has no idea that these multipliers exist; it will behave as though the base tabled values are in force. For the moment, I think this is the best option. I looked at trying to have the AI take it into account, and things like max velocity are referenced in so many places that it doesn't look very feasible to me -- even setting aside the implementation hassle, I have no idea what effect it'd have on performance. Further, these curves permit things like weapons whose velocity changes based on the distance to the target -- if we imagine trying to hit something like a fighter with one of those, even a human would have a lot of difficulty performing that logic. I think keeping it simple and allowing the modder to control the AI behavior using the tabled values will work best.

Also, I attempted to add multi support. If I'm understanding correctly I think it will work, but I'm not ultimately very familiar with the multi code at all. Additionally, my method requires adding an extra float to each turret_fired and flak_fired packet, and I have no idea if that's an acceptable cost given that the functions are going to the trouble of squishing ints down into shorts.

@BMagnu BMagnu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small things.
Also, someone more familiar with multi code should take a look here.

Comment thread code/ai/aiturret.cpp Outdated
* Set the next fire timestamp for a turret, based on weapon type and ai class
*/
void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship_subsys *turret, const ai_info *aip)
void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship_subsys *turret, const ai_info *aip, WeaponLaunchCurveData launch_curve_data)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take a const ref for the curve data

Comment thread code/ai/aiturret.cpp
* Fire a weapon from a turret
*/
bool turret_fire_weapon(int weapon_num, ship_subsys *turret, int parent_objnum, const vec3d *orig_firing_pos, const vec3d *orig_firing_vec, const vec3d *predicted_pos = nullptr, float flak_range_override = 100.0f, bool play_sound = true)
bool turret_fire_weapon(int weapon_num,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

ADD_FLOAT(ZERO_VALUE);
}

ADD_FLOAT(dist_to_target);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API change and thus needs to increment the multi version number at some point in this PR.

Comment thread code/scripting/api/objs/subsystem.cpp Outdated

void sexp_beam_or_turret_free_one(ship_subsys *turret, bool is_beam, bool free);
bool turret_fire_weapon(int weapon_num, ship_subsys *turret, int parent_objnum, const vec3d *orig_firing_pos, const vec3d *orig_firing_vec, const vec3d *predicted_pos = nullptr, float flak_range_override = 100.0f, bool play_sound = true);
bool turret_fire_weapon(int weapon_num, ship_subsys *turret, int parent_objnum, WeaponLaunchCurveData launch_curve_data, const vec3d *orig_firing_pos, const vec3d *orig_firing_vec, const vec3d *predicted_pos = nullptr, float flak_range_override = 100.0f, bool play_sound = true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ref as well

Comment thread code/weapon/weapon.h Outdated
bool is_spawned = false,
float fof_cooldown = 0.0f,
ship_subsys *src_turret = nullptr,
WeaponLaunchCurveData launch_curve_data = WeaponLaunchCurveData {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@wookieejedi wookieejedi added enhancement A new feature or upgrade of an existing feature to add additional functionality. Requested by Active Mod A feature request that has been requested by a mod that is actively in development. labels May 25, 2025

@JohnAFernandez JohnAFernandez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multi related changes do look safe, but we are going to need to increment the multi version, which is in multi.h. Ping me on discord if you need more detailed instructions.

@Kestrellius Kestrellius force-pushed the weapon-launch-curves branch from c341e8a to 70b7f88 Compare May 26, 2025 21:15
@BMagnu BMagnu merged commit 66d9335 into scp-fs2open:master May 26, 2025
16 checks passed
@Kestrellius Kestrellius deleted the weapon-launch-curves branch May 27, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or upgrade of an existing feature to add additional functionality. Requested by Active Mod A feature request that has been requested by a mod that is actively in development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants