Fixes AI camera static not updating when the AI enters a mecha (#70385)

* it just works

* kick the eye out of the mecha on mob_exit
This commit is contained in:
Sealed101
2022-10-19 20:32:35 -04:00
committed by GitHub
parent b8214cedfc
commit b1ed2d03f2
4 changed files with 18 additions and 6 deletions
@@ -67,16 +67,18 @@ GLOBAL_DATUM_INIT(cameranet, /datum/cameranet, new)
for(var/mob/camera/ai_eye/eye as anything in moved_eyes)
var/list/visibleChunks = list()
///Get the eye's turf in case it's located in an object like a mecha
var/turf/eye_turf = get_turf(eye)
if(eye.loc)
var/static_range = eye.static_visibility_range
var/x1 = max(1, eye.x - static_range)
var/y1 = max(1, eye.y - static_range)
var/x2 = min(world.maxx, eye.x + static_range)
var/y2 = min(world.maxy, eye.y + static_range)
var/x1 = max(1, eye_turf.x - static_range)
var/y1 = max(1, eye_turf.y - static_range)
var/x2 = min(world.maxx, eye_turf.x + static_range)
var/y2 = min(world.maxy, eye_turf.y + static_range)
for(var/x = x1; x <= x2; x += CHUNK_SIZE)
for(var/y = y1; y <= y2; y += CHUNK_SIZE)
visibleChunks |= getCameraChunk(x, y, eye.z)
visibleChunks |= getCameraChunk(x, y, eye_turf.z)
var/list/remove = eye.visibleCameraChunks - visibleChunks
var/list/add = visibleChunks - eye.visibleCameraChunks
@@ -83,6 +83,12 @@
var/turf/upperright = locate(min(world.maxx, lowerleft.x + (view[1] - 1)), min(world.maxy, lowerleft.y + (view[2] - 1)), lowerleft.z)
return block(lowerleft, upperright)
/// Used in cases when the eye is located in a movable object (i.e. mecha)
/mob/camera/ai_eye/proc/update_visibility()
SIGNAL_HANDLER
if(use_static)
ai.camera_visibility(src)
// Use this when setting the aiEye's location.
// It will also stream the chunk that the new loc is in.
@@ -98,7 +98,8 @@
AI.ai_restore_power()
mecha_flags |= SILICON_PILOT
moved_inside(AI)
AI.cancel_camera()
AI.eyeobj?.forceMove(src)
AI.eyeobj?.RegisterSignal(src, COMSIG_MOVABLE_MOVED, /mob/camera/ai_eye/proc/update_visibility)
AI.controlled_equipment = src
AI.remote_control = src
to_chat(AI, AI.can_dominate_mechs ? span_greenannounce("Takeover of [name] complete! You are now loaded onto the onboard computer. Do not attempt to leave the station sector!") :\
@@ -112,6 +112,9 @@
mob_container = brain.container
else if(isAI(M))
var/mob/living/silicon/ai/AI = M
//stop listening to this signal, as the static update is now handled by the eyeobj's setLoc
AI.eyeobj?.UnregisterSignal(src, COMSIG_MOVABLE_MOVED)
AI.eyeobj?.forceMove(newloc) //kick the eye out as well
if(forced)//This should only happen if there are multiple AIs in a round, and at least one is Malf.
AI.gib() //If one Malf decides to steal a mech from another AI (even other Malfs!), they are destroyed, as they have nowhere to go when replaced.
AI = null