From 2aa349a8a1d005cc476883247e1308f1264c8200 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Tue, 22 Nov 2016 08:05:47 -0800 Subject: [PATCH] More typecaching hostile mob targetting --- code/modules/mob/living/simple_animal/hostile/bees.dm | 8 ++++---- code/modules/mob/living/simple_animal/hostile/hostile.dm | 6 ++++-- .../mob/living/simple_animal/hostile/mecha_pilot.dm | 4 ++-- .../mob/living/simple_animal/hostile/mining_mobs.dm | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/code/modules/mob/living/simple_animal/hostile/bees.dm b/code/modules/mob/living/simple_animal/hostile/bees.dm index 0ec5aebdef5..130651c9f4a 100644 --- a/code/modules/mob/living/simple_animal/hostile/bees.dm +++ b/code/modules/mob/living/simple_animal/hostile/bees.dm @@ -125,7 +125,7 @@ if(istype(A, /obj/machinery/hydroponics)) var/obj/machinery/hydroponics/Hydro = A if(Hydro.myseed && !Hydro.dead && !Hydro.recent_bee_visit) - wanted_objects |= /obj/machinery/hydroponics //so we only hunt them while they're alive/seeded/not visisted + wanted_objects |= typecacheof(/obj/machinery/hydroponics) //so we only hunt them while they're alive/seeded/not visisted return 1 if(isliving(A)) var/mob/living/H = A @@ -142,7 +142,7 @@ var/obj/structure/beebox/BB = target loc = BB target = null - wanted_objects -= /obj/structure/beebox //so we don't attack beeboxes when not going home + wanted_objects -= typecacheof(/obj/structure/beebox) //so we don't attack beeboxes when not going home else if(beegent && isliving(target)) var/mob/living/L = target @@ -165,7 +165,7 @@ return target = null //so we pick a new hydro tray next FindTarget(), instead of loving the same plant for eternity - wanted_objects -= /obj/machinery/hydroponics //so we only hunt them while they're alive/seeded/not visisted + wanted_objects -= typecacheof(/obj/machinery/hydroponics) //so we only hunt them while they're alive/seeded/not visisted Hydro.recent_bee_visit = TRUE spawn(BEE_TRAY_RECENT_VISIT) if(Hydro) @@ -200,7 +200,7 @@ idle = max(0, --idle) if(idle <= BEE_IDLE_GOHOME && prob(BEE_PROB_GOHOME)) if(!FindTarget()) - wanted_objects += /obj/structure/beebox //so we don't attack beeboxes when not going home + wanted_objects |= typecacheof(/obj/structure/beebox) //so we don't attack beeboxes when not going home target = beehome if(!beehome) //add outselves to a beebox (of the same reagent) if we have no home for(var/obj/structure/beebox/BB in view(vision_range, src)) diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index 76e12b72840..543eea9f4af 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -40,7 +40,7 @@ var/aggro_vision_range = 9 //If a mob is aggro, we search in this radius. Defaults to 9 to keep in line with original simple mob aggro radius var/idle_vision_range = 9 //If a mob is just idling around, it's vision range is limited to this. Defaults to 9 to keep in line with original simple mob aggro radius var/search_objects = 0 //If we want to consider objects when searching around, set this to 1. If you want to search for objects while also ignoring mobs until hurt, set it to 2. To completely ignore mobs, even when attacked, set it to 3 - var/list/wanted_objects = list() //A list of objects that will be checked against to attack, should we have search_objects enabled + var/list/wanted_objects = list() //A typecache of objects types that will be checked against to attack, should we have search_objects enabled var/stat_attack = 0 //Mobs with stat_attack to 1 will attempt to attack things that are unconscious, Mobs with stat_attack set to 2 will attempt to attack the dead. var/stat_exclusive = 0 //Mobs with this set to 1 will exclusively attack things defined by stat_attack, stat_attack 2 means they will only attack corpses var/attack_same = 0 //Set us to 1 to allow us to attack our own faction, or 2, to only ever attack our own faction @@ -50,9 +50,11 @@ /mob/living/simple_animal/hostile/New() ..() + if(!targets_from) targets_from = src environment_target_typecache = typecacheof(environment_target_typecache) + wanted_objects = typecacheof(wanted_objects) /mob/living/simple_animal/hostile/Destroy() @@ -197,7 +199,7 @@ if(isobj(the_target)) - if(is_type_in_list(the_target, wanted_objects)) + if(is_type_in_typecache(the_target, wanted_objects)) return 1 return 0 diff --git a/code/modules/mob/living/simple_animal/hostile/mecha_pilot.dm b/code/modules/mob/living/simple_animal/hostile/mecha_pilot.dm index 46c3a62aca8..3519c01631a 100644 --- a/code/modules/mob/living/simple_animal/hostile/mecha_pilot.dm +++ b/code/modules/mob/living/simple_animal/hostile/mecha_pilot.dm @@ -41,7 +41,7 @@ /mob/living/simple_animal/hostile/syndicate/mecha_pilot/no_mech/New() ..() - wanted_objects = subtypesof(/obj/mecha/combat) + wanted_objects = typecacheof(/obj/mecha/combat, ignore_root_path=TRUE) /mob/living/simple_animal/hostile/syndicate/mecha_pilot/nanotrasen //nanotrasen are syndies! no it's just a weird path. name = "Nanotrasen Mecha Pilot" @@ -101,7 +101,7 @@ targets_from = src //Find a new mecha - wanted_objects = subtypesof(/obj/mecha/combat) + wanted_objects = typecacheof(/obj/mecha/combat, ignore_root_path=TRUE) var/search_aggressiveness = 2 for(var/obj/mecha/combat/C in range(vision_range,src)) if(is_valid_mecha(C)) diff --git a/code/modules/mob/living/simple_animal/hostile/mining_mobs.dm b/code/modules/mob/living/simple_animal/hostile/mining_mobs.dm index 68af4a647b7..1f8f60d8843 100644 --- a/code/modules/mob/living/simple_animal/hostile/mining_mobs.dm +++ b/code/modules/mob/living/simple_animal/hostile/mining_mobs.dm @@ -917,7 +917,7 @@ ..() /mob/living/simple_animal/hostile/asteroid/gutlunch/AttackingTarget() - if(is_type_in_list(target,wanted_objects)) //we eats + if(is_type_in_typecache(target,wanted_objects)) //we eats udder.generateMilk() regenerate_icons() visible_message("[src] slurps up [target].")