Skip to content

Commit

Permalink
Adds weapon support, switches parse ordering (scp-fs2open#6254)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kestrellius authored Jul 29, 2024
1 parent cb75da4 commit 35db8e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
23 changes: 8 additions & 15 deletions code/object/collideweaponweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ int collide_weapon_weapon( obj_pair * pair )
if (wipA->weapon_hitpoints > 0) {
if (wipB->weapon_hitpoints > 0) { // Two bombs collide, detonate both.
if ((wipA->wi_flags[Weapon::Info_Flags::Bomb]) && (wipB->wi_flags[Weapon::Info_Flags::Bomb])) {
wpA->lifeleft = 0.001f;
wpA->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpA->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
wpB->lifeleft = 0.001f;
wpB->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
weapon_hit(A, B, &A->pos, -1, nullptr);
wpB->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(B, A, &B->pos, -1, nullptr);
} else {
A->hull_strength -= bDamage;
B->hull_strength -= aDamage;
Expand All @@ -155,36 +153,31 @@ int collide_weapon_weapon( obj_pair * pair )
}

if (A->hull_strength < 0.0f) {
wpA->lifeleft = 0.001f;
wpA->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpA->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(A, B, &A->pos, -1, nullptr);
}
if (B->hull_strength < 0.0f) {
wpB->lifeleft = 0.001f;
wpB->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpB->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(B, A, &B->pos, -1, nullptr);
}
}
} else {
A->hull_strength -= bDamage;
wpB->lifeleft = 0.001f;
wpB->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpB->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(B, A, &B->pos, -1, nullptr);
if (A->hull_strength < 0.0f) {
wpA->lifeleft = 0.001f;
wpA->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpA->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(A, B, &A->pos, -1, nullptr);
}
}
} else if (wipB->weapon_hitpoints > 0) {
B->hull_strength -= aDamage;
wpA->lifeleft = 0.001f;
wpA->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpA->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(A, B, &A->pos, -1, nullptr);
if (B->hull_strength < 0.0f) {
wpB->lifeleft = 0.001f;
wpB->weapon_flags.set(Weapon::Weapon_Flags::Begun_detonation);
wpB->weapon_flags.set(Weapon::Weapon_Flags::Destroyed_by_weapon);
weapon_hit(B, A, &B->pos, -1, nullptr);
}
}

Expand Down
30 changes: 20 additions & 10 deletions code/weapon/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2383,13 +2383,13 @@ int parse_weapon(int subtype, bool replace, const char *filename)
required_string("+Armor Type:");
stuff_string(fname, F_NAME, NAME_LENGTH);
armor_index = armor_type_get_idx(fname);
required_string("+Effect Name:");
ci.effect = particle::util::parseEffect(wip->name);
parse_optional_float_into("+Min Health Threshold:", &ci.min_health_threshold);
parse_optional_float_into("+Max Health Threshold:", &ci.max_health_threshold);
parse_optional_float_into("+Min Angle Threshold:", &ci.min_angle_threshold);
parse_optional_float_into("+Max Angle Threshold:", &ci.max_angle_threshold);
parse_optional_bool_into("+Dinky:", &ci.dinky);
required_string("+Effect Name:");
ci.effect = particle::util::parseEffect(wip->name);
SCP_vector<ConditionalImpact> ci_vec;
if (wip->conditional_impacts.count(armor_index) == 1) {
SCP_vector<ConditionalImpact> existing_cis = wip->conditional_impacts[armor_index];
Expand Down Expand Up @@ -7533,6 +7533,8 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
bool hit_target = false;

ship *shipp;
weapon *target_wp;
weapon_info *target_wip;
int objnum;

Assert((weapon_type >= 0) && (weapon_type < weapon_info_size()));
Expand Down Expand Up @@ -7576,15 +7578,23 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
hit_angle = vm_vec_delta_ang(hitnormal, &reverse_incoming, nullptr);
}

if (other_obj != nullptr && other_obj->type == OBJ_SHIP) {
shipp = &Ships[other_obj->instance];
if (quadrant == -1) {
relevant_armor_idx = shipp->armor_type_idx;
relevant_fraction = other_obj->hull_strength / shipp->ship_max_hull_strength;
if (wip->conditional_impacts.size() > 0 && other_obj != nullptr && (other_obj->type == OBJ_SHIP || other_obj->type == OBJ_WEAPON)) {
if (other_obj->type == OBJ_SHIP) {
shipp = &Ships[other_obj->instance];
if (quadrant == -1) {
relevant_armor_idx = shipp->armor_type_idx;
relevant_fraction = other_obj->hull_strength / i2fl(shipp->ship_max_hull_strength);
} else {
relevant_armor_idx = shipp->shield_armor_type_idx;
relevant_fraction = ship_quadrant_shield_strength(other_obj, quadrant);
}
} else {
relevant_armor_idx = shipp->shield_armor_type_idx;
relevant_fraction = ship_quadrant_shield_strength(other_obj, quadrant);
target_wp = &Weapons[other_obj->instance];
target_wip = &Weapon_info[target_wp->weapon_info_index];
relevant_armor_idx = target_wip->armor_type_idx;
relevant_fraction = other_obj->hull_strength / i2fl(target_wip->weapon_hitpoints);
}

if (wip->conditional_impacts.count(relevant_armor_idx) == 1) {
for (const auto& ci : wip->conditional_impacts[relevant_armor_idx]) {
if (((!armed_weapon) == ci.dinky)
Expand Down Expand Up @@ -7744,7 +7754,7 @@ void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int qu
}

//No other_obj means this weapon detonates
if (wip->pierce_objects && other_obj)
if (wip->pierce_objects && other_obj && other_obj->type != OBJ_WEAPON)
return;

// For all objects that had this weapon as a target, wipe it out, forcing find of a new enemy
Expand Down

0 comments on commit 35db8e3

Please sign in to comment.