-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathzlook.dm
132 lines (120 loc) · 5.48 KB
/
zlook.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#define LOOKING_DIRECTION_UP 1
#define LOOKING_DIRECTION_NONE 0
#define LOOKING_DIRECTION_DOWN -1
/// The current direction the player is ACTUALLY looking, regardless of intent.
/mob/living/var/looking_direction = LOOKING_DIRECTION_NONE
/// The current direction the player is trying to look.
/mob/living/var/attempt_looking_direction = LOOKING_DIRECTION_NONE
///Checks if the user is incapacitated and cannot look up/down
/mob/living/proc/can_look_direction()
return !(incapacitated(ignore_restraints = TRUE))
/// Tell the mob to attempt to look this direction until it's set back to NONE
/mob/living/proc/set_attempted_looking_direction(direction)
if(attempt_looking_direction == direction && direction != LOOKING_DIRECTION_NONE) // we are already trying to look this way, reset
set_attempted_looking_direction(LOOKING_DIRECTION_NONE)
return
attempt_looking_direction = direction
set_look_direction(attempt_looking_direction)
/// Actually sets the looking direction, but it won't try to stay that way if we move out of range
/mob/living/proc/set_look_direction(direction, automatic = FALSE)
// Handle none/failure
if(direction == LOOKING_DIRECTION_NONE || !can_look_direction(direction))
looking_direction = LOOKING_DIRECTION_NONE
reset_perspective()
return
// Automatic attempts should not trigger the cooldown
if(!automatic)
changeNext_move(CLICK_CD_LOOK_UP)
looking_direction = direction
var/look_str = direction == LOOKING_DIRECTION_UP ? "up" : "down"
if(update_looking_move(automatic))
visible_message("<span class='notice'>[src] looks [look_str].</span>", "<span class='notice'>You look [look_str].</span>")
/// Called by /mob/living/Moved(), checks if we can continue looking
/mob/living/proc/update_looking_move(automatic = FALSE)
// Try looking the attempted direction now that we've moved
if(attempt_looking_direction != LOOKING_DIRECTION_NONE && looking_direction == LOOKING_DIRECTION_NONE)
set_look_direction(attempt_looking_direction, automatic = TRUE) // this won't loop recursively because looking_direction cannot be NONE above
// We can't try looking nowhere!
if(looking_direction == LOOKING_DIRECTION_NONE)
return FALSE
// Something changed, stop looking
if(!can_look_direction(looking_direction))
set_look_direction(LOOKING_DIRECTION_NONE)
// Update perspective
var/turf/base = find_visible_hole_in_direction(looking_direction)
if(!isturf(base))
if(!automatic)
to_chat(src, "<span class='warning'>You can't see through the [looking_direction == LOOKING_DIRECTION_UP ? "ceiling above" : "floor below"] you.</span>")
set_look_direction(LOOKING_DIRECTION_NONE)
return FALSE
reset_perspective(base)
return TRUE
/mob/living/verb/look_up_short()
set name = "Look Up"
set category = "IC"
// you pressed the verb while holding a keybind, unlock!
attempt_looking_direction = LOOKING_DIRECTION_NONE
if(looking_direction == LOOKING_DIRECTION_UP)
set_look_direction(LOOKING_DIRECTION_NONE)
return
look_up()
/**
* look_up Changes the perspective of the mob to any openspace turf above the mob
* lock: If it should continue to try looking even if there is no seethrough turf
*/
/mob/living/proc/look_up(lock = FALSE)
if(lock)
set_attempted_looking_direction(LOOKING_DIRECTION_UP)
else
set_look_direction(LOOKING_DIRECTION_UP)
/mob/living/verb/look_down_short()
set name = "Look Down"
set category = "IC"
// you pressed the verb while holding a keybind, unlock!
attempt_looking_direction = LOOKING_DIRECTION_NONE
if(looking_direction == LOOKING_DIRECTION_DOWN)
set_look_direction(LOOKING_DIRECTION_NONE)
return
look_down()
/**
* look_down Changes the perspective of the mob to any openspace turf below the mob
* lock: If it should continue to try looking even if there is no seethrough turf
*/
/mob/living/proc/look_down(lock = FALSE)
if(lock)
set_attempted_looking_direction(LOOKING_DIRECTION_DOWN)
else
set_look_direction(LOOKING_DIRECTION_DOWN)
/// Helper, resets from looking up or down, and unlocks the view.
/mob/living/proc/look_reset()
set_attempted_looking_direction(LOOKING_DIRECTION_NONE)
/mob/living/proc/find_visible_hole_in_direction(direction)
// Our current z-level turf
var/turf/turf_base = get_turf(src)
// The target z-level turf
var/turf/turf_other = get_step_multiz(turf_base, direction == LOOKING_DIRECTION_UP ? UP : DOWN)
if(!turf_other) // There is nothing above/below
return FALSE
// This turf is the one we are looking through
var/turf/seethrough_turf = direction == LOOKING_DIRECTION_UP ? turf_other : turf_base
// The turf we should end up looking at.
var/turf/end_turf = turf_other
if(istransparentturf(seethrough_turf)) //There is no turf we can look through directly above/below us, look for nearby turfs
return end_turf
// Turf in front of you to try to look through before anything else
var/turf/seethrough_turf_front = get_step(seethrough_turf, dir)
if(istransparentturf(seethrough_turf_front))
return direction == LOOKING_DIRECTION_UP ? seethrough_turf_front : get_step_multiz(seethrough_turf_front, DOWN)
var/target_z = direction == LOOKING_DIRECTION_UP ? turf_other.z : z
var/list/checkturfs = block(locate(x-1,y-1,target_z),locate(x+1,y+1,target_z))-turf_base-turf_other
for(var/turf/checkhole in checkturfs)
if(istransparentturf(checkhole))
seethrough_turf = checkhole
end_turf = direction == LOOKING_DIRECTION_UP ? checkhole : get_step_multiz(checkhole, DOWN)
break
if(!istransparentturf(seethrough_turf))
return FALSE
return end_turf
#undef LOOKING_DIRECTION_UP
#undef LOOKING_DIRECTION_NONE
#undef LOOKING_DIRECTION_DOWN