Fixes empty casings not being ejected or cycled

This commit is contained in:
mwerezak
2015-02-16 16:08:44 -05:00
parent 2791a93bf2
commit 9b3ab4358d
2 changed files with 31 additions and 18 deletions

View File

@@ -26,6 +26,10 @@
var/obj/item/ammo_magazine/ammo_magazine = null //stored magazine var/obj/item/ammo_magazine/ammo_magazine = null //stored magazine
var/auto_eject = 0 //if the magazine should automatically eject itself when empty. var/auto_eject = 0 //if the magazine should automatically eject itself when empty.
var/auto_eject_sound = null var/auto_eject_sound = null
//TODO generalize ammo icon states for guns
//var/magazine_states = 0
//var/list/icon_keys = list() //keys
//var/list/ammo_states = list() //values
/obj/item/weapon/gun/projectile/New() /obj/item/weapon/gun/projectile/New()
..() ..()
@@ -37,8 +41,7 @@
update_icon() update_icon()
/obj/item/weapon/gun/projectile/consume_next_projectile() /obj/item/weapon/gun/projectile/consume_next_projectile()
//store the next ammo_casing in a var so that handle_post_fire() knows which one to eject //get the next casing
//also we might as well remove chambered here, so that we don't have to figure out where it came from later
if(loaded.len) if(loaded.len)
chambered = loaded[1] //load next casing. chambered = loaded[1] //load next casing.
if(handle_casings != HOLD_CASINGS) if(handle_casings != HOLD_CASINGS)
@@ -47,23 +50,34 @@
chambered = ammo_magazine.stored_ammo[1] chambered = ammo_magazine.stored_ammo[1]
if(handle_casings != HOLD_CASINGS) if(handle_casings != HOLD_CASINGS)
ammo_magazine.stored_ammo -= chambered ammo_magazine.stored_ammo -= chambered
return chambered.BB
if (chambered)
return chambered.BB
return null
/obj/item/weapon/gun/projectile/handle_post_fire() /obj/item/weapon/gun/projectile/handle_post_fire()
..() ..()
if(chambered) if(chambered)
chambered.expend() chambered.expend()
process_chambered()
//check chambered again in case it deleted itself /obj/item/weapon/gun/projectile/handle_click_empty()
if(chambered && handle_casings != HOLD_CASINGS) ..()
switch(handle_casings) process_chambered()
if(EJECT_CASINGS) //eject casing onto ground.
chambered.loc = get_turf(src) /obj/item/weapon/gun/projectile/proc/process_chambered()
if(CYCLE_CASINGS) //cycle the casing back to the end. if (!chambered) return
if(ammo_magazine)
ammo_magazine.stored_ammo += chambered switch(handle_casings)
else if(EJECT_CASINGS) //eject casing onto ground.
loaded += chambered chambered.loc = get_turf(src)
if(CYCLE_CASINGS) //cycle the casing back to the end.
if(ammo_magazine)
ammo_magazine.stored_ammo += chambered
else
loaded += chambered
if(handle_casings != HOLD_CASINGS)
chambered = null chambered = null
@@ -118,7 +132,6 @@
update_icon() update_icon()
//attempts to unload src. If allow_dump is set to 0, the speedloader unloading method will be disabled //attempts to unload src. If allow_dump is set to 0, the speedloader unloading method will be disabled
/obj/item/weapon/gun/projectile/proc/unload_ammo(mob/user, var/allow_dump=1) /obj/item/weapon/gun/projectile/proc/unload_ammo(mob/user, var/allow_dump=1)
if(ammo_magazine) if(ammo_magazine)
@@ -172,7 +185,7 @@
playsound(user, auto_eject_sound, 40, 1) playsound(user, auto_eject_sound, 40, 1)
ammo_magazine.update_icon() ammo_magazine.update_icon()
ammo_magazine = null ammo_magazine = null
update_icon() update_icon() //make sure to do this after unsetting ammo_magazine
/obj/item/weapon/gun/projectile/examine(mob/user) /obj/item/weapon/gun/projectile/examine(mob/user)
..(user) ..(user)

View File

@@ -48,7 +48,7 @@
return return
/obj/item/weapon/gun/projectile/automatic/sts35 /obj/item/weapon/gun/projectile/automatic/sts35
name = "\improper STS-35 Automatic Rifle" name = "\improper STS-35 automatic rifle"
desc = "A durable, rugged looking automatic weapon of make popular on the frontier, despite it's bulk. Uses 7.62mm rounds. It is unmarked." desc = "A durable, rugged looking automatic weapon of make popular on the frontier, despite it's bulk. Uses 7.62mm rounds. It is unmarked."
icon_state = "assltrifle" icon_state = "assltrifle"
item_state = "shotgun" item_state = "shotgun"