From b392ab8e0e11a8130385e48292572d3294d8a03b 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. --- 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 ed51a5c44af..a7d08fe8713 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -6,6 +6,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 17fb4fc3ebe..242e2d1ce2e 100644 --- a/code/modules/mob/living/carbon/human/human_damage.dm +++ b/code/modules/mob/living/carbon/human/human_damage.dm @@ -245,6 +245,7 @@ This function restores all organs. if( (damage > (10*W.w_class)) && ( (sharp && !ismob(W.loc)) || prob(damage/W.w_class) ) ) 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)) @@ -252,4 +253,4 @@ This function restores all organs. H.drop_item() W.loc = src - return 1 \ No newline at end of file + return 1 diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm index 9657085e2a6..654538194cc 100644 --- a/code/modules/mob/living/carbon/human/human_defense.dm +++ b/code/modules/mob/living/carbon/human/human_defense.dm @@ -99,6 +99,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) diff --git a/code/modules/mob/living/carbon/human/human_movement.dm b/code/modules/mob/living/carbon/human/human_movement.dm index 77cd03d5eed..689319059b8 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 eae1cc405ce..00368c2debd 100644 --- a/code/modules/mob/living/carbon/human/life.dm +++ b/code/modules/mob/living/carbon/human/life.dm @@ -105,7 +105,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 @@ -1059,6 +1059,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