From 037fc6c703eb00f319e2fc9ab2a65e6ef0355f82 Mon Sep 17 00:00:00 2001 From: FalloutFalcon Date: Thu, 5 Sep 2024 15:41:06 -0500 Subject: [PATCH] aghhh i hate powered --- code/__DEFINES/guns.dm | 1 + code/_globalvars/bitfields.dm | 4 +- code/modules/projectiles/guns/ballistic.dm | 99 ++++++++++++++++++- .../projectiles/guns/ballistic/gauss.dm | 7 +- code/modules/projectiles/guns/powered.dm | 96 +----------------- 5 files changed, 108 insertions(+), 99 deletions(-) diff --git a/code/__DEFINES/guns.dm b/code/__DEFINES/guns.dm index cb5665a1d9bb..90ae8c46cf67 100644 --- a/code/__DEFINES/guns.dm +++ b/code/__DEFINES/guns.dm @@ -93,6 +93,7 @@ #define AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE (1<<11) //The ammo stay in the magazine until the last moment #define AMMO_RECIEVER_AUTO_EJECT_LOCKED (1<<12) //Not allowed to turn automatic unloading off #define AMMO_RECIEVER_CELL (1<<13) +#define AMMO_RECIEVER_SECONDARY_CELL (1<<14) ///////////////// // ATTACHMENTS // diff --git a/code/_globalvars/bitfields.dm b/code/_globalvars/bitfields.dm index 5a3211cfaeeb..b2ee7fa29a59 100644 --- a/code/_globalvars/bitfields.dm +++ b/code/_globalvars/bitfields.dm @@ -301,5 +301,7 @@ DEFINE_BITFIELD(reciever_flags, list( "AMMO_RECIEVER_DO_NOT_EJECT_HANDFULS" = AMMO_RECIEVER_DO_NOT_EJECT_HANDFULS, "AMMO_RECIEVER_DO_NOT_EMPTY_ROUNDS_AFTER_FIRE" = AMMO_RECIEVER_DO_NOT_EMPTY_ROUNDS_AFTER_FIRE, "AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE" = AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE, - "AMMO_RECIEVER_AUTO_EJECT_LOCKED" = AMMO_RECIEVER_AUTO_EJECT_LOCKED + "AMMO_RECIEVER_AUTO_EJECT_LOCKED" = AMMO_RECIEVER_AUTO_EJECT_LOCKED, + "AMMO_RECIEVER_CELL" = AMMO_RECIEVER_CELL, + "AMMO_RECIEVER_SECONDARY_CELL" = AMMO_RECIEVER_SECONDARY_CELL )) diff --git a/code/modules/projectiles/guns/ballistic.dm b/code/modules/projectiles/guns/ballistic.dm index 6ec8f717e15b..f0eb024d93c5 100644 --- a/code/modules/projectiles/guns/ballistic.dm +++ b/code/modules/projectiles/guns/ballistic.dm @@ -45,7 +45,7 @@ magazine = new default_ammo_type(src) if (!default_ammo_type) get_ammo_list(drop_all = TRUE) - if(default_cell_type && reciever_flags & GUN_AMMO_COUNT_BY_PERCENTAGE) + if(default_cell_type && reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) installed_cell = new default_cell_type(src) chamber_round() update_appearance() @@ -186,10 +186,30 @@ SEND_SIGNAL(src, COMSIG_UPDATE_AMMO_HUD) /obj/item/gun/ballistic/can_shoot() + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if(QDELETED(installed_cell)) + return FALSE + var/obj/item/ammo_casing/caseless/gauss/shot = chambered + if(!shot) + return FALSE + if(installed_cell.charge < shot.energy_cost * burst_size) + return FALSE + if(safety) return FALSE return chambered +/obj/item/gun/ballistic/before_firing(atom/target,mob/user) + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + var/obj/item/ammo_casing/caseless/gauss/shot = chambered + if(shot?.energy_cost) + bullet_energy_cost = shot.energy_cost + +/obj/item/gun/ballistic/shoot_live_shot(mob/living/user, pointblank = FALSE, mob/pbtarget, message = 1, stam_cost = 0) + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + installed_cell.use(bullet_energy_cost) + return ..() + /obj/item/gun/ballistic/reload(obj/item/new_mag, mob/living/user, params, force = FALSE) if (!internal_magazine && istype(new_mag, /obj/item/ammo_box/magazine)) var/obj/item/ammo_box/magazine/AM = new_mag @@ -208,13 +228,79 @@ chambered = null var/num_loaded = magazine.attackby(new_mag, user, params) if (num_loaded) - to_chat(user, "You load [num_loaded] [cartridge_wording]\s into \the [src].") + to_chat(user, span_notice("You load [num_loaded] [cartridge_wording]\s into \the [src].")) playsound(src, load_sound, load_sound_volume, load_sound_vary) if (chambered == null && bolt_type == BOLT_TYPE_NO_BOLT) chamber_round() new_mag.update_appearance() update_appearance() return TRUE + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if (!internal_cell && istype(new_mag, /obj/item/stock_parts/cell/gun)) + var/obj/item/stock_parts/cell/gun/new_cell = new_mag + if(!(new_cell.type in allowed_cell_types)) + return + if(installed_cell) + to_chat(user, span_warning("\The [new_mag] already has a cell")) + insert_cell(user, new_cell) + +/obj/item/gun/ballistic/proc/insert_cell(mob/user, obj/item/stock_parts/cell/gun/C) + if(user.transferItemToLoc(C, src)) + installed_cell = C + to_chat(user, span_notice("You load the [C] into \the [src].")) + playsound(src, load_sound, load_sound_volume, load_sound_vary) + update_appearance() + return TRUE + else + to_chat(user, span_warning("You cannot seem to get \the [src] out of your hands!")) + return FALSE + +/obj/item/gun/ballistic/proc/eject_cell(mob/user, obj/item/stock_parts/cell/gun/tac_load = null) + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + playsound(src, load_sound, load_sound_volume, load_sound_vary) + installed_cell.forceMove(drop_location()) + var/obj/item/stock_parts/cell/gun/old_cell = installed_cell + installed_cell = null + user.put_in_hands(old_cell) + old_cell.update_appearance() + to_chat(user, span_notice("You pull the cell out of \the [src].")) + update_appearance() + +/obj/item/gun/ballistic/screwdriver_act(mob/living/user, obj/item/I) + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if(installed_cell && !internal_cell) + to_chat(user, span_notice("You begin unscrewing and pulling out the cell...")) + if(I.use_tool(src, user, unscrewing_time, volume=100)) + to_chat(user, span_notice("You remove the power cell.")) + eject_cell(user) + return ..() + +/obj/item/gun/ballistic/update_overlays() + . = ..() + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if(!automatic_charge_overlays) + return + var/overlay_icon_state = "[icon_state]_charge" + var/charge_ratio = get_charge_ratio() + if(installed_cell) + . += "[icon_state]_cell" + if(charge_ratio == 0) + . += "[icon_state]_cellempty" + else + if(!shaded_charge) + var/mutable_appearance/charge_overlay = mutable_appearance(icon, overlay_icon_state) + for(var/i in 1 to charge_ratio) + charge_overlay.pixel_x = ammo_x_offset * (i - 1) + charge_overlay.pixel_y = ammo_y_offset * (i - 1) + . += new /mutable_appearance(charge_overlay) + else + . += "[icon_state]_charge[charge_ratio]" + +/obj/item/gun/ballistic/proc/get_charge_ratio() + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if(!installed_cell) + return FALSE + return CEILING(clamp(installed_cell.charge / installed_cell.maxcharge, 0, 1) * charge_sections, 1)// Sets the ratio to 0 if the gun doesn't have enough charge to fire, or if its power cell is removed. ///Prefire empty checks for the bolt drop /obj/item/gun/ballistic/proc/prefire_empty_checks() @@ -295,6 +381,15 @@ . += 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 unique action key. By default, this is Space") +/obj/item/gun/ballistic/automatic/powered/examine_ammo_count(mob/user) + var/list/dat = list() + if(reciever_flags & AMMO_RECIEVER_SECONDARY_CELL) + if(installed_cell) + dat += span_notice("[src]'s cell is [round(installed_cell.charge / installed_cell.maxcharge, 0.1) * 100]% full.") + else + dat += span_notice("[src] doesn't seem to have a cell!") + return dat + /* /obj/item/gun/ballistic/adjust_current_rounds(obj/item/mag, new_rounds) var/obj/item/ammo_box/magazine/magazine = mag diff --git a/code/modules/projectiles/guns/ballistic/gauss.dm b/code/modules/projectiles/guns/ballistic/gauss.dm index 9ef9c769c0b8..4d6cae78f0e8 100644 --- a/code/modules/projectiles/guns/ballistic/gauss.dm +++ b/code/modules/projectiles/guns/ballistic/gauss.dm @@ -34,6 +34,7 @@ name = "Model H" desc = "A standard-issue pistol exported from the Solarian Confederation. It fires slow flesh-rending ferromagnetic slugs at a high energy cost, however they are ineffective on any armor." default_ammo_type = /obj/item/ammo_box/magazine/modelh + allowed_ammo_types = list(/obj/item/ammo_box/magazine/modelh) icon = 'icons/obj/guns/manufacturer/solararmories/48x32.dmi' lefthand_file = 'icons/obj/guns/manufacturer/solararmories/lefthand.dmi' righthand_file = 'icons/obj/guns/manufacturer/solararmories/righthand.dmi' @@ -42,7 +43,6 @@ item_state = "model-h" fire_sound = 'sound/weapons/gun/gauss/modelh.ogg' load_sound = 'sound/weapons/gun/gauss/pistol_reload.ogg' - default_cell_type = /obj/item/stock_parts/cell/gun/solgov slot_flags = ITEM_SLOT_BELT w_class = WEIGHT_CLASS_SMALL fire_delay = 0.6 SECONDS //pistol, but heavy caliber. @@ -60,7 +60,6 @@ /obj/item/gun/ballistic/automatic/powered/gauss/modelh/suns desc = "A standard-issue pistol exported from the Solarian Confederation. It fires slow flesh-rending ferromagnetic slugs at a high energy cost, however they are ineffective on any armor. It is painted in the colors of SUNS." - default_ammo_type = /obj/item/ammo_box/magazine/modelh icon_state = "model-h_suns" item_state = "model-h_suns" @@ -68,6 +67,7 @@ name = "Claris" desc = "An antiquated Solarian rifle. Chambered in ferromagnetic pellets, just as the founding Solarians intended." default_ammo_type = /obj/item/ammo_box/magazine/internal/claris + allowed_ammo_types = list(/obj/item/ammo_box/magazine/internal/claris) icon = 'icons/obj/guns/manufacturer/solararmories/48x32.dmi' lefthand_file = 'icons/obj/guns/manufacturer/solararmories/lefthand.dmi' righthand_file = 'icons/obj/guns/manufacturer/solararmories/righthand.dmi' @@ -76,7 +76,6 @@ item_state = "claris" fire_sound = 'sound/weapons/gun/gauss/claris.ogg' load_sound = 'sound/weapons/gun/gauss/sniper_reload.ogg' - default_cell_type = /obj/item/stock_parts/cell/gun/solgov fire_delay = 0.4 SECONDS bolt_type = BOLT_TYPE_NO_BOLT internal_magazine = TRUE @@ -94,6 +93,7 @@ name = "Solar 'GAR' Carbine" desc = "A Solarian carbine, unusually modern for its producers. Launches ferromagnetic lances at alarming speeds." default_ammo_type = /obj/item/ammo_box/magazine/gar + allowed_ammo_types = list(/obj/item/ammo_box/magazine/gar) icon = 'icons/obj/guns/manufacturer/solararmories/48x32.dmi' lefthand_file = 'icons/obj/guns/manufacturer/solararmories/lefthand.dmi' righthand_file = 'icons/obj/guns/manufacturer/solararmories/righthand.dmi' @@ -102,7 +102,6 @@ item_state = "gar" fire_sound = 'sound/weapons/gun/gauss/gar.ogg' load_sound = 'sound/weapons/gun/gauss/rifle_reload.ogg' - default_cell_type = /obj/item/stock_parts/cell/gun/solgov burst_size = 1 fire_delay = 0.2 SECONDS diff --git a/code/modules/projectiles/guns/powered.dm b/code/modules/projectiles/guns/powered.dm index cc40f31a6b8f..e8dba995736a 100644 --- a/code/modules/projectiles/guns/powered.dm +++ b/code/modules/projectiles/guns/powered.dm @@ -1,94 +1,6 @@ /obj/item/gun/ballistic/automatic/powered default_ammo_type = /obj/item/ammo_box/magazine/gauss - reciever_flags = AMMO_RECIEVER_MAGAZINES|AMMO_RECIEVER_CELL - -/obj/item/gun/ballistic/automatic/powered/examine_ammo_count(mob/user) - var/list/dat = list() - if(installed_cell) - dat += span_notice("[src]'s cell is [round(installed_cell.charge / installed_cell.maxcharge, 0.1) * 100]% full.") - else - dat += span_notice("[src] doesn't seem to have a cell!") - return dat - -/obj/item/gun/ballistic/automatic/powered/can_shoot() - if(QDELETED(installed_cell)) - return FALSE - - var/obj/item/ammo_casing/caseless/gauss/shot = chambered - if(!shot) - return FALSE - if(installed_cell.charge < shot.energy_cost * burst_size) - return FALSE - return ..() - -/obj/item/gun/ballistic/automatic/powered/before_firing(atom/target,mob/user) - var/obj/item/ammo_casing/caseless/gauss/shot = chambered - if(shot?.energy_cost) - bullet_energy_cost = shot.energy_cost - -/obj/item/gun/ballistic/automatic/powered/shoot_live_shot(mob/living/user, pointblank = FALSE, mob/pbtarget, message = 1, stam_cost = 0) - installed_cell.use(bullet_energy_cost) - return ..() - -/obj/item/gun/ballistic/automatic/powered/reload(obj/item/new_mag, mob/living/user, params, force = FALSE) - if(..()) - return TRUE - if (!internal_cell && istype(new_mag, /obj/item/stock_parts/cell/gun)) - var/obj/item/stock_parts/cell/gun/new_cell = new_mag - if(installed_cell) - to_chat(user, span_warning("\The [new_mag] already has a cell")) - insert_cell(user, new_cell) - -/obj/item/gun/ballistic/automatic/powered/proc/insert_cell(mob/user, obj/item/stock_parts/cell/gun/C) - if(user.transferItemToLoc(C, src)) - installed_cell = C - to_chat(user, span_notice("You load the [C] into \the [src].")) - playsound(src, load_sound, load_sound_volume, load_sound_vary) - update_appearance() - return TRUE - else - to_chat(user, span_warning("You cannot seem to get \the [src] out of your hands!")) - return FALSE - -/obj/item/gun/ballistic/automatic/powered/proc/eject_cell(mob/user, obj/item/stock_parts/cell/gun/tac_load = null) - playsound(src, load_sound, load_sound_volume, load_sound_vary) - installed_cell.forceMove(drop_location()) - var/obj/item/stock_parts/cell/gun/old_cell = installed_cell - installed_cell = null - user.put_in_hands(old_cell) - old_cell.update_appearance() - to_chat(user, span_notice("You pull the cell out of \the [src].")) - update_appearance() - -/obj/item/gun/ballistic/automatic/powered/screwdriver_act(mob/living/user, obj/item/I) - if(installed_cell && !internal_cell) - to_chat(user, span_notice("You begin unscrewing and pulling out the cell...")) - if(I.use_tool(src, user, unscrewing_time, volume=100)) - to_chat(user, span_notice("You remove the power cell.")) - eject_cell(user) - return ..() - -/obj/item/gun/ballistic/automatic/powered/update_overlays() - . = ..() - if(!automatic_charge_overlays) - return - var/overlay_icon_state = "[icon_state]_charge" - var/charge_ratio = get_charge_ratio() - if(installed_cell) - . += "[icon_state]_cell" - if(charge_ratio == 0) - . += "[icon_state]_cellempty" - else - if(!shaded_charge) - var/mutable_appearance/charge_overlay = mutable_appearance(icon, overlay_icon_state) - for(var/i in 1 to charge_ratio) - charge_overlay.pixel_x = ammo_x_offset * (i - 1) - charge_overlay.pixel_y = ammo_y_offset * (i - 1) - . += new /mutable_appearance(charge_overlay) - else - . += "[icon_state]_charge[charge_ratio]" - -/obj/item/gun/ballistic/automatic/powered/proc/get_charge_ratio() - if(!installed_cell) - return FALSE - return CEILING(clamp(installed_cell.charge / installed_cell.maxcharge, 0, 1) * charge_sections, 1)// Sets the ratio to 0 if the gun doesn't have enough charge to fire, or if its power cell is removed. + allowed_ammo_types = list(/obj/item/ammo_box/magazine/gauss) + default_cell_type = /obj/item/stock_parts/cell/gun/solgov + allowed_cell_types = list(/obj/item/stock_parts/cell/gun/solgov) + reciever_flags = AMMO_RECIEVER_MAGAZINES|AMMO_RECIEVER_SECONDARY_CELL