ID:177379
 
I realized I don't have much experience with adding/deleting turfs at runtime, so I could use some advice on this:

My map is setup with a block of locations like this:

ABBBC (A,B,C are different turf types)

Based on the number of players in the current game, I'd like to change the turfs to either of these:

ABBC or ABC

Thus, I first need to identify if turf A or B is at a given location, then add/del turfs as necessary. This is further complicated because I will also have a separate background turf in addition to the above, so I don't want to delete ALL turfs at a location. Is there a list of turfs for a given map location that I can access?

If there is a good library/tutorial that would help me get familiar with this, please let me know.

You should probably use objects instead of turfs if you're dynamically changing them. But, assuming they are objects, you want something like this...
<code> obj A B C New() while(world.Players > x-initial(x)) new /obj/B(loc) x++ var/Players mob Login() Players++ ..() Logout() Players-- ..() </code>

Untested, but it should work. Just start it off with no B objects, and just have it like:

<code>AC</code>

And it will adjust itself. If you want it to change as players join and leave, replace <code>New()</code> with <code>proc/Adjust()</code> , and put in <code>for(var/obj/C/C) C.Adjust()</code> into the Login() and Logout() procs.

Or, if you want the number of B's to be based on the number of players, not the exact number of players, you can use round(Players/2) or whatever.
dramstud wrote:
I realized I don't have much experience with adding/deleting turfs at runtime, so I could use some advice on this:

My map is setup with a block of locations like this:

ABBBC (A,B,C are different turf types)

Based on the number of players in the current game, I'd like to change the turfs to either of these:

ABBC or ABC

Thus, I first need to identify if turf A or B is at a given location, then add/del turfs as necessary. This is further complicated because I will also have a separate background turf in addition to the above, so I don't want to delete ALL turfs at a location. Is there a list of turfs for a given map location that I can access?

Actually there's a bit of a common misconception surrounding turfs, that isn't helped by the fact that the map editor gracefully hides the details of how it does this.
When you place a turf on another one in the map editor, what's really happening is that the bottom turf becomes an underlay for the top.

There is, in fact, only one turf per map location.

The way I'd change turfs would be to create a new temporary obj and copy all its underlays from the original turf. Then, create your new turf, which will delete the old; add the obj's underlays to that turf, and then delete the obj.
var/obj/O=new
O.underlays+=T.underlays
T=new myturf(T)
T.underlays+=O.underlays
del(O)

Lummox JR
In response to Lummox JR (#2)
fascinating...

I guess now I just need to be careful that my background image is the underlay and not the turf itself (ie. if I change my background). It definitely makes more sense now though.

Thanks.
In response to Dramstud (#3)
You could also trying using an area for the background, instead of turfs. It works about the same way, but you can have one area and one turf in the same map square.
In response to Foomer (#4)
Yeah, but you run into the same kind of problem, you can't have more than 1 area at a single loc. Like I siad before, objects are probably the way to go.
In response to Foomer (#4)
Foomer wrote:
You could also trying using an area for the background, instead of turfs. It works about the same way, but you can have one area and one turf in the same map square.

If I wasn't using areas for other things, that would work. However, all the regions where game tiles end up had to be areas, as when I made them turfs initially, they were moved on top of each other even though I set density to 1 and used the built in Move() proc.
In response to Dramstud (#6)
Then you have to use objects. My suggestion should work.