Region

by Forum_account
Lets you specify regions of the map that trigger Entered and Exited events.
ID:402423
 
I just added some new features to the library. Suppose you place regions on the map like this:


(the region is the red area)

The region is placed so that it connects each button with a door. We can write the button's New() proc so that it uses the region to find what door it's associated with:

turf
button
var
turf/door/door

New()
..()
door = region.get(src, /turf/door)

Entered()
door.open()

The region.get() proc takes two arguments. The first is the source atom. The second is an object type to search for. The get() proc returns an instance of the specified type that resides in the same connected component of the region. Because it only looks in the part of the region that's connected to the source atom, we can use this same region type to create groupings between many pairs of buttons and doors.
Is there any advantage to using this over say, identification tags? As in you specify connected components with tags and call locate(tag) to get a reference to the object?

Additionally, I wonder if there's a feasible way to get regions to behave like areas do graphically. Maybe you could show a these relationships between the switches and their doors on the map, like a trail of wiring.
In response to D4RK3 54B3R
D4RK3 54B3R wrote:
Is there any advantage to using this over say, identification tags? As in you specify connected components with tags and call locate(tag) to get a reference to the object?

1. Tags are waaaay more annoying to set. Drawing a region on the map to connect objects is much easier than using the instance editor.

2. Tags don't offer a graphical representation in the map editor of which objects are linked.

3. Tags can't as easily be used for linking to multiple objects. I could easily give buttons a list of doors and call region.get_list instead.

4. Tags can't be used on instanced maps.

[Edit: Also, like many BYOND features, using tags for one thing may prevent you from using them for another.]

Additionally, I wonder if there's a feasible way to get regions to behave like areas do graphically. Maybe you could show a these relationships between the switches and their doors on the map, like a trail of wiring.

I could add a region.get_path(atom, type) proc which returns a path from the atom to an instance of the specified type, but I don't think the library would help with creating the graphical effect.