From bcc3972fbe6e675ff27bcec2b716248ba63f5e02 Mon Sep 17 00:00:00 2001 From: Uristqwerty Date: Mon, 14 May 2012 04:04:56 -0400 Subject: [PATCH 1/4] Minimap (work in progress): - Uses freelook visibility calculations - all visible turfs represented as a 2x2 square - - doors, windows, and structural objects that block movement show up in different colours from walls, floors, and space - - windows and windoors that only block the edge of a tile show as a 1x2 line - Areas that were visble but now aren't display in red. This will happen during regular activity, as doors open and close, as well as during abnormal circumstances, such as a camera being disabled/destroyed, or additional walls being constructed that block a camera's LOS. - changes in visibility in an area triggers a map update which takes place two minutes later, reducing amount of processing (since further update triggers are ignored until the pending update has taken place), and give antagonists time after disabling a camera to conduct their business, before the map reveals that anything is out of the ordinary. Sample screenshot: http://i.imgur.com/PS2vF.png Todo: - Remove test verb available to everyone, replace with AI-only (and perhaps avaiable to admins and ghosts?) verb. - Clicking a tile immediately enters freelook and jumps to that tile - Perhaps overlay blinking blue for areas with atmosphere alerts, brown for power? Independant of visibility, or centred on APC? - A verb to force-update the current 3x3 area, while in freelook? --- code/WorkInProgress/AI_Visibility.dm | 121 +++++++++++++++++++++++---- icons/minimap.dmi | Bin 0 -> 206 bytes interface/skin.dmf | 65 ++++++++++++++ 3 files changed, 169 insertions(+), 17 deletions(-) create mode 100644 icons/minimap.dmi diff --git a/code/WorkInProgress/AI_Visibility.dm b/code/WorkInProgress/AI_Visibility.dm index 79567037892..5f6ea0fd1b8 100644 --- a/code/WorkInProgress/AI_Visibility.dm +++ b/code/WorkInProgress/AI_Visibility.dm @@ -33,9 +33,79 @@ var/list/turfs = list() var/list/seenby = list() var/visible = 0 - var/changed = 0 + var/changed = 1 var/updating = 0 + var/x + var/y + var/z + + var/minimap_updating = 0 + + var/icon/minimap_icon = new('minimap.dmi', "chunk_base") + var/obj/minimap_obj = new() + +/mob/verb/minimap_test() + winshow(src, "minimapwindow", 1) + client.screen |= cameranet.minimap + + +/datum/camerachunk/proc/update_minimap() + if(changed && !updating) + update() + + minimap_icon.Blend(rgb(255, 0, 0), ICON_MULTIPLY) + + var/list/turfs = visibleTurfs | dimTurfs + + for(var/turf/turf in turfs) + var/x = (turf.x & 0xf) * 2 + var/y = (turf.y & 0xf) * 2 + + if(turf.density) + minimap_icon.DrawBox(rgb(100, 100, 100), x + 1, y + 1, x + 2, y + 2) + continue + + else if(istype(turf, /turf/space)) + minimap_icon.DrawBox(rgb(0, 0, 0), x + 1, y + 1, x + 2, y + 2) + + else + minimap_icon.DrawBox(rgb(200, 200, 200), x + 1, y + 1, x + 2, y + 2) + + for(var/obj/structure/o in turf) + if(o.density) + if(istype(o, /obj/structure/window) && (o.dir == NORTH || o.dir == SOUTH || o.dir == EAST || o.dir == WEST)) + if(o.dir == NORTH) + minimap_icon.DrawBox(rgb(150, 150, 200), x + 1, y + 2, x + 2, y + 2) + else if(o.dir == SOUTH) + minimap_icon.DrawBox(rgb(150, 150, 200), x + 1, y + 1, x + 2, y + 1) + else if(o.dir == EAST) + minimap_icon.DrawBox(rgb(150, 150, 200), x + 3, y + 1, x + 2, y + 2) + else if(o.dir == WEST) + minimap_icon.DrawBox(rgb(150, 150, 200), x + 1, y + 1, x + 1, y + 2) + + else + minimap_icon.DrawBox(rgb(150, 150, 150), x + 1, y + 1, x + 2, y + 2) + break + + for(var/obj/machinery/door/o in turf) + if(istype(o, /obj/machinery/door/window)) + if(o.dir == NORTH) + minimap_icon.DrawBox(rgb(100, 150, 100), x + 1, y + 2, x + 2, y + 2) + else if(o.dir == SOUTH) + minimap_icon.DrawBox(rgb(100, 150, 100), x + 1, y + 1, x + 2, y + 1) + else if(o.dir == EAST) + minimap_icon.DrawBox(rgb(100, 150, 100), x + 2, y + 1, x + 2, y + 2) + else if(o.dir == WEST) + minimap_icon.DrawBox(rgb(100, 150, 100), x + 1, y + 1, x + 1, y + 2) + + else + minimap_icon.DrawBox(rgb(100, 150, 100), x + 1, y + 1, x + 2, y + 2) + break + + minimap_obj.screen_loc = "minimap:[src.x / 16],[src.y / 16]" + minimap_obj.icon = minimap_icon + /mob/aiEye var/list/visibleCameraChunks = list() var/mob/ai = null @@ -50,6 +120,7 @@ seenby += ai if(changed && !updating) update() + changed = 0 /datum/camerachunk/proc/remove(mob/aiEye/ai) ai.visibleCameraChunks -= src @@ -76,20 +147,28 @@ else changed = 1 + if(!minimap_updating) + minimap_updating = 1 + + spawn(1200) + if(changed && !updating) + update() + changed = 0 + + update_minimap() + minimap_updating = 0 + /datum/camerachunk/proc/update() + var/list/newDimTurfs = list() var/list/newVisibleTurfs = list() for(var/obj/machinery/camera/c in cameras) var/lum = c.luminosity c.luminosity = 7 - for(var/turf/t in view(7, c)) - if(t in turfs) - newDimTurfs += t - for(var/turf/t in view(6, c)) - if(t in turfs) - newVisibleTurfs += t + newDimTurfs |= turfs & view(7, c) + newVisibleTurfs |= turfs & view(6, c) c.luminosity = lum @@ -154,29 +233,26 @@ m.ai.client.images += t.obscured - /datum/camerachunk/New(loc, x, y, z) x &= ~0xf y &= ~0xf + src.x = x + src.y = y + src.z = z + for(var/obj/machinery/camera/c in range(16, locate(x + 8, y + 8, z))) if(c.status) 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 + turfs = block(locate(x, y, z), locate(min(world.maxx, x + 15), min(world.maxy, y + 15), z)) for(var/obj/machinery/camera/c in cameras) var/lum = c.luminosity c.luminosity = 7 - for(var/turf/t in view(7, c)) - if(t in turfs) - dimTurfs += t - for(var/turf/t in view(6, c)) - if(t in turfs) - visibleTurfs += t + dimTurfs |= turfs & view(7, c) + visibleTurfs |= turfs & view(6, c) c.luminosity = lum @@ -197,6 +273,8 @@ dim += t.dim + cameranet.minimap += minimap_obj + var/datum/cameranet/cameranet = new() /datum/cameranet @@ -205,9 +283,18 @@ var/datum/cameranet/cameranet = new() var/network = "net1" var/ready = 0 + var/list/minimap = list() + /datum/cameranet/New() ..() + spawn(200) + for(var/x = 0, x <= world.maxx, x += 16) + for(var/y = 0, y <= world.maxy, y += 16) + sleep(1) + var/datum/camerachunk/c = getCameraChunk(x, y, 1) + c.update_minimap() + /datum/cameranet/proc/chunkGenerated(x, y, z) var/key = "[x],[y],[z]" return key in chunks diff --git a/icons/minimap.dmi b/icons/minimap.dmi new file mode 100644 index 0000000000000000000000000000000000000000..26aecb84b96f224ffd7a44d4a7e1a14e97584fe4 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;m;-!5T!HlRD%)E?Dz7ReqQoV& zIJqdZpd>RtkAb0LPH Date: Wed, 16 May 2012 02:08:34 -0400 Subject: [PATCH 2/4] Basic teleport-to-clicked-location, menu with size dropdown. --- code/WorkInProgress/AI_Visibility.dm | 22 ++++++++++++- interface/skin.dmf | 49 +++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/code/WorkInProgress/AI_Visibility.dm b/code/WorkInProgress/AI_Visibility.dm index 5f6ea0fd1b8..44563c8367f 100644 --- a/code/WorkInProgress/AI_Visibility.dm +++ b/code/WorkInProgress/AI_Visibility.dm @@ -43,7 +43,27 @@ var/minimap_updating = 0 var/icon/minimap_icon = new('minimap.dmi', "chunk_base") - var/obj/minimap_obj = new() + var/obj/minimap_obj/minimap_obj = new() + +/obj/minimap_obj/Click(location, control, params) + var/list/par = params2list(params) + var/screen_loc = par["screen-loc"] + + if(findtext(screen_loc, "minimap:") != 1) + return + + screen_loc = copytext(screen_loc, length("minimap:") + 1) + + var/x_text = copytext(screen_loc, 1, findtext(screen_loc, ",")) + var/y_text = copytext(screen_loc, findtext(screen_loc, ",") + 1) + + var/x = (text2num(copytext(x_text, 1, findtext(x_text, ":"))) - 1) * 16 + x += round((text2num(copytext(x_text, findtext(x_text, ":") + 1)) + 1) / 2) + + var/y = (text2num(copytext(y_text, 1, findtext(y_text, ":"))) - 1) * 16 + y += round((text2num(copytext(y_text, findtext(y_text, ":") + 1)) + 1) / 2) + + usr.loc = locate(max(1, x - 1), max(1, y - 1), usr.z) /mob/verb/minimap_test() winshow(src, "minimapwindow", 1) diff --git a/interface/skin.dmf b/interface/skin.dmf index 67bf4a6b589..22e3d79dbd0 100644 --- a/interface/skin.dmf +++ b/interface/skin.dmf @@ -327,6 +327,53 @@ menu "menu" is-disabled = false saved-params = "is-checked" +menu "minimap_menu" + elem + name = "Size" + command = "" + category = "" + is-checked = false + can-check = false + group = "" + is-disabled = false + saved-params = "is-checked" + elem + name = "50%" + command = ".winset \"minimap.icon-size=16\"" + category = "Size" + is-checked = false + can-check = true + group = "minimap_size" + is-disabled = false + saved-params = "is-checked" + elem + name = "100%" + command = ".winset \"minimap.icon-size=32\"" + category = "Size" + is-checked = true + can-check = true + group = "minimap_size" + is-disabled = false + saved-params = "is-checked" + elem + name = "200%" + command = ".winset \"minimap.icon-size=64\"" + category = "Size" + is-checked = false + can-check = true + group = "minimap_size" + is-disabled = false + saved-params = "is-checked" + elem + name = "stretch" + command = ".winset \"minimap.icon-size=0\"" + category = "Size" + is-checked = false + can-check = true + group = "minimap_size" + is-disabled = false + saved-params = "is-checked" + window "Telecomms IDE" elem "Telecomms IDE" @@ -1245,7 +1292,7 @@ window "minimapwindow" transparent-color = none alpha = 255 macro = "" - menu = "" + menu = "minimap_menu" on-close = "" elem "minimap" type = MAP From 68edf995690d656e995cb3a03777cc595f8c743a Mon Sep 17 00:00:00 2001 From: Uristqwerty Date: Fri, 18 May 2012 20:12:38 -0400 Subject: [PATCH 3/4] Finishing the minimap: - Removed test verb - Added verbs for admins, ghosts, and AIs - If you open the minimap before it finishes initializing, it will try to update you with missing sections as they become available --- code/WorkInProgress/AI_Visibility.dm | 47 ++++++++++++++++++++++++++-- code/modules/admin/admin_verbs.dm | 1 + 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/code/WorkInProgress/AI_Visibility.dm b/code/WorkInProgress/AI_Visibility.dm index 44563c8367f..16e97323146 100644 --- a/code/WorkInProgress/AI_Visibility.dm +++ b/code/WorkInProgress/AI_Visibility.dm @@ -8,6 +8,9 @@ //(And therefore also be portable to another similar codebase simply by transferring the file and including it after the other AI code files.) //There are probably a few parts that don't do that at the moment, but I'll fix them at some point. + +#define MINIMAP_UPDATE_DELAY 1200 + /turf var/image/obscured var/image/dim @@ -46,6 +49,9 @@ var/obj/minimap_obj/minimap_obj = new() /obj/minimap_obj/Click(location, control, params) + if(!istype(usr, /mob/dead) && !istype(usr, /mob/living/silicon/ai) && !(usr.client && usr.client.holder && usr.client.holder.level >= 4)) + return + var/list/par = params2list(params) var/screen_loc = par["screen-loc"] @@ -63,12 +69,38 @@ var/y = (text2num(copytext(y_text, 1, findtext(y_text, ":"))) - 1) * 16 y += round((text2num(copytext(y_text, findtext(y_text, ":") + 1)) + 1) / 2) - usr.loc = locate(max(1, x - 1), max(1, y - 1), usr.z) + if(istype(usr, /mob/living/silicon/ai)) + var/mob/living/silicon/ai/ai = usr + ai.freelook() + ai.eyeobj.loc = locate(max(1, x - 1), max(1, y - 1), ai.eyeobj.z) + cameranet.visibility(ai.eyeobj) -/mob/verb/minimap_test() + else + usr.loc = locate(max(1, x - 1), max(1, y - 1), usr.z) + +/mob/dead/verb/Open_Minimap() + set category = "Ghost" winshow(src, "minimapwindow", 1) client.screen |= cameranet.minimap + if(cameranet.generating_minimap) + cameranet.minimap_viewers += src + +/mob/living/silicon/ai/verb/Open_Minimap() + set category = "AI Commands" + winshow(src, "minimapwindow", 1) + client.screen |= cameranet.minimap + + if(cameranet.generating_minimap) + cameranet.minimap_viewers += src + +/client/proc/Open_Minimap() + set category = "Admin" + winshow(src, "minimapwindow", 1) + screen |= cameranet.minimap + + if(cameranet.generating_minimap) + cameranet.minimap_viewers += src.mob /datum/camerachunk/proc/update_minimap() if(changed && !updating) @@ -170,7 +202,7 @@ if(!minimap_updating) minimap_updating = 1 - spawn(1200) + spawn(MINIMAP_UPDATE_DELAY) if(changed && !updating) update() changed = 0 @@ -305,6 +337,9 @@ var/datum/cameranet/cameranet = new() var/list/minimap = list() + var/generating_minimap = TRUE + var/list/minimap_viewers = list() + /datum/cameranet/New() ..() @@ -315,6 +350,12 @@ var/datum/cameranet/cameranet = new() var/datum/camerachunk/c = getCameraChunk(x, y, 1) c.update_minimap() + for(var/mob/m in minimap_viewers) + m.client.screen |= c.minimap_obj + + generating_minimap = FALSE + minimap_viewers = list() + /datum/cameranet/proc/chunkGenerated(x, y, z) var/key = "[x],[y],[z]" return key in chunks diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 7574cfc2270..cb7b9f56ecf 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -219,6 +219,7 @@ verbs += /client/proc/jumptokey verbs += /client/proc/jumptomob verbs += /client/proc/jumptoturf + verbs += /client/proc/open_minimap verbs += /client/proc/cmd_admin_delete verbs += /client/proc/cmd_admin_add_freeform_ai_law verbs += /client/proc/cmd_admin_add_random_ai_law From 1ce3bce2664a4f135b7f74960a83aed4b5fa4cb3 Mon Sep 17 00:00:00 2001 From: Uristqwerty Date: Fri, 18 May 2012 20:46:29 -0400 Subject: [PATCH 4/4] Turns out last minute capitalization changes break compiling. --- code/modules/admin/admin_verbs.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index cb7b9f56ecf..1a09aebb549 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -219,7 +219,7 @@ verbs += /client/proc/jumptokey verbs += /client/proc/jumptomob verbs += /client/proc/jumptoturf - verbs += /client/proc/open_minimap + verbs += /client/proc/Open_Minimap verbs += /client/proc/cmd_admin_delete verbs += /client/proc/cmd_admin_add_freeform_ai_law verbs += /client/proc/cmd_admin_add_random_ai_law