Skip to content

Commit 106afbe

Browse files
authored
scale effects for muzzle and hits (scp-fs2open#6731)
* scale effects for muzzle and hits * move calcs into if block * aesthetics
1 parent 25dbfc6 commit 106afbe

5 files changed

Lines changed: 35 additions & 18 deletions

File tree

code/ai/aiturret.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,10 +2030,15 @@ bool turret_fire_weapon(int weapon_num,
20302030

20312031
// do mflash if the weapon has it
20322032
if (wip->muzzle_effect.isValid()) {
2033+
float radius_mult = 1.f;
2034+
if (wip->render_type == WRT_LASER) {
2035+
radius_mult = wip->weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LASER_RADIUS_MULT, *wp, &wp->modular_curves_instance);
2036+
}
20332037
//spawn particle effect
20342038
auto particleSource = particle::ParticleManager::get()->createSource(wip->muzzle_effect);
20352039
particleSource->setHost(make_unique<EffectHostTurret>(&Objects[parent_ship->objnum], turret->system_info->turret_gun_sobj, turret->turret_next_fire_pos));
2036-
particleSource->setTriggerRadius(objp->radius);
2040+
particleSource->setTriggerRadius(objp->radius * radius_mult);
2041+
particleSource->setTriggerVelocity(vm_vec_mag_quick(&objp->phys_info.vel));
20372042
particleSource->finishCreation();
20382043
}
20392044
else if (wip->muzzle_flash >= 0) {

code/ship/ship.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13407,7 +13407,7 @@ int ship_fire_primary(object * obj, int force, bool rollback_shot)
1340713407
}
1340813408
}
1340913409
// create the muzzle flash effect
13410-
shipfx_flash_create( obj, sip->model_num, &pnt, &dir, 1, weapon_idx );
13410+
shipfx_flash_create( obj, sip->model_num, &pnt, &dir, 1, weapon_idx, weapon_objnum );
1341113411

1341213412
// maybe shudder the ship - if its me
1341313413
if((winfo_p->wi_flags[Weapon::Info_Flags::Shudder]) && (obj == Player_obj) && !(Game_mode & GM_STANDALONE_SERVER)){
@@ -14200,7 +14200,7 @@ int ship_fire_secondary( object *obj, int allow_swarm, bool rollback_shot )
1420014200
has_fired = true;
1420114201

1420214202
// create the muzzle flash effect
14203-
shipfx_flash_create(obj, sip->model_num, &pnt, &dir, 0, weapon_idx);
14203+
shipfx_flash_create(obj, sip->model_num, &pnt, &dir, 0, weapon_idx, weapon_num);
1420414204

1420514205
if((wip->wi_flags[Weapon::Info_Flags::Shudder]) && (obj == Player_obj) && !(Game_mode & GM_STANDALONE_SERVER)){
1420614206
// calculate some arbitrary value between 100

code/ship/shipfx.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ void shipfx_flash_init()
10351035
/**
10361036
* Given that a ship fired a weapon, light up the model accordingly.
10371037
*/
1038-
void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index)
1038+
void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index, int weapon_objnum)
10391039
{
10401040
int i;
10411041
int objnum = OBJ_INDEX(objp);
@@ -1055,7 +1055,10 @@ void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun
10551055
objp == Player_obj
10561056
&& Ship_info[Ships[objp->instance].ship_info_index].flags[Ship::Info_Flags::Show_ship_model]
10571057
&& (!Show_ship_only_if_cockpits_enabled || Cockpit_active));
1058-
if (!(Weapon_info[weapon_info_index].wi_flags[Weapon::Info_Flags::Flak]) &&
1058+
1059+
auto* wip = &Weapon_info[weapon_info_index];
1060+
1061+
if (!(wip->wi_flags[Weapon::Info_Flags::Flak]) &&
10591062
(objp != Player_obj || Render_player_mflash || (!in_cockpit_view || player_show_ship_model))) {
10601063
// if there's a muzzle effect entry, we use that
10611064
if (Weapon_info[weapon_info_index].muzzle_effect.isValid()) {
@@ -1067,15 +1070,18 @@ void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun
10671070
//This should probably end up attached to the subobject, not the object, but it's not that much of a problem since primaries / secondaries rarely move.
10681071
particleSource->setHost(make_unique<EffectHostObject>(objp, *gun_pos, gunOrient, true));
10691072

1070-
// set radius manually following logic in weapon_create function --wookieejedi
1071-
if (Weapon_info[weapon_info_index].collision_radius_override > 0.0f)
1072-
particleSource->setTriggerRadius(Weapon_info[weapon_info_index].collision_radius_override);
1073-
else if (Weapon_info[weapon_info_index].render_type == WRT_POF) {
1074-
particleSource->setTriggerRadius(model_get_radius(Weapon_info[weapon_info_index].model_num));
1075-
} else if (Weapon_info[weapon_info_index].render_type == WRT_LASER) {
1076-
particleSource->setTriggerRadius(Weapon_info[weapon_info_index].laser_head_radius);
1073+
auto *weapon_objp = &Objects[weapon_objnum];
1074+
auto *wp = &Weapons[weapon_objp->instance];
1075+
1076+
float radius_mult = 1.f;
1077+
1078+
if (wip->render_type == WRT_LASER) {
1079+
radius_mult = wip->weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LASER_RADIUS_MULT, *wp, &wp->modular_curves_instance);
10771080
}
10781081

1082+
particleSource->setTriggerRadius(weapon_objp->radius * radius_mult);
1083+
particleSource->setTriggerVelocity(vm_vec_mag_quick(&weapon_objp->phys_info.vel));
1084+
10791085
particleSource->finishCreation();
10801086
// if there's a muzzle flash entry and no muzzle effect entry, we use the mflash
10811087
} else if (Weapon_info[weapon_info_index].muzzle_flash >= 0) {

code/ship/shipfx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void shipfx_flash_init();
135135
// accordingly.
136136
// Set is_primary to non-zero if this is a primary weapon.
137137
// Gun_pos should be in object's frame of reference, not world!!!
138-
void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index);
138+
void shipfx_flash_create(object *objp, int model_num, vec3d *gun_pos, vec3d *gun_dir, int is_primary, int weapon_info_index, int weapon_objnum);
139139

140140
// Does whatever processing needs to be done each frame.
141141
void shipfx_flash_do_frame(float frametime);

code/weapon/weapons.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7850,6 +7850,12 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
78507850
vec3d reverse_incoming = weapon_obj->orient.vec.fvec;
78517851
vm_vec_negate(&reverse_incoming);
78527852

7853+
float radius_mult = 1.f;
7854+
7855+
if (wip->render_type == WRT_LASER) {
7856+
radius_mult = wip->weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LASER_RADIUS_MULT, *wp, &wp->modular_curves_instance);
7857+
}
7858+
78537859
if (hitnormal) {
78547860
hit_angle = vm_vec_delta_ang(hitnormal, &reverse_incoming, nullptr);
78557861
}
@@ -7886,7 +7892,7 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
78867892
) {
78877893
auto particleSource = particle::ParticleManager::get()->createSource(ci.effect);
78887894
particleSource->setHost(weapon_hit_make_effect_host(weapon_obj, impacted_obj, submodel, hitpos, local_hitpos));
7889-
particleSource->setTriggerRadius(weapon_obj->radius);
7895+
particleSource->setTriggerRadius(weapon_obj->radius * radius_mult);
78907896
particleSource->setTriggerVelocity(vm_vec_mag_quick(&weapon_obj->phys_info.vel));
78917897

78927898
if (hitnormal)
@@ -7906,7 +7912,7 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
79067912
auto particleSource = particle::ParticleManager::get()->createSource(wip->impact_weapon_expl_effect);
79077913

79087914
particleSource->setHost(weapon_hit_make_effect_host(weapon_obj, impacted_obj, submodel, hitpos, local_hitpos));
7909-
particleSource->setTriggerRadius(weapon_obj->radius);
7915+
particleSource->setTriggerRadius(weapon_obj->radius * radius_mult);
79107916
particleSource->setTriggerVelocity(vm_vec_mag_quick(&weapon_obj->phys_info.vel));
79117917

79127918
if (hitnormal)
@@ -7917,7 +7923,7 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
79177923
} else if (!valid_conditional_impact && wip->dinky_impact_weapon_expl_effect.isValid() && !armed_weapon) {
79187924
auto particleSource = particle::ParticleManager::get()->createSource(wip->dinky_impact_weapon_expl_effect);
79197925
particleSource->setHost(weapon_hit_make_effect_host(weapon_obj, impacted_obj, submodel, hitpos, local_hitpos));
7920-
particleSource->setTriggerRadius(weapon_obj->radius);
7926+
particleSource->setTriggerRadius(weapon_obj->radius * radius_mult);
79217927
particleSource->setTriggerVelocity(vm_vec_mag_quick(&weapon_obj->phys_info.vel));
79227928

79237929
if (hitnormal)
@@ -7960,7 +7966,7 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
79607966

79617967
auto primarySource = ParticleManager::get()->createSource(wip->piercing_impact_effect);
79627968
primarySource->setHost(weapon_hit_make_effect_host(weapon_obj, impacted_obj, submodel, hitpos, local_hitpos));
7963-
primarySource->setTriggerRadius(weapon_obj->radius);
7969+
primarySource->setTriggerRadius(weapon_obj->radius * radius_mult);
79647970
primarySource->setTriggerVelocity(vm_vec_mag_quick(&weapon_obj->phys_info.vel));
79657971

79667972
if (hitnormal)
@@ -7972,7 +7978,7 @@ void weapon_hit( object* weapon_obj, object* impacted_obj, const vec3d* hitpos,
79727978
if (wip->piercing_impact_secondary_effect.isValid()) {
79737979
auto secondarySource = ParticleManager::get()->createSource(wip->piercing_impact_secondary_effect);
79747980
secondarySource->setHost(weapon_hit_make_effect_host(weapon_obj, impacted_obj, submodel, hitpos, local_hitpos));
7975-
secondarySource->setTriggerRadius(weapon_obj->radius);
7981+
secondarySource->setTriggerRadius(weapon_obj->radius * radius_mult);
79767982
secondarySource->setTriggerVelocity(vm_vec_mag_quick(&weapon_obj->phys_info.vel));
79777983

79787984
if (hitnormal)

0 commit comments

Comments
 (0)