ID:916527   Aug 6 2012, 12:01 pm (See the best response by DarkCampainger.) Code: ``` ShowMap() var buf = "" top = min(y+client.view+6.5, world.maxy) bottom = max(y-client.view-6.5, 1) left = max(x-client.view-13, 1) right = min(x+client.view+13, world.maxx) for(var/yy = top, yy >= bottom, yy--) for(var/xx = left, xx <= right, xx++) var/turf/T = locate(xx,yy,z) var/obj/Misc/O = locate() in T var/mob/M = locate() in T if(M) buf += M.text else if(O) buf += O.text else if(T) buf += T.text buf += "\n" mb_msgout("\n") mb_msgout(buf) mb_msgout("Location: [x],[y]") mb_msgout("\n") for(var/mob/M in oview(0)) mb_msgout("[M.name] is here.") mb_msgout("\n") ``` Problem description: I'm not sure how to wrap the map with this code does anyone have an idea on how to i'm not sure on how to approach it.
 Aug 6 2012, 12:42 pm Can you define what you mean by "wrap"? It should be wrapping at the end of each row already.
 Aug 6 2012, 12:45 pm i mean by wrapping the map like it never ends.
 Aug 6 2012, 12:54 pm So you want to connect the West and East sides of the map (and North and South) so it appears like there's no edge? First, remove the min()/max() on the top, bottom, left, and right bounds. Then, within your loop, create two new variables "ax" and "ay" (I chose "a" for absolute) and set them to something like this: ```var/ay = ((yy + world.maxy - 1) % world.maxy) + 1 ``` Basically, whenever yy dips below 1 or beyond maxy, it loops back around. It does this by using the modulus (%) operator, which finds the remainder between a numerator and denominator. You could also do it with a couple of if() statements. I'll let you figure out the matching one for ax. Once you have them, locate the turf at ax/ay/z instead of xx/yy/z. That will draw the map to wrap. However, you'll need to write custom view()/oview()/range()/step_towards()/get_dir()/ect code to handle the seams correctly.
 Aug 6 2012, 1:07 pm ``` ShowMap() var buf = "" top = y+client.view+6.5 bottom = y-client.view-6.5 left = x-client.view-13 right = x+client.view+13 for(var/yy = top, yy >= bottom, yy--) for(var/xx = left, xx <= right, xx++) var/ay = ((yy + world.maxy - 1) % world.maxy) + 1 var/ax = ((xx + world.maxx - 1) % world.maxx) + 1 var/turf/T = locate(ax,ay,z) var/obj/Misc/O = locate() in T var/mob/M = locate() in T if(M && !M.invis) buf += M.text else if(O) buf += O.text else if(T) buf += T.text ``` seems to be working i just need to add a way to get to the other side now!
 Aug 7 2012, 12:46 am If you could further assist me i noticed the issue that comes with this regarding moving towards a mob for example if a mob is chasing me and i goto the other side of the map he will not follow through the edge.. i am guessing this has to do with get_dir and step_towards could you point me in the right direction on how i could fix this?
 Aug 7 2012, 11:18 am Yep, that's because the built-in processes don't handle the map wrapping, so your AI doesn't realize its target is actually right next to it as oppose to on the opposite side of the map. You've been making a lot of posts in Dev Help lately, so I think this would be a good exercise for you to try on your own. Basically you need to soft-code some of the built-in processes to wrap the map: view() and all variants, get_step(), get_dir(), get_dist(), step_towards(), ect. Any map-related built-in process that you use in your game needs to be replaced with your own custom version. It sounds hard, but if you take it one process at a time, I think you'll find they're each relatively simple.
 Aug 7 2012, 11:27 am I see thanks. I think BYOND should really add it as a built in feature when you create the map as an option it would be cool.
 Aug 7 2012, 11:35 am It would be nice. The ability to go from one map to another (thereby getting around the map size limit) seamlessly would be great.
 Aug 7 2012, 2:01 pm So far i just started messing with it ``` mob_view(distance) var/list/mobs = list() var/top = y+distance var/bottom = y-distance var/left = x-distance var/right = x+distance for(var/yy = top, yy >= bottom, yy--) for(var/xx = left, xx <= right, xx++) var/ay = ((yy + world.maxy - 1) % world.maxy) + 1 var/ax = ((xx + world.maxx - 1) % world.maxx) + 1 var/turf/T = locate(ax,ay,z) var/mob/M = locate() in T for(M in T) mobs.Add(M) return mobs ``` seems to work so far. now i just need to make an oview get step etc.
 Aug 7 2012, 2:04 pm In response to Gokussj99 Don't forget that opaque objects and objects blocked by opaque objects aren't included in view() ;) To account for this (Since I don't know the specifics of how opacity is managed in the actual view()), I would use view(dist, usr) and wrap it around. If you do view(5) and you only have three tiles to your right until you hit the edge of the map, then just grab the 1,1 tile and do view(2,tile). Not sure if that made sense to you, but it made perfect sense to me. If you are confused just let me know.
 Aug 7 2012, 2:16 pm (Edited on Aug 7 2012, 4:52 pm) Yeah i also had to change it to atoms dumb me so it would work with objects etc blah ``` a_view(distance, atom/center=src) var/list/atoms = list() var/top = center.y+distance var/bottom = center.y-distance var/left = center.x-distance var/right = center.x+distance for(var/yy = top, yy >= bottom, yy--) for(var/xx = left, xx <= right, xx++) var/ay = ((yy + world.maxy - 1) % world.maxy) + 1 var/ax = ((xx + world.maxx - 1) % world.maxx) + 1 var/turf/T = locate(ax,ay,z) var/atom/A = locate() in T for(A in T) atoms.Add(A) if(!atoms.len) return else return atoms a_oview(distance, atom/center=src) var/list/atoms = list() var/top = center.y+distance var/bottom = center.y-distance var/left = center.x-distance var/right = center.x+distance for(var/yy = top, yy >= bottom, yy--) for(var/xx = left, xx <= right, xx++) var/ay = ((yy + world.maxy - 1) % world.maxy) + 1 var/ax = ((xx + world.maxx - 1) % world.maxx) + 1 var/turf/T = locate(ax,ay,z) var/atom/A = locate() in T for(A in T) if(A != center) atoms.Add(A) if(!atoms.len) return else return atoms ``` I'm going to get all that stuff sorted eventually just doing testing although i've been a member of BYOND for 10 years lol.. I'm just really starting to learn. :/ i haven't really touched BYOND a lot in the past until recently. I'm learning and have been working on one creation for nearly 3 months so far so its going well.. more than i thought id ever progress.. and learn.
 Aug 7 2012, 4:47 pm Although I'm not sure how i would ignore the edges on get_distance or step etc.. ``` a_get_dist(atom/center=src, atom/a) var/distance = max(abs(center.x - a.x), abs(center.y - a.y)) if(!distance) return else return distance ``` because it doesnt check turfs it checks coordinates just returns the distance of the whole map distance between us hrm ;/
 Aug 7 2012, 4:56 pm Try grabbing the distance between them normally and the distance between them by wrapping and comparing them, returning the smaller value. ```a_get_dist(atom/a = src, atom/b) var dist1 = get_dist(a, b) var d = get_dir(a, b) var dist2 = world.maxx // just set it high so the normal get_dist is smaller by default // If they are to your east, let's wrap to the west var turf/t if(d & EAST) t = locate(1, a.y, a.z) dist2 = get_dist(a, t) t = locate(world.maxx, a.y, a.z) if(d & WEST) t = locate(world.maxx, a.y, a.z) dist2 = get_dist(a, t) t = locate(1, a.y, a.z) dist2 += get_dist(t, b) return min(dist1, dist2) ``` Probably not the best example, more of an idea starter.
 Aug 7 2012, 5:08 pm works pretty well except not diagonal hrm ill toy with it
 Aug 7 2012, 5:48 pm I haven't tested how efficient it is, but you could implement it simply by trying all 6 variations: ```proc/get_dist_wrap(atom/A, atom/B) return max(min( abs(A.x - B.x), abs(A.x - B.x - world.maxx), abs(A.x - B.x + world.maxx) ), min( abs(A.y - B.y), abs(A.y - B.y - world.maxy), abs(A.y - B.y + world.maxy) )) ``` First it gets the distance from A to B at their actual locations, then it wraps B off the west side of the map, then it wraps B off the east side of the map. Similar for the y-value.
 Aug 7 2012, 5:56 pm (Edited on Aug 7 2012, 8:02 pm) Now i need to figure out how to get the direction and calculate the steps to get there.
 Aug 7 2012, 10:18 pm can anyone give me an example of how i would write the walk_towards proc soft-coded but with wrapping.
 Aug 7 2012, 10:22 pm In response to Gokussj99 Once you have get_dir_wrap(), you just keeping stepping in that direction until get_dist_wrap() is zero or 1 (I can't remember which it stops at...)
 Aug 7 2012, 10:25 pm Yeah I'm still trying to figure out how to get the direction wrapped in a simpler way I'm just so tired I gotta figure this out before i goto bed lol 4:25 and today is my birthday! (off topic).
Page: 1 2