From 39bfcc1e7a17aec0d60d0225c90c7d7125b48484 Mon Sep 17 00:00:00 2001 From: Ccomp5950 Date: Thu, 13 Feb 2014 21:56:58 -0600 Subject: [PATCH] Code effeciency project: handle_embedded_objects Before: EVERYTIME someone moved their character this proc would be called and loop through every organ looking for implanted items to see if it needs to apply damage. After: We create a flag that is set when an item embeddes, only when that flag is set do we do that loop through organs upon movement. Also every 10 ticks while that flag is set we will check to see if we need to unset it. Conflicts: code/modules/mob/living/carbon/human/human_damage.dm --- code/modules/mob/living/carbon/human/human.dm | 1 + code/modules/mob/living/carbon/human/human_damage.dm | 3 ++- code/modules/mob/living/carbon/human/human_defense.dm | 1 + code/modules/mob/living/carbon/human/human_movement.dm | 3 ++- code/modules/mob/living/carbon/human/life.dm | 9 ++++++++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 4455d7c27aa..b36fc9044df 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -7,6 +7,7 @@ icon_state = "body_m_s" var/list/hud_list = list() var/datum/species/species //Contains icon generation and language information, set during New(). + var/embedded_flag //To check if we've need to roll for damage on movement while an item is imbedded in us. /mob/living/carbon/human/dummy real_name = "Test Dummy" diff --git a/code/modules/mob/living/carbon/human/human_damage.dm b/code/modules/mob/living/carbon/human/human_damage.dm index dec63819493..d09fa5b20da 100644 --- a/code/modules/mob/living/carbon/human/human_damage.dm +++ b/code/modules/mob/living/carbon/human/human_damage.dm @@ -251,6 +251,7 @@ if(!istype(W, /obj/item/weapon/butch/meatcleaver)) organ.implants += W visible_message("\The [W] sticks in the wound!") + embedded_flag = 1 src.verbs += /mob/proc/yank_out_object W.add_blood(src) if(ismob(W.loc)) @@ -273,4 +274,4 @@ if(prob(60)) step_rand(H) if(!stat) - src << "Your [H] fell off!" \ No newline at end of file + src << "Your [H] fell off!" diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm index 8ec602fc0c0..f3575e3bf5d 100644 --- a/code/modules/mob/living/carbon/human/human_defense.dm +++ b/code/modules/mob/living/carbon/human/human_defense.dm @@ -100,6 +100,7 @@ emp_act (SP.loc) = organ organ.implants += SP visible_message("The projectile sticks in the wound!") + embedded_flag = 1 src.verbs += /mob/proc/yank_out_object SP.add_blood(src) return (..(P , def_zone)) diff --git a/code/modules/mob/living/carbon/human/human_movement.dm b/code/modules/mob/living/carbon/human/human_movement.dm index 51a68c4da91..32df867a023 100644 --- a/code/modules/mob/living/carbon/human/human_movement.dm +++ b/code/modules/mob/living/carbon/human/human_movement.dm @@ -6,7 +6,8 @@ if (istype(loc, /turf/space)) return -1 // It's hard to be slowed down in space by... anything - handle_embedded_objects() //Moving with objects stuck in you can cause bad times. + if(embedded_flag) + handle_embedded_objects() //Moving with objects stuck in you can cause bad times. if(reagents.has_reagent("hyperzine")) return -1 diff --git a/code/modules/mob/living/carbon/human/life.dm b/code/modules/mob/living/carbon/human/life.dm index 087018404e0..59c0d5325a4 100644 --- a/code/modules/mob/living/carbon/human/life.dm +++ b/code/modules/mob/living/carbon/human/life.dm @@ -130,7 +130,7 @@ handle_environment(environment) //Status updates, death etc. - handle_regular_status_updates() //TODO: optimise ~Carn + handle_regular_status_updates() //TODO: optimise ~Carn NO SHIT ~Ccomp update_canmove() //Update our name based on whether our face is obscured/disfigured @@ -1146,6 +1146,13 @@ if(halloss > 0) adjustHalLoss(-1) + if(embedded_flag && !(life_tick % 10)) + var/list/E + E = get_visible_implants(0) + if(!E.len) + embedded_flag = 0 + + //Eyes if(sdisabilities & BLIND) //disabled-blind, doesn't get better on its own blinded = 1