Skip to content

Commit

Permalink
fix(projectiles): fixes space inertia && diagonal shooting
Browse files Browse the repository at this point in the history
  • Loading branch information
Zert0X authored Nov 6, 2023
1 parent d8e2366 commit 106e22c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
4 changes: 3 additions & 1 deletion code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@

//actually attempt to shoot
var/turf/targloc = get_turf(target) //cache this in case target gets deleted during shooting, e.g. if it was a securitron that got destroyed.
var/fired = FALSE
for(var/i in 1 to burst)
var/obj/projectile = consume_next_projectile(user)
if(!projectile)
handle_click_empty(user)
break

fired = TRUE
process_accuracy(projectile, user, target, i, held_twohanded)

if(pointblank)
Expand All @@ -288,7 +290,7 @@
//update timing
var/turf/T = get_turf(user)
var/area/A = get_area(T)
if((istype(T, /turf/space)) || (A.has_gravity == FALSE))
if(((istype(T, /turf/space)) || (A.has_gravity == FALSE)) && fired)
user.inertia_dir = get_dir(target, src)
user.setMoveCooldown(shoot_time) //no moving while shooting either
step(user, user.inertia_dir) // they're in space, move em in the opposite direction
Expand Down
36 changes: 23 additions & 13 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

check_armour = "bullet" //Defines what armor to use when it hits things. Must be set to bullet, laser, energy,or bomb //Cael - bio and rad are also valid

var/bumped = 0 //Prevents it from hitting more than one guy at once
var/bumped = FALSE //Prevents it from hitting more than one guy at once
var/def_zone = "" //Aiming at
var/mob/firer = null//Who shot it
var/silenced = 0 //Attack message
Expand Down Expand Up @@ -283,14 +283,14 @@

/obj/item/projectile/Bump(atom/A, forced = FALSE)
if(A == src)
return 0 //no
return FALSE //no

if(A == firer)
loc = A.loc
return 0 //cannot shoot yourself
return FALSE //cannot shoot yourself

if((bumped && !forced) || (A in permutated))
return 0
return FALSE

if(istype(A, /obj/effect/portal))
var/obj/effect/portal/P = A
Expand All @@ -299,10 +299,10 @@
permutated.Add(P)
return

var/passthrough = 0 //if the projectile should continue flying
var/passthrough = FALSE //if the projectile should continue flying
var/distance = get_dist(starting,loc)

bumped = 1
bumped = TRUE
if(ismob(A))
var/mob/M = A
if(istype(A, /mob/living))
Expand All @@ -315,7 +315,7 @@

passthrough = !attack_mob(M, distance)
else
passthrough = 1 //so ghosts don't stop bullets
passthrough = TRUE //so ghosts don't stop bullets
else
passthrough = (A.bullet_act(src, def_zone) == PROJECTILE_CONTINUE) //backwards compatibility
if(isturf(A))
Expand All @@ -327,7 +327,7 @@
//penetrating projectiles can pass through things that otherwise would not let them
if(!passthrough && penetrating > 0)
if(check_penetrate(A))
passthrough = 1
passthrough = TRUE
penetrating--

//the bullet passes through a dense object!
Expand All @@ -339,8 +339,8 @@
else
loc = A.loc
permutated.Add(A)
bumped = 0 //reset bumped variable!
return 0
bumped = FALSE //reset bumped variable!
return FALSE

//stop flying
on_impact(A)
Expand Down Expand Up @@ -493,13 +493,22 @@
on_impact(loc)
qdel(src)
return

if (QDELETED(src))
return

last_projectile_move = world.time
if(!nondirectional_sprite && !hitscanning)
var/matrix/M = new
M.Turn(Angle)
transform = M
trajectory.increment(trajectory_multiplier)
var/turf/T = trajectory.return_turf()

if (!T) // Nowhere to go. Just die.
qdel(src)
return

if(T.z != loc.z)
before_move()
before_z_change(loc, T)
Expand All @@ -511,9 +520,10 @@
pixel_x = trajectory.return_px()
pixel_y = trajectory.return_py()
else
before_move()
step_towards(src, T)
after_move()
if(T != loc)
before_move()
Move(T)
after_move()
if(!hitscanning)
pixel_x = trajectory.return_px() - trajectory.mpx * trajectory_multiplier
pixel_y = trajectory.return_py() - trajectory.mpy * trajectory_multiplier
Expand Down

0 comments on commit 106e22c

Please sign in to comment.