Skip to content

Commit

Permalink
Makes random life factor of children configurable. (scp-fs2open#6166)
Browse files Browse the repository at this point in the history
* Makes random life factor of children configurable.

* Renames parameter and associated variables.
  • Loading branch information
Kestrellius authored May 26, 2024
1 parent 914f895 commit c6efd0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions code/weapon/weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ struct weapon_info
int maximum_children_spawned; // An upper bound for the total number of spawned children, used by multi
spawn_weapon_info spawn_info[MAX_SPAWN_TYPES_PER_WEAPON];

float lifetime_variation_factor_when_child;

// swarm count
short swarm_count; // how many swarm missiles are fired for this weapon
int SwarmWait; // *Swarm firewait, default is 150 -Et1
Expand Down
11 changes: 10 additions & 1 deletion code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,11 @@ int parse_weapon(int subtype, bool replace, const char *filename)
}
}

if (optional_string("$Lifetime Variation Factor When Child:"))
{
stuff_float(&wip->lifetime_variation_factor_when_child);
}

if (wip->wi_flags[Weapon::Info_Flags::Local_ssm] && optional_string("$Local SSM:"))
{
if(optional_string("+Warpout Delay:")) {
Expand Down Expand Up @@ -6969,7 +6974,9 @@ void spawn_child_weapons(object *objp, int spawn_index_override)
rand_val = static_randf(objp->net_signature + j);
}

Weapons[Objects[weapon_objnum].instance].lifeleft *= rand_val*0.4f + 0.8f;
float child_factor = child_wip->lifetime_variation_factor_when_child;

Weapons[Objects[weapon_objnum].instance].lifeleft *= std::max(0.01f, rand_val*(child_factor*2.0f) + (1.0f - child_factor));
if (child_wip->wi_flags[Weapon::Info_Flags::Remote]) {
parent_shipp->weapons.detonate_weapon_time = timestamp((int)(DEFAULT_REMOTE_DETONATE_TRIGGER_WAIT * 1000));
parent_shipp->weapons.remote_detonaters_active++;
Expand Down Expand Up @@ -9243,6 +9250,8 @@ void weapon_info::reset()
this->spawn_info[i].spawn_chance = 1.f;
}

this->lifetime_variation_factor_when_child = 0.2;

this->swarm_count = -1;
// *Default is 150 -Et1
this->SwarmWait = SWARM_MISSILE_DELAY;
Expand Down

0 comments on commit c6efd0a

Please sign in to comment.