-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathanomaly_placer.dm
66 lines (56 loc) · 1.86 KB
/
anomaly_placer.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/datum/anomaly_placer
var/static/list/allowed_areas
/**
* Returns an area which is safe to place an anomaly inside.
*/
/datum/anomaly_placer/proc/findValidArea()
if(!allowed_areas)
generateAllowedAreas()
var/list/possible_areas = typecache_filter_list(GLOB.areas, allowed_areas)
if (!length(possible_areas))
CRASH("No valid areas for anomaly found.")
var/area/landing_area = pick(possible_areas)
var/list/turf_test = get_area_turfs(landing_area)
if(!turf_test.len)
CRASH("Anomaly : No valid turfs found for [landing_area] - [landing_area.type]")
return landing_area
/**
* Returns a turf which is safe to place an anomaly on.
*
* Arguments
* * target_area - Area to return a turf from.
*/
/datum/anomaly_placer/proc/findValidTurf(area/target_area)
var/list/valid_turfs = list()
for (var/turf/try_turf as anything in get_area_turfs(target_area))
if (!is_valid_destination(try_turf))
continue
valid_turfs += try_turf
if (!valid_turfs.len)
CRASH("Dimensional anomaly attempted to reach invalid location [target_area].")
return pick(valid_turfs)
/**
* Returns true if the provided turf is valid to place an anomaly on.
*
* Arguments
* * tested - Turf to try landing on.
*/
/datum/anomaly_placer/proc/is_valid_destination(turf/tested)
if (isspaceturf(tested))
return FALSE
if (tested.is_blocked_turf(exclude_mobs = TRUE))
return FALSE
if (islava(tested))
return FALSE
if (ischasm(tested))
return FALSE
return TRUE
/**
* Populates the allowed areas list.
*/
/datum/anomaly_placer/proc/generateAllowedAreas()
//Places that shouldn't explode
var/static/list/safe_area_types = typecacheof(ANOMALY_AREA_BLACKLIST)
//Subtypes from the above that actually should explode.
var/static/list/unsafe_area_subtypes = typecacheof(ANOMALY_AREA_SUBTYPE_WHITELIST)
allowed_areas = make_associative(GLOB.the_station_areas) - safe_area_types + unsafe_area_subtypes