# Output Layer probability property for automapping

I saw there was a probability tile property to use with the terrain tool but is there also a way to specify the probability to use one of the output layers for automapping?
A layer wide property on the output layer would probably work best.
Currently, if I want to have tile A appears 95% of the time, and tile B 5%, I copy tile A 19 times as output1_prop ->output19_prop and tile B.
Isn’t there a way to do it faster with properties? I haven’t found it mentioned there or in the documentation, but I may have missed it.
.

Such a thing is currently not supported, but it should certainly be possible to add. I’ll have a look at it in the next week.

Thanks! That would be really helpful.

Would it also be possible to set up automap regions to handle diagonals (or not) both for isometric and orthgonal maps?

Hmm, you mean the current regions are not belonging together when they are only connected by diagonals, and sometimes you would want this? Controllable as a custom property on the regions layer?

It would require adapting the following function to somehow return `true` when `rect` is touching any corners of `region`:

``````static bool isCoherentTo(const QRect &rect, const QRegion &region)
{
// check if the region is coherent at top or bottom
return true;
// check if the region is coherent at left or right side
return true;

return false;
}
``````

Actually, now that I think about it, that should be pretty much:

``````static bool isCoherentWithDiagonalsTo(const QRect &rect, const QRegion &region)
{
// check if the rect touches the region, including diagonal touching
}
``````

So yeah, that could certainly be an option.

Exactly! The option was rather to make it sure it remained backwards compatible, as it could break a lot of things for everyone using this feature if diagonals start to count as they didn’t before.
Thanks!
A last question regarding automaps:
Is there a way to indicate “something” or “nothing” on an input layer (at a given position)?
For instance, if I have a tree_item on the terrain_type_layer, and nothing on the sprite_layer, I would want to put a random tree sprite on the sprite_layer, but if there is already something, I don’t want to add anything there.

Hopefully @stefanbeller could provide an answer here.

I was just looking at the layer probability thing, and there’s one small problem. The AutoMapper chooses randomly between different sets of output layers, that are sharing the same index. So it is not immediately obvious where the probability should be stored, since multiple layers can be involved in one random output.

I’m thinking I could just check each of the output layers for a possible “probability” custom property, and when there are multiple output layers using the same index, the last one for that index will simply win.

you mean that if I have 3 layers named

``````  output1_trees
output1_trees
output2_trees
``````

then the autmapper will first choose one of the output1_trees layer randomly, and then choose randomly whether to output the selected output1_trees or the output2_trees layer?
ie the probabilities would be

``````  output1_trees 25%
output1_trees 25%
output2_trees 50%
``````

Then I think the easiest would be to have a weight probability (ie some arbitrary int or float value) that would be set by default to 1.
we can either choose the last one of a given index and check its probability property (or use 1), or pick randomly between all of the ones with a given index depending on their probability property, and then use the probability property of the “winner” against the ones of the output layers with another index. For instance

``````  output1_trees, probability = 3
output1_trees, probability not set
output2_trees, probability = 3
``````

choice 1:
50% of the first output1_trees layer selected, then 50% as both it and output2 trees have the same probability of 3
50% of the second output1_trees selected, then 25% to have it chosen over output2_trees
so the resulting probabilities would be:

``````   output1_trees 25%
output1_trees 12.5%
output2_trees 62.5%
``````

choice 2:
75% of the first output1_trees layer selected, then 50% as both it and output2 trees have the same probability of 3
25% of the second output1_trees selected, then 25% to have it chosen over output2_trees
so the resulting probabilities would be:

``````   output1_trees 37.5%
output1_trees 6.25%
output2_trees 56.25%
``````

I don’t know which one is the most intuitive, but both can work IMO.

The AutoMapper currently only randomly picks once, when there are multiple prefixes (in the code it calls these “indexes”). It does not support outputting to the same layer multiple times from the same prefix. In that case, it seems the last layer wins (would probably be good to turn this into an error, or to indeed support picking random twice).

I’ve just changed the related code a little while seeing what it does, if you’re interested:

https://github.com/bjorn/tiled/commit/e943c67493d8495084388b30f622f844e93bf8b1

An error would be appropriate in the case of several output layers using the same prefix indeed.
If I understand correctly, if there is at least one match, then one set if output layer is selected.
So for instance, if I have output1_trees, output2_trees, and output_grass, then the automapper would randomly select between output1_trees+output_grass and output2_trees+output_grass. I am correct?
And if there is some rule overlap, it will choose the first met?
I think a good way to randomize it could be to have each output layer be given a “weight” property (but I suppose calling it probability would convey it better).
so a set of output layers could have a weight equal to the product of all of the weight properties of its output layers.

For instance, if we now have output1_trees(p=2), output2_trees(p=1), output1_grass(p=2), output2_grass(p=1), then the output weights would be:
output1_trees+output1_grass = 22
output1_trees+output2_grass = 2
1
output2_trees+output1_grass = 12
output2_trees+output2_grass = 1
1
and the resulting probabilities would be:
output1_trees+output1_grass = 4/9
output1_trees+output2_grass = 2/9
output2_trees+output1_grass = 2/9
output2_trees+output2_grass = 1/9

If output1_tree and output1_grass have to be picked together, (and output2_tree+output2_grass too), then the same formula may be used, and it becomes even simpler:
output1_trees+output1_grass = 4/5
output2_trees+output2_grass = 1/5

Howdy, l was wondering if there were any updates on this or if I should attempt my own implementation and make a PR.

Hey @yaomon. I haven’t worked on this feature in particular but would be happy to help you with any questions if you’d like to give this a try!

If we take the logic suggested by @Galdred in his last comment (the final suggestion, where output1_tree and output1_grass are picked together), it should not be too hard to implement. Currently each set of outputs is given equal weight in this code:

It could be modified to calculate the weight for each `RuleOutput` by the logic above and then use the `RandomPicker` helper class to pick an index taking into account these weights.

1 Like