From 8d72c64910f9485bb0aebcbead0050d4342c4813 Mon Sep 17 00:00:00 2001 From: TiviPlus <57223640+TiviPlus@users.noreply.github.com> Date: Fri, 7 Aug 2020 17:09:16 +0200 Subject: [PATCH] Lazylists some /mob and /living stuff (#52750) * lazy * Apply suggestions from code review Co-authored-by: Rohesie Co-authored-by: TiviPlus Co-authored-by: Rohesie --- code/datums/action.dm | 4 ++-- code/datums/diseases/_disease.dm | 6 +++--- code/datums/diseases/cold.dm | 2 +- code/game/objects/items/robot/robot_upgrades.dm | 4 ++-- .../modules/mining/lavaland/necropolis_chests.dm | 2 +- code/modules/mob/living/blood.dm | 2 +- .../living/carbon/alien/humanoid/caste/hunter.dm | 4 ++-- .../living/carbon/human/species_types/golems.dm | 16 ++++++++-------- code/modules/mob/living/living_defines.dm | 6 +++--- .../mining_mobs/elites/goliath_broodmother.dm | 8 ++++---- .../mob/living/simple_animal/hostile/statue.dm | 1 + code/modules/mob/mob.dm | 4 ++-- code/modules/mob/mob_defines.dm | 4 ++-- code/modules/mob/transform_procs.dm | 2 +- .../chemistry/reagents/other_reagents.dm | 2 +- code/modules/spells/spell_types/charge.dm | 2 +- code/modules/spells/spell_types/shapeshift.dm | 1 + 17 files changed, 36 insertions(+), 34 deletions(-) diff --git a/code/datums/action.dm b/code/datums/action.dm index b0d93058423..012b951bc40 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -64,7 +64,7 @@ break bitflag *= 2 - M.actions += src + LAZYADD(M.actions, src) if(M.client) M.client.screen += button button.locked = M.client.prefs.buttons_locked || button.id ? M.client.prefs.action_buttons_screen_locs["[name]_[button.id]"] : FALSE //even if it's not defaultly locked we should remember we locked it before @@ -77,7 +77,7 @@ if(M) if(M.client) M.client.screen -= button - M.actions -= src + LAZYREMOVE(M.actions, src) M.update_action_buttons() owner = null button.moved = FALSE //so the button appears in its normal position when given to another owner. diff --git a/code/datums/diseases/_disease.dm b/code/datums/diseases/_disease.dm index 690e9194f34..f3f76ca42b2 100644 --- a/code/datums/diseases/_disease.dm +++ b/code/datums/diseases/_disease.dm @@ -48,7 +48,7 @@ //add the disease with no checks /datum/disease/proc/infect(var/mob/living/infectee, make_copy = TRUE) var/datum/disease/D = make_copy ? Copy() : src - infectee.diseases += D + LAZYADD(infectee.diseases, D) D.affected_mob = infectee SSdisease.active_diseases += D //Add it to the active diseases list, now that it's actually in a mob and being processed. @@ -133,7 +133,7 @@ /datum/disease/proc/cure(add_resistance = TRUE) if(affected_mob) if(add_resistance && (disease_flags & CAN_RESIST)) - affected_mob.disease_resistances |= GetDiseaseID() + LAZYOR(affected_mob.disease_resistances, GetDiseaseID()) qdel(src) /datum/disease/proc/IsSame(datum/disease/D) @@ -166,7 +166,7 @@ return "[type]" /datum/disease/proc/remove_disease() - affected_mob.diseases -= src //remove the datum from the list + LAZYREMOVE(affected_mob.diseases, src) //remove the datum from the list affected_mob.med_hud_set_status() affected_mob = null diff --git a/code/datums/diseases/cold.dm b/code/datums/diseases/cold.dm index 6f7d1a415e5..4b8189cac3b 100644 --- a/code/datums/diseases/cold.dm +++ b/code/datums/diseases/cold.dm @@ -47,7 +47,7 @@ if(prob(1)) to_chat(affected_mob, "Mucous runs down the back of your throat.") if(prob(1) && prob(50)) - if(!affected_mob.disease_resistances.Find(/datum/disease/flu)) + if(!LAZYFIND(affected_mob.disease_resistances, /datum/disease/flu)) var/datum/disease/Flu = new /datum/disease/flu() affected_mob.ForceContractDisease(Flu, FALSE, TRUE) cure() diff --git a/code/game/objects/items/robot/robot_upgrades.dm b/code/game/objects/items/robot/robot_upgrades.dm index 9f1ebd71400..61145a0e646 100644 --- a/code/game/objects/items/robot/robot_upgrades.dm +++ b/code/game/objects/items/robot/robot_upgrades.dm @@ -267,12 +267,12 @@ /obj/item/borg/upgrade/lavaproof/action(mob/living/silicon/robot/R, user = usr) . = ..() if(.) - R.weather_immunities += "lava" + LAZYADD(R.weather_immunities, "lava") /obj/item/borg/upgrade/lavaproof/deactivate(mob/living/silicon/robot/R, user = usr) . = ..() if (.) - R.weather_immunities -= "lava" + LAZYREMOVE(R.weather_immunities, "lava") /obj/item/borg/upgrade/selfrepair name = "self-repair module" diff --git a/code/modules/mining/lavaland/necropolis_chests.dm b/code/modules/mining/lavaland/necropolis_chests.dm index cd1b13b3e55..c3b3cf5a61b 100644 --- a/code/modules/mining/lavaland/necropolis_chests.dm +++ b/code/modules/mining/lavaland/necropolis_chests.dm @@ -932,7 +932,7 @@ user.mind.AddSpell(D) if(4) to_chat(user, "You feel like you could walk straight through lava now.") - H.weather_immunities |= "lava" + LAZYOR(H.weather_immunities, "lava") playsound(user.loc,'sound/items/drink.ogg', rand(10,50), TRUE) qdel(src) diff --git a/code/modules/mob/living/blood.dm b/code/modules/mob/living/blood.dm index 9aa1b1c21b7..e11505af826 100644 --- a/code/modules/mob/living/blood.dm +++ b/code/modules/mob/living/blood.dm @@ -171,7 +171,7 @@ blood_data["viruses"] += D.Copy() blood_data["blood_DNA"] = dna.unique_enzymes - if(disease_resistances && disease_resistances.len) + if(LAZYLEN(disease_resistances)) blood_data["resistances"] = disease_resistances.Copy() var/list/temp_chem = list() for(var/datum/reagent/R in reagents.reagent_list) diff --git a/code/modules/mob/living/carbon/alien/humanoid/caste/hunter.dm b/code/modules/mob/living/carbon/alien/humanoid/caste/hunter.dm index 66859e1e11b..bac9260e7c7 100644 --- a/code/modules/mob/living/carbon/alien/humanoid/caste/hunter.dm +++ b/code/modules/mob/living/carbon/alien/humanoid/caste/hunter.dm @@ -45,13 +45,13 @@ else //Maybe uses plasma in the future, although that wouldn't make any sense... leaping = 1 - weather_immunities += "lava" + LAZYADD(weather_immunities,"lava") update_icons() throw_at(A, MAX_ALIEN_LEAP_DIST, 1, src, FALSE, TRUE, callback = CALLBACK(src, .proc/leap_end)) /mob/living/carbon/alien/humanoid/hunter/proc/leap_end() leaping = 0 - weather_immunities -= "lava" + LAZYREMOVE(weather_immunities, "lava") update_icons() /mob/living/carbon/alien/humanoid/hunter/throw_impact(atom/hit_atom, datum/thrownthing/throwingdatum) diff --git a/code/modules/mob/living/carbon/human/species_types/golems.dm b/code/modules/mob/living/carbon/human/species_types/golems.dm index d744647704e..bbd40f1a802 100644 --- a/code/modules/mob/living/carbon/human/species_types/golems.dm +++ b/code/modules/mob/living/carbon/human/species_types/golems.dm @@ -223,11 +223,11 @@ /datum/species/golem/titanium/on_species_gain(mob/living/carbon/C, datum/species/old_species) . = ..() - C.weather_immunities |= "ash" + LAZYOR(C.weather_immunities, "ash") /datum/species/golem/titanium/on_species_loss(mob/living/carbon/C) . = ..() - C.weather_immunities -= "ash" + LAZYREMOVE(C.weather_immunities, "ash") //Immune to ash storms and lava /datum/species/golem/plastitanium @@ -242,13 +242,13 @@ /datum/species/golem/plastitanium/on_species_gain(mob/living/carbon/C, datum/species/old_species) . = ..() - C.weather_immunities |= "lava" - C.weather_immunities |= "ash" + LAZYOR(C.weather_immunities, "lava") + LAZYOR(C.weather_immunities, "ash") /datum/species/golem/plastitanium/on_species_loss(mob/living/carbon/C) . = ..() - C.weather_immunities -= "ash" - C.weather_immunities -= "lava" + LAZYREMOVE(C.weather_immunities, "ash") + LAZYREMOVE(C.weather_immunities, "lava") //Fast and regenerates... but can only speak like an abductor /datum/species/golem/alloy @@ -1034,7 +1034,7 @@ /datum/species/golem/snow/on_species_gain(mob/living/carbon/C, datum/species/old_species) . = ..() - C.weather_immunities |= "snow" + LAZYOR(C.weather_immunities, "snow") ball = new ball.charge_counter = 0 C.AddSpell(ball) @@ -1044,7 +1044,7 @@ /datum/species/golem/snow/on_species_loss(mob/living/carbon/C) . = ..() - C.weather_immunities -= "snow" + LAZYREMOVE(C.weather_immunities, "snow") if(ball) C.RemoveSpell(ball) if(cryo) diff --git a/code/modules/mob/living/living_defines.dm b/code/modules/mob/living/living_defines.dm index 409baa4a681..59966571324 100644 --- a/code/modules/mob/living/living_defines.dm +++ b/code/modules/mob/living/living_defines.dm @@ -86,7 +86,7 @@ var/hellbound = 0 ///People who've signed infernal contracts are unrevivable. - var/list/weather_immunities = list() + var/list/weather_immunities var/stun_absorption = null ///converted to a list of stun absorption sources this mob has when one is added @@ -120,8 +120,8 @@ var/losebreath = 0 //List of active diseases - var/list/diseases = list() /// list of all diseases in a mob - var/list/disease_resistances = list() + var/list/diseases /// list of all diseases in a mob + var/list/disease_resistances var/slowed_by_drag = TRUE ///Whether the mob is slowed down when dragging another prone mob diff --git a/code/modules/mob/living/simple_animal/hostile/mining_mobs/elites/goliath_broodmother.dm b/code/modules/mob/living/simple_animal/hostile/mining_mobs/elites/goliath_broodmother.dm index ac9b00cab08..c0c4c70107c 100644 --- a/code/modules/mob/living/simple_animal/hostile/mining_mobs/elites/goliath_broodmother.dm +++ b/code/modules/mob/living/simple_animal/hostile/mining_mobs/elites/goliath_broodmother.dm @@ -246,7 +246,7 @@ /obj/item/crusher_trophy/broodmother_tongue/on_mark_detonation(mob/living/target, mob/living/user) if(rand(1, 100) <= bonus_value && target.stat != DEAD) new /obj/effect/temp_visual/goliath_tentacle/broodmother/patch(get_turf(target), user) - + /obj/item/crusher_trophy/broodmother_tongue/attack_self(mob/user) if(!isliving(user)) return @@ -257,10 +257,10 @@ else if("lava" in living_user.weather_immunities) to_chat(living_user, "You stare at the tongue. You don't think this is any use to you.") return - living_user.weather_immunities |= "lava" + LAZYOR(living_user.weather_immunities, "lava") to_chat(living_user, "You squeeze the tongue, and some transluscent liquid shoots out all over you.") addtimer(CALLBACK(src, .proc/remove_lavaproofing, living_user), 10 SECONDS) use_time = world.time + 60 SECONDS - + /obj/item/crusher_trophy/broodmother_tongue/proc/remove_lavaproofing(mob/living/user) - user.weather_immunities -= "lava" + LAZYREMOVE(user.weather_immunities, "lava") diff --git a/code/modules/mob/living/simple_animal/hostile/statue.dm b/code/modules/mob/living/simple_animal/hostile/statue.dm index 936a98ab718..7d2ff1ad648 100644 --- a/code/modules/mob/living/simple_animal/hostile/statue.dm +++ b/code/modules/mob/living/simple_animal/hostile/statue.dm @@ -60,6 +60,7 @@ /mob/living/simple_animal/hostile/statue/Initialize(mapload, mob/living/creator) . = ..() // Give spells + LAZYINITLIST(mob_spell_list) mob_spell_list += new /obj/effect/proc_holder/spell/aoe_turf/flicker_lights(src) mob_spell_list += new /obj/effect/proc_holder/spell/aoe_turf/blindness(src) mob_spell_list += new /obj/effect/proc_holder/spell/targeted/night_vision(src) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index fe34e22ab74..bec4fa3e05d 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -1000,7 +1000,7 @@ ///Add a spell to the mobs spell list /mob/proc/AddSpell(obj/effect/proc_holder/spell/S) - mob_spell_list += S + LAZYADD(mob_spell_list, S) S.action.Grant(src) ///Remove a spell from the mobs spell list @@ -1010,7 +1010,7 @@ for(var/X in mob_spell_list) var/obj/effect/proc_holder/spell/S = X if(istype(S, spell)) - mob_spell_list -= S + LAZYREMOVE(mob_spell_list, S) qdel(S) ///Return any anti magic atom on this mob that matches the magic type diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index d6b6e4839df..f1afd6339c1 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -29,7 +29,7 @@ /// The calculated mob speed slowdown based on the modifiers list var/cached_multiplicative_slowdown /// List of action hud items the user has - var/list/datum/action/actions = list() + var/list/datum/action/actions /// A special action? No idea why this lives here var/list/datum/action/chameleon_item_actions @@ -156,7 +156,7 @@ * Spells that do not transfer from one mob to another and can not be lost in mindswap. * obviously do not live in the mind */ - var/list/mob_spell_list = list() + var/list/mob_spell_list /// bitflags defining which status effects can be inflicted (replaces canknockdown, canstun, etc) diff --git a/code/modules/mob/transform_procs.dm b/code/modules/mob/transform_procs.dm index 9f8711705ab..8305868d4c8 100644 --- a/code/modules/mob/transform_procs.dm +++ b/code/modules/mob/transform_procs.dm @@ -244,7 +244,7 @@ //keep viruses? if (tr_flags & TR_KEEPVIRUS) O.diseases = diseases - diseases = list() + diseases = null //null the old diseases, bye bye! for(var/thing in O.diseases) var/datum/disease/D = thing D.affected_mob = O diff --git a/code/modules/reagents/chemistry/reagents/other_reagents.dm b/code/modules/reagents/chemistry/reagents/other_reagents.dm index e49071e1eba..4d44630c985 100644 --- a/code/modules/reagents/chemistry/reagents/other_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/other_reagents.dm @@ -111,7 +111,7 @@ var/datum/disease/D = thing if(D.GetDiseaseID() in data) D.cure() - L.disease_resistances |= data + LAZYOR(L.disease_resistances, data) /datum/reagent/vaccine/on_merge(list/data) if(istype(data)) diff --git a/code/modules/spells/spell_types/charge.dm b/code/modules/spells/spell_types/charge.dm index 694b34153db..524af8b8f4c 100644 --- a/code/modules/spells/spell_types/charge.dm +++ b/code/modules/spells/spell_types/charge.dm @@ -20,7 +20,7 @@ if(L.pulling && isliving(L.pulling)) var/mob/living/M = L.pulling - if(M.mob_spell_list.len != 0 || (M.mind && M.mind.spell_list.len != 0)) + if(LAZYLEN(M.mob_spell_list) || (LAZYLEN(M.mind?.spell_list))) for(var/obj/effect/proc_holder/spell/S in M.mob_spell_list) S.charge_counter = S.charge_max if(M.mind) diff --git a/code/modules/spells/spell_types/shapeshift.dm b/code/modules/spells/spell_types/shapeshift.dm index b5f94acbe92..2e947a8967e 100644 --- a/code/modules/spells/spell_types/shapeshift.dm +++ b/code/modules/spells/spell_types/shapeshift.dm @@ -26,6 +26,7 @@ /obj/effect/proc_holder/spell/targeted/shapeshift/cast(list/targets,mob/user = usr) if(src in user.mob_spell_list) + LAZYREMOVE(user.mob_spell_list, src) user.mob_spell_list.Remove(src) user.mind.AddSpell(src) if(user.buckled)