Skip to content

Commit

Permalink
Fixes additional projectiles (#7406)
Browse files Browse the repository at this point in the history
# About the pull request

Fixes Issue #3053 (and potentially #1764)
This PR aims to fix a bug that has been around for a long time which is
explained below.
Changes tested.

The reason why buckshots and any other multi-projectile weapons (or
explosions) are not working correctly is because of the PR that added
random speed variance for projectiles (#1608). This PR caused the
buckshot's additional projectiles to either lag behind or go faster than
the main projectile which stuns the target, causing the additional
projectiles to not hit the target most of the time.
However there is also another factor which causes the additional
projectiles to not hit the target. That is the fact that when the main
projectile hits and stuns the target (makes them fall down to the
floor), the additional projectiles miss the target because they are on
the floor and go over the target.
This causes the shotgun to not deal the intended damage because only the
main projectile hits and barely does any damage.

**This is a bugfix. It doesnt buff the projectile damage in any way. It
technically also only affects stunnable targets because the problem is
targets being stunned and the projectiles missing them.
For example; Hivelords dont get stunned, therefore they dont have an
issue with the additional projectiles.**

# Explain why it's good for the game

A buckshot shouldn't miss a target that you are adjacent to.
The bug causes the buckshot to be completely useless at times, because
it doesnt work as intended.
Even though you are adjacent to your target, the projectiles miss the
target which clearly shouldn't happen.
If you are still confused as to what this PR fixes exactly, videos below
should show the problem.

# Testing Photographs and Procedure

**These are before / after footages. First video is before the fix,
second video is after the fix.**
<details>
<summary>Screenshots & Videos</summary>

Before


https://github.com/user-attachments/assets/364bb19e-25a5-4f6f-9dd3-ce4beea0fcfa

After


https://github.com/user-attachments/assets/b797c3b3-97d2-476b-bac6-f450b976efe6



</details>


# Changelog
:cl: Ansekishoku
fix: Buckshot additional projectiles no more miss the target when they
get stunned by the main projectile.
/:cl:

---------

Co-authored-by: Doubleumc <Doubleumc@users.noreply.github.com>
  • Loading branch information
Ansekishokuu and Doubleumc authored Oct 28, 2024
1 parent 37d1f25 commit 5652e07
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion code/datums/ammo/ammo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
final_angle += rand(-total_scatter_angle, total_scatter_angle)
var/turf/new_target = get_angle_target_turf(curloc, final_angle, 30)

P.fire_at(new_target, original_P.firer, original_P.shot_from, P.ammo.max_range, P.ammo.shell_speed, original_P.original) //Fire!
P.fire_at(new_target, original_P.firer, original_P.shot_from, P.ammo.max_range, P.ammo.shell_speed, original_P.original, FALSE) //Fire!

/datum/ammo/proc/drop_flame(turf/turf, datum/cause_data/cause_data) // ~Art updated fire 20JAN17
if(!istype(turf))
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@
return
. = body_position
body_position = new_value
body_position_changed = world.time
SEND_SIGNAL(src, COMSIG_LIVING_SET_BODY_POSITION, new_value, .)
if(new_value == LYING_DOWN) // From standing to lying down.
on_lying_down()
Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/living/living_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@

/// Variable to track the body position of a mob, regardgless of the actual angle of rotation (usually matching it, but not necessarily).
var/body_position = STANDING_UP
/// For knowing when was the body position changed
var/body_position_changed = 0
/// Number of degrees of rotation of a mob. 0 means no rotation, up-side facing NORTH. 90 means up-side rotated to face EAST, and so on.
VAR_PROTECTED/lying_angle = 0
/// Value of lying lying_angle before last change. TODO: Remove the need for this.
Expand Down
14 changes: 10 additions & 4 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
return damage

// Target, firer, shot from (i.e. the gun), projectile range, projectile speed, original target (who was aimed at, not where projectile is going towards)
/obj/projectile/proc/fire_at(atom/target, atom/F, atom/S, range = 30, speed = 1, atom/original_override)
/obj/projectile/proc/fire_at(atom/target, atom/F, atom/S, range = 30, speed = 1, atom/original_override, randomize_speed = TRUE)
SHOULD_NOT_SLEEP(TRUE)
original = original || original_override || target
if(!loc)
Expand Down Expand Up @@ -230,6 +230,7 @@

//If we have the right kind of ammo, we can fire several projectiles at once.
if(ammo.bonus_projectiles_amount && ammo.bonus_projectiles_type)
randomize_speed = FALSE
ammo.fire_bonus_projectiles(src)
bonus_projectile_check = 1 //Mark this projectile as having spawned a set of bonus projectiles.

Expand All @@ -241,8 +242,11 @@
src.speed = speed
// Randomize speed by a small factor to help bullet animations look okay
// Otherwise you get a s t r e a m of warping bullets in same positions
src.speed *= (1 + (rand()-0.5) * 0.30) // 15.0% variance either way
src.speed = clamp(src.speed, 0.1, 100) // Safety to avoid loop hazards
if (randomize_speed)
src.speed *= (1 + (rand()-0.5) * 0.30) // 15.0% variance either way

// Safety to avoid loop hazards
src.speed = clamp(src.speed, 0.1, 100)

// Also give it some headstart, flying it now ahead of tick
var/delta_time = world.tick_lag * rand() * 0.4
Expand Down Expand Up @@ -835,8 +839,10 @@
//mobs use get_projectile_hit_chance instead of get_projectile_hit_boolean

/mob/living/proc/get_projectile_hit_chance(obj/projectile/P)
if((body_position == LYING_DOWN || HAS_TRAIT(src, TRAIT_NO_STRAY)) && src != P.original)
if(HAS_TRAIT(src, TRAIT_NO_STRAY) && src != P.original)
return FALSE
if(body_position == LYING_DOWN && src != P.original && world.time - body_position_changed > 0.1 SECONDS)
return FALSE // Fixes for buckshot projectiles not hitting stunned targets
var/ammo_flags = P.ammo.flags_ammo_behavior | P.projectile_override_flags
if(ammo_flags & AMMO_XENO)
if((status_flags & XENO_HOST) && HAS_TRAIT(src, TRAIT_NESTED))
Expand Down

0 comments on commit 5652e07

Please sign in to comment.