Skip to content

Commit 8f012c8

Browse files
VmpOS2NHSkhkejA9WrillSirRichardFrancis
authored
Make it harder to decapitate people with rods and ammo boxes (#8561)
* changes * Update stack.dm * Update stack.dm * Apply suggestions from code review Co-authored-by: SirRichardFrancis <65828539+SirRichardFrancis@users.noreply.github.com> * Update stack.dm --------- Co-authored-by: Wrill <86113712+WrillWasTaken@users.noreply.github.com> Co-authored-by: SirRichardFrancis <65828539+SirRichardFrancis@users.noreply.github.com>
1 parent 70c3216 commit 8f012c8

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

code/game/objects/items/stacks/rods.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
max_amount = 60
1616
attack_verb = list("hit", "bludgeoned", "whacked")
1717
price_tag = 1
18+
automerge = TRUE
1819

1920
/obj/item/stack/rods/random
2021
rand_min = 2
@@ -31,6 +32,7 @@
3132
charge_costs = list(500)
3233
stacktype = /obj/item/stack/rods
3334
spawn_tags = null
35+
automerge = FALSE
3436

3537
/obj/item/stack/rods/attackby(obj/item/I, mob/living/user)
3638
..()

code/game/objects/items/stacks/stack.dm

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,38 @@
2626
var/consumable = TRUE // Will the stack disappear entirely once the amount is used up?
2727
var/splittable = TRUE // Is the stack capable of being splitted?
2828
var/novariants = TRUE //Determines whether the item should update it's sprites based on amount.
29+
var/automerge = FALSE // Automatically merge with stacks on the same tile?
2930

3031
//If either of these two are set to nonzero values, the stack will have randomised quantity on spawn
3132
//Used for the /random subtypes of material stacks. any stack works
3233
var/rand_min = 0
3334
var/rand_max = 0
34-
35-
36-
35+
//Damage dealt to something when falling on it, per amount in the stack.
36+
//IE, if this is 0.2 a stack of 120 will deal 24 base damage when falling on a mob
37+
var/fall_damage_per_amount = 0.2
3738

3839
/obj/item/stack/New(var/loc, var/amount=null)
3940
.=..()
4041
if (amount)
4142
src.amount = amount
4243

4344
/obj/item/stack/Initialize()
44-
.=..()
45+
. = ..()
4546
if (!stacktype)
4647
stacktype = type
4748

4849
if (rand_min || rand_max)
4950
amount = rand(rand_min, rand_max)
5051
amount = round(amount, 1) //Just in case
5152
update_icon()
53+
if(automerge)
54+
return INITIALIZE_HINT_LATELOAD
55+
56+
//do this a little later because trying to merge with uninitialized stacks is an easy way to cause runtimes
57+
/obj/item/stack/LateInitialize()
58+
. = ..()
59+
if(automerge)
60+
merge_loc_stacks()
5261

5362
/obj/item/stack/update_icon()
5463
if(novariants)
@@ -378,6 +387,9 @@
378387
else
379388
return ..()
380389

390+
/obj/item/stack/get_fall_damage()
391+
return amount * fall_damage_per_amount
392+
381393
//Verb to split stacks
382394
/obj/item/stack/verb/split_verb()
383395
set src in view(1)
@@ -413,6 +425,16 @@
413425
/obj/item/stack/get_item_cost(export)
414426
return amount * ..()
415427

428+
/obj/item/stack/Crossed(O)
429+
. = ..()
430+
if(automerge && (O != src) && istype(O, /obj/item/stack))
431+
transfer_to(O)
432+
433+
/obj/item/stack/proc/merge_loc_stacks()
434+
for(var/obj/item/stack/material/loc_stack in loc)
435+
if(loc_stack != src)
436+
transfer_to(loc_stack)
437+
416438
/*
417439
* Recipe datum
418440
*/

code/modules/materials/material_sheets.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
throw_range = 3
99
max_amount = 120
1010
bad_type = /obj/item/stack/material
11+
automerge = TRUE
1112

1213
var/default_type = MATERIAL_STEEL
1314
var/material/material
@@ -90,7 +91,6 @@
9091
..()
9192
update_strings()
9293

93-
9494
/obj/item/stack/material/iron
9595
name = "iron"
9696
icon_state = "sheet-iron"
@@ -271,6 +271,7 @@
271271
apply_colour = 1
272272
price_tag = 50
273273
novariants = FALSE
274+
fall_damage_per_amount = 0.5
274275

275276
/obj/item/stack/material/osmium/full
276277
amount = 120

code/modules/projectiles/ammunition.dm

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
for(var/mattertype in .)
162162
.[mattertype] *= amount // multiply matter appropriately
163163

164+
/obj/item/ammo_casing/get_fall_damage()
165+
return (amount >= min(maxamount, 10))
166+
164167
//An item that holds casings and can be used to put them inside guns
165168
/obj/item/ammo_magazine
166169
name = "magazine"
@@ -366,10 +369,25 @@
366369
to_chat(usr, SPAN_NOTICE("[src] is already empty!"))
367370
return
368371
to_chat(usr, SPAN_NOTICE("You take out ammo from [src]."))
369-
for(var/i=1 to stored_ammo.len)
370-
var/obj/item/ammo_casing/C = removeCasing()
371-
C.forceMove(target)
372-
C.set_dir(pick(cardinal))
372+
373+
while(LAZYLEN(stored_ammo))
374+
375+
var/obj/item/ammo_casing/stack = removeCasing()
376+
stack.forceMove(target)
377+
stack.set_dir(pick(cardinal))
378+
379+
if(LAZYLEN(stored_ammo))
380+
// We end on -1 since we already removed one
381+
for(var/i = 1, i <= stack.maxamount - 1, i++)
382+
if(!LAZYLEN(stored_ammo))
383+
stack.update_icon()
384+
break
385+
var/obj/item/ammo_casing/AC = removeCasing()
386+
if(!stack.mergeCasing(AC, null, null, TRUE, TRUE))
387+
insertCasing(AC)
388+
stack.update_icon()
389+
break
390+
373391
update_icon()
374392

375393
/obj/item/ammo_magazine/proc/get_label(value)

0 commit comments

Comments
 (0)