Skip to content

Commit

Permalink
stupid idiot commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thgvr committed Sep 29, 2024
1 parent b4aad1e commit cb094d6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 31 deletions.
10 changes: 5 additions & 5 deletions code/modules/projectiles/ammunition/_ammo_casing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
ammo_stack.update_ammo_count()
to_chat(user, span_notice("You collect [boolets] round\s. [ammo_stack] now contains [length(ammo_stack.stored_ammo)] round\s."))
else
to_chat(user, span_warning("You fail to collect anything!"))
to_chat(user, span_warning("You can't stack any more!"))
return

else if(istype(attacking_item, /obj/item/ammo_casing))
Expand All @@ -107,19 +107,19 @@
return
if(caliber != other_casing.caliber)
if(user)
to_chat(user, span_warning("I can't stack different calibers."))
to_chat(user, span_warning("You can't stack different calibers."))
return
if(stack_type != other_casing.stack_type)
if(user)
to_chat(user, span_warning("I can't stack [other_casing] with [src]."))
to_chat(user, span_warning("You can't stack [other_casing] with [src]."))
return
if(!BB || !other_casing.BB)
if(user)
to_chat(user, span_warning("I can't stack empty casings."))
to_chat(user, span_warning("You can't stack empty casings."))
return
if((item_flags & IN_STORAGE) || (other_casing.item_flags & IN_STORAGE))
if(user)
to_chat(user, span_warning("Can't stack casings while they are inside storage."))
to_chat(user, span_warning("You can't stack casings while they are inside storage."))
return
var/obj/item/ammo_box/magazine/ammo_stack/ammo_stack = other_casing.stack_with(src)
if(user)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/ballistic/shotgun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/obj/item/ammo_casing/shotgun
name = "shotgun slug"
desc = "A 12-gauge lead slug."
icon = 'icons/obj/ammo_shotshells.dmi'
icon_state = "slug"
caliber = "12ga"
custom_materials = list(/datum/material/iron=4000)
projectile_type = /obj/projectile/bullet/slug
stack_size = 8 //Not too big of a handful, not too small
bullet_per_box = 25

bounce_sfx_override = 'sound/weapons/gun/general/bulletcasing_shotgun_bounce.ogg'
Expand Down
33 changes: 27 additions & 6 deletions code/modules/projectiles/boxes_magazines/_box_magazine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,39 @@
. = ..()
if(!base_icon_state)
base_icon_state = icon_state

if(!bullet_cost)
for (var/material in custom_materials)
var/material_amount = custom_materials[material]
LAZYSET(base_cost, material, (material_amount * 0.10))

material_amount *= 0.90 // 10% for the container
material_amount /= max_ammo
LAZYSET(bullet_cost, material, material_amount)
LAZYSET(bullet_cost, material, material_amount).

if(!start_empty)
for(var/i = 1, i <= max_ammo, i++)
stored_ammo += new ammo_type(src)
update_ammo_count()
top_off(starting = TRUE)

update_appearance()

/**
* top_off is used to refill the magazine to max, in case you want to increase the size of a magazine with VV then refill it at once
*
* Arguments:
* * load_type - if you want to specify a specific ammo casing type to load, enter the path here, otherwise it'll use the basic [/obj/item/ammo_box/var/ammo_type]. Must be a compatible round
* * starting - Relevant for revolver cylinders, if FALSE then we mind the nulls that represent the empty cylinders (since those nulls don't exist yet if we haven't initialized when this is TRUE)
*/
/obj/item/ammo_box/proc/top_off(load_type, starting=FALSE)
if(!load_type) //this check comes first so not defining an argument means we just go with default ammo
load_type = ammo_type

var/obj/item/ammo_casing/round_check = load_type
if(!starting && (caliber && initial(round_check.caliber) != caliber) || (!caliber && load_type != ammo_type))
stack_trace("Tried loading unsupported ammocasing type [load_type] into ammo box [type].")
return

for(var/i = max(1, stored_ammo.len), i <= max_ammo, i++)
stored_ammo += new round_check(src)

///gets a round from the magazine, if keep is TRUE the round will stay in the gun
/obj/item/ammo_box/proc/get_round(keep = FALSE)
Expand Down Expand Up @@ -100,7 +121,7 @@
if(istype(attacking_obj, /obj/item/ammo_box/magazine/ammo_stack))
var/obj/item/ammo_box/attacking_box = attacking_obj
for(var/obj/item/ammo_casing/casing_to_insert in attacking_box.stored_ammo)
if(!((instant_load && attacking_box.instant_load) || (stored_ammo.len >= max_ammo) || do_after(user, 1 SECONDS, attacking_box)))
if(!((instant_load && attacking_box.instant_load) || (stored_ammo.len >= max_ammo) || do_after(user, 1 SECONDS, attacking_box, timed_action_flags = IGNORE_USER_LOC_CHANGE)))
break
var/did_load = give_round(casing_to_insert, replace_spent)
if(!did_load)
Expand Down Expand Up @@ -136,7 +157,7 @@
if(!(user.is_holding(src) || H.l_store == src || H.r_store == src) || !user.put_in_hands(A)) //incase they're using TK
A.bounce_away(FALSE, NONE)
playsound(src, 'sound/weapons/gun/general/mag_bullet_insert.ogg', 60, TRUE)
to_chat(user, "<span class='notice'>You remove a round from [src]!</span>")
to_chat(user, span_notice("You remove a round from [src]!"))
update_ammo_count()

/// Updates the materials and appearance of this ammo box
Expand Down
39 changes: 20 additions & 19 deletions code/modules/projectiles/boxes_magazines/ammo_stack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
/obj/item/ammo_box/magazine/ammo_stack
name = "ammo stack"
desc = "A stack of ammo."
desc = "A pile of live rounds."
icon = 'icons/obj/ammo_bullets.dmi'
icon_state = "pistol-brass"
base_icon_state = "pistol-brass"
Expand All @@ -19,15 +19,16 @@
icon = initial(icon)
cut_overlays()
return ..()
// thgvr todo: doesn't support shotshells/different icon files, fix that

/obj/item/ammo_box/magazine/ammo_stack/update_icon_state()
. = ..()
cut_overlays()
icon_state = ""
for(var/casing in stored_ammo)
var/image/bullet = image(initial(icon), src, "[base_icon_state]")
bullet.pixel_x = rand(-6, 6)
bullet.pixel_y = rand(-6, 6)
bullet.pixel_x = rand(-8, 8)
bullet.pixel_y = rand(-8, 8)
bullet.transform = bullet.transform.Turn(round(45 * rand(0, 32) / 2))
add_overlay(bullet)
return UPDATE_ICON_STATE | UPDATE_OVERLAYS

Expand All @@ -38,41 +39,41 @@
var/obj/item/ammo = get_round(FALSE)
ammo.forceMove(loc_before_del)
ammo.throw_at(loc_before_del)
check_for_del()
update_ammo_count()

/obj/item/ammo_box/magazine/ammo_stack/update_ammo_count()
. = ..()
check_for_del()

/obj/item/ammo_box/magazine/ammo_stack/proc/check_for_del()
. = FALSE
if((ammo_count(TRUE) <= 0) && !QDELETED(src))
// qdel(src) thgvr todo: this needs to exist so there isn't a
if((ammo_count() <= 0) && !QDELETED(src))
qdel(src)
return

/obj/item/ammo_box/magazine/ammo_stack/attackby(obj/item/A, mob/user, params, silent = FALSE, replace_spent = 0)
/obj/item/ammo_box/magazine/ammo_stack/attackby(obj/item/handful, mob/user, params, silent = FALSE, replace_spent = 0)
var/num_loaded = 0
if(!can_load(user))
return

if(istype(A, /obj/item/ammo_box))
var/obj/item/ammo_box/AM = A
for(var/obj/item/ammo_casing/AC in AM.stored_ammo)
var/did_load = give_round(AC, replace_spent)
if(istype(handful, /obj/item/ammo_box))
var/obj/item/ammo_box/ammo_box = handful
for(var/obj/item/ammo_casing/casing in ammo_box.stored_ammo)
var/did_load = give_round(casing, replace_spent)
if(did_load)
AM.stored_ammo -= AC
ammo_box.stored_ammo -= casing
num_loaded++
if(!did_load || !multiload)
break
if(num_loaded)
AM.update_ammo_count()
ammo_box.update_ammo_count()

if(istype(A, /obj/item/ammo_casing))
var/obj/item/ammo_casing/AC = A
if(give_round(AC, replace_spent))
user.transferItemToLoc(AC, src, TRUE)
if(istype(handful, /obj/item/ammo_casing))
var/obj/item/ammo_casing/casing = handful
if(give_round(casing, replace_spent))
user.transferItemToLoc(casing, src, TRUE)
num_loaded++
AC.update_appearance()
casing.update_appearance()

if(num_loaded)
if(!silent)
Expand Down
16 changes: 16 additions & 0 deletions code/modules/projectiles/boxes_magazines/premade_ammo_stacks.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/obj/item/ammo_box/magazine/ammo_stack/prefilled

/obj/item/ammo_box/magazine/ammo_stack/prefilled/Initialize(mapload)
. = ..()
var/obj/item/ammo_casing/casing_to_copy = new ammo_type()
var/obj/item/ammo_box/magazine/ammo_stack/current_stack = casing_to_copy.stack_with(new ammo_type())
//top_off already works off of ammo_type var, shouldn't need redundancy here
src.top_off()
//Just in case top_off misbehaves
if(length(current_stack.stored_ammo) > current_stack.max_ammo)
casing_to_copy = current_stack.get_round(keep = FALSE)
qdel(casing_to_copy)

/obj/item/ammo_box/magazine/ammo_stack/prefilled/buckshot
ammo_type = /obj/item/ammo_casing/shotgun/buckshot
max_ammo = 8 //should mirror stack_size on the casing
Binary file modified icons/obj/ammo_bullets.dmi
Binary file not shown.
1 change: 1 addition & 0 deletions shiptest.dme
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,7 @@
#include "code\modules\projectiles\boxes_magazines\ammo_boxes.dm"
#include "code\modules\projectiles\boxes_magazines\ammo_stack.dm"
#include "code\modules\projectiles\boxes_magazines\generic_ammo_box.dm"
#include "code\modules\projectiles\boxes_magazines\premade_ammo_stacks.dm"
#include "code\modules\projectiles\boxes_magazines\external\gauss.dm"
#include "code\modules\projectiles\boxes_magazines\external\grenade.dm"
#include "code\modules\projectiles\boxes_magazines\external\lmg.dm"
Expand Down

0 comments on commit cb094d6

Please sign in to comment.