From 8b89b542330bf07904f1148340b757a7017abbb8 Mon Sep 17 00:00:00 2001 From: Chinsky Date: Fri, 8 Nov 2013 03:18:25 +0400 Subject: [PATCH] Caches side effect types to a global list, less loops on addition. Makes them process only every 15 ticks, to cut down on the calls. Removes damage because it was supposed to be gone, no idea why I didn't delete the lines. --- code/WorkInProgress/Cib/MedicalSideEffects.dm | 32 +++++++++---------- code/__HELPERS/global_lists.dm | 8 +++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/code/WorkInProgress/Cib/MedicalSideEffects.dm b/code/WorkInProgress/Cib/MedicalSideEffects.dm index 2d0b8b6ba82..15580c4bd2e 100644 --- a/code/WorkInProgress/Cib/MedicalSideEffects.dm +++ b/code/WorkInProgress/Cib/MedicalSideEffects.dm @@ -23,7 +23,8 @@ /datum/medical_effect/proc/cure(mob/living/carbon/human/H) for(var/R in cures) if(H.reagents.has_reagent(R)) - H <<"\red [cure_message]" + if (cure_message) + H <<"\blue [cure_message]" return 1 return 0 @@ -39,16 +40,21 @@ M.start = life_tick return - var/list/L = typesof(/datum/medical_effect)-/datum/medical_effect - for(var/T in L) - var/datum/medical_effect/M = new T - if(M.name == name) - M.strength = strength - M.start = life_tick - side_effects += M + var/T = side_effects[name] + if (!T) + return + + var/datum/medical_effect/M = new T + if(M.name == name) + M.strength = strength + M.start = life_tick + side_effects += M /mob/living/carbon/human/proc/handle_medical_side_effects() + //Going to handle those things only every few ticks. + if(life_tick % 15 != 0) + return 0 var/list/L = typesof(/datum/medical_effect)-/datum/medical_effect for(var/T in L) @@ -60,18 +66,14 @@ for (var/datum/medical_effect/M in side_effects) if (!M) continue var/strength_percent = sin((life_tick - M.start) / 2) -// log_debug ("[src], tick [life_tick] : Processing [M], Current phase: [strength_percent]") // Only do anything if the effect is currently strong enough if(strength_percent >= 0.4) -// log_debug ("[src], tick [life_tick] : Active phase ; strength [M.strength]") if (M.cure(src) || M.strength > 50) -// log_debug ("[src], tick [life_tick] : [M] cured or reached end of lifecycle") side_effects -= M - del(M) + M = null else if(life_tick % 45 == 0) -// log_debug ("[src], tick [life_tick] : Activating [M] ") M.on_life(src, strength_percent*M.strength) // Effect slowly growing stronger M.strength+=0.08 @@ -92,7 +94,6 @@ H.custom_pain("You feel a throbbing pain in your head!",1) if(31 to INFINITY) H.custom_pain("You feel an excrutiating pain in your head!",1) - H.adjustBrainLoss(1) // BAD STOMACH // =========== @@ -110,7 +111,6 @@ H.custom_pain("Your stomach hurts.",0) if(31 to INFINITY) H.custom_pain("You feel sick.",1) - H.adjustToxLoss(1) // CRAMPS // ====== @@ -129,7 +129,6 @@ if(31 to INFINITY) H.emote("me",1,"flinches as all the muscles in their body cramp up.") H.custom_pain("There's pain all over your body.",1) - H.adjustToxLoss(1) // ITCH // ==== @@ -148,4 +147,3 @@ if(31 to INFINITY) H.emote("me",1,"shivers slightly.") H.custom_pain("This itch makes it really hard to concentrate.",1) - H.adjustToxLoss(1) \ No newline at end of file diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 956e6be2557..9625d9c716a 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -15,6 +15,7 @@ var/global/list/chemical_reactions_list //list of all /datum/chemical_reactio var/global/list/chemical_reagents_list //list of all /datum/reagent datums indexed by reagent id. Used by chemistry stuff var/global/list/landmarks_list = list() //list of all landmarks created var/global/list/surgery_steps = list() //list of all surgery steps |BS12 +var/global/list/side_effects = list() //list of all medical sideeffects types by thier names |BS12 var/global/list/mechas_list = list() //list of all mechs. Used by hostile mobs target tracking. //Languages/species/whitelist. @@ -75,6 +76,13 @@ var/global/list/backbaglist = list("Nothing", "Backpack", "Satchel", "Satchel Al surgery_steps += S sort_surgeries() + //Medical side effects. List all effects by their names + paths = typesof(/datum/medical_effect)-/datum/medical_effect + for(var/T in paths) + var/datum/medical_effect/M = new T + side_effects[S.name] = T + + //Languages and species. paths = typesof(/datum/language)-/datum/language for(var/T in paths)