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

Alternative IFF #4723

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
332c096
Smartgun IFF changes and buff!
Oct 17, 2023
8cd8f53
Smartgun IFF weird fixes
morrowwolf Oct 13, 2023
95764fe
test
Oct 18, 2023
7062da8
oops
Oct 18, 2023
ee43ac2
bruh
Oct 18, 2023
2fca683
ok
Oct 18, 2023
1dcf38a
almost there
Oct 19, 2023
475db0a
oops
Oct 19, 2023
7eb7131
Smartgun IFF changes and buff!
Oct 17, 2023
1ed266f
Smartgun IFF weird fixes
morrowwolf Oct 13, 2023
1ce8b40
test
Oct 18, 2023
17eca83
oops
Oct 18, 2023
e564781
bruh
Oct 18, 2023
8bc3232
ok
Oct 18, 2023
55acaaf
almost there
Oct 19, 2023
385ba5d
oops
Oct 19, 2023
a0f46d1
Merge remote-tracking branch 'origin/erm' into erm
Oct 19, 2023
ecdb4c6
eeeeh
Oct 19, 2023
1439872
rebase
Oct 19, 2023
21b0557
I don't know what to put here
Oct 19, 2023
cee59df
fix?
Oct 19, 2023
0450ad3
m46c unnerf + bugfix
Oct 19, 2023
83da250
code doc
Oct 19, 2023
4978be4
revert MD removal
Oct 19, 2023
48170a1
Update code/_onclick/hud/fullscreen.dm
ihatethisengine Oct 20, 2023
bcbe17a
hm
Oct 20, 2023
81472f0
Merge remote-tracking branch 'origin/erm' into erm
Oct 20, 2023
3fea902
more signals
Oct 20, 2023
84c17a2
uhhhh
Oct 20, 2023
5a4135e
IFF for PB
Oct 21, 2023
091b8cb
ignore scout
Oct 21, 2023
442ab6d
Merge branch 'cmss13-devs:master' into erm
ihatethisengine Oct 22, 2023
2b812cf
ultimate snowflake fix
Oct 22, 2023
ca123b2
Merge branch 'master' into erm
ihatethisengine Nov 3, 2023
0a63185
Merge branch 'master' into erm
ihatethisengine Nov 7, 2023
0301306
Merge branch 'master' into erm
ihatethisengine Nov 11, 2023
2571e99
Update colonialmarines.dme
ihatethisengine Nov 12, 2023
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
34 changes: 34 additions & 0 deletions code/__DEFINES/dcs/signals/atom/signals_gun.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#define COMSIG_GUN_FIRE "gun_fire"
#define COMSIG_GUN_STOP_FIRE "gun_stop_fire"
#define COMSIG_GUN_FIRE_MODE_TOGGLE "gun_fire_mode_toggle"
#define COMSIG_GUN_AUTOFIREDELAY_MODIFIED "gun_autofiredelay_modified"
#define COMSIG_GUN_BURST_SHOTS_TO_FIRE_MODIFIED "gun_burst_shots_to_fire_modified"
#define COMSIG_GUN_BURST_SHOT_DELAY_MODIFIED "gun_burst_shot_delay_modified"

#define COMSIG_GUN_VULTURE_FIRED_ONEHAND "gun_vulture_fired_onehand"
#define COMSIG_VULTURE_SCOPE_MOVED "vulture_scope_moved"
#define COMSIG_VULTURE_SCOPE_SCOPED "vulture_scope_scoped"
#define COMSIG_VULTURE_SCOPE_UNSCOPED "vulture_scope_unscoped"

/// from /obj/item/weapon/gun/proc/recalculate_attachment_bonuses() : ()
#define COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES "gun_recalculate_attachment_bonuses"

/// from /obj/item/weapon/gun/proc/load_into_chamber() : ()
#define COMSIG_GUN_INTERRUPT_FIRE "gun_interrupt_fire"

//Signals for automatic fire at component
#define COMSIG_AUTO_START_SHOOTING_AT "auto_start_shooting_at"
#define COMSIG_AUTO_STOP_SHOOTING_AT "auto_stop_shooting_at"
#define COMSIG_AUTO_SHOOT "auto_shoot"

//Signals for gun auto fire component
#define COMSIG_GET_BURST_FIRE "get_burst_fire"
#define BURST_FIRING (1<<0)

/// Called before a gun fires a projectile, note NOT point blanks, /obj/item/weapon/gun/proc/handle_fire()
#define COMSIG_GUN_BEFORE_FIRE "gun_before_fire"
#define COMPONENT_CANCEL_GUN_BEFORE_FIRE (1<<0) //continue full-auto/burst attempts
#define COMPONENT_HARD_CANCEL_GUN_BEFORE_FIRE (1<<1) //hard stop firing

/// Called when IFF is toggled on or off
#define COMSIG_GUN_IFF_TOGGLED "gun_iff_toggled"
28 changes: 0 additions & 28 deletions code/__DEFINES/dcs/signals/atom/signals_item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,5 @@
#define COMSIG_ITEM_ZOOM "item_zoom"
/// from /obj/item/proc/unzoom() : (mob/user)
#define COMSIG_ITEM_UNZOOM "item_unzoom"

//Signals for automatic fire at component
#define COMSIG_AUTOMATIC_SHOOTER_START_SHOOTING_AT "start_shooting_at"
#define COMSIG_AUTOMATIC_SHOOTER_STOP_SHOOTING_AT "stop_shooting_at"
#define COMSIG_AUTOMATIC_SHOOTER_SHOOT "shoot"

//Signals for gun auto fire component
#define COMSIG_GET_BURST_FIRE "get_burst_fire"
#define BURST_FIRING (1<<0)

#define COMSIG_GUN_FIRE "gun_fire"
#define COMSIG_GUN_STOP_FIRE "gun_stop_fire"
#define COMSIG_GUN_FIRE_MODE_TOGGLE "gun_fire_mode_toggle"
#define COMSIG_GUN_AUTOFIREDELAY_MODIFIED "gun_autofiredelay_modified"
#define COMSIG_GUN_BURST_SHOTS_TO_FIRE_MODIFIED "gun_burst_shots_to_fire_modified"
#define COMSIG_GUN_BURST_SHOT_DELAY_MODIFIED "gun_burst_shot_delay_modified"

#define COMSIG_GUN_VULTURE_FIRED_ONEHAND "gun_vulture_fired_onehand"
#define COMSIG_VULTURE_SCOPE_MOVED "vulture_scope_moved"
#define COMSIG_VULTURE_SCOPE_SCOPED "vulture_scope_scoped"
#define COMSIG_VULTURE_SCOPE_UNSCOPED "vulture_scope_unscoped"

/// from /obj/item/weapon/gun/proc/recalculate_attachment_bonuses() : ()
#define COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES "gun_recalculate_attachment_bonuses"

/// from /obj/item/weapon/gun/proc/load_into_chamber() : ()
#define COMSIG_GUN_INTERRUPT_FIRE "gun_interrupt_fire"

//from /datum/authority/branch/role/proc/equip_role()
#define COMSIG_POST_SPAWN_UPDATE "post_spawn_update"
7 changes: 7 additions & 0 deletions code/_onclick/hud/fullscreen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
else
client.remove_from_screen(screen)

//Get the distance to the farthest edge of the screen
/mob/proc/get_maximum_view_range()
if(!client)
return world.view

var/offset = max(abs(client.pixel_x), abs(client.pixel_y))
return client.view + offset / 32

/atom/movable/screen/fullscreen
icon = 'icons/mob/hud/screen1_full.dmi'
Expand Down
2 changes: 1 addition & 1 deletion code/datums/ammo/bullet/pistol.dm
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
flags_ammo_behavior = AMMO_BALLISTIC

accuracy = HIT_ACCURACY_TIER_8
damage = 30
damage = 36
penetration = 20
shrapnel_chance = SHRAPNEL_CHANCE_TIER_2

6 changes: 3 additions & 3 deletions code/datums/ammo/bullet/special_ammo.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

max_range = 12
accuracy = HIT_ACCURACY_TIER_4
damage = 30
damage = 36
penetration = 0

/datum/ammo/bullet/smartgun/armor_piercing
Expand All @@ -20,7 +20,7 @@

accurate_range = 12
accuracy = HIT_ACCURACY_TIER_2
damage = 20
damage = 24
penetration = ARMOR_PENETRATION_TIER_8
damage_armor_punch = 1

Expand Down Expand Up @@ -98,7 +98,7 @@
icon_state = "bullet" // Keeping it bog standard with the turret but allows it to be changed

accurate_range = 12
damage = 35
damage = 36
penetration= ARMOR_PENETRATION_TIER_10 //Bumped the penetration to serve a different role from sentries, MGs are a bit more offensive
accuracy = HIT_ACCURACY_TIER_3

Expand Down
105 changes: 105 additions & 0 deletions code/datums/components/iff_fire_prevention.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#define IFF_HALT_COOLDOWN 0.5 SECONDS

/// A component that prevents gun (although you can attach it to anything else that shoot projectiles) from shooting when mob from the same faction stands in the way.
/// You can also pass number of ticks, to make gun have an additional delay if firing prevention comes into play, but it is not neccesary.
/datum/component/iff_fire_prevention
var/iff_additional_fire_delay
ihatethisengine marked this conversation as resolved.
Show resolved Hide resolved
COOLDOWN_DECLARE(iff_halt_cooldown)

/datum/component/iff_fire_prevention/Initialize(additional_fire_delay = 0)
. = ..()
iff_additional_fire_delay = additional_fire_delay


/datum/component/iff_fire_prevention/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_GUN_BEFORE_FIRE, PROC_REF(check_firing_lane))
RegisterSignal(parent, COMSIG_GUN_IFF_TOGGLED, PROC_REF(handle_iff_toggle))

/datum/component/iff_fire_prevention/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, list(
COMSIG_GUN_BEFORE_FIRE,
COMSIG_GUN_IFF_TOGGLED
))

/datum/component/iff_fire_prevention/proc/check_firing_lane(obj/firing_weapon, obj/projectile/projectile_to_fire, atom/target, mob/living/user)
SIGNAL_HANDLER

var/angle = get_angle(user, target)

var/range_to_check = user.get_maximum_view_range()

var/extended_target_turf = get_angle_target_turf(user, angle, range_to_check)

var/turf/starting_turf = get_turf(user)

if(!starting_turf || !extended_target_turf)
return COMPONENT_CANCEL_GUN_BEFORE_FIRE

var/list/checked_turfs = getline2(starting_turf, extended_target_turf)

//Don't shoot yourself, thanks
if(target == user)
if(COOLDOWN_FINISHED(src, iff_halt_cooldown) && user.client)
playsound_client(user.client, 'sound/weapons/smartgun_fail.ogg', src, 25)
to_chat(user, SPAN_WARNING("[firing_weapon] halts firing as an IFF marked target crosses your field of fire!"))
COOLDOWN_START(src, iff_halt_cooldown, IFF_HALT_COOLDOWN)
if(iff_additional_fire_delay)
var/obj/item/weapon/gun/gun = firing_weapon
if(istype(gun))
LAZYSET(user.fire_delay_next_fire, gun, world.time + iff_additional_fire_delay)
return COMPONENT_CANCEL_GUN_BEFORE_FIRE

//At some angles (scatter or otherwise) the original target is not in checked_turfs so we put it in there in order based on distance from user
//If we are literally clicking on someone with IFF then we don't want to fire, feels funny as a user otherwise
if(projectile_to_fire.original)
var/turf/original_target_turf = get_turf(projectile_to_fire.original)

if(original_target_turf && !(original_target_turf in checked_turfs))
var/user_to_target_dist = get_dist(starting_turf, original_target_turf)
var/list/temp_checked_turfs = checked_turfs.Copy()
checked_turfs = list()

for(var/turf/checked_turf as anything in temp_checked_turfs)
if(!(original_target_turf in checked_turfs) && user_to_target_dist < get_dist(starting_turf, checked_turf))
checked_turfs += original_target_turf

checked_turfs += checked_turf

for(var/turf/checked_turf as anything in checked_turfs)

//Wall, should block the bullet so we're good to stop checking.
if(istype(checked_turf, /turf/closed))
return

for(var/mob/living/checked_living in checked_turf)
if(checked_living == user) // sometimes it still happens
continue
if(checked_living.lying && projectile_to_fire.original != checked_living)
continue

if(checked_living.get_target_lock(user.faction_group))
if(HAS_TRAIT(checked_living, TRAIT_CLOAKED))
continue
if(COOLDOWN_FINISHED(src, iff_halt_cooldown) && user.client)
playsound_client(user.client, 'sound/weapons/smartgun_fail.ogg', src, 25)
ihatethisengine marked this conversation as resolved.
Show resolved Hide resolved
to_chat(user, SPAN_WARNING("[firing_weapon] halts firing as an IFF marked target crosses your field of fire!"))
COOLDOWN_START(src, iff_halt_cooldown, IFF_HALT_COOLDOWN)
if(iff_additional_fire_delay)
var/obj/item/weapon/gun/gun = firing_weapon
if(istype(gun))
LAZYSET(user.fire_delay_next_fire, gun, world.time + iff_additional_fire_delay)
return COMPONENT_CANCEL_GUN_BEFORE_FIRE

return //if we have a target we *can* hit and find it before any IFF targets we want to fire

/// Disable fire prevention when IFF is toggled off and other way around
/datum/component/iff_fire_prevention/proc/handle_iff_toggle(obj/gun, iff_enabled)
SIGNAL_HANDLER
if(iff_enabled)
RegisterSignal(parent, COMSIG_GUN_BEFORE_FIRE, PROC_REF(check_firing_lane))
else
UnregisterSignal(parent, COMSIG_GUN_BEFORE_FIRE)

#undef IFF_HALT_COOLDOWN
12 changes: 11 additions & 1 deletion code/modules/cm_marines/smartgun_mount.dm
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
var/user_old_y = 0

/// How much time should pass in between full auto shots, slightly higher than burst due to click delay and similar things that slow firing down
var/fire_delay = 0.3 SECONDS
var/fire_delay = 0.25 SECONDS
/// How much time should pass in between burst fire shots
var/burst_fire_delay = 0.2 SECONDS
/// How many rounds are fired per burst
Expand Down Expand Up @@ -512,6 +512,7 @@
burst_scatter_mult = SCATTER_AMOUNT_TIER_7
update_icon()
AddComponent(/datum/component/automatedfire/autofire, fire_delay, burst_fire_delay, burst_amount, gun_firemode, autofire_slow_mult, CALLBACK(src, PROC_REF(set_burst_firing)), CALLBACK(src, PROC_REF(reset_fire)), CALLBACK(src, PROC_REF(try_fire)), CALLBACK(src, PROC_REF(display_ammo)))
AddComponent(/datum/component/iff_fire_prevention)

/obj/structure/machinery/m56d_hmg/Destroy(force) //Make sure we pick up our trash.
operator?.unset_interaction()
Expand Down Expand Up @@ -723,6 +724,15 @@
final_angle += rand(-total_scatter_angle, total_scatter_angle)
target = get_angle_target_turf(T, final_angle, 30)

var/before_fire_cancel = SEND_SIGNAL(src, COMSIG_GUN_BEFORE_FIRE, in_chamber, target, operator)

if(before_fire_cancel)
if(before_fire_cancel & COMPONENT_CANCEL_GUN_BEFORE_FIRE)
return AUTOFIRE_CONTINUE

if(before_fire_cancel & COMPONENT_HARD_CANCEL_GUN_BEFORE_FIRE)
return

in_chamber.weapon_cause_data = create_cause_data(initial(name), operator)
in_chamber.setDir(dir)
in_chamber.def_zone = pick("chest","chest","chest","head")
Expand Down
Loading