Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PORT] The recoilening #589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions code/__HELPERS/animation.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
///Makes a recoil-like animation on the mob camera.
/proc/recoil_camera(mob/M, duration, backtime_duration, strength, angle)
if(!M || !M.client)
return
var/client/sufferer = M.client
strength *= world.icon_size
var/oldx = sufferer.pixel_x
var/oldy = sufferer.pixel_y

//get pixels to move the camera in an angle
var/mpx = sin(angle) * strength
var/mpy = cos(angle) * strength
animate(sufferer, pixel_x = oldx+mpx, pixel_y = oldy+mpy, time = duration, flags = ANIMATION_RELATIVE)
animate(pixel_x = oldx, pixel_y = oldy, time = backtime_duration, easing = BACK_EASING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about this being a whole file by itself, but the code otherwise checks out.

13 changes: 11 additions & 2 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
var/suppressed_sound = 'sound/weapons/gun/general/heavy_shot_suppressed.ogg'
var/suppressed_volume = 60
var/can_unsuppress = TRUE
var/recoil = 0 //boom boom shake the room
var/clumsy_check = TRUE
var/obj/item/ammo_casing/chambered = null
trigger_guard = TRIGGER_GUARD_NORMAL //trigger guard on the weapon, hulks can't fire them with their big meaty fingers
Expand Down Expand Up @@ -85,6 +84,13 @@

var/pb_knockback = 0

///boom boom shake the room
var/recoil = 0
///a multiplier of the duration the recoil takes to go back to normal view, this is (recoil*recoil_backtime_multiplier)+1
var/recoil_backtime_multiplier = 2
///this is how much deviation the gun recoil can have, recoil pushes the screen towards the reverse angle you shot + some deviation which this is the max.
var/recoil_deviation = 22.5

/obj/item/gun/Initialize(mapload)
. = ..()
if(pin)
Expand Down Expand Up @@ -171,8 +177,11 @@
playsound(src, fire_sound, fire_sound_volume, vary_fire_sound)

/obj/item/gun/proc/shoot_live_shot(mob/living/user, pointblank = 0, atom/pbtarget = null, message = 1)
var/angle = get_angle(user, pbtarget)+rand(-recoil_deviation, recoil_deviation) + 180
if(angle > 360)
angle -= 360
if(recoil && !tk_firing(user))
shake_camera(user, recoil + 1, recoil)
recoil_camera(user, recoil+1, (recoil*recoil_backtime_multiplier) + 1, recoil, angle)
fire_sounds()
if(!suppressed)
if(message)
Expand Down
2 changes: 2 additions & 0 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
var/misfire_percentage_increment = 0
///What is the cap on our misfire probability? Do not set this to 100.
var/misfire_probability_cap = 25
/// How much recoil the gun has.
recoil = 1

/obj/item/gun/ballistic/Initialize(mapload)
. = ..()
Expand Down
2 changes: 2 additions & 0 deletions code/modules/projectiles/guns/energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
var/use_cyborg_cell = FALSE
///set to true so the gun is given an empty cell
var/dead_cell = FALSE
/// How much recoil the gun has.
recoil = 0.2

/obj/item/gun/energy/fire_sounds()
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/guns/energy/energy_gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ammo_x_offset = 2
charge_sections = 3
single_shot_type_overlay = FALSE
recoil = 0.1

/obj/item/gun/energy/e_gun/mini/add_seclight_point()
// The mini energy gun's light comes attached but is unremovable.
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/guns/energy/stun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
inhand_icon_state = null
ammo_type = list(/obj/item/ammo_casing/energy/disabler)
ammo_x_offset = 2
recoil = 0.1

/obj/item/gun/energy/disabler/add_seclight_point()
AddComponent(/datum/component/seclite_attachable, \
Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
#include "code\__HELPERS\_string_lists.dm"
#include "code\__HELPERS\admin.dm"
#include "code\__HELPERS\ai.dm"
#include "code\__HELPERS\animation.dm"
#include "code\__HELPERS\areas.dm"
#include "code\__HELPERS\atmospherics.dm"
#include "code\__HELPERS\atoms.dm"
Expand Down
Loading