bettering of get area procs (#20066)

typecacheof

Removed get_all_area_atoms proc.

else

ispath is valid too
This commit is contained in:
xxalpha
2016-08-26 12:05:57 +12:00
committed by oranges
parent 420f83f14d
commit 62aebce039
2 changed files with 42 additions and 39 deletions
+39 -37
View File
@@ -624,58 +624,60 @@ Turf and target are seperate in case you want to teleport some distance from a t
//Takes: Area type as text string or as typepath OR an instance of the area.
//Returns: A list of all areas of that type in the world.
/proc/get_areas(areatype)
if(!areatype)
return null
/proc/get_areas(areatype, subtypes=TRUE)
if(istext(areatype))
areatype = text2path(areatype)
if(isarea(areatype))
else if(isarea(areatype))
var/area/areatemp = areatype
areatype = areatemp.type
else if(!ispath(areatype))
return null
var/list/areas = new/list()
for(var/area/N in world)
if(istype(N, areatype))
areas += N
var/list/areas = list()
if(subtypes)
var/list/cache = typecacheof(areatype)
for(var/V in sortedAreas)
var/area/A = V
if(cache[A.type])
areas += V
else
for(var/V in sortedAreas)
var/area/A = V
if(A.type == areatype)
areas += V
return areas
//Takes: Area type as text string or as typepath OR an instance of the area.
//Returns: A list of all turfs in areas of that type of that type in the world.
/proc/get_area_turfs(areatype, target_z = 0)
if(!areatype)
return null
/proc/get_area_turfs(areatype, target_z = 0, subtypes=FALSE)
if(istext(areatype))
areatype = text2path(areatype)
if(isarea(areatype))
else if(isarea(areatype))
var/area/areatemp = areatype
areatype = areatemp.type
else if(!ispath(areatype))
return null
var/list/turfs = new/list()
for(var/area/N in world)
if(istype(N, areatype))
for(var/turf/T in N)
var/list/turfs = list()
if(subtypes)
var/list/cache = typecacheof(areatype)
for(var/V in sortedAreas)
var/area/A = V
if(!cache[A.type])
continue
for(var/turf/T in A)
if(target_z == 0 || target_z == T.z)
turfs += T
else
for(var/V in sortedAreas)
var/area/A = V
if(A.type != areatype)
continue
for(var/turf/T in A)
if(target_z == 0 || target_z == T.z)
turfs += T
return turfs
//Takes: Area type as text string or as typepath OR an instance of the area.
//Returns: A list of all atoms (objs, turfs, mobs) in areas of that type of that type in the world.
/proc/get_area_all_atoms(areatype)
if(!areatype)
return null
if(istext(areatype))
areatype = text2path(areatype)
if(isarea(areatype))
var/area/areatemp = areatype
areatype = areatemp.type
var/list/atoms = new/list()
for(var/area/N in world)
if(istype(N, areatype))
for(var/atom/A in N)
atoms += A
return atoms
/proc/get_cardinal_dir(atom/A, atom/B)
var/dx = abs(B.x - A.x)
var/dy = abs(B.y - A.y)
@@ -1299,13 +1301,13 @@ B --><-- A
/proc/get_areas_in_z(zlevel)
. = list()
var/validarea = 0
var/validarea = FALSE
for(var/V in sortedAreas)
var/area/A = V
validarea = 1
validarea = TRUE
for(var/turf/T in A)
if(T.z != zlevel)
validarea = 0
validarea = FALSE
break
if(validarea)
. += A
@@ -717,7 +717,8 @@
/obj/machinery/turretid/initialize() //map-placed turrets autolink turrets
if(control_area && istext(control_area))
for(var/area/A in world)
for(var/V in sortedAreas)
var/area/A = V
if(A.name == control_area)
control_area = A
break
@@ -729,7 +730,7 @@
else
control_area = CA
for(var/obj/machinery/porta_turret/T in get_area_all_atoms(control_area))
for(var/obj/machinery/porta_turret/T in control_area)
turrets |= T
/obj/machinery/turretid/attackby(obj/item/I, mob/user, params)