Skip to content

Commit 3cf3aa9

Browse files
authored
Launch curves followup (#6742)
* this went very badly * fix burst mult bug * increment multi * fix uninitialized variable * fixes * further fixes * concision
1 parent 6e7128f commit 3cf3aa9

File tree

7 files changed

+60
-20
lines changed

7 files changed

+60
-20
lines changed

code/ai/aiturret.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,10 @@ void turret_set_next_fire_timestamp(int weapon_num, const weapon_info *wip, ship
15541554
{
15551555
Assert(weapon_num < MAX_SHIP_WEAPONS);
15561556
float wait = 1000.0f;
1557-
// should subtract 1 from firepoints to match behavior of wip->burst_shots
1558-
int burst_shots = (wip->burst_flags[Weapon::Burst_Flags::Num_firepoints_burst_shots] ? turret->system_info->turret_num_firing_points - 1 : wip->burst_shots);
1559-
burst_shots = fl2i(i2fl(burst_shots) * wip->weapon_launch_curves.get_output(weapon_info::WeaponLaunchCurveOutputs::BURST_SHOTS_MULT, launch_curve_data));
1557+
// we have to add 1 to wip->burst_shots so that the multiplier behaves as expected, then remove 1 from burst_shots to match the zero-indexed burst_counter
1558+
int base_burst_shots = (wip->burst_flags[Weapon::Burst_Flags::Num_firepoints_burst_shots] ? turret->system_info->turret_num_firing_points : wip->burst_shots + 1);
1559+
float burst_shots_mult = wip->weapon_launch_curves.get_output(weapon_info::WeaponLaunchCurveOutputs::BURST_SHOTS_MULT, launch_curve_data);
1560+
int burst_shots = MAX(fl2i(i2fl(base_burst_shots) * burst_shots_mult) - 1, 0);
15601561

15611562
if (burst_shots > turret->weapons.burst_counter[weapon_num]) {
15621563
wait *= wip->burst_delay;
@@ -1888,7 +1889,8 @@ bool turret_fire_weapon(int weapon_num,
18881889
}
18891890
// now do anything else
18901891
else {
1891-
int shots = fl2i(i2fl(wip->shots) * wip->weapon_launch_curves.get_output(weapon_info::WeaponLaunchCurveOutputs::SHOTS_MULT, launch_curve_data));
1892+
float shots_mult = wip->weapon_launch_curves.get_output(weapon_info::WeaponLaunchCurveOutputs::SHOTS_MULT, launch_curve_data);
1893+
int shots = fl2i(i2fl(wip->shots) * shots_mult);
18921894
for (int i = 0; i < shots; i++) {
18931895
if (!in_lab && turret->system_info->flags[Model::Subsystem_Flags::Turret_use_ammo]) {
18941896
int bank_to_fire, num_slots = turret->system_info->turret_num_firing_points;
@@ -2052,9 +2054,9 @@ bool turret_fire_weapon(int weapon_num,
20522054
subsys_index = ship_get_subsys_index(turret);
20532055
Assert( subsys_index != -1 );
20542056
if(wip->wi_flags[Weapon::Info_Flags::Flak]){
2055-
send_flak_fired_packet( parent_objnum, subsys_index, weapon_objnum, flak_range, launch_curve_data.distance_to_target );
2057+
send_flak_fired_packet( parent_objnum, subsys_index, weapon_objnum, flak_range, launch_curve_data.distance_to_target, launch_curve_data.target_radius );
20562058
} else {
2057-
send_turret_fired_packet( parent_objnum, subsys_index, weapon_objnum, launch_curve_data.distance_to_target );
2059+
send_turret_fired_packet( parent_objnum, subsys_index, weapon_objnum, launch_curve_data.distance_to_target, launch_curve_data.target_radius );
20582060
}
20592061
}
20602062

@@ -2127,6 +2129,7 @@ void turret_swarm_fire_from_turret(turret_swarm_info *tsi)
21272129
auto launch_curve_data = WeaponLaunchCurveData {
21282130
tsi->turret->system_info->turret_num_firing_points,
21292131
0.f,
2132+
0.f,
21302133
};
21312134

21322135
// create weapon and homing info
@@ -2181,7 +2184,7 @@ void turret_swarm_fire_from_turret(turret_swarm_info *tsi)
21812184

21822185
subsys_index = ship_get_subsys_index(tsi->turret);
21832186
Assert( subsys_index != -1 );
2184-
send_turret_fired_packet( tsi->parent_objnum, subsys_index, weapon_objnum, 0.f);
2187+
send_turret_fired_packet( tsi->parent_objnum, subsys_index, weapon_objnum, 0.f, 0.f);
21852188
}
21862189
}
21872190
}
@@ -2328,15 +2331,19 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss)
23282331

23292332
// Don't try to fire beyond weapon_limit_range
23302333
// WMC moved the range check to within the loop, but we can still calculate the enemy distance here
2334+
float base_dist_to_enemy = 0.0f;
23312335
float dist_to_enemy = 0.0f;
23322336
if (lep) {
2333-
if (The_mission.ai_profile->flags[AI::Profile_Flags::Turrets_ignore_target_radius]) {
2334-
dist_to_enemy = MAX(0.0f, vm_vec_normalized_dir(&v2e, &predicted_enemy_pos, &global_gun_pos));
2335-
} else {
2336-
dist_to_enemy = MAX(0.0f, vm_vec_normalized_dir(&v2e, &predicted_enemy_pos, &global_gun_pos) - lep->radius);
2337+
base_dist_to_enemy = vm_vec_normalized_dir(&v2e, &predicted_enemy_pos, &global_gun_pos);
2338+
dist_to_enemy = base_dist_to_enemy;
2339+
if (!The_mission.ai_profile->flags[AI::Profile_Flags::Turrets_ignore_target_radius]) {
2340+
dist_to_enemy -= lep->radius;
23372341
}
2342+
base_dist_to_enemy = MAX(0.0f, base_dist_to_enemy);
2343+
dist_to_enemy = MAX(0.0f, dist_to_enemy);
23382344
} else if (in_lab) {
2339-
dist_to_enemy = 500.0f;
2345+
base_dist_to_enemy = 500.0f;
2346+
dist_to_enemy = base_dist_to_enemy;
23402347
vm_vec_normalized_dir(&v2e, &predicted_enemy_pos, &global_gun_pos);
23412348
}
23422349

@@ -2349,10 +2356,17 @@ void ai_turret_execute_behavior(const ship *shipp, ship_subsys *ss)
23492356

23502357
float turret_barrel_length = -1.0f;
23512358

2359+
float target_radius = 0.f;
2360+
2361+
if (lep != nullptr) {
2362+
target_radius = lep->radius;
2363+
}
2364+
23522365
// grab the data for the launch curve inputs
23532366
auto launch_curve_data = WeaponLaunchCurveData {
23542367
ss->system_info->turret_num_firing_points,
2355-
dist_to_enemy,
2368+
base_dist_to_enemy,
2369+
target_radius,
23562370
};
23572371

23582372
//WMC - go through all valid weapons. Fire spawns if there are any.

code/network/multi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class player;
7575
// Version 59 - 12/9/2022 - New IDs for SEXP operators
7676
// Version 60 - 3/27/2023 - Added generic lua data packet
7777
// Version 61 - 4/17/2023 - Added compatibility for whackable asteroids (added force)
78-
// Version 62 - 5/26/2025 - Added some modular curve input data to turret firing packets
78+
// Version 62 - 5/26/2025 - Added some modular curve input data to turret firing packets; 5/31/2025 - Added another input
7979
// STANDALONE_ONLY
8080

8181
#define MULTI_FS_SERVER_VERSION 62

code/network/multimsgs.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ void process_countermeasure_fired_packet( ubyte *data, header *hinfo )
33153315
}
33163316

33173317
// send a packet indicating that a turret has been fired
3318-
void send_turret_fired_packet( int ship_objnum, int subsys_index, int weapon_objnum, float dist_to_target )
3318+
void send_turret_fired_packet( int ship_objnum, int subsys_index, int weapon_objnum, float dist_to_target, float target_radius )
33193319
{
33203320
int packet_size;
33213321
ushort pnet_signature;
@@ -3372,6 +3372,8 @@ void send_turret_fired_packet( int ship_objnum, int subsys_index, int weapon_obj
33723372
}
33733373

33743374
ADD_FLOAT(dist_to_target);
3375+
3376+
ADD_FLOAT(target_radius);
33753377

33763378
multi_io_send_to_all(data, packet_size);
33773379

@@ -3393,6 +3395,7 @@ void process_turret_fired_packet( ubyte *data, header *hinfo )
33933395
ship *shipp;
33943396
float angle1, angle2;
33953397
float dist_to_target;
3398+
float target_radius;
33963399

33973400
// get the data for the turret fired packet
33983401
offset = HEADER_LENGTH;
@@ -3409,6 +3412,7 @@ void process_turret_fired_packet( ubyte *data, header *hinfo )
34093412
GET_FLOAT( angle1 );
34103413
GET_FLOAT( angle2 );
34113414
GET_FLOAT( dist_to_target );
3415+
GET_FLOAT( target_radius );
34123416
PACKET_SET_SIZE(); // move our counter forward the number of bytes we have read
34133417

34143418
// if we don't have a valid weapon index then bail
@@ -3455,6 +3459,7 @@ void process_turret_fired_packet( ubyte *data, header *hinfo )
34553459
auto launch_curve_data = WeaponLaunchCurveData {
34563460
ssp->system_info->turret_num_firing_points,
34573461
dist_to_target,
3462+
target_radius,
34583463
};
34593464

34603465
// create the weapon object
@@ -8629,7 +8634,7 @@ void process_weapon_detonate_packet(ubyte *data, header *hinfo)
86298634
}
86308635

86318636
// flak fired packet
8632-
void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum, float flak_range, float dist_to_target)
8637+
void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum, float flak_range, float dist_to_target, float target_radius)
86338638
{
86348639
int packet_size;
86358640
ushort pnet_signature;
@@ -8679,6 +8684,8 @@ void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum
86798684
ADD_FLOAT( flak_range );
86808685

86818686
ADD_FLOAT( dist_to_target );
8687+
8688+
ADD_FLOAT( target_radius );
86828689

86838690
multi_io_send_to_all(data, packet_size);
86848691

@@ -8699,6 +8706,7 @@ void process_flak_fired_packet(ubyte *data, header *hinfo)
86998706
float angle1, angle2;
87008707
float flak_range;
87018708
float dist_to_target;
8709+
float target_radius;
87028710

87038711
// get the data for the turret fired packet
87048712
offset = HEADER_LENGTH;
@@ -8710,6 +8718,7 @@ void process_flak_fired_packet(ubyte *data, header *hinfo)
87108718
GET_FLOAT( angle2 );
87118719
GET_FLOAT( flak_range );
87128720
GET_FLOAT( dist_to_target );
8721+
GET_FLOAT( target_radius );
87138722
PACKET_SET_SIZE(); // move our counter forward the number of bytes we have read
87148723

87158724
// if we don't have a valid weapon index then bail
@@ -8755,6 +8764,7 @@ void process_flak_fired_packet(ubyte *data, header *hinfo)
87558764
auto launch_curve_data = WeaponLaunchCurveData {
87568765
ssp->system_info->turret_num_firing_points,
87578766
dist_to_target,
8767+
target_radius,
87588768
};
87598769

87608770
// create the weapon object

code/network/multimsgs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,11 @@ void send_weapon_detonate_packet(object *objp);
530530
void process_weapon_detonate_packet(ubyte *data, header *hinfo);
531531

532532
// turret fired packet
533-
void send_turret_fired_packet( int objnum, int subsys_index, int weapon_objnum, float dist_to_target );
533+
void send_turret_fired_packet( int objnum, int subsys_index, int weapon_objnum, float dist_to_target, float target_radius );
534534
void process_turret_fired_packet( ubyte *data, header *hinfo );
535535

536536
// flak fired packet
537-
void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum, float flak_range, float dist_to_target);
537+
void send_flak_fired_packet(int ship_objnum, int subsys_index, int weapon_objnum, float flak_range, float dist_to_target, float target_radius );
538538
void process_flak_fired_packet(ubyte *data, header *hinfo);
539539

540540
// player pain packet

code/scripting/api/objs/subsystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,11 @@ ADE_FUNC(fireWeapon, l_Subsystem, "[number TurretWeaponIndex = 1, number FlakRan
891891
if (override_gvec != nullptr)
892892
vm_vec_copy_normalize(&gvec, override_gvec);
893893

894-
// we don't have a target, so just set the range to 0
894+
// we don't have a target, so just set the range and radius to 0
895895
auto launch_curve_data = WeaponLaunchCurveData {
896896
sso->ss->system_info->turret_num_firing_points,
897897
0.f,
898+
0.f,
898899
};
899900

900901
bool rtn = turret_fire_weapon(wnum, sso->ss, sso->objh.objnum, launch_curve_data, &gpos, &gvec, nullptr, flak_range);

code/ship/ship.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12789,10 +12789,16 @@ int ship_fire_primary(object * obj, int force, bool rollback_shot)
1278912789
}
1279012790

1279112791
int num_slots = pm->gun_banks[bank_to_fire].num_slots;
12792+
float target_radius = 0.f;
12793+
12794+
if (aip->target_objnum >= 0) {
12795+
target_radius = Objects[aip->target_objnum].radius;
12796+
}
1279212797

1279312798
auto launch_curve_data = WeaponLaunchCurveData {
1279412799
num_slots,
1279512800
dist_to_target,
12801+
target_radius,
1279612802
};
1279712803

1279812804
// do timestamp stuff for next firing time
@@ -14065,10 +14071,16 @@ int ship_fire_secondary( object *obj, int allow_swarm, bool rollback_shot )
1406514071
}
1406614072

1406714073
num_slots = pm->missile_banks[bank].num_slots;
14074+
float target_radius = 0.f;
14075+
14076+
if (target_objnum >= 0) {
14077+
target_radius = Objects[target_objnum].radius;
14078+
}
1406814079

1406914080
auto launch_curve_data = WeaponLaunchCurveData {
1407014081
num_slots,
1407114082
dist_to_target,
14083+
target_radius,
1407214084
};
1407314085

1407414086
// determine if there is enough ammo left to fire weapons on this bank. As with primary

code/weapon/weapon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ float beam_get_warmdown_age(const beam& wp);
354354
struct WeaponLaunchCurveData {
355355
int num_firepoints;
356356
float distance_to_target;
357+
float target_radius;
357358
};
358359

359360
struct weapon_info;
@@ -711,7 +712,8 @@ struct weapon_info
711712
std::pair {"FoF Mult", WeaponLaunchCurveOutputs::FOF_MULT},
712713
},
713714
std::pair {"Num Firepoints", modular_curves_submember_input<&WeaponLaunchCurveData::num_firepoints>{}},
714-
std::pair {"Distance to Target", modular_curves_submember_input<&WeaponLaunchCurveData::distance_to_target>{}}
715+
std::pair {"Distance to Target", modular_curves_submember_input<&WeaponLaunchCurveData::distance_to_target>{}},
716+
std::pair {"Target Radius", modular_curves_submember_input<&WeaponLaunchCurveData::target_radius>{}}
715717
);
716718

717719
public:
@@ -1020,6 +1022,7 @@ int weapon_create( const vec3d *pos,
10201022
ship_subsys *src_turret = nullptr,
10211023
const WeaponLaunchCurveData& launch_curve_data = WeaponLaunchCurveData {
10221024
0,
1025+
0.f,
10231026
0.f
10241027
});
10251028
void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_objnum, int target_is_locked = 0, ship_subsys *target_subsys = NULL);

0 commit comments

Comments
 (0)