Skip to content

Commit

Permalink
Making all edge/sharpness checks use getters.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Jan 9, 2025
1 parent 5c9340d commit d1a5c81
Show file tree
Hide file tree
Showing 90 changed files with 246 additions and 249 deletions.
16 changes: 5 additions & 11 deletions code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -692,23 +692,17 @@ Turf and target are seperate in case you want to teleport some distance from a t
return zone_to_descriptor_mapping[zone] || zone

//Whether or not the given item counts as sharp in terms of dealing damage
/proc/is_sharp(obj/O)
if (!O) return 0
if (O.sharp) return 1
if (O.edge) return 1
return 0
/obj/proc/is_sharp()
return FALSE

//Whether or not the given item counts as cutting with an edge in terms of removing limbs
/proc/has_edge(obj/O)
if (!O) return 0
if (O.edge) return 1
return 0

/obj/proc/has_edge()
return FALSE

//For items that can puncture e.g. thick plastic but aren't necessarily sharp
//Returns 1 if the given item is capable of popping things like balloons, inflatable barriers, or cutting police tape.
/obj/item/proc/can_puncture()
return sharp
return is_sharp()

/obj/item/screwdriver/can_puncture()
return 1
Expand Down
4 changes: 2 additions & 2 deletions code/_onclick/item_attack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ avoid code duplication. This includes items that may sometimes act as a standard
if(milkable.handle_milked(used_item, user))
return TRUE

if(used_item.edge && has_extension(src, /datum/extension/shearable))
if(used_item.has_edge() && has_extension(src, /datum/extension/shearable))
var/datum/extension/shearable/shearable = get_extension(src, /datum/extension/shearable)
if(shearable.handle_sheared(used_item, user))
return TRUE
Expand Down Expand Up @@ -165,7 +165,7 @@ avoid code duplication. This includes items that may sometimes act as a standard
/obj/item/proc/apply_hit_effect(mob/living/target, mob/living/user, var/hit_zone)
var/use_hitsound = hitsound
if(!use_hitsound)
if(edge || sharp)
if(has_edge() || is_sharp())
use_hitsound = 'sound/weapons/bladeslice.ogg'
else
use_hitsound = "swing_hit"
Expand Down
11 changes: 5 additions & 6 deletions code/game/objects/__objs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
var/list/req_access
var/list/matter //Used to store information about the contents of the object.
var/w_class // Size of the object.
var/sharp = 0 // whether this object cuts
var/edge = 0 // whether this object is more likely to dismember

var/in_use = 0 // If we have a user using us, this will be set on. We will check if the user has stopped using us, and thus stop updating and LAGGING EVERYTHING!
var/armor_penetration = 0
var/anchor_fall = FALSE
Expand Down Expand Up @@ -119,12 +118,12 @@

/obj/proc/damage_flags()
. = 0
if(has_edge(src))
. |= DAM_EDGE
if(is_sharp(src))
. |= DAM_SHARP
if(is_sharp())
. |= DAM_SHARP|DAM_EDGE
if(atom_damage_type == BURN)
. |= DAM_LASER
else if(has_edge())
. |= DAM_EDGE

/obj/attackby(obj/item/used_item, mob/user)
// We need to call parent even if we lack dexterity, so that storage can work.
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/spiders.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

var/damage = W.get_attack_force(user) / 4

if(W.edge)
if(W.has_edge())
damage += 5

if(IS_WELDER(W))
Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/items/__item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,11 @@ modules/mob/living/human/life.dm if you die, you will be zoomed out.
/obj/item/proc/get_autopsy_descriptors()
var/list/descriptors = list()
descriptors += w_class_description()
if(sharp)
if(is_sharp())
descriptors += "sharp"
if(edge)
if(has_edge())
descriptors += "edged"
if(get_attack_force(dry_run = TRUE) >= 10 && !sharp && !edge)
if(get_attack_force(dry_run = TRUE) >= 10 && !is_sharp() && !has_edge())
descriptors += "heavy"
if(material)
descriptors += "made of [material.solid_name]"
Expand Down
24 changes: 6 additions & 18 deletions code/game/objects/items/_item_force.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@
_cached_attack_force = null
_base_attack_force = new_force

/obj/item/proc/set_edge(new_edge)
if(edge != new_edge)
edge = new_edge
return TRUE
return FALSE

/obj/item/proc/set_sharp(new_sharp)
if(sharp != new_sharp)
sharp = new_sharp
return TRUE
return FALSE

/obj/item/proc/update_attack_force()

// Get our base force.
Expand All @@ -68,14 +56,14 @@
// Check if this material is hard enough to hold an edge.
if(!material.can_hold_edge())
set_edge(FALSE)
else if(!edge)
set_edge(initial(edge))
else if(!_edge)
set_edge(initial(_edge))

// Check if this material can hold a point.
if(!material.can_hold_sharpness())
set_sharp(FALSE)
else if(!sharp)
set_sharp(initial(sharp))
else if(!_sharp)
set_sharp(initial(_sharp))

// Work out where we're going to cap our calculated force.
// Any additional force resulting from hardness or weight turn into armour penetration.
Expand Down Expand Up @@ -119,7 +107,7 @@
var/list/item_effects = weapon.get_item_effects(IE_CAT_DAMAGE)
if(length(item_effects))
for(var/decl/item_effect/damage_effect as anything in item_effects)
. = damage_effect.modify_attack_damage(., weapon, src, parameters = item_effects[damage_effect])
. = damage_effect.modify_attack_damage(., weapon, src, dry_run, item_effects[damage_effect])
return round(.)

// Debug proc - leaving in for future work. Linter hates protected var access so leave commented.
Expand Down Expand Up @@ -164,7 +152,7 @@
(attk_force + expected_material_mod),
(attk_force * item._wielded_force_multiplier),
item.armor_penetration,
(item.sharp||item.edge)
(item._sharp|item._edge)
), "|")
text2file(jointext(rows, "\n"), "weapon_stats_dump.csv")
Expand Down
21 changes: 21 additions & 0 deletions code/game/objects/items/_item_sharpness.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/obj/item
var/_sharp = FALSE
var/_edge = FALSE

/obj/item/is_sharp()
return _sharp

/obj/item/has_edge()
return _edge

/obj/item/proc/set_edge(new_edge)
if(_edge != new_edge)
_edge = new_edge
return TRUE
return FALSE

/obj/item/proc/set_sharp(new_sharp)
if(_sharp != new_sharp)
_sharp = new_sharp
return TRUE
return FALSE
4 changes: 2 additions & 2 deletions code/game/objects/items/blades/_blade.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
origin_tech = @'{"materials":1,"combat":1}'
attack_verb = list("slashed", "stabbed", "sliced", "torn", "ripped", "diced", "cut")
obj_flags = OBJ_FLAG_CONDUCTIBLE
sharp = TRUE
edge = TRUE
_sharp = TRUE
_edge = TRUE
item_flags = ITEM_FLAG_IS_WEAPON
pickup_sound = 'sound/foley/knife1.ogg'
drop_sound = 'sound/foley/knifedrop3.ogg'
Expand Down
7 changes: 3 additions & 4 deletions code/game/objects/items/blades/folding.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
desc = "A small folding knife."
icon = 'icons/obj/items/bladed/folding.dmi'
w_class = ITEM_SIZE_SMALL
sharp = FALSE
_sharp = FALSE
pommel_material = null
guard_material = null
slot_flags = null
Expand Down Expand Up @@ -53,9 +53,8 @@

/obj/item/bladed/folding/update_attack_force()
..()
// TODO: check sharp/edge.
edge = open
sharp = open
set_edge(open)
set_sharp(open)
if(open)
w_class = open_item_size
attack_verb = open_attack_verbs
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/blades/spear.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
desc = "A haphazardly-constructed yet still deadly weapon of ancient design."
icon = 'icons/obj/items/bladed/spear.dmi'
throw_speed = 3
edge = 0
sharp = 1
_edge = FALSE
_sharp = TRUE
attack_verb = list("attacked", "poked", "jabbed", "torn", "gored")
does_spin = FALSE
abstract_type = /obj/item/bladed/polearm/spear
8 changes: 4 additions & 4 deletions code/game/objects/items/rock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
desc = "The secret is to bang the rocks together, guys."
icon = 'icons/obj/items/rock.dmi'
icon_state = ICON_STATE_WORLD
sharp = TRUE
edge = TRUE
_sharp = TRUE
_edge = TRUE
_base_attack_force = 3
material_alteration = MAT_FLAG_ALTERATION_COLOR | MAT_FLAG_ALTERATION_NAME
w_class = ITEM_SIZE_SMALL
Expand Down Expand Up @@ -49,6 +49,6 @@
name = "striker"
desc = "A squared-off, rather worn-down piece of stone."
icon = 'icons/obj/items/striker.dmi'
sharp = FALSE
edge = FALSE
_sharp = FALSE
_edge = FALSE
w_class = ITEM_SIZE_TINY
8 changes: 4 additions & 4 deletions code/game/objects/items/toys.dm
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
/obj/item/energy_blade/sword/toy
name = "toy sword"
desc = "A cheap, plastic replica of an energy sword. Realistic sounds! Ages 8 and up."
sharp = FALSE
edge = FALSE
_sharp = FALSE
_edge = FALSE
attack_verb = list("hit")
material = /decl/material/solid/organic/plastic
active_hitsound = 'sound/weapons/genhit.ogg'
Expand Down Expand Up @@ -497,8 +497,8 @@
desc = "An arcane weapon (made of foam) wielded by the followers of the hit Saturday morning cartoon \"King Nursee and the Acolytes of Heroism\"."
icon = 'icons/obj/items/weapon/swords/cult.dmi'
material = /decl/material/solid/organic/plastic/foam
edge = 0
sharp = 0
_edge = FALSE
_sharp = FALSE

/obj/item/inflatable_duck //#TODO: Move under obj/item/toy ?
name = "inflatable duck"
Expand Down
13 changes: 6 additions & 7 deletions code/game/objects/items/weapons/material/folding.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
icon = 'icons/obj/items/weapon/knives/folding/basic.dmi'
w_class = ITEM_SIZE_SMALL
attack_verb = list("prodded", "tapped")
edge = FALSE
sharp = FALSE
_edge = FALSE
_sharp = FALSE
draw_handle = TRUE
valid_handle_colors = list(COLOR_DARK_GRAY, COLOR_RED_GRAY, COLOR_BLUE_GRAY, COLOR_DARK_BLUE_GRAY, COLOR_GREEN_GRAY, COLOR_DARK_GREEN_GRAY)
material = /decl/material/solid/metal/steel
Expand All @@ -29,15 +29,14 @@
/obj/item/knife/folding/update_attack_force()
..()
if(open)
// TODO: check sharp/edge.
edge = TRUE
sharp = TRUE
set_edge(TRUE)
set_sharp(TRUE)
w_class = ITEM_SIZE_NORMAL
attack_verb = list("slashed", "stabbed")
..()
else
edge = initial(edge)
sharp = initial(sharp)
set_edge(initial(_edge))
set_sharp(initial(_sharp))
w_class = initial(w_class)
attack_verb = closed_attack_verbs

Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/items/weapons/material/knives.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
material = /decl/material/solid/metal/steel
origin_tech = @'{"materials":1}'
obj_flags = OBJ_FLAG_CONDUCTIBLE
sharp = TRUE
edge = TRUE
_sharp = TRUE
_edge = TRUE
item_flags = ITEM_FLAG_CAN_HIDE_IN_SHOES | ITEM_FLAG_IS_WEAPON
material_alteration = MAT_FLAG_ALTERATION_COLOR | MAT_FLAG_ALTERATION_NAME
pickup_sound = 'sound/foley/knife1.ogg'
Expand Down Expand Up @@ -104,7 +104,7 @@
name = "meat hook"
desc = "A sharp, metal hook what sticks into things."
icon = 'icons/obj/items/weapon/knives/hook.dmi'
sharp = FALSE
_sharp = FALSE

/obj/item/knife/ritual
name = "ritual knife"
Expand Down
12 changes: 6 additions & 6 deletions code/game/objects/items/weapons/material/misc.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/obj/item/harpoon
name = "harpoon"
desc = "A short throwing spear with a deep barb, specifically designed to embed itself in its target."
sharp = 1
edge = 1
_sharp = TRUE
_edge = TRUE
icon = 'icons/obj/items/weapon/harpoon.dmi'
icon_state = "harpoon"
item_state = "harpoon"
Expand Down Expand Up @@ -39,16 +39,16 @@
SetName("broken harpoon")
desc = "A short spear with just a barb - if it once had a spearhead, it doesn't any more."
icon_state = "harpoon_bomb_spent"
sharp = FALSE
edge = FALSE
_sharp = FALSE
_edge = FALSE

/obj/item/scythe
name = "scythe"
desc = "A sharp and curved blade on a long fibremetal handle, this tool makes it easy to reap what you sow."
icon = 'icons/obj/items/tool/scythe.dmi'
icon_state = ICON_STATE_WORLD
sharp = 1
edge = 1
_sharp = TRUE
_edge = TRUE
throw_speed = 1
throw_range = 3
w_class = ITEM_SIZE_HUGE
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/material/shards.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
desc = "Made of nothing. How does this even exist?" // set based on material, if this desc is visible it's a bug (shards default to being made of glass)
icon_state = "large"
randpixel = 8
sharp = 1
edge = 1
_sharp = TRUE
_edge = TRUE
w_class = ITEM_SIZE_SMALL
item_state = "shard-glass"
attack_verb = list("stabbed", "slashed", "sliced", "cut")
Expand Down
8 changes: 4 additions & 4 deletions code/game/objects/items/weapons/material/stick.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

/obj/item/stick/attackby(obj/item/W, mob/user)

if(W.sharp && W.edge && !sharp)
if(W.is_sharp() && W.has_edge() && !_sharp)
user.visible_message("<span class='warning'>[user] sharpens [src] with [W].</span>", "<span class='warning'>You sharpen [src] using [W].</span>")
sharp = 1 //Sharpen stick
set_sharp(TRUE)
SetName("sharpened " + name)
update_attack_force()
return TRUE

if(!sharp && (istype(W, /obj/item/stack/material/bolt) || istype(W, /obj/item/stack/material/bundle)))
if(!_sharp && (istype(W, /obj/item/stack/material/bolt) || istype(W, /obj/item/stack/material/bundle)))

var/choice = input(user, "Do you want to make a torch, or a splint?", "Stick Crafting") as null|anything in list("Torch", "Splint")
if(!choice || QDELETED(user) || user.get_active_held_item() != W || QDELETED(W) || !QDELETED(src) || (loc != user && !Adjacent(user)) || sharp)
if(!choice || QDELETED(user) || user.get_active_held_item() != W || QDELETED(W) || !QDELETED(src) || (loc != user && !Adjacent(user)) || _sharp)
return TRUE

var/obj/item/stack/material/cloth = W
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/material/swiss.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
else
siemens_coefficient = initial(siemens_coefficient)
else
edge = initial(edge)
sharp = initial(sharp)
set_edge(initial(_edge))
set_sharp(initial(_sharp))
attack_verb = closed_attack_verbs
siemens_coefficient = initial(siemens_coefficient)

Expand Down
Loading

0 comments on commit d1a5c81

Please sign in to comment.