mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
TGMC Final Commit - Fixes Ammo Count + symbols + Medigun/Curabitur
Changes: - Code copied over to hud.dm and commented out, to prep for upstream pull. - Commented-out, unused code removed. - CHOMPEdits removed, pending upstream PR. - Medigun no longer shows 2x the actual ammo loaded. - Curabitur now fetches the amount of shots correctly, bar 1 extra for some reason. - Curabitur ammo updates on automatic recharge ticks. - A ton of projectile get_ammo_count optimization - mostly swaps the massive if/else for for loops. Fixes multiple guns not getting ammo properly, now casings won't register as ammo unless they have a shell in the casing. - hud_state_empty defined as base on all bullets. - Corrects energy weapons missing a hud_state_empty. - Gives Ion weapons a hud_state_empty All changes have been tested, and bar the Curabitur having an extra shot for ??? reason, which is a base bug I've yet to fix, this is entirely ready for testmerge.
This commit is contained in:
@@ -92,9 +92,9 @@
|
||||
|
||||
power_supply.give(rechargeamt) //... to recharge 1/5th the battery
|
||||
update_icon()
|
||||
var/mob/living/M = loc // CHOMPEdit: TGMC Ammo HUD
|
||||
if(istype(M)) // CHOMPEdit: TGMC Ammo HUD
|
||||
M?.hud_used.update_ammo_hud(M, src) // CHOMPEdit: TGMC Ammo HUD
|
||||
var/mob/living/M = loc // TGMC Ammo HUD
|
||||
if(istype(M)) // TGMC Ammo HUD
|
||||
M?.hud_used.update_ammo_hud(M, src) // TGMC Ammo HUD
|
||||
else
|
||||
charge_tick = 0
|
||||
return 1
|
||||
@@ -114,8 +114,8 @@
|
||||
if(!power_supply) return null
|
||||
if(!ispath(projectile_type)) return null
|
||||
if(!power_supply.checked_use(charge_cost)) return null
|
||||
var/mob/living/M = loc // CHOMPEdit: TGMC Ammo HUD
|
||||
if(istype(M)) // CHOMPEdit: TGMC Ammo HUD
|
||||
var/mob/living/M = loc // TGMC Ammo HUD
|
||||
if(istype(M)) // TGMC Ammo HUD
|
||||
M?.hud_used.update_ammo_hud(M, src)
|
||||
return new projectile_type(src)
|
||||
|
||||
@@ -138,7 +138,7 @@
|
||||
playsound(src, 'sound/weapons/flipblade.ogg', 50, 1)
|
||||
update_icon()
|
||||
update_held_icon()
|
||||
user.hud_used.update_ammo_hud(user, src) // CHOMPEdit: TGMC Ammo HUD
|
||||
user.hud_used.update_ammo_hud(user, src) // TGMC Ammo HUD
|
||||
else
|
||||
to_chat(user, "<span class='notice'>This cell is not fitted for [src].</span>")
|
||||
return
|
||||
@@ -155,7 +155,7 @@
|
||||
playsound(src, 'sound/weapons/empty.ogg', 50, 1)
|
||||
update_icon()
|
||||
update_held_icon()
|
||||
user.hud_used.update_ammo_hud(user, src) // CHOMPEdit: TGMC Ammo HUD
|
||||
user.hud_used.update_ammo_hud(user, src) // TGMC Ammo HUD
|
||||
else
|
||||
to_chat(user, "<span class='notice'>[src] does not have a power cell.</span>")
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
|
||||
return results
|
||||
|
||||
// CHOMPEDIT: TGMC AMMO HUD PORT Start
|
||||
// TGMC AMMO HUD
|
||||
/obj/item/weapon/gun/energy/has_ammo_counter()
|
||||
return TRUE
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@
|
||||
|
||||
var/obj/item/ammo_casing/microbattery/batt = chambered
|
||||
|
||||
charge_left = batt.shots_left
|
||||
max_charge = initial(batt.shots_left)
|
||||
if(ammo_magazine) //Crawl to find more
|
||||
for(var/obj/item/ammo_casing/microbattery/bullet as anything in ammo_magazine.stored_ammo)
|
||||
if(istype(bullet,batt.type))
|
||||
@@ -68,6 +66,9 @@
|
||||
chambered = new_batt
|
||||
update_charge()
|
||||
update_icon()
|
||||
var/mob/living/M = loc // TGMC Ammo HUD
|
||||
if(istype(M)) // TGMC Ammo HUD
|
||||
M?.hud_used.update_ammo_hud(M, src)
|
||||
|
||||
/obj/item/weapon/gun/projectile/cell_loaded/attack_self(mob/user)
|
||||
if(!chambered)
|
||||
@@ -170,6 +171,11 @@
|
||||
update_icon()
|
||||
playsound(src, 'sound/weapons/flipblade.ogg', 50, 1)
|
||||
update_icon()
|
||||
if(istype(loc, /obj/item/weapon/gun/projectile/cell_loaded)) // Update the HUD if we're in a gun + have a user. Not that one should be able to reload the mag while it's in a gun, but just in caaaaase.
|
||||
var/obj/item/weapon/gun/projectile/cell_loaded/cell_load = loc
|
||||
var/mob/living/M = cell_load.loc
|
||||
if(istype(M))
|
||||
M?.hud_used.update_ammo_hud(M, cell_load)
|
||||
|
||||
/obj/item/ammo_magazine/cell_mag/update_icon()
|
||||
cut_overlays()
|
||||
@@ -278,4 +284,31 @@
|
||||
new /obj/item/ammo_casing/microbattery/combat/xray(src)
|
||||
new /obj/item/ammo_casing/microbattery/medical/stabilize2(src)
|
||||
new /obj/item/ammo_casing/microbattery/medical/haste(src)
|
||||
new /obj/item/ammo_casing/microbattery/medical/resist(src)
|
||||
new /obj/item/ammo_casing/microbattery/medical/resist(src)
|
||||
|
||||
// TGMC Ammo HUD: Custom handling for cell-loaded weaponry.
|
||||
/*
|
||||
/obj/item/weapon/gun/projectile/cell_loaded/get_ammo_type()
|
||||
if(!projectile_type)
|
||||
return list("unknown", "unknown")
|
||||
else
|
||||
var/obj/item/projectile/P = projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
*/
|
||||
/obj/item/weapon/gun/projectile/cell_loaded/get_ammo_count()
|
||||
if(!chambered)
|
||||
return 0 // We're not chambered, so we have 0 rounds loaded.
|
||||
|
||||
var/obj/item/ammo_casing/microbattery/batt = chambered
|
||||
|
||||
var/shots
|
||||
if(ammo_magazine) // Check how much ammo we have
|
||||
for(var/obj/item/ammo_casing/microbattery/bullet as anything in ammo_magazine.stored_ammo)
|
||||
if(istype(bullet,batt.type))
|
||||
shots += bullet.shots_left
|
||||
if(shots > 0) // We have shots ready to fire.
|
||||
return shots
|
||||
else // We're out of shots.
|
||||
return 0
|
||||
else // Else, we're unloaded/don't have a magazine.
|
||||
return 0
|
||||
@@ -57,4 +57,16 @@
|
||||
/obj/item/weapon/gun/projectile/multi_cannon/unload_ammo(mob/user, var/allow_dump=1)
|
||||
.=..()
|
||||
update_icon()
|
||||
chambered = null
|
||||
chambered = null
|
||||
|
||||
/obj/item/weapon/gun/projectile/multi_cannon/get_ammo_count() // Custom handling for the Curabitur.
|
||||
if(istype(chambered, /obj/item/ammo_casing/macrobattery))
|
||||
var/obj/item/ammo_casing/macrobattery/battery = chambered
|
||||
if(battery.charge) // Does the battery have charge?
|
||||
return battery.charge // This should safely return the amount of shots we have. Every time we fire, we decrement charge by 1, at least in all the cells I can see.
|
||||
else // No charge in the battery.
|
||||
return 0 // Return 0 ammo to the HUD.
|
||||
else if(chambered == null)
|
||||
return 0
|
||||
else
|
||||
CRASH("/obj/item/weapon/gun/projectile/multi_cannon/get_ammo_count() was called from [src] but did not have a valid magazine loaded, somehow! Chambered is currently [chambered].")
|
||||
@@ -38,6 +38,12 @@
|
||||
//alright, the below seems jank. it IS jank, but for whatever reason I can't reuse BB. big bad
|
||||
BB = null
|
||||
BB = new projectile_type
|
||||
// TGMC Ammo HUD - Update the HUD every time we expend/fire, given the Curabitur's method of handling firing.
|
||||
if(istype(loc, /obj/item/weapon/gun/projectile/multi_cannon))
|
||||
var/obj/item/weapon/gun/projectile/multi_cannon = loc
|
||||
var/mob/living/user = multi_cannon.loc
|
||||
if(istype(user))
|
||||
user?.hud_used.update_ammo_hud(user, multi_cannon)
|
||||
return
|
||||
else
|
||||
BB = null
|
||||
@@ -52,6 +58,13 @@
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
if(istype(loc,/obj/item/weapon/gun/projectile/multi_cannon))
|
||||
loc.update_icon()
|
||||
|
||||
// TGMC Ammo HUD - Update the HUD every time we're called to recharge.
|
||||
if(istype(loc, /obj/item/weapon/gun/projectile/multi_cannon))
|
||||
var/obj/item/weapon/gun/projectile/multi_cannon = loc
|
||||
var/mob/living/user = multi_cannon.loc
|
||||
if(istype(user))
|
||||
user?.hud_used.update_ammo_hud(user, multi_cannon)
|
||||
|
||||
//variants here, there's not many of them.
|
||||
|
||||
|
||||
@@ -212,6 +212,7 @@
|
||||
else
|
||||
to_chat(user, "<span class='warning'>[src] is empty.</span>")
|
||||
update_icon()
|
||||
user.hud_used.update_ammo_hud(user, src)
|
||||
|
||||
/obj/item/weapon/gun/projectile/attackby(var/obj/item/A as obj, mob/user as mob)
|
||||
..()
|
||||
@@ -242,6 +243,7 @@
|
||||
ammo_magazine.update_icon()
|
||||
ammo_magazine = null
|
||||
update_icon() //make sure to do this after unsetting ammo_magazine
|
||||
user.hud_used.update_ammo_hud(user, src)
|
||||
|
||||
/obj/item/weapon/gun/projectile/examine(mob/user)
|
||||
. = ..()
|
||||
@@ -276,57 +278,66 @@
|
||||
return TRUE
|
||||
|
||||
/obj/item/weapon/gun/projectile/get_ammo_type()
|
||||
if(load_method == MAGAZINE)
|
||||
if(load_method & MAGAZINE)
|
||||
if(chambered) // Do we have an ammo casing chambered
|
||||
var/obj/item/ammo_casing/A = chambered
|
||||
var/obj/item/projectile/P = A.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
else if(ammo_magazine && ammo_magazine.stored_ammo.len) // Are we loaded, have a mag, and have ammo in the mag?
|
||||
else if(ammo_magazine && ammo_magazine.stored_ammo.len) // Do we have a mag, and have ammo in the mag, but nothing chambered?
|
||||
var/obj/item/ammo_casing/A = ammo_magazine.stored_ammo[1]
|
||||
var/obj/item/projectile/P = A.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
else if(!ammo_magazine && !chambered && src.projectile_type) // Else, we're entirely empty, and have no mag/nothing loaded in the gun, and nothing in the chamber. Return the DEFAULT projectile_type on the gun, if set.
|
||||
else if(src.projectile_type) // Else, we're entirely empty, and irregardless of the mag we have loaded (as it's empty, or it would've passed the length check above), return the DEFAULT projectile_type on the gun, if set.
|
||||
var/obj/item/projectile/P = src.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
else
|
||||
return list("unknown", "unknown") // Safety, this shouldn't happen, but just in case
|
||||
else if(load_method == (SINGLE_CASING | SPEEDLOADER))
|
||||
else if(load_method & (SINGLE_CASING|SPEEDLOADER)) // Do we load with single casings OR speedloaders?
|
||||
if(chambered) // Do we have an ammo casing loaded in the chamber? All casings still have a projectile_type var.
|
||||
var/obj/item/ammo_casing/A = chambered
|
||||
var/obj/item/projectile/P = A.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty)) // Return the casing's projectile_type ammo hud state
|
||||
else if(!chambered && loaded.len) // Else, is the gun loaded, but no ammo casings in chamber currently?
|
||||
else if(loaded.len) // Else, is the gun loaded, but no ammo casings in chamber currently?
|
||||
var/obj/item/ammo_casing/A = loaded[1]
|
||||
var/obj/item/projectile/P = A.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty)) // Return the ammunition loaded in the gun's hud_state
|
||||
else if(!chambered && !loaded.len && src.projectile_type) // Else, we're entirely empty, and have no mag/nothing loaded in the gun, and nothing in the chamber. Return the DEFAULT projectile_type on the gun, if set.
|
||||
else if(src.projectile_type) // Else, we're entirely empty, and have nothing loaded in the gun, and nothing in the chamber. Return the DEFAULT projectile_type on the gun, if set.
|
||||
var/obj/item/projectile/P = src.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
else
|
||||
return list("unknown", "unknown") // Safety, this shouldn't happen, but just in case
|
||||
else
|
||||
return list("unknown", "unknown") // Failsafe if we somehow fail both methods
|
||||
else if(src.projectile_type) // Failsafe if we somehow don't pass the above. Return the DEFAULT projectile_type on the gun, if set.
|
||||
var/obj/item/projectile/P = src.projectile_type
|
||||
return list(initial(P.hud_state), initial(P.hud_state_empty))
|
||||
else // Failsafe if we somehow fail all three methods
|
||||
return list("unknown", "unknown")
|
||||
|
||||
/obj/item/weapon/gun/projectile/get_ammo_count()
|
||||
if(load_method == MAGAZINE)
|
||||
if(!ammo_magazine && chambered) // No magazine, and we have a casing chambered? Return if we have a round chambered or not. BB is the var for the round inside the casing.
|
||||
return chambered.BB ? 1 : 0
|
||||
else if(ammo_magazine && chambered) // If we have a magazine loaded, check if chambered and return either the magazine + chambered or the loaded amount
|
||||
return chambered.BB ? (ammo_magazine.stored_ammo.len + 1) : ammo_magazine.stored_ammo.len
|
||||
else if(!chambered && ammo_magazine) // If we have a magazine loaded, but nothing chambered, return the magazine amount, if it exists.
|
||||
return ammo_magazine.stored_ammo.len
|
||||
else // Completely unloaded or code failure.
|
||||
return 0
|
||||
else if(load_method == SINGLE_CASING | SPEEDLOADER)
|
||||
if(chambered && chambered.BB && !loaded.len) // Chambered and has a round in the casing, but nothing in the magazine/internal ammo. BB is the var for the round inside the casing.
|
||||
return chambered.BB ? 1 : 0
|
||||
else if(chambered && chambered.BB && loaded.len) // Chambered casing + round + has ammo. BB is the var for the round inside the casing.
|
||||
return loaded.len + (chambered.BB ? 1 : 0)
|
||||
else if(chambered && !chambered.BB && loaded.len) // Has ammo, no round chambered (but might have a casing still in the breech). BB is the var for the round inside the casing.
|
||||
return loaded.len
|
||||
else if(!chambered && loaded.len) // Has ammo, not chambered, or doesn't use the chambered var
|
||||
return loaded.len
|
||||
else // Completely unloaded, nothing in chamber or ammo, or code failed???
|
||||
return 0
|
||||
else
|
||||
CRASH("/obj/item/weapon/gun/projectile/get_ammo_count() was called from [src] but did not have a valid load_method set! Load_method set was [load_method].")
|
||||
if(ammo_magazine) // Do we have a magazine loaded?
|
||||
var/shots_left
|
||||
if(chambered && chambered.BB) // Do we have a bullet in the currently-chambered casing, if any?
|
||||
shots_left++
|
||||
for(var/obj/item/ammo_casing/bullet in ammo_magazine.stored_ammo)
|
||||
if(bullet.BB)
|
||||
shots_left++
|
||||
|
||||
if(shots_left > 0)
|
||||
return shots_left
|
||||
else
|
||||
return 0 // No ammo left or failsafe.
|
||||
else if(loaded) // Do we use internal ammunition
|
||||
var/shots_left
|
||||
if(chambered && chambered.BB) // Do we have a bullet in the currently-chambered casing, if any?
|
||||
shots_left++
|
||||
for(var/obj/item/ammo_casing/bullet in loaded)
|
||||
if(bullet.BB) // Only increment how many shots we have left if we're loaded.
|
||||
shots_left++
|
||||
|
||||
if(shots_left > 0)
|
||||
return shots_left
|
||||
else
|
||||
return 0 // No ammo left or failsafe.
|
||||
else if(chambered) // If we don't have a magazine or internal ammunition loaded, but we have a casing in chamber, return the amount.
|
||||
return chambered.BB ? 1 : 0
|
||||
else // Failsafe, or completely unloaded
|
||||
return 0
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
impact_effect_type = /obj/effect/temp_visual/impact_effect
|
||||
var/mob_passthrough_check = 0
|
||||
hud_state = "pistol_lightap"
|
||||
hud_state_empty = "pistol_empty" // Just in case we somehow have no hud_state_empty defined
|
||||
|
||||
muzzle_type = /obj/effect/projectile/muzzle/bullet
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
hitsound_wall = 'sound/weapons/effects/searwall.ogg'
|
||||
hitsound = 'sound/weapons/zapbang.ogg'
|
||||
hud_state = "plasma"
|
||||
hud_state = "battery_empty"
|
||||
hud_state_empty = "battery_empty"
|
||||
|
||||
var/flash_strength = 10
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
light_power = 0.5
|
||||
light_color = "#55AAFF"
|
||||
hud_state = "plasma_blast"
|
||||
hud_state_empty = "battery_empty"
|
||||
|
||||
combustion = FALSE
|
||||
impact_effect_type = /obj/effect/temp_visual/impact_effect/ion
|
||||
|
||||
Reference in New Issue
Block a user