How to check for a tile within an auto-tiled bitmask region (Godot 3.3.1)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By star0chris

So I am using simplex noise to procedurally generate a map using auto-tiles and bitmasks, but I am also trying to manually place some tiles on the map as well. These manually placed tiles are called “Obstacles” and they spawn on parts of the map I have specified, but I want to be able to check if it’s within a bitmask region to then not spawn them. Right now my Obstacles sometimes spawn within my “Forest” parts of the map and they overlap.

So how can I check to see if I am within the Forest region before I create an Obstacle.

Here are my functions for creating the Forest and Obstacle parts of the map:
enter image description here
Checking to see (on line 67) if the Forest cell isn’t there(-1), then spawn an Obstacle, doesn’t seem to work the way I want. I think this is because this only checks the one part of the Forest region where the bitmask originates from, so only one tile for an entire column of Forests.

This is what the bitmask looks like for the Forest:
enter image description here
Here is an example of what the map looks like with the Obstacles spawning on where the Forest tiles are generated:
enter image description here
As you can see, some of the Obstacles/rocks spawn where the Forest is and I would like to be able to check for that in any way really. I have tried a number of ways, but I feel like this can be an easy solution and I am just not aware of how to go about it as I am pretty new to Godot and gdscript. If more parts of the code need to be shared just let me know, and thanks in advance for anyone who helps.

:bust_in_silhouette: Reply From: dethland

I think I have a solution for this.
Every time you create a forest, registe the location to a list.
When your program is trying to add the “obstacles”, check through this list.
If the location of the obstacle is already registered, simply skip this one.
Then it may achive the effect you want.
Hope this will help you.
:slight_smile:

Sorry for sending two answers, I clicked the send too fast.

dethland | 2021-10-09 18:46

SOLVED: I ended up just making a tilemap that was more filled out for bitmask use. I made it just one tree tile that was copied and then had each different bitmask possible for each copy. I guess problems like these are just made when there isn’t a proper bitmask.

Thanks for the response!
So I have tried variations of this before, and the problem with it is that it basically comes down to the fact that not every forest tile on the screen is technically an actual registered forest tile. I have checked this by just getting the cell of every forest (get_used_cells()) and then comparing that to what I see generated on the map and it only will grab some of the forests in a column. I probably should have mentioned this in my initial post, sorry about that.
I’m not sure how this works exactly, but I think what is happening is that it will set like a “root” of the autotile and then it will fill in the rest of the autotile automatically without actually setting it as a forest cell. I don’t know what it bases that off of at all; I might just have something inherently wrong with my code (maybe something with how it is bitmasked), but I can’t seem to find anything blaringly wrong about it. I’ll attach an example to show what I mean and hopefully someone can make sense out of it.

Here is a picture showing another map example. I marked which parts are recognized as forest tiles in the code (for just the first batch of trees at the top). Columns are the x axis and rows are the y axis.

Here is a screenshot of the code printing the used cells as well as the output for this example. It scans through the grid from left to right and then top to bottom.

So as you can see it just clearly ignores more than half of that part of the forest for whatever reason. I guess this is an entirely different problem, so that’s why I figured I would just ask here if there is a way to check within an entire bitmask region, instead of this problem, with a function like within_bitmask_region() or something. (sounds too good to be a thing though lol)

If anything else needs to be clarified just let me know because I know I could have probably explained this problem a bit better. Thanks again for the response!

star0chris | 2021-10-10 08:56

:bust_in_silhouette: Reply From: dethland

I think I have a solution for this.
Every time you create a forest, register the location on a list.
When your program is trying to add the “obstacles”, check through this list.
If the location of the obstacle is already registered, simply skip this one.
Then it may achieve the effect you want.
Hope this will help you.
:slight_smile: