From 3035bf565c684b65464cf86bcf298f93b9aa8ab4 Mon Sep 17 00:00:00 2001 From: "aranclanos@hotmail.com" Date: Fri, 8 Mar 2013 07:22:34 +0000 Subject: [PATCH] Changes on how some simple hostile mobs search for targets, they now make a list of mobs at sight with the heareable() proc and add the mechs of a new global list instead of checking all the atoms in a radius of 21x21. The new global list is called mechas_list, it contains all the mechs (sadly the 8 mechs of centcomm are added to this list, just to avoid problems with other servers with different maps) Clowns, goats and spiders still use the old way to track targets (the view() proc). The goal of this commit is to reduce lag, it will be really noticeable on the carp migration event, they should be 70% less laggy. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@5820 316c924e-a436-60f5-8080-3fe189b3f50e --- code/__HELPERS/global_lists.dm | 4 ++++ code/game/mecha/mecha.dm | 2 ++ .../mob/living/simple_animal/hostile/bear.dm | 4 ++-- .../living/simple_animal/hostile/giant_spider.dm | 2 +- .../mob/living/simple_animal/hostile/hostile.dm | 14 +++++++++----- .../mob/living/simple_animal/hostile/mimic.dm | 5 +++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 566a587b8a0..9ca77defe8f 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -15,6 +15,10 @@ 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/mechas_list = list() //list of all mechs. Used by hostile mobs target tracking. + +var/global/list/portals = list() //for use by portals + //Preferences stuff //Hairstyles var/global/list/hair_styles_list = list() //stores /datum/sprite_accessory/hair indexed by name diff --git a/code/game/mecha/mecha.dm b/code/game/mecha/mecha.dm index d70512148c6..9d8291733cb 100644 --- a/code/game/mecha/mecha.dm +++ b/code/game/mecha/mecha.dm @@ -86,10 +86,12 @@ removeVerb(/atom/movable/verb/pull) log_message("[src.name] created.") loc.Entered(src) + mechas_list += src //global mech list return /obj/mecha/Del() src.go_out() + mechas_list -= src //global mech list ..() return diff --git a/code/modules/mob/living/simple_animal/hostile/bear.dm b/code/modules/mob/living/simple_animal/hostile/bear.dm index c9f52de2be2..6fd7db5d10e 100644 --- a/code/modules/mob/living/simple_animal/hostile/bear.dm +++ b/code/modules/mob/living/simple_animal/hostile/bear.dm @@ -61,7 +61,7 @@ stop_automated_movement = 1 stance_step++ if(stance_step >= 10) //rests for 10 ticks - if(target_mob && target_mob in ListTargets()) + if(target_mob && target_mob in ListTargets(10)) stance = HOSTILE_STANCE_ATTACK //If the mob he was chasing is still nearby, resume the attack, otherwise go idle. else stance = HOSTILE_STANCE_IDLE @@ -69,7 +69,7 @@ if(HOSTILE_STANCE_ALERT) stop_automated_movement = 1 var/found_mob = 0 - if(target_mob && target_mob in ListTargets()) + if(target_mob && target_mob in ListTargets(10)) if(!(SA_attackable(target_mob))) stance_step = max(0, stance_step) //If we have not seen a mob in a while, the stance_step will be negative, we need to reset it to 0 as soon as we see a mob again. stance_step++ diff --git a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm index 669541687f2..3b82b645409 100644 --- a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm +++ b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm @@ -100,7 +100,7 @@ ..() if(!stat) if(stance == HOSTILE_STANCE_IDLE) - var/list/can_see = ListTargets() + var/list/can_see = view(src, 10) //30% chance to stop wandering and do something if(!busy && prob(30)) //first, check for potential food nearby to cocoon diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index b8c5d4150bd..c0ce321c4dc 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -18,7 +18,7 @@ var/atom/T = null stop_automated_movement = 0 - for(var/atom/A in ListTargets()) + for(var/atom/A in ListTargets(10)) if(A == src) continue @@ -40,6 +40,8 @@ T = L break + else + if (can_see(src, A, 10)) if(istype(A, /obj/mecha)) var/obj/mecha/M = A if (M.occupant) @@ -63,7 +65,7 @@ stop_automated_movement = 1 if(!target_mob || SA_attackable(target_mob)) stance = HOSTILE_STANCE_IDLE - if(target_mob in ListTargets()) + if(target_mob in ListTargets(10)) if(ranged) if(get_dist(src, target_mob) <= 6) OpenFire(target_mob) @@ -79,7 +81,7 @@ if(!target_mob || SA_attackable(target_mob)) LoseTarget() return 0 - if(!(target_mob in ListTargets())) + if(!(target_mob in ListTargets(10))) LostTarget() return 0 if(get_dist(src, target_mob) <= 1) //Attacking @@ -109,8 +111,10 @@ walk(src, 0) -/mob/living/simple_animal/hostile/proc/ListTargets() - return view(src, 10) +/mob/living/simple_animal/hostile/proc/ListTargets(var/dist = 7) + var/list/L = hearers(src, dist) + L += mechas_list + return L /mob/living/simple_animal/hostile/Die() ..() diff --git a/code/modules/mob/living/simple_animal/hostile/mimic.dm b/code/modules/mob/living/simple_animal/hostile/mimic.dm index a910e74f5fe..fb1d63ca348 100644 --- a/code/modules/mob/living/simple_animal/hostile/mimic.dm +++ b/code/modules/mob/living/simple_animal/hostile/mimic.dm @@ -77,7 +77,7 @@ /mob/living/simple_animal/hostile/mimic/crate/ListTargets() if(attempt_open) - return view(src, 10) + return ..() return view(src, 1) /mob/living/simple_animal/hostile/mimic/crate/FindTarget() @@ -149,7 +149,8 @@ var/global/list/protected_objects = list(/obj/structure/table, /obj/structure/ca /mob/living/simple_animal/hostile/mimic/copy/ListTargets() // Return a list of targets that isn't the creator - return view(src, 7) - creator + . = ..() + return . - creator /mob/living/simple_animal/hostile/mimic/copy/proc/CopyObject(var/obj/O, var/mob/living/creator)