diff --git a/code/ZAS/Atom.dm b/code/ZAS/Atom.dm index b4d1de20af4..8d479ecfb14 100644 --- a/code/ZAS/Atom.dm +++ b/code/ZAS/Atom.dm @@ -29,6 +29,16 @@ atom/proc/CanPass(atom/movable/mover, turf/target, height=1.5, air_group = 0) return 0 return 1 + +//Convenience function for atoms to update turfs they occupy +/atom/movable/proc/update_nearby_tiles(need_rebuild) + if(!air_master) + return 0 + + for(var/turf/simulated/turf in locs) + air_master.mark_for_update(turf) + + return 1 //Basically another way of calling CanPass(null, other, 0, 0) and CanPass(null, other, 1.5, 1). //Returns: diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 10ab63c9259..8e6118f6f46 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -396,4 +396,190 @@ proc/listclearnulls(list/list) /proc/find_record(field, value, list/L) for(var/datum/data/record/R in L) if(R.fields[field] == value) - return R \ No newline at end of file + return R + + +/proc/dd_sortedObjectList(var/list/L, var/cache=list()) + if(L.len < 2) + return L + var/middle = L.len / 2 + 1 // Copy is first,second-1 + return dd_mergeObjectList(dd_sortedObjectList(L.Copy(0,middle), cache), dd_sortedObjectList(L.Copy(middle), cache), cache) //second parameter null = to end of list + +/proc/dd_mergeObjectList(var/list/L, var/list/R, var/list/cache) + var/Li=1 + var/Ri=1 + var/list/result = new() + while(Li <= L.len && Ri <= R.len) + var/LLi = L[Li] + var/RRi = R[Ri] + var/LLiV = cache[LLi] + var/RRiV = cache[RRi] + if(!LLiV) + LLiV = LLi:dd_SortValue() + cache[LLi] = LLiV + if(!RRiV) + RRiV = RRi:dd_SortValue() + cache[RRi] = RRiV + if(LLiV < RRiV) + result += L[Li++] + else + result += R[Ri++] + + if(Li <= L.len) + return (result + L.Copy(Li, 0)) + return (result + R.Copy(Ri, 0)) + +// Insert an object into a sorted list, preserving sortedness +/proc/dd_insertObjectList(var/list/L, var/O) + var/min = 1 + var/max = L.len + var/Oval = O:dd_SortValue() + + while(1) + var/mid = min+round((max-min)/2) + + if(mid == max) + L.Insert(mid, O) + return + + var/Lmid = L[mid] + var/midval = Lmid:dd_SortValue() + if(Oval == midval) + L.Insert(mid, O) + return + else if(Oval < midval) + max = mid + else + min = mid+1 + +/* +proc/dd_sortedObjectList(list/incoming) + /* + Use binary search to order by dd_SortValue(). + This works by going to the half-point of the list, seeing if the node in + question is higher or lower cost, then going halfway up or down the list + and checking again. This is a very fast way to sort an item into a list. + */ + var/list/sorted_list = new() + var/low_index + var/high_index + var/insert_index + var/midway_calc + var/current_index + var/current_item + var/current_item_value + var/current_sort_object_value + var/list/list_bottom + + var/current_sort_object + for (current_sort_object in incoming) + low_index = 1 + high_index = sorted_list.len + while (low_index <= high_index) + // Figure out the midpoint, rounding up for fractions. (BYOND rounds down, so add 1 if necessary.) + midway_calc = (low_index + high_index) / 2 + current_index = round(midway_calc) + if (midway_calc > current_index) + current_index++ + current_item = sorted_list[current_index] + + current_item_value = current_item:dd_SortValue() + current_sort_object_value = current_sort_object:dd_SortValue() + if (current_sort_object_value < current_item_value) + high_index = current_index - 1 + else if (current_sort_object_value > current_item_value) + low_index = current_index + 1 + else + // current_sort_object == current_item + low_index = current_index + break + + // Insert before low_index. + insert_index = low_index + + // Special case adding to end of list. + if (insert_index > sorted_list.len) + sorted_list += current_sort_object + continue + + // Because BYOND lists don't support insert, have to do it by: + // 1) taking out bottom of list, 2) adding item, 3) putting back bottom of list. + list_bottom = sorted_list.Copy(insert_index) + sorted_list.Cut(insert_index) + sorted_list += current_sort_object + sorted_list += list_bottom + return sorted_list +*/ + +proc/dd_sortedtextlist(list/incoming, case_sensitive = 0) + // Returns a new list with the text values sorted. + // Use binary search to order by sortValue. + // This works by going to the half-point of the list, seeing if the node in question is higher or lower cost, + // then going halfway up or down the list and checking again. + // This is a very fast way to sort an item into a list. + var/list/sorted_text = new() + var/low_index + var/high_index + var/insert_index + var/midway_calc + var/current_index + var/current_item + var/list/list_bottom + var/sort_result + + var/current_sort_text + for (current_sort_text in incoming) + low_index = 1 + high_index = sorted_text.len + while (low_index <= high_index) + // Figure out the midpoint, rounding up for fractions. (BYOND rounds down, so add 1 if necessary.) + midway_calc = (low_index + high_index) / 2 + current_index = round(midway_calc) + if (midway_calc > current_index) + current_index++ + current_item = sorted_text[current_index] + + if (case_sensitive) + sort_result = sorttextEx(current_sort_text, current_item) + else + sort_result = sorttext(current_sort_text, current_item) + + switch(sort_result) + if (1) + high_index = current_index - 1 // current_sort_text < current_item + if (-1) + low_index = current_index + 1 // current_sort_text > current_item + if (0) + low_index = current_index // current_sort_text == current_item + break + + // Insert before low_index. + insert_index = low_index + + // Special case adding to end of list. + if (insert_index > sorted_text.len) + sorted_text += current_sort_text + continue + + // Because BYOND lists don't support insert, have to do it by: + // 1) taking out bottom of list, 2) adding item, 3) putting back bottom of list. + list_bottom = sorted_text.Copy(insert_index) + sorted_text.Cut(insert_index) + sorted_text += current_sort_text + sorted_text += list_bottom + return sorted_text + + +proc/dd_sortedTextList(list/incoming) + var/case_sensitive = 1 + return dd_sortedtextlist(incoming, case_sensitive) + + +datum/proc/dd_SortValue() + return "[src]" + +/obj/machinery/dd_SortValue() + return "[sanitize(name)]" + +/obj/machinery/camera/dd_SortValue() + return "[c_tag]" \ No newline at end of file diff --git a/code/datums/ai_laws.dm b/code/datums/ai_laws.dm index d81bbf67085..e1fc26d1709 100644 --- a/code/datums/ai_laws.dm +++ b/code/datums/ai_laws.dm @@ -179,6 +179,11 @@ datum/ai_laws/tyrant //This probably shouldn't be a default lawset. /datum/ai_laws/proc/clear_ion_laws() src.ion = list() + +/datum/ai_laws/proc/clear_zeroth_law(var/law_borg = null) + src.zeroth = null + if(law_borg) + src.zeroth_borg = null /datum/ai_laws/proc/show_laws(var/who) diff --git a/code/datums/visibility_networks/chunk.dm b/code/datums/visibility_networks/chunk.dm deleted file mode 100644 index 4abc1340b0f..00000000000 --- a/code/datums/visibility_networks/chunk.dm +++ /dev/null @@ -1,179 +0,0 @@ -#define UPDATE_BUFFER 25 // 2.5 seconds - -// CAMERA CHUNK -// -// A 16x16 grid of the map with a list of turfs that can be seen, are visible and are dimmed. -// Allows the mob using this chunk to stream these chunks and know what it can and cannot see. - -/datum/visibility_chunk - var/obscured_image = 'icons/effects/cameravis.dmi' - var/obscured_sub = "black" - var/list/obscuredTurfs = list() - var/list/visibleTurfs = list() - var/list/obscured = list() - var/list/viewpoints = list() - var/list/turfs = list() - var/list/seenby = list() - var/visible = 0 - var/changed = 0 - var/updating = 0 - var/x = 0 - var/y = 0 - var/z = 0 - -/datum/visibility_chunk/proc/add(mob/new_mob) - - // if this thing doesn't use one of these visibility systems, kick it out - if (!new_mob.visibility_interface) - return - - // if the mob being added isn't a valid form of that mob, kick it out - if (!new_mob.visibility_interface:canBeAddedToChunk(src)) - return - - // add this chunk to the list of visible chunks - new_mob.visibility_interface:addChunk(src) - - visible++ - seenby += new_mob - if(changed && !updating) - update() - -/datum/visibility_chunk/proc/remove(mob/new_mob) - // if this thing doesn't use one of these visibility systems, kick it out - if (!new_mob.visibility_interface) - return - - // if the mob being added isn't a valid form of that mob, kick it out - if (!new_mob.visibility_interface:canBeAddedToChunk(src)) - return - - // remove the chunk - new_mob.visibility_interface:removeChunk(src) - - // remove the mob from out lists - seenby -= new_mob - if(visible > 0) - visible-- - -/datum/visibility_chunk/proc/visibilityChanged(turf/loc) - if(!visibleTurfs[loc]) - return - hasChanged() - -/datum/visibility_chunk/proc/hasChanged(var/update_now = 0) - if(visible || update_now) - if(!updating) - updating = 1 - spawn(UPDATE_BUFFER) // Batch large changes, such as many doors opening or closing at once - update() - updating = 0 - else - changed = 1 - - -/* -This function needs to be overwritten to return True if the viewpoint object is valid, and false if it is not. -*/ -/datum/visibility_chunk/proc/validViewpoint(var/viewpoint) - return FALSE - -/* -This function needs to be overwritten to return a list of visible turfs for that viewpoint -*/ -/datum/visibility_chunk/proc/getVisibleTurfsForViewpoint(var/viewpoint) - return list() - -// returns a list of turfs which can be seen in by the chunks viewpoints -/datum/visibility_chunk/proc/getVisibleTurfs() - var/list/newVisibleTurfs = list() - for(var/viewpoint in viewpoints) - if (validViewpoint(viewpoint)) - for (var/turf/t in getVisibleTurfsForViewpoint(viewpoint)) - newVisibleTurfs[t]=t - return newVisibleTurfs - -/* -This function needs to be overwritten to find nearby viewpoint objects to the chunk center. -*/ -/datum/visibility_chunk/proc/findNearbyViewpoints() - return FALSE - -/* -This function can be overwritten to change or randomize the obscuring images -*/ -/datum/visibility_chunk/proc/setObscuredImage(var/turf/target_turf) - if(!target_turf.obscured) - target_turf.obscured = image(obscured_image, target_turf, obscured_sub, 15) - -/datum/visibility_chunk/proc/update() - - set background = 1 - - // get a list of all the turfs that our viewpoints can see - var/list/newVisibleTurfs = getVisibleTurfs() - - // Removes turf that isn't in turfs. - newVisibleTurfs &= turfs - - var/list/visAdded = newVisibleTurfs - visibleTurfs - var/list/visRemoved = visibleTurfs - newVisibleTurfs - - visibleTurfs = newVisibleTurfs - obscuredTurfs = turfs - newVisibleTurfs - - // update the visibility overlays - for(var/turf in visAdded) - var/turf/t = turf - if(t.obscured) - obscured -= t.obscured - for(var/mob/current_mob in seenby) - if (current_mob.visibility_interface) - current_mob.visibility_interface:removeObscuredTurf(t) - - for(var/turf in visRemoved) - var/turf/t = turf - if(obscuredTurfs[t]) - setObscuredImage(t) - obscured += t.obscured - for(var/mob/current_mob in seenby) - if (current_mob.visibility_interface) - current_mob.visibility_interface:addObscuredTurf(t) - else - seenby -= current_mob - - -// Create a new chunk, since the chunks are made as they are needed. -/datum/visibility_chunk/New(loc, x, y, z) - - // 0xf = 15 - x &= ~0xf - y &= ~0xf - - src.x = x - src.y = y - src.z = z - - for(var/turf/t in range(10, locate(x + 8, y + 8, z))) - if(t.x >= x && t.y >= y && t.x < x + 16 && t.y < y + 16) - turfs[t] = t - - // locate all nearby viewpoints - findNearbyViewpoints() - - // get the turfs that are visible to those viewpoints - visibleTurfs = getVisibleTurfs() - - // Removes turf that isn't in turfs. - visibleTurfs &= turfs - - // create the list of turfs we can't see - obscuredTurfs = turfs - visibleTurfs - - // create the list of obscuring images to add to viewing clients - for(var/turf in obscuredTurfs) - var/turf/t = turf - setObscuredImage(t) - obscured += t.obscured - -#undef UPDATE_BUFFER \ No newline at end of file diff --git a/code/datums/visibility_networks/dictionary.dm b/code/datums/visibility_networks/dictionary.dm deleted file mode 100644 index 5f57ddd7a17..00000000000 --- a/code/datums/visibility_networks/dictionary.dm +++ /dev/null @@ -1,11 +0,0 @@ -var/datum/visibility_network/cameras/cameranet = new() -var/datum/visibility_network/cult/cultNetwork = new() -var/datum/visibility_network/list/visibility_networks = list("ALL_CAMERAS"=cameranet, "CULT" = cultNetwork) - - -// used by turfs and objects to update all visibility networks -/proc/updateVisibilityNetworks(atom/A, var/opacity_check = 1) - var/datum/visibility_network/currentNetwork - for (var/networkName in visibility_networks) - currentNetwork = visibility_networks[networkName] - currentNetwork.updateVisibility(A, opacity_check) \ No newline at end of file diff --git a/code/datums/visibility_networks/update_triggers.dm b/code/datums/visibility_networks/update_triggers.dm deleted file mode 100644 index 97ed2db3a6c..00000000000 --- a/code/datums/visibility_networks/update_triggers.dm +++ /dev/null @@ -1,94 +0,0 @@ -//UPDATE TRIGGERS, when the chunk (and the surrounding chunks) should update. - -// TURFS - -/turf - var/image/obscured - -/turf/proc/visibilityChanged() - if(ticker) - updateVisibilityNetworks(src) - -/turf/simulated/Del() - visibilityChanged() - ..() - -/turf/simulated/New() - ..() - visibilityChanged() - - - -// STRUCTURES - -/obj/structure/Del() - if(ticker) - updateVisibilityNetworks(src) - ..() - -/obj/structure/New() - ..() - if(ticker) - updateVisibilityNetworks(src) - -// EFFECTS - -/obj/effect/Del() - if(ticker) - updateVisibilityNetworks(src) - ..() - -/obj/effect/New() - ..() - if(ticker) - updateVisibilityNetworks(src) - - -// DOORS - -// Simply updates the visibility of the area when it opens/closes/destroyed. -/obj/machinery/door/proc/update_nearby_tiles(need_rebuild) - - if(!glass) - updateVisibilityNetworks(src,0) - - if(!air_master) - return 0 - - for(var/turf/simulated/turf in locs) - update_heat_protection(turf) - air_master.mark_for_update(turf) - - return 1 - - - -#define UPDATE_VISIBILITY_NETWORK_BUFFER 30 - -/mob - var/datum/visibility_network/list/visibilityNetworks=list() - var/updatingVisibilityNetworks=FALSE - -/mob/Move(n,direct) - var/oldLoc = src.loc - //. = ..() - if(..(n,direct)) - if(src.visibilityNetworks.len) - if(!src.updatingVisibilityNetworks) - src.updatingVisibilityNetworks = 1 - spawn(UPDATE_VISIBILITY_NETWORK_BUFFER) - if(oldLoc != src.loc) - for (var/datum/visibility_network/currentNetwork in src.visibilityNetworks) - currentNetwork.updateMob(src) - src.updatingVisibilityNetworks = 0 - return . - -/mob/proc/addToVisibilityNetwork(var/datum/visibility_network/network) - if(network) - src.visibilityNetworks+=network - -/mob/proc/removeFromVisibilityNetwork(var/datum/visibility_network/network) - if(network) - src.visibilityNetworks|=network - -#undef UPDATE_VISIBILITY_NETWORK_BUFFER \ No newline at end of file diff --git a/code/datums/visibility_networks/visibility_interface.dm b/code/datums/visibility_networks/visibility_interface.dm deleted file mode 100644 index 7d8efba41d3..00000000000 --- a/code/datums/visibility_networks/visibility_interface.dm +++ /dev/null @@ -1,46 +0,0 @@ -/datum/visibility_interface - var/chunk_type = null - var/mob/controller = null - var/list/visible_chunks = list() - - -/datum/visibility_interface/New(var/mob/controller) - src.controller = controller - - -/datum/visibility_interface/proc/validMob() - return getClient() - -/datum/visibility_interface/proc/getClient() - return controller.client - -/datum/visibility_interface/proc/canBeAddedToChunk(var/datum/visibility_chunk/test_chunk) - return istype(test_chunk,chunk_type) - - -/datum/visibility_interface/proc/addChunk(var/datum/visibility_chunk/test_chunk) - visible_chunks+=test_chunk - var/client/currentClient = getClient() - if(currentClient) - currentClient.images += test_chunk.obscured - - -/datum/visibility_interface/proc/removeChunk(var/datum/visibility_chunk/test_chunk) - visible_chunks-=test_chunk - var/client/currentClient = getClient() - if(currentClient) - currentClient.images -= test_chunk.obscured - - -/datum/visibility_interface/proc/removeObscuredTurf(var/turf/target_turf) - if(validMob()) - var/client/currentClient = getClient() - if(currentClient) - currentClient.images -= target_turf.obscured - - -/datum/visibility_interface/proc/addObscuredTurf(var/turf/target_turf) - if(validMob()) - var/client/currentClient = getClient() - if(currentClient) - currentClient.images -= target_turf.obscured \ No newline at end of file diff --git a/code/datums/visibility_networks/visibility_network.dm b/code/datums/visibility_networks/visibility_network.dm deleted file mode 100644 index f1bc24e771a..00000000000 --- a/code/datums/visibility_networks/visibility_network.dm +++ /dev/null @@ -1,144 +0,0 @@ -/datum/visibility_network - var/list/viewpoints = list() - - // the type of chunk used by this network - var/datum/visibility_chunk/ChunkType = /datum/visibility_chunk - - // The chunks of the map, mapping the areas that the viewpoints can see. - var/list/chunks = list() - - var/ready = 0 - - -// Creates a chunk key string from x,y,z coordinates -/datum/visibility_network/proc/createChunkKey(x,y,z) - x &= ~0xf - y &= ~0xf - return "[x],[y],[z]" - - -// Checks if a chunk has been Generated in x, y, z. -/datum/visibility_network/proc/chunkGenerated(x, y, z) - return (chunks[createChunkKey(x, y, z)]) - - -// Returns the chunk in the x, y, z. -// If there is no chunk, it creates a new chunk and returns that. -/datum/visibility_network/proc/getChunk(x, y, z) - var/key = createChunkKey(x, y, z) - if(!chunks[key]) - chunks[key] = new ChunkType(null, x, y, z) - return chunks[key] - - -/datum/visibility_network/proc/visibility(var/mob/targetMob) - - // if we've got not visibility interface on the mob, we canot do this - if (!targetMob.visibility_interface) - return - - // 0xf = 15 - var/x1 = max(0, targetMob.x - 16) & ~0xf - var/y1 = max(0, targetMob.y - 16) & ~0xf - var/x2 = min(world.maxx, targetMob.x + 16) & ~0xf - var/y2 = min(world.maxy, targetMob.y + 16) & ~0xf - - var/list/visibleChunks = list() - - for(var/x = x1; x <= x2; x += 16) - for(var/y = y1; y <= y2; y += 16) - visibleChunks += getChunk(x, y, targetMob.z) - - var/list/remove = targetMob.visibility_interface:visible_chunks - visibleChunks - var/list/add = visibleChunks - targetMob.visibility_interface:visible_chunks - - for(var/datum/visibility_chunk/chunk in remove) - chunk.remove(targetMob) - - for(var/datum/visibility_chunk/chunk in add) - chunk.add(targetMob) - - -// Updates the chunks that the turf is located in. Use this when obstacles are destroyed or when doors open. -/datum/visibility_network/proc/updateVisibility(atom/A, var/opacity_check = 1) - if(!ticker || (opacity_check && !A.opacity)) - return - majorChunkChange(A, 2) - - -/datum/visibility_network/proc/updateChunk(x, y, z) - if(!chunkGenerated(x, y, z)) - return - var/datum/visibility_chunk/chunk = getChunk(x, y, z) - chunk.hasChanged() - - -/datum/visibility_network/proc/validViewpoint(var/viewpoint) - return FALSE - - -/datum/visibility_network/proc/addViewpoint(var/viewpoint) - if(validViewpoint(viewpoint)) - majorChunkChange(viewpoint, 1) - - -/datum/visibility_network/proc/removeViewpoint(var/viewpoint) - if(validViewpoint(viewpoint)) - majorChunkChange(viewpoint, 0) - -/datum/visibility_network/proc/getViewpointFromMob(var/mob/currentMob) - return FALSE - -/datum/visibility_network/proc/updateMob(var/mob/currentMob) - var/viewpoint = getViewpointFromMob(currentMob) - if(viewpoint) - updateViewpoint(viewpoint) - - -/datum/visibility_network/proc/updateViewpoint(var/viewpoint) - if(validViewpoint(viewpoint)) - majorChunkChange(viewpoint, 1) - - -// Never access this proc directly!!!! -// This will update the chunk and all the surrounding chunks. -// It will also add the atom to the cameras list if you set the choice to 1. -// Setting the choice to 0 will remove the viewpoint from the chunks. -// If you want to update the chunks around an object, without adding/removing a viewpoint, use choice 2. -/datum/visibility_network/proc/majorChunkChange(atom/c, var/choice) - // 0xf = 15 - if(!c) - return - - var/turf/T = get_turf(c) - if(T) - var/x1 = max(0, T.x - 8) & ~0xf - var/y1 = max(0, T.y - 8) & ~0xf - var/x2 = min(world.maxx, T.x + 8) & ~0xf - var/y2 = min(world.maxy, T.y + 8) & ~0xf - - for(var/x = x1; x <= x2; x += 16) - for(var/y = y1; y <= y2; y += 16) - if(chunkGenerated(x, y, T.z)) - var/datum/visibility_chunk/chunk = getChunk(x, y, T.z) - if(choice == 0) - // Remove the viewpoint. - chunk.viewpoints -= c - else if(choice == 1) - // You can't have the same viewpoint in the list twice. - chunk.viewpoints |= c - chunk.hasChanged() - -// checks if the network can see a particular atom -/datum/visibility_network/proc/checkCanSee(var/atom/target) - var/turf/position = get_turf(target) - return checkTurfVis(position) - -/datum/visibility_network/proc/checkTurfVis(var/turf/position) - var/datum/visibility_chunk/chunk = getChunk(position.x, position.y, position.z) - if(chunk) - if(chunk.changed) - chunk.hasChanged(1) // Update now, no matter if it's visible or not. - if(chunk.visibleTurfs[position]) - return 1 - return 0 \ No newline at end of file diff --git a/code/defines/obj/weapon.dm b/code/defines/obj/weapon.dm index c5c01751482..a2bcbfdb59e 100644 --- a/code/defines/obj/weapon.dm +++ b/code/defines/obj/weapon.dm @@ -494,7 +494,7 @@ /obj/item/weapon/camera_bug/attack_self(mob/usr as mob) var/list/cameras = new/list() - for (var/obj/machinery/camera/C in cameranet.viewpoints) + for (var/obj/machinery/camera/C in cameranet.cameras) if (C.bugged && C.status) cameras.Add(C) if (length(cameras) == 0) diff --git a/code/game/area/Space Station 13 areas.dm b/code/game/area/Space Station 13 areas.dm index e703f7ba3b2..0ee9267ca01 100644 --- a/code/game/area/Space Station 13 areas.dm +++ b/code/game/area/Space Station 13 areas.dm @@ -22,6 +22,7 @@ NOTE: there are two lists of areas in the end of this file: centcom and station var/poweralm = 1 var/party = null var/radalert = 0 + var/report_alerts = 1 // Should atmos alerts notify the AI/computers level = null name = "Space" icon = 'icons/turf/areas.dmi' @@ -1983,6 +1984,11 @@ area/security/podbay //Traitor Station +/area/traitor + name = "\improper Syndicate Base" + icon_state = "syndie_hall" + report_alerts = 0 + /area/traitor/rnd name = "\improper Syndicate Research and Development" icon_state = "syndie_rnd" diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 70909088ce0..02924c8657d 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -52,25 +52,32 @@ InitializeLighting() -/area/proc/poweralert(var/state, var/obj/source as obj) +/area/proc/poweralert(var/state, var/obj/source as obj) if (state != poweralm) poweralm = state if(istype(source)) //Only report power alarms on the z-level where the source is located. var/list/cameras = list() for (var/area/RA in related) for (var/obj/machinery/camera/C in RA) + if(!report_alerts) + break cameras += C if(state == 1) + C.network.Remove("Power Alarms") else C.network.Add("Power Alarms") for (var/mob/living/silicon/aiPlayer in player_list) + if(!report_alerts) + break if(aiPlayer.z == source.z) if (state == 1) aiPlayer.cancelAlarm("Power", src, source) else aiPlayer.triggerAlarm("Power", src, cameras, source) for(var/obj/machinery/computer/station_alert/a in machines) + if(!report_alerts) + break if(a.z == source.z) if(state == 1) a.cancelAlarm("Power", src, source) @@ -107,11 +114,17 @@ for(var/area/RA in related) //updateicon() for(var/obj/machinery/camera/C in RA) + if(!report_alerts) + break cameras += C C.network.Add("Atmosphere Alarms") for(var/mob/living/silicon/aiPlayer in player_list) + if(!report_alerts) + break aiPlayer.triggerAlarm("Atmosphere", src, cameras, src) for(var/obj/machinery/computer/station_alert/a in machines) + if(!report_alerts) + break a.triggerAlarm("Atmosphere", src, cameras, src) air_doors_activated=1 CloseFirelocks() @@ -119,10 +132,16 @@ else if (atmosalm == 2) for(var/area/RA in related) for(var/obj/machinery/camera/C in RA) + if(!report_alerts) + break C.network.Remove("Atmosphere Alarms") for(var/mob/living/silicon/aiPlayer in player_list) + if(!report_alerts) + break aiPlayer.cancelAlarm("Atmosphere", src, src) for(var/obj/machinery/computer/station_alert/a in machines) + if(!report_alerts) + break a.cancelAlarm("Atmosphere", src, src) air_doors_activated=0 OpenFirelocks() @@ -162,11 +181,17 @@ var/list/cameras = list() for(var/area/RA in related) for (var/obj/machinery/camera/C in RA) + if(!report_alerts) + continue cameras.Add(C) C.network.Add("Fire Alarms") for (var/mob/living/silicon/ai/aiPlayer in player_list) + if(!report_alerts) + continue aiPlayer.triggerAlarm("Fire", src, cameras, src) for (var/obj/machinery/computer/station_alert/a in machines) + if(!report_alerts) + continue a.triggerAlarm("Fire", src, cameras, src) /area/proc/firereset() @@ -176,10 +201,16 @@ updateicon() for(var/area/RA in related) for (var/obj/machinery/camera/C in RA) + if(!report_alerts) + continue C.network.Remove("Fire Alarms") for (var/mob/living/silicon/ai/aiPlayer in player_list) + if(!report_alerts) + continue aiPlayer.cancelAlarm("Fire", src, src) for (var/obj/machinery/computer/station_alert/a in machines) + if(!report_alerts) + continue a.cancelAlarm("Fire", src, src) OpenFirelocks() diff --git a/code/game/gamemodes/cult/ritual.dm b/code/game/gamemodes/cult/ritual.dm index 02e20eb7a2f..0bcc4f1a603 100644 --- a/code/game/gamemodes/cult/ritual.dm +++ b/code/game/gamemodes/cult/ritual.dm @@ -72,13 +72,11 @@ var/engwords = list("travel", "blood", "join", "hell", "destroy", "technology", blood.override = 1 for(var/mob/living/silicon/ai/AI in player_list) AI.client.images += blood - cultNetwork.viewpoints+=src - cultNetwork.addViewpoint(src) + cult_viewpoints += src /obj/effect/rune/Del() ..() - cultNetwork.viewpoints-=src - cultNetwork.removeViewpoint(src) + cult_viewpoints -= src /obj/effect/rune/examine() set src in view(2) diff --git a/code/game/gamemodes/malfunction/Malf_Modules.dm b/code/game/gamemodes/malfunction/Malf_Modules.dm index 844669ff039..39c0c004a5c 100644 --- a/code/game/gamemodes/malfunction/Malf_Modules.dm +++ b/code/game/gamemodes/malfunction/Malf_Modules.dm @@ -313,7 +313,7 @@ rcd light flash thingy on matter drain power_type = /client/proc/reactivate_camera -/client/proc/reactivate_camera(obj/machinery/camera/C as obj in cameranet.viewpoints) +/client/proc/reactivate_camera(obj/machinery/camera/C as obj in cameranet.cameras) set name = "Reactivate Camera" set category = "Malfunction" if (istype (C, /obj/machinery/camera)) @@ -337,7 +337,7 @@ rcd light flash thingy on matter drain power_type = /client/proc/upgrade_camera -/client/proc/upgrade_camera(obj/machinery/camera/C as obj in cameranet.viewpoints) +/client/proc/upgrade_camera(obj/machinery/camera/C as obj in cameranet.cameras) set name = "Upgrade Camera" set category = "Malfunction" if(istype(C)) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 1424886eae7..ea1107ad722 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -458,6 +458,7 @@ alert_signal.transmission_method = 1 alert_signal.data["zone"] = alarm_area.name alert_signal.data["type"] = "Atmospheric" + alert_signal.data["hidden"] = hidden if(alert_level==2) alert_signal.data["alert"] = "severe" diff --git a/code/game/machinery/bots/bots.dm b/code/game/machinery/bots/bots.dm index 539dd775b0f..30ed21fbede 100644 --- a/code/game/machinery/bots/bots.dm +++ b/code/game/machinery/bots/bots.dm @@ -583,7 +583,7 @@ obj/machinery/bot/proc/start_patrol() new_destination = "__nearest__" post_signal(beacon_freq, "findbeacon", "patrol") awaiting_beacon = 1 - spawn(150) + spawn(200) awaiting_beacon = 0 if(nearest_beacon) set_destination(nearest_beacon) diff --git a/code/game/machinery/camera/camera.dm b/code/game/machinery/camera/camera.dm index 977c1bd3d3e..9c7085c581d 100644 --- a/code/game/machinery/camera/camera.dm +++ b/code/game/machinery/camera/camera.dm @@ -8,17 +8,20 @@ active_power_usage = 10 layer = 5 - var/datum/wires/camera/wires = null // Wires datum var/list/network = list("SS13") var/c_tag = null var/c_tag_order = 999 - var/status = 1.0 + var/status = 1 anchored = 1.0 - var/invuln = null + panel_open = 0 // 0 = Closed / 1 = Open + var/indestructible = 0 var/bugged = 0 var/obj/item/weapon/camera_assembly/assembly = null - var/watcherslist = list() - var/obj/item/device/camera_bug/hasbug = null + + var/toughness = 5 //sorta fragile + + // WIRES + var/datum/wires/camera/wires = null // Wires datum //OTHER @@ -28,15 +31,18 @@ var/light_disabled = 0 var/alarm_on = 0 var/busy = 0 - var/indestructible = 0 // If set, prevents aliens from destroying it + + var/obj/item/device/camera_bug/hasbug = null /obj/machinery/camera/New() wires = new(src) - assembly = new(src) assembly.state = 4 + + invalidateCameraCache() + /* // Use this to look for cameras that have the same c_tag. - for(var/obj/machinery/camera/C in cameranet.viewpoints) + for(var/obj/machinery/camera/C in cameranet.cameras) var/list/tempnetwork = C.network&src.network if(C != src && C.c_tag == src.c_tag && tempnetwork.len) world.log << "[src.c_tag] [src.x] [src.y] [src.z] conflicts with [C.c_tag] [C.x] [C.y] [C.z]" @@ -50,51 +56,48 @@ ASSERT(src.network.len > 0) ..() +/obj/machinery/camera/Del() + if(!alarm_on) + triggerCameraAlarm() + + cancelCameraAlarm() + ..() + /obj/machinery/camera/emp_act(severity) if(!isEmpProof()) if(prob(100/severity)) - icon_state = "[initial(icon_state)]emp" - var/list/previous_network = network - network = list() - cameranet.removeCamera(src) + invalidateCameraCache() stat |= EMPED SetLuminosity(0) + kick_viewers() triggerCameraAlarm() + update_icon() + spawn(900) - network = previous_network - icon_state = initial(icon_state) stat &= ~EMPED cancelCameraAlarm() - if(can_use()) - cameranet.addCamera(src) - for(var/mob/O in mob_list) - if(O.client && O.client.eye == src) - O.unset_machine() - O.reset_view(null) - O << "The screen bursts into static." + update_icon() + invalidateCameraCache() ..() +/obj/machinery/camera/bullet_act(var/obj/item/projectile/P) + if(P.damage_type == BRUTE || P.damage_type == BURN) + take_damage(P.damage) /obj/machinery/camera/ex_act(severity) - if(src.invuln) + if(indestructible) return - else - ..(severity) - return + + //camera dies if an explosion touches it! + if(severity <= 2 || prob(50)) + destroy() + + ..() //and give it the regular chance of being deleted outright + /obj/machinery/camera/blob_act() - del(src) return - -/obj/machinery/camera/proc/setViewRange(var/num = 7) - src.view_range = num - cameranet.updateVisibility(src, 0) - -/obj/machinery/camera/proc/shock(var/mob/living/user) - if(!istype(user)) - return - user.electrocute_act(10, src) - + /obj/machinery/camera/attack_paw(mob/living/carbon/alien/humanoid/user as mob) if(!istype(user)) return @@ -107,10 +110,22 @@ add_hiddenprint(user) deactivate(user,0) -/obj/machinery/camera/attackby(W as obj, mob/living/user as mob) +/obj/machinery/camera/hitby(AM as mob|obj) + ..() + if (istype(AM, /obj)) + var/obj/O = AM + if (O.throwforce >= src.toughness) + visible_message("[src] was hit by [O].") + take_damage(O.throwforce) +/obj/machinery/camera/proc/setViewRange(var/num = 7) + src.view_range = num + cameranet.updateVisibility(src, 0) + +/obj/machinery/camera/attackby(obj/W as obj, mob/living/user as mob) + invalidateCameraCache() // DECONSTRUCTION - if(istype(W, /obj/item/weapon/screwdriver)) + if(isscrewdriver(W)) //user << "You start to [panel_open ? "close" : "open"] the camera's panel." //if(toggle_panel(user)) // No delay because no one likes screwdrivers trying to be hip and have a duration cooldown panel_open = !panel_open @@ -118,19 +133,21 @@ "You screw the camera's panel [panel_open ? "open" : "closed"].") playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1) - else if((istype(W, /obj/item/weapon/wirecutters) || istype(W, /obj/item/device/multitool)) && panel_open) - wires.Interact(user) + else if((iswirecutter(W) || ismultitool(W)) && panel_open) + interact(user) - else if(istype(W, /obj/item/weapon/weldingtool) && wires.CanDeconstruct()) + else if(iswelder(W) && (wires.CanDeconstruct() || (stat & BROKEN))) if(weld(W, user)) - if(assembly) + if (stat & BROKEN) + new /obj/item/stack/cable_coil(src.loc, length=2) + else if(assembly) assembly.loc = src.loc assembly.state = 1 + new /obj/item/stack/cable_coil(src.loc, length=2) del(src) - // OTHER - else if ((istype(W, /obj/item/weapon/paper) || istype(W, /obj/item/device/pda)) && isliving(user)) + else if (can_use() && (istype(W, /obj/item/weapon/paper) || istype(W, /obj/item/device/pda)) && isliving(user)) var/mob/living/U = user var/obj/item/weapon/paper/X = null var/obj/item/device/pda/P = null @@ -152,11 +169,12 @@ else O << "[U] holds \a [itemname] up to one of your cameras ..." O << browse(text("
Name | Status | Location | Control |
| [Bot.hacked ? "(!) [Bot.name]" : Bot.name] ([Bot.bot_type_name]) | " //If the bot is on, it will display the bot's current mode status. If the bot is not mode, it will just report "Idle". "Inactive if it is not on at all. @@ -631,8 +630,6 @@ var/list/ai_list = list() /mob/living/silicon/ai/proc/switchCamera(var/obj/machinery/camera/C) - src.cameraFollow = null - if (!C || stat == 2) //C.can_use()) return 0 @@ -706,7 +703,6 @@ var/list/ai_list = list() set category = "AI Commands" set name = "Jump To Network" unset_machine() - src.cameraFollow = null var/cameralist[0] if(usr.stat == 2) @@ -715,11 +711,11 @@ var/list/ai_list = list() var/mob/living/silicon/ai/U = usr - for (var/obj/machinery/camera/C in cameranet.viewpoints) + for (var/obj/machinery/camera/C in cameranet.cameras) if(!C.can_use()) continue - var/list/tempnetwork = difflist(C.network,RESTRICTED_CAMERA_NETWORKS,1) + var/list/tempnetwork = difflist(C.network,restricted_camera_networks,1) if(tempnetwork.len) for(var/i in tempnetwork) cameralist[i] = i @@ -733,7 +729,7 @@ var/list/ai_list = list() if(isnull(network)) network = old_network // If nothing is selected else - for(var/obj/machinery/camera/C in cameranet.viewpoints) + for(var/obj/machinery/camera/C in cameranet.cameras) if(!C.can_use()) continue if(network in C.network) @@ -912,3 +908,52 @@ var/list/ai_list = list() src << "Accessing Subspace Transceiver control..." if (src.aiRadio) src.aiRadio.interact(src) + + +/mob/living/silicon/ai/proc/open_nearest_door(mob/living/target as mob) + if(!istype(target)) return + spawn(0) + if(istype(target, /mob/living/carbon/human)) + var/mob/living/carbon/human/H = target + if(H.wear_id && istype(H.wear_id.GetID(), /obj/item/weapon/card/id/syndicate)) + src << "Unable to locate an airlock" + return + if(H.wear_id && istype(H.wear_id.GetID(), /obj/item/weapon/card/id/syndicate)) + src << "Unable to locate an airlock" + return + if(istype(H.head, /obj/item/clothing/head/helmet/space/space_ninja) && !H.head.canremove) + src << "Unable to locate an airlock" + return + if(H.digitalcamo) + src << "Unable to locate an airlock" + return + if (!near_camera(target)) + src << "Target is not near any active cameras." + return + var/obj/machinery/door/airlock/tobeopened + var/dist = -1 + for(var/obj/machinery/door/airlock/D in range(3,target)) + if(!D.density) continue + if(dist < 0) + dist = get_dist(D, target) + //world << dist + tobeopened = D + else + if(dist > get_dist(D, target)) + dist = get_dist(D, target) + //world << dist + tobeopened = D + //world << "found [tobeopened.name] closer" + else + //world << "[D.name] not close enough | [get_dist(D, target)] | [dist]" + if(tobeopened) + switch(alert(src, "Do you want to open \the [tobeopened] for [target]?","Doorknob_v2a.exe","Yes","No")) + if("Yes") + var/nhref = "src=\ref[tobeopened];aiEnable=7" + tobeopened.Topic(nhref, params2list(nhref), tobeopened, 1) + src << "\blue You've opened \the [tobeopened] for [target]." + if("No") + src << "\red You deny the request." + else + src << "\red You've failed to open an airlock for [target]" + return \ No newline at end of file diff --git a/code/modules/mob/living/silicon/ai/freelook/cameranet.dm b/code/modules/mob/living/silicon/ai/freelook/cameranet.dm index b0caf3b4a69..584af962874 100644 --- a/code/modules/mob/living/silicon/ai/freelook/cameranet.dm +++ b/code/modules/mob/living/silicon/ai/freelook/cameranet.dm @@ -1,25 +1,156 @@ -/datum/visibility_network/cameras - ChunkType = /datum/visibility_chunk/camera +// CAMERA NET +// +// The datum containing all the chunks. -/datum/visibility_network/cameras/getViewpointFromMob(var/mob/currentMob) - var/mob/living/silicon/robot/currentRobot=currentMob - if(currentRobot) - return currentRobot.camera - return FALSE +var/datum/cameranet/cameranet = new() -/datum/visibility_network/cameras/validViewpoint(var/viewpoint) - var/obj/machinery/camera/c = viewpoint - if (!c) - return FALSE - return c.can_use() +/datum/cameranet + // The cameras on the map, no matter if they work or not. Updated in obj/machinery/camera.dm by New() and Del(). + var/list/cameras = list() + var/cameras_unsorted = 1 + // The chunks of the map, mapping the areas that the cameras can see. + var/list/chunks = list() + var/ready = 0 +/datum/cameranet/proc/process_sort() + if(cameras_unsorted) + cameras = dd_sortedObjectList(cameras) + cameras_unsorted = 0 -// adding some indirection so that I don't have to edit a ton of files -/datum/visibility_network/cameras/proc/addCamera(var/camera) - return addViewpoint(camera) +// Checks if a chunk has been Generated in x, y, z. +/datum/cameranet/proc/chunkGenerated(x, y, z) + x &= ~0xf + y &= ~0xf + var/key = "[x],[y],[z]" + return (chunks[key]) -/datum/visibility_network/cameras/proc/removeCamera(var/camera) - return removeViewpoint(camera) +// Returns the chunk in the x, y, z. +// If there is no chunk, it creates a new chunk and returns that. +/datum/cameranet/proc/getCameraChunk(x, y, z) + x &= ~0xf + y &= ~0xf + var/key = "[x],[y],[z]" + if(!chunks[key]) + chunks[key] = new /datum/camerachunk(null, x, y, z) -/datum/visibility_network/cameras/proc/checkCameraVis(var/atom/target) - return checkCanSee(target) + return chunks[key] + +// Updates what the aiEye can see. It is recommended you use this when the aiEye moves or it's location is set. + +/datum/cameranet/proc/visibility(mob/aiEye/ai) + // 0xf = 15 + var/x1 = max(0, ai.x - 16) & ~0xf + var/y1 = max(0, ai.y - 16) & ~0xf + var/x2 = min(world.maxx, ai.x + 16) & ~0xf + var/y2 = min(world.maxy, ai.y + 16) & ~0xf + + var/list/visibleChunks = list() + + for(var/x = x1; x <= x2; x += 16) + for(var/y = y1; y <= y2; y += 16) + visibleChunks += getCameraChunk(x, y, ai.z) + + var/list/remove = ai.visibleCameraChunks - visibleChunks + var/list/add = visibleChunks - ai.visibleCameraChunks + + for(var/chunk in remove) + var/datum/camerachunk/c = chunk + c.remove(ai) + + for(var/chunk in add) + var/datum/camerachunk/c = chunk + c.add(ai) + +// Updates the chunks that the turf is located in. Use this when obstacles are destroyed or when doors open. + +/datum/cameranet/proc/updateVisibility(atom/A, var/opacity_check = 1) + + if(!ticker || (opacity_check && !A.opacity)) + return + majorChunkChange(A, 2) + +/datum/cameranet/proc/updateChunk(x, y, z) + // 0xf = 15 + if(!chunkGenerated(x, y, z)) + return + var/datum/camerachunk/chunk = getCameraChunk(x, y, z) + chunk.hasChanged() + +// Removes a camera from a chunk. + +/datum/cameranet/proc/removeCamera(obj/machinery/camera/c) + if(c.can_use()) + majorChunkChange(c, 0) + +// Add a camera to a chunk. + +/datum/cameranet/proc/addCamera(obj/machinery/camera/c) + if(c.can_use()) + majorChunkChange(c, 1) + +// Used for Cyborg cameras. Since portable cameras can be in ANY chunk. + +/datum/cameranet/proc/updatePortableCamera(obj/machinery/camera/c) + if(c.can_use()) + majorChunkChange(c, 1) + //else + // majorChunkChange(c, 0) + +// Never access this proc directly!!!! +// This will update the chunk and all the surrounding chunks. +// It will also add the atom to the cameras list if you set the choice to 1. +// Setting the choice to 0 will remove the camera from the chunks. +// If you want to update the chunks around an object, without adding/removing a camera, use choice 2. + +/datum/cameranet/proc/majorChunkChange(atom/c, var/choice) + // 0xf = 15 + if(!c) + return + + var/turf/T = get_turf(c) + if(T) + var/x1 = max(0, T.x - 8) & ~0xf + var/y1 = max(0, T.y - 8) & ~0xf + var/x2 = min(world.maxx, T.x + 8) & ~0xf + var/y2 = min(world.maxy, T.y + 8) & ~0xf + + //world << "X1: [x1] - Y1: [y1] - X2: [x2] - Y2: [y2]" + + for(var/x = x1; x <= x2; x += 16) + for(var/y = y1; y <= y2; y += 16) + if(chunkGenerated(x, y, T.z)) + var/datum/camerachunk/chunk = getCameraChunk(x, y, T.z) + if(choice == 0) + // Remove the camera. + chunk.cameras -= c + else if(choice == 1) + // You can't have the same camera in the list twice. + chunk.cameras |= c + chunk.hasChanged() + +// Will check if a mob is on a viewable turf. Returns 1 if it is, otherwise returns 0. + +/datum/cameranet/proc/checkCameraVis(mob/living/target as mob) + + // 0xf = 15 + var/turf/position = get_turf(target) + return checkTurfVis(position) + +/datum/cameranet/proc/checkTurfVis(var/turf/position) + var/datum/camerachunk/chunk = getCameraChunk(position.x, position.y, position.z) + if(chunk) + if(chunk.changed) + chunk.hasChanged(1) // Update now, no matter if it's visible or not. + if(chunk.visibleTurfs[position]) + return 1 + return 0 + +// Debug verb for VVing the chunk that the turf is in. +/* +/turf/verb/view_chunk() + set src in world + + if(cameranet.chunkGenerated(x, y, z)) + var/datum/camerachunk/chunk = cameranet.getCameraChunk(x, y, z) + usr.client.debug_variables(chunk) +*/ \ No newline at end of file diff --git a/code/modules/mob/living/silicon/ai/freelook/chunk.dm b/code/modules/mob/living/silicon/ai/freelook/chunk.dm index ba4e7892f57..fda4ef2f78e 100644 --- a/code/modules/mob/living/silicon/ai/freelook/chunk.dm +++ b/code/modules/mob/living/silicon/ai/freelook/chunk.dm @@ -1,23 +1,168 @@ -/datum/visibility_chunk/camera +#define UPDATE_BUFFER 25 // 2.5 seconds -/datum/visibility_chunk/camera/validViewpoint(var/viewpoint) - var/obj/machinery/camera/c = viewpoint - if(!c) - return FALSE - if(!c.can_use()) - return FALSE - var/turf/point = locate(src.x + 8, src.y + 8, src.z) - if(get_dist(point, c) > 24) - return FALSE - return TRUE +// CAMERA CHUNK +// +// A 16x16 grid of the map with a list of turfs that can be seen, are visible and are dimmed. +// Allows the AI Eye to stream these chunks and know what it can and cannot see. +/datum/camerachunk + var/list/obscuredTurfs = list() + var/list/visibleTurfs = list() + var/list/obscured = list() + var/list/cameras = list() + var/list/turfs = list() + var/list/seenby = list() + var/visible = 0 + var/changed = 0 + var/updating = 0 + var/x = 0 + var/y = 0 + var/z = 0 -/datum/visibility_chunk/camera/getVisibleTurfsForViewpoint(var/viewpoint) - var/obj/machinery/camera/c = viewpoint - return c.can_see() +// Add an AI eye to the chunk, then update if changed. +/datum/camerachunk/proc/add(mob/aiEye/ai) + if(!ai.ai) + return + ai.visibleCameraChunks += src + if(ai.ai.client) + ai.ai.client.images += obscured + visible++ + seenby += ai + if(changed && !updating) + update() + +// Remove an AI eye from the chunk, then update if changed. + +/datum/camerachunk/proc/remove(mob/aiEye/ai) + if(!ai.ai) + return + ai.visibleCameraChunks -= src + if(ai.ai.client) + ai.ai.client.images -= obscured + seenby -= ai + if(visible > 0) + visible-- + +// Called when a chunk has changed. I.E: A wall was deleted. + +/datum/camerachunk/proc/visibilityChanged(turf/loc) + if(!visibleTurfs[loc]) + return + hasChanged() + +// Updates the chunk, makes sure that it doesn't update too much. If the chunk isn't being watched it will +// instead be flagged to update the next time an AI Eye moves near it. + +/datum/camerachunk/proc/hasChanged(var/update_now = 0) + if(visible || update_now) + if(!updating) + updating = 1 + spawn(UPDATE_BUFFER) // Batch large changes, such as many doors opening or closing at once + update() + updating = 0 + else + changed = 1 + +// The actual updating. It gathers the visible turfs from cameras and puts them into the appropiate lists. + +/datum/camerachunk/proc/update() + + set background = 1 + + var/list/newVisibleTurfs = list() + + for(var/camera in cameras) + var/obj/machinery/camera/c = camera + + if(!c) + continue + + if(!c.can_use()) + continue + + var/turf/point = locate(src.x + 8, src.y + 8, src.z) + if(get_dist(point, c) > 24) + continue + + for(var/turf/t in c.can_see()) + newVisibleTurfs[t] = t + + // Removes turf that isn't in turfs. + newVisibleTurfs &= turfs + + var/list/visAdded = newVisibleTurfs - visibleTurfs + var/list/visRemoved = visibleTurfs - newVisibleTurfs + + visibleTurfs = newVisibleTurfs + obscuredTurfs = turfs - newVisibleTurfs + + for(var/turf in visAdded) + var/turf/t = turf + if(t.obscured) + obscured -= t.obscured + for(var/eye in seenby) + var/mob/aiEye/m = eye + if(!m || !m.ai) + continue + if(m.ai.client) + m.ai.client.images -= t.obscured + + for(var/turf in visRemoved) + var/turf/t = turf + if(obscuredTurfs[t]) + if(!t.obscured) + t.obscured = image('icons/effects/cameravis.dmi', t, "black", 15) + + obscured += t.obscured + for(var/eye in seenby) + var/mob/aiEye/m = eye + if(!m || !m.ai) + seenby -= m + continue + if(m.ai.client) + m.ai.client.images += t.obscured + +// Create a new camera chunk, since the chunks are made as they are needed. + +/datum/camerachunk/New(loc, x, y, z) + + // 0xf = 15 + x &= ~0xf + y &= ~0xf + + src.x = x + src.y = y + src.z = z -/datum/visibility_chunk/camera/findNearbyViewpoints() for(var/obj/machinery/camera/c in range(16, locate(x + 8, y + 8, z))) if(c.can_use()) - viewpoints += c + cameras += c + + for(var/turf/t in range(10, locate(x + 8, y + 8, z))) + if(t.x >= x && t.y >= y && t.x < x + 16 && t.y < y + 16) + turfs[t] = t + + for(var/camera in cameras) + var/obj/machinery/camera/c = camera + if(!c) + continue + + if(!c.can_use()) + continue + + for(var/turf/t in c.can_see()) + visibleTurfs[t] = t + + // Removes turf that isn't in turfs. + visibleTurfs &= turfs + + obscuredTurfs = turfs - visibleTurfs + + for(var/turf in obscuredTurfs) + var/turf/t = turf + if(!t.obscured) + t.obscured = image('icons/effects/cameravis.dmi', t, "black", 15) + obscured += t.obscured + +#undef UPDATE_BUFFER \ No newline at end of file diff --git a/code/modules/mob/living/silicon/ai/freelook/eye.dm b/code/modules/mob/living/silicon/ai/freelook/eye.dm index c2c23b02188..8218bec993e 100644 --- a/code/modules/mob/living/silicon/ai/freelook/eye.dm +++ b/code/modules/mob/living/silicon/ai/freelook/eye.dm @@ -1,13 +1,12 @@ // AI EYE // -// A mob that the AI controls to look around the station with. +// An invisible (no icon) mob that the AI controls to look around the station with. // It streams chunks as it moves around, which will show it what the AI can and cannot see. /mob/aiEye name = "Inactive AI Eye" - icon = 'icons/mob/AI.dmi' - icon_state = "eye" - alpha = 127 + icon = 'icons/obj/status_display.dmi' // For AI friend secret shh :o + var/list/visibleCameraChunks = list() var/mob/living/silicon/ai/ai = null density = 0 status_flags = GODMODE // You can't damage it. @@ -15,20 +14,16 @@ see_in_dark = 7 invisibility = INVISIBILITY_AI_EYE -/mob/aiEye/New() - ..() - visibility_interface = new /datum/visibility_interface/ai_eye(src) - // Movement code. Returns 0 to stop air movement from moving it. /mob/aiEye/Move() return 0 // Hide popout menu verbs -/mob/aiEye/examine() +/mob/aiEye/examine(atom/A as mob|obj|turf in view()) set popup_menu = 0 set src = usr.contents return 0 - + /mob/aiEye/pull() set popup_menu = 0 set src = usr.contents @@ -41,11 +36,15 @@ // Use this when setting the aiEye's location. // It will also stream the chunk that the new loc is in. +/mob/aiEye/setLoc(var/T, var/cancel_tracking = 1) -/mob/aiEye/setLoc(var/T) if(ai) if(!isturf(ai.loc)) return + + if(cancel_tracking) + ai.ai_cancel_tracking() + T = get_turf(T) loc = T cameranet.visibility(src) @@ -55,9 +54,12 @@ if(ai.holo) ai.holo.move_hologram() +/mob/aiEye/proc/getLoc() -/mob/aiEye/Move() - return 0 + if(ai) + if(!isturf(ai.loc) || !ai.client) + return + return ai.eyeobj.loc // AI MOVEMENT @@ -70,7 +72,6 @@ var/acceleration = 1 var/obj/machinery/hologram/holopad/holo = null - // Intiliaze the eye by assigning it's "ai" variable to us. Then set it's loc to us. /mob/living/silicon/ai/New() ..() @@ -79,7 +80,7 @@ spawn(5) eyeobj.loc = src.loc -/mob/living/silicon/ai/Destroy() +/mob/living/silicon/ai/Del() eyeobj.ai = null del(eyeobj) // No AI, no Eye ..() @@ -88,9 +89,7 @@ if(istype(usr, /mob/living/silicon/ai)) var/mob/living/silicon/ai/AI = usr if(AI.eyeobj && AI.client.eye == AI.eyeobj) - AI.cameraFollow = null - if (isturf(src.loc) || isturf(src)) - AI.eyeobj.setLoc(src) + AI.eyeobj.setLoc(src) // This will move the AIEye. It will also cause lights near the eye to light up, if toggled. // This is handled in the proc below this one. @@ -114,23 +113,24 @@ else user.sprint = initial - user.cameraFollow = null - //user.unset_machine() //Uncomment this if it causes problems. //user.lightNearbyCamera() // Return to the Core. -/mob/living/silicon/ai/proc/view_core() +/mob/living/silicon/ai/proc/core() + set category = "AI Commands" + set name = "AI Core" + + view_core() + + +/mob/living/silicon/ai/proc/view_core() current = null - cameraFollow = null unset_machine() - if(src.eyeobj && src.loc) - src.eyeobj.z = src.z - src.eyeobj.loc = src.loc - else + if(!src.eyeobj) src << "ERROR: Eyeobj not found. Creating new eye..." src.eyeobj = new(src.loc) src.eyeobj.ai = src @@ -138,11 +138,11 @@ if(client && client.eye) client.eye = src - - for(var/datum/visibility_chunk/camera/c in eyeobj.visibility_interface.visible_chunks) + for(var/datum/camerachunk/c in eyeobj.visibleCameraChunks) c.remove(eyeobj) + src.eyeobj.setLoc(src) -/mob/living/silicon/ai/verb/toggle_acceleration() +/mob/living/silicon/ai/proc/toggle_acceleration() set category = "AI Commands" set name = "Toggle Camera Acceleration" diff --git a/code/modules/mob/living/silicon/ai/freelook/read_me.dm b/code/modules/mob/living/silicon/ai/freelook/read_me.dm index e71b0903b85..53e68ff1377 100644 --- a/code/modules/mob/living/silicon/ai/freelook/read_me.dm +++ b/code/modules/mob/living/silicon/ai/freelook/read_me.dm @@ -20,7 +20,7 @@ HOW IT WORKS It works by first creating a camera network datum. Inside of this camera network are "chunks" (which will be - explained later) and "cameras". The cameras list is kept up to date by obj/machinery/camera/New() and Destroy(). + explained later) and "cameras". The cameras list is kept up to date by obj/machinery/camera/New() and Del(). Next the camera network has chunks. These chunks are a 16x16 tile block of turfs and cameras contained inside the chunk. These turfs are then sorted out based on what the cameras can and cannot see. If none of the cameras can see the turf, inside @@ -43,7 +43,7 @@ WHERE IS EVERYTHING? - cameraNetwork.dm = Everything about the cameraNetwork datum. + cameranet.dm = Everything about the cameranet datum. chunk.dm = Everything about the chunk datum. eye.dm = Everything about the AI and the AIEye. updating.dm = Everything about triggers that will update chunks. diff --git a/code/modules/mob/living/silicon/ai/freelook/update_triggers.dm b/code/modules/mob/living/silicon/ai/freelook/update_triggers.dm index 775d8864751..9458a768633 100644 --- a/code/modules/mob/living/silicon/ai/freelook/update_triggers.dm +++ b/code/modules/mob/living/silicon/ai/freelook/update_triggers.dm @@ -1,3 +1,80 @@ +#define BORG_CAMERA_BUFFER 30 + +//UPDATE TRIGGERS, when the chunk (and the surrounding chunks) should update. + +// TURFS + +/turf + var/image/obscured + +/turf/proc/visibilityChanged() + if(ticker) + cameranet.updateVisibility(src) + +/turf/simulated/Del() + visibilityChanged() + ..() + +/turf/simulated/New() + ..() + visibilityChanged() + + + +// STRUCTURES + +/obj/structure/Del() + if(ticker) + cameranet.updateVisibility(src) + ..() + +/obj/structure/New() + ..() + if(ticker) + cameranet.updateVisibility(src) + +// EFFECTS + +/obj/effect/Del() + if(ticker) + cameranet.updateVisibility(src) + ..() + +/obj/effect/New() + ..() + if(ticker) + cameranet.updateVisibility(src) + + +// DOORS + +// Simply updates the visibility of the area when it opens/closes/destroyed. +/obj/machinery/door/update_nearby_tiles(need_rebuild) + . = ..(need_rebuild) + // Glass door glass = 1 + // don't check then? + if(!glass && cameranet) + cameranet.updateVisibility(src, 0) + + +// ROBOT MOVEMENT + +// Update the portable camera everytime the Robot moves. +// This might be laggy, comment it out if there are problems. +/mob/living/silicon/robot/var/updating = 0 + +/mob/living/silicon/robot/Move() + var/oldLoc = src.loc + . = ..() + if(.) + if(src.camera && src.camera.network.len) + if(!updating) + updating = 1 + spawn(BORG_CAMERA_BUFFER) + if(oldLoc != src.loc) + cameranet.updatePortableCamera(src.camera) + updating = 0 + // CAMERA // An addition to deactivate which removes/adds the camera from the chunk list based on if it works or not. @@ -5,23 +82,29 @@ /obj/machinery/camera/deactivate(user as mob, var/choice = 1) ..(user, choice) if(src.can_use()) - cameranet.addViewpoint(src) + cameranet.addCamera(src) else src.SetLuminosity(0) - cameranet.removeViewpoint(src) + cameranet.removeCamera(src) /obj/machinery/camera/New() ..() - cameranet.viewpoints += src //Camera must be added to global list of all cameras no matter what... - var/list/open_networks = difflist(network,RESTRICTED_CAMERA_NETWORKS) //...but if all of camera's networks are restricted, it only works for specific camera consoles. + //Camera must be added to global list of all cameras no matter what... + if(cameranet.cameras_unsorted || !ticker) + cameranet.cameras += src + cameranet.cameras_unsorted = 1 + else + dd_insertObjectList(cameranet.cameras, src) + + var/list/open_networks = difflist(network,restricted_camera_networks) //...but if all of camera's networks are restricted, it only works for specific camera consoles. if(open_networks.len) //If there is at least one open network, chunk is available for AI usage. - cameranet.addViewpoint(src) + cameranet.addCamera(src) /obj/machinery/camera/Del() - cameranet.viewpoints -= src - var/list/open_networks = difflist(network,RESTRICTED_CAMERA_NETWORKS) + cameranet.cameras -= src + var/list/open_networks = difflist(network,restricted_camera_networks) if(open_networks.len) - cameranet.removeViewpoint(src) + cameranet.removeCamera(src) ..() #undef BORG_CAMERA_BUFFER \ No newline at end of file diff --git a/code/modules/mob/living/silicon/ai/freelook/visibility_interface.dm b/code/modules/mob/living/silicon/ai/freelook/visibility_interface.dm deleted file mode 100644 index b55598c6090..00000000000 --- a/code/modules/mob/living/silicon/ai/freelook/visibility_interface.dm +++ /dev/null @@ -1,10 +0,0 @@ -/datum/visibility_interface/ai_eye - chunk_type = /datum/visibility_chunk/camera - -/datum/visibility_interface/ai_eye/getClient() - var/mob/aiEye/eye = controller - if (!eye) - return FALSE - if (!eye.ai) - return FALSE - return eye.ai.client diff --git a/code/modules/mob/living/silicon/ai/laws.dm b/code/modules/mob/living/silicon/ai/laws.dm index ab6b19e6190..9d30afc6e4d 100755 --- a/code/modules/mob/living/silicon/ai/laws.dm +++ b/code/modules/mob/living/silicon/ai/laws.dm @@ -23,6 +23,10 @@ /mob/living/silicon/ai/proc/set_zeroth_law(var/law, var/law_borg) src.laws_sanity_check() src.laws.set_zeroth_law(law, law_borg) + +/mob/living/silicon/ai/proc/clear_zeroth_law(var/law_borg) + src.laws_sanity_check() + src.laws.clear_zeroth_law(law_borg) /mob/living/silicon/ai/proc/add_inherent_law(var/law) src.laws_sanity_check() diff --git a/code/modules/mob/living/silicon/robot/laws.dm b/code/modules/mob/living/silicon/robot/laws.dm index 84377b6adb4..38267256f4b 100644 --- a/code/modules/mob/living/silicon/robot/laws.dm +++ b/code/modules/mob/living/silicon/robot/laws.dm @@ -77,6 +77,10 @@ laws_sanity_check() laws.set_zeroth_law(law) +/mob/living/silicon/robot/proc/clear_zeroth_law() + laws_sanity_check() + laws.clear_zeroth_law() + /mob/living/silicon/robot/proc/add_inherent_law(var/law) laws_sanity_check() laws.add_inherent_law(law) diff --git a/code/modules/mob/mob_helpers.dm b/code/modules/mob/mob_helpers.dm index 0432e4baef6..b652a106824 100644 --- a/code/modules/mob/mob_helpers.dm +++ b/code/modules/mob/mob_helpers.dm @@ -161,6 +161,14 @@ proc/hasorgans(A) /proc/hsl2rgb(h, s, l) return + +proc/hassensorlevel(A, var/level) + var/mob/living/carbon/human/H = A + if(istype(H) && istype(H.w_uniform, /obj/item/clothing/under)) + var/obj/item/clothing/under/U = H.w_uniform + return U.sensor_mode >= level + return 0 + /proc/check_zone(zone) diff --git a/code/modules/mob/spirit/cultnet.dm b/code/modules/mob/spirit/cultnet.dm index df0cd57ff5d..c3f37f8fdd1 100644 --- a/code/modules/mob/spirit/cultnet.dm +++ b/code/modules/mob/spirit/cultnet.dm @@ -19,54 +19,6 @@ It reuses a lot of code from the AIEye cameraNetwork. In order to work properly, if (vp) return TRUE return FALSE - - -/datum/visibility_chunk/cult/validViewpoint(var/atom/viewpoint) - var/turf/point = locate(src.x + 8, src.y + 8, src.z) - if(get_dist(point, viewpoint) > 24) - return FALSE - - if (isCultRune(viewpoint) || isCultViewpoint(viewpoint)) - return viewpoint:can_use() - return FALSE - - -/datum/visibility_chunk/cult/getVisibleTurfsForViewpoint(var/viewpoint) - var/obj/effect/rune/rune = viewpoint - if (rune) - return rune.can_see() - var/obj/cult_viewpoint/cvp = viewpoint - if (cvp) - return cvp.can_see() - return null - - -/datum/visibility_chunk/cult/findNearbyViewpoints() - for(var/obj/cult_viewpoint/vp in range(16, locate(x + 8, y + 8, z))) - if(vp.can_use()) - viewpoints += vp - for(var/obj/effect/rune/rune in range(16, locate(x + 8, y + 8, z))) - viewpoints += rune - - -/datum/visibility_network/cult - ChunkType = /datum/visibility_chunk/cult - - -/datum/visibility_network/cult/validViewpoint(var/viewpoint) - if (isCultRune(viewpoint) || isCultViewpoint(viewpoint)) - return viewpoint:can_use() - return FALSE - -/datum/visibility_network/cult/getViewpointFromMob(var/mob/currentMob) - for(var/obj/cult_viewpoint/currentView in currentMob) - return currentView - return FALSE - - -/datum/visibility_interface/cult - chunk_type = /datum/visibility_chunk/cult - /* RUNE JUNK diff --git a/code/modules/mob/spirit/movement.dm b/code/modules/mob/spirit/movement.dm index bd794b6fd2b..b5ac53fbeae 100644 --- a/code/modules/mob/spirit/movement.dm +++ b/code/modules/mob/spirit/movement.dm @@ -52,7 +52,6 @@ mob/spirit/proc/Spirit_Move(direct) mob/spirit/setLoc(var/T) T = get_turf(T) loc = T - cultNetwork.visibility(src) mob/spirit/verb/toggle_acceleration() set category = "Spirit" diff --git a/code/modules/mob/spirit/spirit.dm b/code/modules/mob/spirit/spirit.dm index ce7080b744c..c90f0f569b7 100644 --- a/code/modules/mob/spirit/spirit.dm +++ b/code/modules/mob/spirit/spirit.dm @@ -38,9 +38,6 @@ mob/spirit/New() loc = pick(latejoin) - // hook them to the cult visibility network - visibility_interface = new /datum/visibility_interface/cult(src) - // no nameless spirits if (!name) name = "Boogyman" diff --git a/code/modules/mob/spirit/viewpoint.dm b/code/modules/mob/spirit/viewpoint.dm index b4bd911ea1c..0cd54451361 100644 --- a/code/modules/mob/spirit/viewpoint.dm +++ b/code/modules/mob/spirit/viewpoint.dm @@ -18,9 +18,6 @@ var/obj/cult_viewpoint/list/cult_viewpoints = list() /obj/cult_viewpoint/New(var/mob/target) owner = target //src.loc = owner - owner.addToVisibilityNetwork(cultNetwork) - cultNetwork.viewpoints+=src - cultNetwork.addViewpoint(src) cult_viewpoints+=src //handle_missing_mask() ..() @@ -28,10 +25,7 @@ var/obj/cult_viewpoint/list/cult_viewpoints = list() /obj/cult_viewpoint/Del() processing_objects.Remove(src) - cultNetwork.viewpoints-=src - cultNetwork.removeViewpoint(src) cult_viewpoints-=src - owner.removeFromVisibilityNetwork(cultNetwork) ..() return @@ -134,6 +128,8 @@ var/obj/cult_viewpoint/list/cult_viewpoints = list() /obj/cult_viewpoint/proc/get_display_name() + if(istype(src,/obj/effect/rune)) + return name if (!owner) return if (cult_name) diff --git a/code/modules/nano/JSON Writer.dm b/code/modules/nano/JSON Writer.dm index 3cd3520f177..f4c74d35ebb 100644 --- a/code/modules/nano/JSON Writer.dm +++ b/code/modules/nano/JSON Writer.dm @@ -1,7 +1,7 @@ json_writer proc - WriteObject(list/L) + WriteObject(list/L, cached_data = null) . = "{" var/i = 1 for(var/k in L) @@ -9,6 +9,8 @@ json_writer . += {"\"[k]\":[write(val)]"} if(i++ < L.len) . += "," + if(cached_data) + . = copytext(., 1, lentext(.)) + ",\"cached\":[cached_data]}" .+= "}" write(val) diff --git a/code/modules/nano/_JSON.dm b/code/modules/nano/_JSON.dm index 5692e643baa..4f70e6e664a 100644 --- a/code/modules/nano/_JSON.dm +++ b/code/modules/nano/_JSON.dm @@ -7,6 +7,6 @@ proc var/static/json_reader/_jsonr = new() return _jsonr.ReadObject(_jsonr.ScanJson(json)) - list2json(list/L) + list2json(list/L, var/cached_data = null) var/static/json_writer/_jsonw = new() - return _jsonw.WriteObject(L) + return _jsonw.WriteObject(L, cached_data) diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 54ff6b70b01..01792ad0c3d 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -58,6 +58,9 @@ nanoui is used to open and update nano browser uis var/is_auto_updating = 0 // the current status/visibility of the ui var/status = STATUS_INTERACTIVE + + var/cached_data = null + // Only allow users with a certain user.stat to get updates. Defaults to 0 (concious) var/allowed_user_stat = 0 // -1 = ignore, 0 = alive, 1 = unconcious or alive, 2 = dead concious or alive @@ -370,7 +373,7 @@ nanoui is used to open and update nano browser uis template_data_json = list2json(templates) var/list/send_data = get_send_data(initial_data) - var/initial_data_json = list2json(send_data) + var/initial_data_json = list2json(send_data, cached_data) var/url_parameters_json = list2json(list("src" = "\ref[src]")) @@ -450,6 +453,17 @@ nanoui is used to open and update nano browser uis var/params = "\ref[src]" winset(user, window_id, "on-close=\"nanoclose [params]\"") + +/** + * Appends already processed json txt to the list2json proc when setting initial-data and data pushes + * Used for data that is fucking huge like manifests and camera lists that doesn't change often. + * And we only want to process them when they change. + * + * @return nothing + */ +/datum/nanoui/proc/load_cached_data(var/data) + cached_data = data + return /** * Push data to an already open UI window @@ -464,7 +478,7 @@ nanoui is used to open and update nano browser uis var/list/send_data = get_send_data(data) //user << list2json(data) // used for debugging - user << output(list2params(list(list2json(send_data))),"[window_id].browser:receiveUpdateData") + user << output(list2params(list(list2json(send_data,cached_data))),"[window_id].browser:receiveUpdateData") /** * This Topic() proc is called whenever a user clicks on a link within a Nano UI diff --git a/code/modules/organs/organ_internal.dm b/code/modules/organs/organ_internal.dm index 54aac02d952..e0872804ce3 100644 --- a/code/modules/organs/organ_internal.dm +++ b/code/modules/organs/organ_internal.dm @@ -96,6 +96,7 @@ P.internal_organs = list() P.internal_organs += src H.internal_organs_by_name[name] = src + H.internal_organs |= src owner = H return @@ -196,7 +197,7 @@ src.damage += 0.2 * process_accuracy //Damaged one shares the fun else - var/datum/organ/internal/O = pick(owner.internal_organs_by_name) + var/datum/organ/internal/O = pick(owner.internal_organs) if(O) O.damage += 0.2 * process_accuracy diff --git a/code/setup.dm b/code/setup.dm index 157b5a47d04..4906f0e6bdf 100644 --- a/code/setup.dm +++ b/code/setup.dm @@ -801,11 +801,13 @@ var/list/cheartstopper = list("potassium_chloride") //this stops the heart when #define GETPULSE_HAND 0 //less accurate (hand) #define GETPULSE_TOOL 1 //more accurate (med scanner, sleeper, etc) -var/list/RESTRICTED_CAMERA_NETWORKS = list( //Those networks can only be accessed by preexisting terminals. AIs and new terminals can't use them. +var/list/restricted_camera_networks = list( //Those networks can only be accessed by preexisting terminals. AIs and new terminals can't use them. "CentCom", "ERT", "NukeOps", "Thunderdome", + "UO45", + "UO45R", "Xeno" ) @@ -943,4 +945,10 @@ var/list/hit_appends = list("-OOF", "-ACK", "-UGH", "-HRNK", "-HURGH", "-GLORF") #define AUTOLATHE 4 //Uses glass/metal only. #define CRAFTLATHE 8 //Uses fuck if I know. For use eventually. #define MECHFAB 16 //Remember, objects utilising this flag should have construction_time and construction_cost vars. -//Note: More then one of these can be added to a design but imprinter and lathe designs are incompatable. \ No newline at end of file +//Note: More then one of these can be added to a design but imprinter and lathe designs are incompatable. + +// Suit sensor levels +#define SUIT_SENSOR_OFF 0 +#define SUIT_SENSOR_BINARY 1 +#define SUIT_SENSOR_VITAL 2 +#define SUIT_SENSOR_TRACKING 3 \ No newline at end of file diff --git a/nano/templates/sec_camera.tmpl b/nano/templates/sec_camera.tmpl index b9764555cd6..5aad1e29298 100644 --- a/nano/templates/sec_camera.tmpl +++ b/nano/templates/sec_camera.tmpl @@ -12,7 +12,7 @@ Used In File(s): \code\game\machinery\computer\camera.dm