Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit c8fb972

Browse files
authored
she's z looking (#22850)
1 parent 4072b36 commit c8fb972

File tree

4 files changed

+134
-131
lines changed

4 files changed

+134
-131
lines changed

code/modules/mob/living/living_movement.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
is_shifted = FALSE
66
pixel_x = get_standard_pixel_x_offset(lying)
77
pixel_y = get_standard_pixel_y_offset(lying)
8+
update_looking_move()
89

910
/mob/living/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents)
1011
. = ..()

code/modules/mob/living/zlook.dm

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#define LOOKING_DIRECTION_UP 1
2+
#define LOOKING_DIRECTION_NONE 0
3+
#define LOOKING_DIRECTION_DOWN -1
4+
5+
/// The current direction the player is ACTUALLY looking, regardless of intent.
6+
/mob/living/var/looking_direction = LOOKING_DIRECTION_NONE
7+
/// The current direction the player is trying to look.
8+
/mob/living/var/attempt_looking_direction = LOOKING_DIRECTION_NONE
9+
10+
///Checks if the user is incapacitated and cannot look up/down
11+
/mob/living/proc/can_look_direction()
12+
return !(incapacitated(ignore_restraints = TRUE))
13+
14+
/// Tell the mob to attempt to look this direction until it's set back to NONE
15+
/mob/living/proc/set_attempted_looking_direction(direction)
16+
if(attempt_looking_direction == direction && direction != LOOKING_DIRECTION_NONE) // we are already trying to look this way, reset
17+
set_attempted_looking_direction(LOOKING_DIRECTION_NONE)
18+
return
19+
attempt_looking_direction = direction
20+
set_look_direction(attempt_looking_direction)
21+
22+
/// Actually sets the looking direction, but it won't try to stay that way if we move out of range
23+
/mob/living/proc/set_look_direction(direction, automatic = FALSE)
24+
// Handle none/failure
25+
if(direction == LOOKING_DIRECTION_NONE || !can_look_direction(direction))
26+
looking_direction = LOOKING_DIRECTION_NONE
27+
reset_perspective()
28+
return
29+
// Automatic attempts should not trigger the cooldown
30+
if(!automatic)
31+
changeNext_move(CLICK_CD_LOOK_UP)
32+
looking_direction = direction
33+
var/look_str = direction == LOOKING_DIRECTION_UP ? "up" : "down"
34+
if(update_looking_move(automatic))
35+
visible_message("<span class='notice'>[src] looks [look_str].</span>", "<span class='notice'>You look [look_str].</span>")
36+
37+
/// Called by /mob/living/Moved(), checks if we can continue looking
38+
/mob/living/proc/update_looking_move(automatic = FALSE)
39+
// Try looking the attempted direction now that we've moved
40+
if(attempt_looking_direction != LOOKING_DIRECTION_NONE && looking_direction == LOOKING_DIRECTION_NONE)
41+
set_look_direction(attempt_looking_direction, automatic = TRUE) // this won't loop recursively because looking_direction cannot be NONE above
42+
// We can't try looking nowhere!
43+
if(looking_direction == LOOKING_DIRECTION_NONE)
44+
return FALSE
45+
// Something changed, stop looking
46+
if(!can_look_direction(looking_direction))
47+
set_look_direction(LOOKING_DIRECTION_NONE)
48+
// Update perspective
49+
var/turf/base = find_visible_hole_in_direction(looking_direction)
50+
if(!isturf(base))
51+
if(!automatic)
52+
to_chat(src, "<span class='warning'>You can't see through the [looking_direction == LOOKING_DIRECTION_UP ? "ceiling above" : "floor below"] you.</span>")
53+
set_look_direction(LOOKING_DIRECTION_NONE)
54+
return FALSE
55+
reset_perspective(base)
56+
return TRUE
57+
58+
/mob/living/verb/look_up_short()
59+
set name = "Look Up"
60+
set category = "IC"
61+
// you pressed the verb while holding a keybind, unlock!
62+
attempt_looking_direction = LOOKING_DIRECTION_NONE
63+
if(looking_direction == LOOKING_DIRECTION_UP)
64+
set_look_direction(LOOKING_DIRECTION_NONE)
65+
return
66+
look_up()
67+
68+
/**
69+
* look_up Changes the perspective of the mob to any openspace turf above the mob
70+
* lock: If it should continue to try looking even if there is no seethrough turf
71+
*/
72+
/mob/living/proc/look_up(lock = FALSE)
73+
if(lock)
74+
set_attempted_looking_direction(LOOKING_DIRECTION_UP)
75+
else
76+
set_look_direction(LOOKING_DIRECTION_UP)
77+
78+
/mob/living/verb/look_down_short()
79+
set name = "Look Down"
80+
set category = "IC"
81+
// you pressed the verb while holding a keybind, unlock!
82+
attempt_looking_direction = LOOKING_DIRECTION_NONE
83+
if(looking_direction == LOOKING_DIRECTION_DOWN)
84+
set_look_direction(LOOKING_DIRECTION_NONE)
85+
return
86+
look_down()
87+
88+
/**
89+
* look_down Changes the perspective of the mob to any openspace turf below the mob
90+
* lock: If it should continue to try looking even if there is no seethrough turf
91+
*/
92+
/mob/living/proc/look_down(lock = FALSE)
93+
if(lock)
94+
set_attempted_looking_direction(LOOKING_DIRECTION_DOWN)
95+
else
96+
set_look_direction(LOOKING_DIRECTION_DOWN)
97+
98+
/// Helper, resets from looking up or down, and unlocks the view.
99+
/mob/living/proc/look_reset()
100+
set_attempted_looking_direction(LOOKING_DIRECTION_NONE)
101+
102+
/mob/living/proc/find_visible_hole_in_direction(direction)
103+
// Our current z-level turf
104+
var/turf/turf_base = get_turf(src)
105+
// The target z-level turf
106+
var/turf/turf_other = get_step_multiz(turf_base, direction == LOOKING_DIRECTION_UP ? UP : DOWN)
107+
if(!turf_other) // There is nothing above/below
108+
return FALSE
109+
// This turf is the one we are looking through
110+
var/turf/seethrough_turf = direction == LOOKING_DIRECTION_UP ? turf_other : turf_base
111+
// The turf we should end up looking at.
112+
var/turf/end_turf = turf_other
113+
if(istransparentturf(seethrough_turf)) //There is no turf we can look through directly above/below us, look for nearby turfs
114+
return end_turf
115+
// Turf in front of you to try to look through before anything else
116+
var/turf/seethrough_turf_front = get_step(seethrough_turf, dir)
117+
if(istransparentturf(seethrough_turf_front))
118+
return direction == LOOKING_DIRECTION_UP ? seethrough_turf_front : get_step_multiz(seethrough_turf_front, DOWN)
119+
var/target_z = direction == LOOKING_DIRECTION_UP ? turf_other.z : z
120+
var/list/checkturfs = block(locate(x-1,y-1,target_z),locate(x+1,y+1,target_z))-turf_base-turf_other
121+
for(var/turf/checkhole in checkturfs)
122+
if(istransparentturf(checkhole))
123+
seethrough_turf = checkhole
124+
end_turf = direction == LOOKING_DIRECTION_UP ? checkhole : get_step_multiz(checkhole, DOWN)
125+
break
126+
if(!istransparentturf(seethrough_turf))
127+
return FALSE
128+
return end_turf
129+
130+
#undef LOOKING_DIRECTION_UP
131+
#undef LOOKING_DIRECTION_NONE
132+
#undef LOOKING_DIRECTION_DOWN

code/modules/mob/mob.dm

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,134 +1377,3 @@
13771377
/mob/setMovetype(newval)
13781378
. = ..()
13791379
update_movespeed(FALSE)
1380-
1381-
//I am looking respectfully
1382-
1383-
/mob/living/verb/lookup()
1384-
set name = "Look Up"
1385-
set category = "IC"
1386-
1387-
if(looking_vertically)
1388-
end_look_up()
1389-
else
1390-
look_up()
1391-
1392-
/mob/living/verb/lookdown()
1393-
set name = "Look Down"
1394-
set category = "IC"
1395-
1396-
if(looking_vertically)
1397-
end_look_down()
1398-
else
1399-
look_down()
1400-
1401-
/**
1402-
* look_up Changes the perspective of the mob to any openspace turf above the mob
1403-
*
1404-
* This also checks if an openspace turf is above the mob before looking up or resets the perspective if already looking up
1405-
*
1406-
*/
1407-
/mob/living/proc/look_up()
1408-
if(client.perspective != MOB_PERSPECTIVE) //We are already looking up.
1409-
stop_look_up()
1410-
if(!can_look_up())
1411-
return
1412-
changeNext_move(CLICK_CD_LOOK_UP)
1413-
RegisterSignal(src, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(stop_look_up)) //We stop looking up if we move.
1414-
RegisterSignal(src, COMSIG_MOVABLE_MOVED, PROC_REF(start_look_up)) //We start looking again after we move.
1415-
start_look_up()
1416-
1417-
/mob/living/proc/start_look_up()
1418-
SIGNAL_HANDLER
1419-
var/turf/ceiling = get_step_multiz(src, UP)
1420-
if(!ceiling) //We are at the highest z-level.
1421-
if (prob(0.1))
1422-
to_chat(src, span_warning("You gaze out into the infinite vastness of deep space, for a moment, you have the impulse to continue travelling, out there, out into the deep beyond, before your conciousness reasserts itself and you decide to stay within travelling distance of the station."))
1423-
return
1424-
to_chat(src, span_warning("There's nothing interesting up there."))
1425-
return
1426-
else if(!istransparentturf(ceiling)) //There is no turf we can look through above us
1427-
var/turf/front_hole = get_step(ceiling, dir)
1428-
if(istransparentturf(front_hole))
1429-
ceiling = front_hole
1430-
else
1431-
for(var/turf/checkhole in TURF_NEIGHBORS(ceiling))
1432-
if(istransparentturf(checkhole))
1433-
ceiling = checkhole
1434-
break
1435-
if(!istransparentturf(ceiling))
1436-
to_chat(src, span_warning("You can't see through the floor above you."))
1437-
return
1438-
1439-
looking_vertically = TRUE
1440-
reset_perspective(ceiling)
1441-
1442-
/mob/living/proc/stop_look_up()
1443-
SIGNAL_HANDLER
1444-
reset_perspective()
1445-
1446-
/mob/living/proc/end_look_up()
1447-
stop_look_up()
1448-
looking_vertically = FALSE
1449-
UnregisterSignal(src, COMSIG_MOVABLE_PRE_MOVE)
1450-
UnregisterSignal(src, COMSIG_MOVABLE_MOVED)
1451-
1452-
/**
1453-
* look_down Changes the perspective of the mob to any openspace turf below the mob
1454-
*
1455-
* This also checks if an openspace turf is below the mob before looking down or resets the perspective if already looking up
1456-
*
1457-
*/
1458-
/mob/living/proc/look_down()
1459-
if(client.perspective != MOB_PERSPECTIVE) //We are already looking down.
1460-
stop_look_down()
1461-
if(!can_look_up()) //if we cant look up, we cant look down.
1462-
return
1463-
changeNext_move(CLICK_CD_LOOK_UP)
1464-
RegisterSignal(src, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(stop_look_down)) //We stop looking down if we move.
1465-
RegisterSignal(src, COMSIG_MOVABLE_MOVED, PROC_REF(start_look_down)) //We start looking again after we move.
1466-
start_look_down()
1467-
1468-
/mob/living/proc/start_look_down()
1469-
SIGNAL_HANDLER
1470-
var/turf/floor = get_turf(src)
1471-
var/turf/lower_level = get_step_multiz(floor, DOWN)
1472-
if(!lower_level) //We are at the lowest z-level.
1473-
to_chat(src, span_warning("You can't see through the floor below you."))
1474-
return
1475-
else if(!istransparentturf(floor)) //There is no turf we can look through below us
1476-
var/turf/front_hole = get_step(floor, dir)
1477-
if(istransparentturf(front_hole))
1478-
floor = front_hole
1479-
lower_level = get_step_multiz(front_hole, DOWN)
1480-
else
1481-
// Try to find a hole near us
1482-
for(var/turf/checkhole in TURF_NEIGHBORS(floor))
1483-
if(istransparentturf(checkhole))
1484-
floor = checkhole
1485-
lower_level = get_step_multiz(checkhole, DOWN)
1486-
break
1487-
if(!istransparentturf(floor))
1488-
to_chat(src, span_warning("You can't see through the floor below you."))
1489-
return
1490-
1491-
looking_vertically = TRUE
1492-
reset_perspective(lower_level)
1493-
1494-
/mob/living/proc/stop_look_down()
1495-
SIGNAL_HANDLER
1496-
reset_perspective()
1497-
1498-
/mob/living/proc/end_look_down()
1499-
stop_look_down()
1500-
looking_vertically = FALSE
1501-
UnregisterSignal(src, COMSIG_MOVABLE_PRE_MOVE)
1502-
UnregisterSignal(src, COMSIG_MOVABLE_MOVED)
1503-
1504-
///Checks if the user is incapacitated or on cooldown.
1505-
/mob/living/proc/can_look_up()
1506-
if(next_move > world.time)
1507-
return FALSE
1508-
if(incapacitated(ignore_restraints = TRUE))
1509-
return FALSE
1510-
return TRUE

yogstation.dme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,7 @@
28612861
#include "code\modules\mob\living\status_procs.dm"
28622862
#include "code\modules\mob\living\taste.dm"
28632863
#include "code\modules\mob\living\ventcrawling.dm"
2864+
#include "code\modules\mob\living\zlook.dm"
28642865
#include "code\modules\mob\living\brain\brain.dm"
28652866
#include "code\modules\mob\living\brain\brain_item.dm"
28662867
#include "code\modules\mob\living\brain\death.dm"

0 commit comments

Comments
 (0)