Skip to content

Commit

Permalink
[MIRROR] Vending machines have standardized health
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelbassil authored and SuhEugene committed Jan 15, 2024
1 parent c95f31c commit a5bd74f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 42 deletions.
11 changes: 11 additions & 0 deletions code/game/machinery/_machines_base/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
RefreshParts()
power_change()

/obj/machinery/post_health_change(health_mod, prior_health, damage_type)
if (health_mod < 0 && !health_dead())
var/initial_damage_percentage = Percent(get_max_health() - prior_health, get_max_health(), 0)
var/damage_percentage = get_damage_percentage()
if (damage_percentage >= 75 && initial_damage_percentage < 75)
visible_message("\The [src] looks like it's about to break!" )
else if (damage_percentage >= 50 && initial_damage_percentage < 50)
visible_message("\The [src] looks seriously damaged!" )
else if (damage_percentage >= 25 && initial_damage_percentage < 25)
visible_message("\The [src] shows signs of damage!" )

/obj/machinery/Destroy()
if(istype(wires))
QDEL_NULL(wires)
Expand Down
10 changes: 0 additions & 10 deletions code/game/machinery/doors/door.dm
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,6 @@
/obj/machinery/door/post_health_change(health_mod, prior_health, damage_type)
. = ..()
queue_icon_update()
if (health_mod < 0 && !health_dead())
var/initial_damage_percentage = round((prior_health / get_max_health()) * 100)
var/damage_percentage = get_damage_percentage()
if (damage_percentage >= 75 && initial_damage_percentage < 75)
visible_message("\The [src] looks like it's about to break!" )
else if (damage_percentage >= 50 && initial_damage_percentage < 50)
visible_message("\The [src] looks seriously damaged!" )
else if (damage_percentage >= 25 && initial_damage_percentage < 25)
visible_message("\The [src] shows signs of damage!" )


/obj/machinery/door/on_revive()
. = ..()
Expand Down
37 changes: 18 additions & 19 deletions code/game/machinery/vending/_vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
machine_desc = "Holds an internal stock of items that can be dispensed on-demand or when a charged ID card is swiped, depending on the brand."
idle_power_usage = 10
wires = /datum/wires/vending
health_max = 80

/// The machine's wires, but typed.
var/datum/wires/vending/vendor_wires
Expand Down Expand Up @@ -84,7 +85,7 @@
var/vend_reply //Thank you for shopping!
var/last_reply = 0
var/last_slogan = 0 //When did we last pitch?
var/slogan_delay = 10 MINUTES //How long until we can pitch again?
var/slogan_delay = 2 MINUTES //How long until we can pitch again?
var/seconds_electrified = 0 //Shock customers like an airlock.
var/shoot_inventory = FALSE //Fire items at customers! We're broken!
var/shooting_chance = 2 //The chance that items are being shot per tick
Expand Down Expand Up @@ -135,6 +136,18 @@
if (shoot_inventory && prob(shooting_chance))
throw_item()

/obj/machinery/vending/post_health_change(health_mod, prior_health, damage_type)
. = ..()
queue_icon_update()
if (health_mod < 0 && !health_dead())
var/initial_damage_percentage = Percent(get_max_health() - prior_health, get_max_health(), 0)
var/damage_percentage = get_damage_percentage()
if (damage_percentage >= 25 && initial_damage_percentage < 25 && prob(75))
shut_up = FALSE
else if (damage_percentage >= 50 && initial_damage_percentage < 50)
vendor_wires.RandomCut()
else if (damage_percentage >= 75 && initial_damage_percentage < 75 && prob(10))
malfunction()

/obj/machinery/vending/powered()
return anchored && ..()
Expand Down Expand Up @@ -162,34 +175,19 @@
icon_state = "[initial(icon_state)]-off"
if (panel_open || IsShowingAntag())
AddOverlays(image(icon, "[initial(icon_state)]-panel"))
if (IsShowingAntag() && is_powered())
if ((IsShowingAntag() || get_damage_percentage() >= 50) && is_powered())
AddOverlays(image(icon, "sparks"))
AddOverlays(emissive_appearance(icon, "sparks"))
if (!vend_ready)
AddOverlays(image(icon, "[initial(icon_state)]-shelf[rand(max_overlays)]"))


/obj/machinery/vending/ex_act(severity)
switch(severity)
if (EX_ACT_DEVASTATING)
qdel(src)
if (EX_ACT_HEAVY)
if (prob(50))
qdel(src)
if (EX_ACT_LIGHT)
if (prob(25))
spawn(0)
malfunction()


/obj/machinery/vending/emag_act(remaining_charges, mob/living/user)
if (emagged)
return
emagged = TRUE
req_access.Cut()
if (antag_slogans)
shut_up = FALSE
slogan_delay = 2 MINUTES
slogan_list.Cut()
slogan_list += splittext(antag_slogans, ";")
last_slogan = world.time + rand(0, slogan_delay)
Expand Down Expand Up @@ -272,7 +270,6 @@
var/obj/item/material/coin/challenge/syndie/antagcoin = item
if (antag_slogans)
shut_up = FALSE
slogan_delay = 2 MINUTES
slogan_list.Cut()
slogan_list += splittext(antag_slogans, ";")
last_slogan = world.time + rand(0, slogan_delay)
Expand Down Expand Up @@ -549,7 +546,9 @@


/obj/machinery/vending/proc/malfunction()
for (var/datum/stored_items/vending_products/product in product_records)
for (var/datum/stored_items/vending_products/product in shuffle(product_records))
if (product.category == VENDOR_CATEGORY_ANTAG)
continue
while (product.get_amount() > 0)
product.get_product(loc)
break
Expand Down
4 changes: 1 addition & 3 deletions code/game/machinery/vending/coffee.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@

/obj/machinery/vending/coffee/on_update_icon()
..()
if (MACHINE_IS_BROKEN(src) && prob(20))
icon_state = "[initial(icon_state)]-hellfire"
else if (is_powered())
if (is_powered())
AddOverlays(image(icon, "[initial(icon_state)]-screen"))
9 changes: 0 additions & 9 deletions code/modules/xenoarcheaology/artifacts/artifact.dm
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,6 @@
..()
queue_icon_update()
if (health_mod < 0)
var/initial_damage_percentage = round((prior_health / get_max_health()) * 100)
var/damage_percentage = get_damage_percentage()
if (damage_percentage >= 75 && initial_damage_percentage < 75)
visible_message("\The [src] looks like it's about to break!")
else if (damage_percentage >= 50 && initial_damage_percentage < 50)
visible_message("\The [src] looks seriously damaged!" )
else if (damage_percentage >= 25 && initial_damage_percentage < 25)
visible_message("\The [src] shows signs of damage!" )

for (var/datum/artifact_effect/A in list(my_effect, secondary_effect))
A.holder_damaged(get_current_health(), abs(health_mod))

Expand Down
2 changes: 1 addition & 1 deletion test/check-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exactly 24 "text2path uses" 'text2path'
exactly 4 "update_icon() override" '/update_icon\((.*)\)' -P
exactly 4 "goto use" 'goto '
exactly 1 "NOOP match" 'NOOP'
exactly 342 "spawn uses" '^\s*spawn\s*\(\s*(-\s*)?\d*\s*\)' -P
exactly 341 "spawn uses" '^\s*spawn\s*\(\s*(-\s*)?\d*\s*\)' -P
exactly 0 "tag uses" '\stag = ' -P '**/*.dmm'
exactly 0 "anchored = 0/1" 'anchored\s*=\s*\d' -P
exactly 2 "density = 0/1" 'density\s*=\s*\d' -P
Expand Down

0 comments on commit a5bd74f

Please sign in to comment.