Skip to content

Commit

Permalink
nearly done with factoring ballistic out
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed Sep 6, 2024
1 parent 0739e4b commit b10f22d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 149 deletions.
130 changes: 113 additions & 17 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
var/spawn_empty_mag = FALSE

var/gun_features_flags = GUN_AMMO_COUNTER
var/reciever_flags = AMMO_RECIEVER_MAGAZINES|AMMO_RECIEVER_AUTO_EJECT
var/reciever_flags = AMMO_RECIEVER_MAGAZINES


var/default_cell_type = /obj/item/stock_parts/cell/gun
Expand Down Expand Up @@ -426,15 +426,19 @@
if(manufacturer)
. += "It has <b>[manufacturer]</b> engraved on it."
if(has_safety)
. += "The safety is [safety ? span_green("ON") : span_red("OFF")]. [span_info("<b>Ctrl-Click</b> to toggle the safety.")]"
. += "The safety is [safety ? span_green("ON") : span_red("OFF")]. [span_info("<b>Ctrl-click</b> to toggle the safety.")]"
if(reciever_flags & AMMO_RECIEVER_CELL)
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
if(installed_cell)
. += "\The [name] is on <b>[shot.select_name]</b> mode."
. += "It is on <b>[shot.select_name]</b> mode."
if(ammo_type.len > 1)
. += "You can switch firemodes by pressing the <b>unique action</b> key. By default, this is <b>space</b>"
. += "You can switch firemodes by pressing the <b>unique action</b> key. By default, this is <b>space</b>."
else
. += span_notice("\The [name] doesn't seem to have a cell!")
. += "It doesn't seem to have a cell!"
else
if (bolt_locked)
. += "The [bolt_wording] is locked back and needs to be released before firing."
. += span_info("You can [bolt_wording] it by pressing the <b>unique action</b> key. By default, this is <b>space</b.>")
. += examine_ammo_count(user)

/obj/item/gun/proc/examine_ammo_count(mob/user)
Expand Down Expand Up @@ -480,18 +484,59 @@
return

//called after the gun has successfully fired its chambered ammo.
/obj/item/gun/proc/process_chamber(atom/shooter)
/obj/item/gun/proc/process_chamber(atom/shooter, empty_chamber = TRUE, from_firing = TRUE, chamber_next_round = TRUE)
if(!semi_auto && from_firing)
return
var/obj/item/ammo_casing/casing = chambered //Find chambered round
if(istype(casing)) //there's a chambered round
if(casing_ejector || !from_firing)
casing.on_eject(shooter)
chambered = null
else if(empty_chamber)
chambered = null
if (chamber_next_round && (magazine?.max_ammo > 1))
chamber_round()
SEND_SIGNAL(src, COMSIG_GUN_CHAMBER_PROCESSED)
return FALSE

///Used to chamber a new round and eject the old one
/obj/item/gun/proc/chamber_round(keep_bullet = FALSE)
return
if (chambered || !magazine)
return
if (magazine.ammo_count())
chambered = magazine.get_round(keep_bullet || bolt_type == BOLT_TYPE_NO_BOLT)
if (bolt_type != BOLT_TYPE_OPEN)
chambered.forceMove(src)

///updates a bunch of racking related stuff and also handles the sound effects and the like
/obj/item/gun/proc/rack(mob/user = null, chamber_new_round = TRUE)
return
if (bolt_type == BOLT_TYPE_NO_BOLT) //If there's no bolt, nothing to rack
return
if (bolt_type == BOLT_TYPE_OPEN)
if(!bolt_locked) //If it's an open bolt, racking again would do nothing
if (user)
to_chat(user, "<span class='notice'>\The [src]'s [bolt_wording] is already cocked!</span>")
return
bolt_locked = FALSE
if (user)
to_chat(user, "<span class='notice'>You rack the [bolt_wording] of \the [src].</span>")
process_chamber(user, !chambered, FALSE, chamber_new_round)
if ((bolt_type == BOLT_TYPE_LOCKING && !chambered) || bolt_type == BOLT_TYPE_CLIP)
bolt_locked = TRUE
playsound(src, lock_back_sound, lock_back_sound_volume, lock_back_sound_vary)
else
playsound(src, rack_sound, rack_sound_volume, rack_sound_vary)

SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)

/obj/item/gun/proc/drop_bolt(mob/user = null, chamber_new_round = TRUE)
return
playsound(src, bolt_drop_sound, bolt_drop_sound_volume, FALSE)
if (user)
to_chat(user, "<span class='notice'>You drop the [bolt_wording] of \the [src].</span>")
if(chamber_new_round)
chamber_round()
bolt_locked = FALSE
update_appearance()

//check if there's enough ammo/energy/whatever to shoot one time
//i.e if clicking would make it shoot
/obj/item/gun/proc/can_shoot()
Expand Down Expand Up @@ -546,11 +591,29 @@
// Good job, but we have exta checks to do...
return pre_fire(target, user, TRUE, flag, params, null)

///Prefire empty checks for the bolt drop
/obj/item/gun/proc/prefire_empty_checks()
return
if (!chambered && !get_ammo_count())
if (bolt_type == BOLT_TYPE_OPEN && !bolt_locked)
bolt_locked = TRUE
playsound(src, bolt_drop_sound, bolt_drop_sound_volume)
update_appearance()

///postfire empty checks for bolt locking and sound alarms
/obj/item/gun/proc/postfire_empty_checks(last_shot_succeeded)
return
if (!chambered && !get_ammo_count())
if (last_shot_succeeded)
if (empty_alarm)
playsound(src, empty_alarm_sound, empty_alarm_volume, empty_alarm_vary)
update_appearance()
if (reciever_flags & AMMO_RECIEVER_AUTO_EJECT && !internal_magazine)
eject_mag(display_message = FALSE)
update_appearance()
if (bolt_type == BOLT_TYPE_LOCKING)
bolt_locked = TRUE
update_appearance()
if (bolt_type == BOLT_TYPE_CLIP)
update_appearance()

/obj/item/gun/proc/pre_fire(atom/target, mob/living/user, message = TRUE, flag, params = null, zone_override = "", bonus_spread = 0, dual_wielded_gun = FALSE)
prefire_empty_checks()
Expand Down Expand Up @@ -696,7 +759,7 @@
shoot_live_shot(user, (get_dist(user, target) <= 1), target, message) //Making sure whether the target is in vicinity for the pointblank shot

//process the chamber...
process_chamber(shooter = user)
process_chamber(user)
update_appearance()
//get our current firemode...
var/current_firemode = gun_firemodes[firemode_index]
Expand Down Expand Up @@ -933,7 +996,7 @@
if (magazine)
if (unique_mag_sprites_for_variants)
. += "[icon_state]_mag_[magazine.base_icon_state]"
if (!magazine.ammo_count())
if (!get_ammo_count(countchambered = FALSE))
. += "[icon_state]_mag_empty"
else
. += "[icon_state]_mag"
Expand Down Expand Up @@ -1241,6 +1304,40 @@
else
..()

/obj/item/gun/unique_action(mob/living/user)
if(bolt_type == BOLT_TYPE_NO_BOLT)
chambered = null
var/num_unloaded = 0
for(var/obj/item/ammo_casing/CB in get_ammo_list(FALSE, TRUE))
CB.forceMove(drop_location())

var/angle_of_movement =(rand(-3000, 3000) / 100) + dir2angle(turn(user.dir, 180))
CB.AddComponent(/datum/component/movable_physics, _horizontal_velocity = rand(350, 450) / 100, _vertical_velocity = rand(400, 450) / 100, _horizontal_friction = rand(20, 24) / 100, _z_gravity = PHYSICS_GRAV_STANDARD, _z_floor = 0, _angle_of_movement = angle_of_movement, _bounce_sound = CB.bounce_sfx_override)

num_unloaded++
SSblackbox.record_feedback("tally", "station_mess_created", 1, CB.name)
if (num_unloaded)
to_chat(user, "<span class='notice'>You unload [num_unloaded] [cartridge_wording]\s from [src].</span>")
playsound(user, eject_sound, eject_sound_volume, eject_sound_vary)
update_appearance()
else
to_chat(user, "<span class='warning'>[src] is empty!</span>")
return
if((bolt_type == BOLT_TYPE_LOCKING || bolt_type == BOLT_TYPE_CLIP) && bolt_locked)
drop_bolt(user)
return

if (recent_rack > world.time)
return
recent_rack = world.time + rack_delay
if(bolt_type == BOLT_TYPE_CLIP)
rack(user, FALSE)
update_appearance()
return
rack(user)
update_appearance()
return

/obj/item/gun/proc/fire_select(mob/living/carbon/human/user)

//gun_firemodes = list(FIREMODE_SEMIAUTO, FIREMODE_BURST, FIREMODE_FULLAUTO, FIREMODE_OTHER)
Expand Down Expand Up @@ -1341,7 +1438,7 @@
magazine = inserted_mag
if (display_message)
to_chat(user, "<span class='notice'>You load a new [magazine_wording] into \the [src].</span>")
if (magazine.ammo_count())
if (get_ammo_count(countchambered = FALSE))
playsound(src, load_sound, load_sound_volume, load_sound_vary)
else
playsound(src, load_empty_sound, load_sound_volume, load_sound_vary)
Expand All @@ -1353,7 +1450,6 @@
else
to_chat(user, "<span class='warning'>You cannot seem to get \the [src] out of your hands!</span>")
return FALSE
return

///Handles all the logic of magazine ejection, if tac_load is set that magazine will be tacloaded in the place of the old eject
/obj/item/gun/proc/eject_mag(mob/user, display_message = TRUE, obj/item/ammo_box/magazine/tac_load = null)
Expand All @@ -1380,7 +1476,7 @@
else
if(bolt_type == BOLT_TYPE_OPEN)
chambered = null
if (magazine.ammo_count())
if (get_ammo_count(countchambered = FALSE))
playsound(src, eject_sound, eject_sound_volume, eject_sound_vary)
else
playsound(src, eject_empty_sound, eject_sound_volume, eject_sound_vary)
Expand Down
124 changes: 0 additions & 124 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,134 +36,10 @@
)
)

/obj/item/gun/ballistic/process_chamber(empty_chamber = TRUE, from_firing = TRUE, chamber_next_round = TRUE, atom/shooter)
if(!semi_auto && from_firing)
return
var/obj/item/ammo_casing/casing = chambered //Find chambered round
if(istype(casing)) //there's a chambered round
if(casing_ejector || !from_firing)
casing.on_eject(shooter)
chambered = null
else if(empty_chamber)
chambered = null
if (chamber_next_round && (magazine?.max_ammo > 1))
chamber_round()
SEND_SIGNAL(src, COMSIG_GUN_CHAMBER_PROCESSED)

///Used to chamber a new round and eject the old one
/obj/item/gun/ballistic/chamber_round(keep_bullet = FALSE)
if (chambered || !magazine)
return
if (magazine.ammo_count())
chambered = magazine.get_round(keep_bullet || bolt_type == BOLT_TYPE_NO_BOLT)
if (bolt_type != BOLT_TYPE_OPEN)
chambered.forceMove(src)

///updates a bunch of racking related stuff and also handles the sound effects and the like
/obj/item/gun/ballistic/rack(mob/user = null, chamber_new_round = TRUE)
if (bolt_type == BOLT_TYPE_NO_BOLT) //If there's no bolt, nothing to rack
return
if (bolt_type == BOLT_TYPE_OPEN)
if(!bolt_locked) //If it's an open bolt, racking again would do nothing
if (user)
to_chat(user, "<span class='notice'>\The [src]'s [bolt_wording] is already cocked!</span>")
return
bolt_locked = FALSE
if (user)
to_chat(user, "<span class='notice'>You rack the [bolt_wording] of \the [src].</span>")
process_chamber(!chambered, FALSE, chamber_new_round, user)
if ((bolt_type == BOLT_TYPE_LOCKING && !chambered) || bolt_type == BOLT_TYPE_CLIP)
bolt_locked = TRUE
playsound(src, lock_back_sound, lock_back_sound_volume, lock_back_sound_vary)
else
playsound(src, rack_sound, rack_sound_volume, rack_sound_vary)

SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)

///Drops the bolt from a locked position
/obj/item/gun/ballistic/drop_bolt(mob/user = null, chamber_new_round = TRUE)
playsound(src, bolt_drop_sound, bolt_drop_sound_volume, FALSE)
if (user)
to_chat(user, "<span class='notice'>You drop the [bolt_wording] of \the [src].</span>")
if(chamber_new_round)
chamber_round()
bolt_locked = FALSE
update_appearance()

///Prefire empty checks for the bolt drop
/obj/item/gun/ballistic/prefire_empty_checks()
if (!chambered && !get_ammo_count())
if (bolt_type == BOLT_TYPE_OPEN && !bolt_locked)
bolt_locked = TRUE
playsound(src, bolt_drop_sound, bolt_drop_sound_volume)
update_appearance()

///postfire empty checks for bolt locking and sound alarms
/obj/item/gun/ballistic/postfire_empty_checks(last_shot_succeeded)
if (!chambered && !get_ammo_count())
if (empty_alarm && last_shot_succeeded)
playsound(src, empty_alarm_sound, empty_alarm_volume, empty_alarm_vary)
update_appearance()
if (reciever_flags & AMMO_RECIEVER_AUTO_EJECT && last_shot_succeeded && !internal_magazine)
eject_mag(display_message = FALSE)
update_appearance()
if (last_shot_succeeded && bolt_type == BOLT_TYPE_LOCKING)
bolt_locked = TRUE
update_appearance()
if (last_shot_succeeded && bolt_type == BOLT_TYPE_CLIP)
update_appearance()

/obj/item/gun/ballistic/process_fire(atom/target, mob/living/user, message = TRUE, params = null, zone_override = "", bonus_spread = 0, burst_firing = FALSE, spread_override = 0, iteration = 0)
. = ..() //The gun actually firing
postfire_empty_checks(.)

/obj/item/gun/ballistic/unique_action(mob/living/user)
if(bolt_type == BOLT_TYPE_NO_BOLT)
chambered = null
var/num_unloaded = 0
for(var/obj/item/ammo_casing/CB in get_ammo_list(FALSE, TRUE))
CB.forceMove(drop_location())

var/angle_of_movement =(rand(-3000, 3000) / 100) + dir2angle(turn(user.dir, 180))
CB.AddComponent(/datum/component/movable_physics, _horizontal_velocity = rand(350, 450) / 100, _vertical_velocity = rand(400, 450) / 100, _horizontal_friction = rand(20, 24) / 100, _z_gravity = PHYSICS_GRAV_STANDARD, _z_floor = 0, _angle_of_movement = angle_of_movement, _bounce_sound = CB.bounce_sfx_override)

num_unloaded++
SSblackbox.record_feedback("tally", "station_mess_created", 1, CB.name)
if (num_unloaded)
to_chat(user, "<span class='notice'>You unload [num_unloaded] [cartridge_wording]\s from [src].</span>")
playsound(user, eject_sound, eject_sound_volume, eject_sound_vary)
update_appearance()
else
to_chat(user, "<span class='warning'>[src] is empty!</span>")
return
if((bolt_type == BOLT_TYPE_LOCKING || bolt_type == BOLT_TYPE_CLIP) && bolt_locked)
drop_bolt(user)
return

if (recent_rack > world.time)
return
recent_rack = world.time + rack_delay
if(bolt_type == BOLT_TYPE_CLIP)
rack(user, FALSE)
update_appearance()
return
rack(user)
update_appearance()
return


/obj/item/gun/ballistic/examine(mob/user)
. = ..()
if (bolt_locked)
. += span_notice("The [bolt_wording] is locked back and needs to be released before firing.")
. += span_info("You can [bolt_wording] it by pressing the <b>unique action</b> key. By default, this is <b>Space</b>")

/*
/obj/item/gun/ballistic/adjust_current_rounds(obj/item/mag, new_rounds)
var/obj/item/ammo_box/magazine/magazine = mag
magazine?.current_rounds += new_rounds
*/

///Gets the number of bullets in the gun
/obj/item/gun/ballistic/get_ammo_count(countchambered = TRUE)
var/rounds = 0
Expand Down
3 changes: 1 addition & 2 deletions code/modules/projectiles/guns/ballistic/revolver.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
else
. += "[base_icon_state || initial(icon_state)][safety ? "_hammer_up" : "_hammer_down"]"


/obj/item/gun/ballistic/revolver/process_chamber(empty_chamber = TRUE, from_firing = TRUE, chamber_next_round = TRUE, atom/shooter)
/obj/item/gun/ballistic/revolver/process_chamber(atom/shooter, empty_chamber = TRUE, from_firing = TRUE, chamber_next_round = TRUE)
SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD)
return ..()

Expand Down
6 changes: 1 addition & 5 deletions code/modules/projectiles/guns/ballistic/rifle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if (bolt_locked == FALSE)
to_chat(user, span_notice("You open the bolt of \the [src]."))
playsound(src, rack_sound, rack_sound_volume, rack_sound_vary)
process_chamber(FALSE, FALSE, FALSE, shooter = user)
process_chamber(user, FALSE, FALSE, FALSE)
bolt_locked = TRUE
update_appearance()
if (magazine && !magazine?.ammo_count() && reciever_flags & AMMO_RECIEVER_AUTO_EJECT && !internal_magazine)
Expand All @@ -66,10 +66,6 @@
return
return ..()

/obj/item/gun/ballistic/rifle/examine(mob/user)
. = ..()
. += "The bolt is [bolt_locked ? "open" : "closed"]."

/obj/item/gun/ballistic/rifle/illestren
name = "\improper HP Illestren"
desc = "A sturdy and conventional bolt-action rifle. One of Hunter's Pride's most successful firearms, the Illestren is popular among colonists, pirates, snipers, and countless others. Chambered in 8x50mmR."
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/guns/ballistic/toy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
. = ..()
. += "[icon_state]_toy"

/obj/item/gun/ballistic/shotgun/toy/process_chamber(empty_chamber = 0, from_firing = TRUE, chamber_next_round = TRUE, atom/shooter)
/obj/item/gun/ballistic/shotgun/toy/process_chamber(atom/shooter, empty_chamber = 0, from_firing = TRUE, chamber_next_round = TRUE)
. = ..()
if(chambered && !chambered.BB)
qdel(chambered)
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/guns/energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
recharge_newshot(TRUE)
update_appearance()

///Drops the bolt from a locked position
/obj/item/gun/energy/unique_action(mob/living/user)
if(ammo_type.len > 1)
select_fire(user)
Expand Down

0 comments on commit b10f22d

Please sign in to comment.