Skip to content

Commit

Permalink
aghhh i hate powered
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed Sep 5, 2024
1 parent 2e430c4 commit 037fc6c
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 99 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
Expand Down
4 changes: 3 additions & 1 deletion code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
99 changes: 97 additions & 2 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -208,13 +228,79 @@
chambered = null
var/num_loaded = magazine.attackby(new_mag, user, params)
if (num_loaded)
to_chat(user, "<span class='notice'>You load [num_loaded] [cartridge_wording]\s into \the [src].</span>")
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()
Expand Down Expand Up @@ -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 <b>unique action</b> key. By default, this is <b>Space</b>")

/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
Expand Down
7 changes: 3 additions & 4 deletions code/modules/projectiles/guns/ballistic/gauss.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
Expand All @@ -60,14 +60,14 @@

/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"

/obj/item/gun/ballistic/automatic/powered/gauss/claris
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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down
96 changes: 4 additions & 92 deletions code/modules/projectiles/guns/powered.dm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 037fc6c

Please sign in to comment.