Skip to content

Commit

Permalink
[MIRROR] Make flora destructible
Browse files Browse the repository at this point in the history
  • Loading branch information
sdtwbaj authored and SierraHelper committed Aug 28, 2024
1 parent b44d029 commit e864100
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 34 deletions.
3 changes: 2 additions & 1 deletion baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,6 @@
#include "code\game\objects\structures\extinguisher.dm"
#include "code\game\objects\structures\fireaxe_cabinet.dm"
#include "code\game\objects\structures\fitness.dm"
#include "code\game\objects\structures\flora.dm"
#include "code\game\objects\structures\fountain.dm"
#include "code\game\objects\structures\girders.dm"
#include "code\game\objects\structures\grille.dm"
Expand Down Expand Up @@ -1280,6 +1279,8 @@
#include "code\game\objects\structures\crates_lockers\closets\secure\scientist.dm"
#include "code\game\objects\structures\crates_lockers\closets\secure\security.dm"
#include "code\game\objects\structures\crates_lockers\closets\secure\service.dm"
#include "code\game\objects\structures\flora\flora.dm"
#include "code\game\objects\structures\flora\tree.dm"
#include "code\game\objects\structures\stool_bed_chair_nest\bed.dm"
#include "code\game\objects\structures\stool_bed_chair_nest\chairs.dm"
#include "code\game\objects\structures\stool_bed_chair_nest\stools.dm"
Expand Down
4 changes: 4 additions & 0 deletions code/game/objects/items/weapons/melee/energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,7 @@
origin_tech = list(TECH_MAGNET = 3)
active_attack_verb = list("attacked", "chopped", "cleaved", "torn", "cut")
hitsound = 'sound/weapons/blade1.ogg'


/obj/item/melee/energy/machete/IsHatchet()
return TRUE
4 changes: 2 additions & 2 deletions code/game/objects/structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if (fragile)
return kill_health()
damage = max(damage, 10)
..()
return ..()

/obj/structure/proc/mob_breakout(mob/living/escapee)
set waitfor = FALSE
Expand Down Expand Up @@ -56,7 +56,7 @@
fluid_update()


/obj/structure/use_weapon(obj/item/weapon, mob/user, list/click_params)
/obj/structure/use_weapon(obj/item/weapon, mob/living/user, list/click_params)
// Natural Weapon - Passthrough to generic attack
if (istype(weapon, /obj/item/natural_weapon))
attack_generic(user, weapon.force, pick(weapon.attack_verb), damtype = weapon.damtype, dam_flags = weapon.damage_flags())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
//trees
/obj/structure/flora/tree
name = "tree"
anchored = TRUE
density = TRUE
pixel_x = -16
/obj/structure/flora
name = "flora"
layer = ABOVE_HUMAN_LAYER

/obj/structure/flora/tree/pine
name = "pine tree"
icon = 'icons/obj/flora/pinetrees.dmi'
icon_state = "pine_1"

/obj/structure/flora/tree/pine/New()
..()
icon_state = "pine_[rand(1, 3)]"

/obj/structure/flora/tree/pine/xmas
name = "\improper Christmas tree"
desc = "O Christmas tree, O Christmas tree..."
icon = 'icons/obj/flora/pinetrees.dmi'
icon_state = "pine_c"
/obj/structure/flora/use_tool(obj/item/tool, mob/user, list/click_params)
if (isHatchet(tool))
if (!density)
user.visible_message(
SPAN_NOTICE("[user] cuts away \the [src]."),
SPAN_NOTICE("You cut away \the [src].")
)
qdel_self()
return TRUE
return ..()

/obj/structure/flora/tree/pine/xmas/New()
..()
icon_state = "pine_c"

/obj/structure/flora/tree/dead
icon = 'icons/obj/flora/deadtrees.dmi'
icon_state = "tree_1"

/obj/structure/flora/tree/dead/New()
..()
icon_state = "tree_[rand(1, 6)]"

//grass
/obj/structure/flora/grass
name = "grass"
icon = 'icons/obj/flora/snowflora.dmi'
Expand Down
235 changes: 235 additions & 0 deletions code/game/objects/structures/flora/tree.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/obj/structure/flora/tree
name = "tree"
anchored = TRUE
density = TRUE
pixel_x = -16
layer = ABOVE_HUMAN_LAYER
health_max = 200

/// How much to shake the tree by when struck
var/shake_animation_degrees = 4

/// If set, a material product from cutting the tree down
var/material/product = MATERIAL_WOOD

/// If there is a product, the max amount that can be produced
var/product_max = 10

/// When true, the tree has already been cut down
var/is_stump

/// A local override for damage that should reduce the product_max
var/const/DAMAGE_FLAG_PRODUCT = FLAG(23)


/obj/structure/flora/tree/Initialize()
. = ..()
product = SSmaterials.get_material_by_name(product)
if (!product)
log_debug({"Instance of [type] created with bad product "[initial(product)]""})
return INITIALIZE_HINT_QDEL
health_min_damage = 5


/obj/structure/flora/tree/use_tool(obj/item/tool, mob/living/user, list/click_params)
SHOULD_CALL_PARENT(FALSE)
if (istype(tool, /obj/item/shovel) && user.a_intent != I_HURT)
if (!is_stump)
to_chat(user, SPAN_WARNING("You can't dig up \the [src] without cutting it down first!"))
return
if (!do_after(user, 5 SECONDS, src, DO_PUBLIC_UNIQUE))
return
user.visible_message(
SPAN_ITALIC("\The [user] digs up \a [src] with \a [tool]."),
SPAN_ITALIC("You dig up \the [src] with \the [tool].")
)
qdel(src)
return TRUE
user.setClickCooldown(user.get_attack_speed(tool))
user.do_attack_animation(src)
TryChop(tool, user)
return TRUE


/obj/structure/flora/tree/use_weapon(obj/item/weapon, mob/living/user, list/click_params)
SHOULD_CALL_PARENT(FALSE)
if (!is_stump)
TryChop(weapon, user)
return TRUE
var/other_message = ""
var/self_message = ""
if (istype(weapon, /obj/item/natural_weapon))
var/datum/pronouns/pronouns = user.choose_from_pronouns()
other_message = " with [pronouns.his] [weapon]"
self_message = " with your [weapon]"
else
other_message = " with \a [weapon]"
self_message = " with \the [weapon]"
user.visible_message(
SPAN_ITALIC("\The [user] hits \a [src][other_message]."),
SPAN_ITALIC("You hit \the [src][self_message].") + SPAN_WARNING(" It does nothing!"),
SPAN_WARNING("You hear something impact on wood!")
)
return TRUE


/obj/structure/flora/tree/on_death()
if (holographic || is_stump)
return
if (product && product_max > 0)
var/amount = rand(ceil(product_max / 2), product_max)
product.place_sheet(get_turf(src), amount)
visible_message(SPAN_WARNING("\The [src] is felled!"))
icon_state = "[initial(icon_state)]_stump"
name = "[name] stump"
is_stump = TRUE
density = FALSE
set_light(0)


/obj/structure/flora/tree/proc/TryChop(obj/item/item, mob/living/user)
var/damage
var/damage_flags
var/chop
var/other_message = ""
var/self_message = ""
damage = item.force
chop = item.sharp && item.edge && user.a_intent != I_HURT
if (isHatchet(item))
damage *= 1.5
if (istype(item, /obj/item/natural_weapon))
var/datum/pronouns/pronouns = user.choose_from_pronouns()
other_message = " with [pronouns.his] [item]"
self_message = " with your [item]"
else
other_message = " with \a [item]"
self_message = " with \the [item]"
if (holographic)
other_message = SPAN_ITALIC("\The [user] swipes at \a [src][other_message].")
self_message = SPAN_ITALIC("You swipe at \the [src][self_message].")
damage = 0
else if (chop)
other_message = SPAN_ITALIC("\The [user] chops \a [src][other_message].")
self_message = SPAN_ITALIC("You chop \the [src][self_message].")
else if (item.sharp || item.edge)
other_message = SPAN_ITALIC("\The [user] hacks at \a [src][other_message].")
self_message = SPAN_ITALIC("You hack at \the [src][self_message].")
damage *= 0.5
damage_flags = DAMAGE_FLAG_PRODUCT
else
other_message = SPAN_ITALIC("\The [user] hits \a [src][other_message].")
self_message = SPAN_ITALIC("You hit \the [src][self_message].")
damage *= 0.25
damage_flags = DAMAGE_FLAG_PRODUCT
damage = max(damage, 0)
if (damage)
if (chop)
playsound(src, 'sound/effects/woodcutting.ogg', 50, TRUE)
else if (item?.hitsound)
playsound(src, item.hitsound, 50, TRUE)
if (damage < health_min_damage)
self_message += SPAN_WARNING(" It does nothing!")
else
damage_health(damage, item.damtype, damage_flags)
shake_animation(shake_animation_degrees)
user.visible_message(
other_message,
self_message,
SPAN_WARNING("You hear something impact on wood!")
)


/obj/structure/flora/tree/damage_health(damage, damage_type, damage_flags, severity, skip_can_damage_check)
if (holographic || is_stump)
return FALSE
if (product_max && HAS_FLAGS(damage_flags, DAMAGE_FLAG_PRODUCT))
var/removed = initial(product_max) * damage / get_max_health()
product_max -= max(removed, 0)
return ..()


/obj/structure/flora/tree/ex_act(severity)
damage_health(get_max_health() / severity, DAMAGE_EXPLODE, DAMAGE_FLAG_PRODUCT)


/obj/structure/flora/tree/bullet_act(obj/item/projectile/projectile)
if (!projectile.get_structure_damage())
return
var/amount = projectile.get_structure_damage()
damage_health(amount, projectile.damage_type, DAMAGE_FLAG_PRODUCT)


/obj/structure/flora/tree/pine
name = "pine tree"
icon = 'icons/obj/flora/pinetrees.dmi'
icon_state = "pine"
product = MATERIAL_WOOD
shake_animation_degrees = 3


/obj/structure/flora/tree/pine/Initialize()
. = ..()
var/state = rand(2)
if (state)
icon_state = "[initial(icon_state)]_[state]"


/obj/structure/flora/tree/pine/xmas
name = "\improper Christmas tree"
desc = "O Christmas tree, O Christmas tree..."
icon = 'icons/obj/flora/pinetrees.dmi'
product = MATERIAL_PLASTIC
product_max = 8


/obj/structure/flora/tree/pine/xmas/Initialize()
. = ..()
icon_state = "pine_c"


/obj/structure/flora/tree/festivus
name = "\improper Festivus pole"
desc = "Technically, one could air a grievance with a feat of strength."
icon_state = "festivus_pole"
health_max = 100
product_max = 5


/obj/structure/flora/tree/dead
icon = 'icons/obj/flora/deadtrees.dmi'
icon_state = "tree"


/obj/structure/flora/tree/dead/Initialize()
. = ..()
var/state = rand(5)
if (state)
icon_state = "[initial(icon_state)]_[state]"


/obj/structure/flora/tree/alien
name = "alien tree"
desc = "A large xenofloral specimen."
icon = 'icons/obj/flora/deadtrees.dmi'
icon_state = "tree_sif"


/obj/structure/flora/tree/alien/Initialize()
. = ..()
var/state = rand(5)
if (state)
icon_state = "[initial(icon_state)]_[state]"
queue_icon_update()


/obj/structure/flora/tree/alien/on_death()
..()
update_icon()


/obj/structure/flora/tree/alien/on_update_icon()
ClearOverlays()
if (is_stump)
return
var/mutable_appearance/glow = emissive_appearance(icon, "[icon_state]_glow", src, 128)
AddOverlays(glow)
Binary file modified icons/obj/flora/deadtrees.dmi
Binary file not shown.
Binary file modified icons/obj/flora/pinetrees.dmi
Binary file not shown.
Binary file added sound/effects/woodcutting.ogg
Binary file not shown.

0 comments on commit e864100

Please sign in to comment.