Question about Noise Expressions and autoplacing new tiles

Place to get help with not working mods / modding interface.
Danacus
Inserter
Inserter
Posts: 29
Joined: Sun Sep 18, 2016 5:25 pm
Contact:

Question about Noise Expressions and autoplacing new tiles

Post by Danacus »

Hi

I'm trying to make a mod that adds a cave surface. I want to use a noise function to generate "cave wall" tiles and thought it would be a good idea to use the new Noise Expression system. So far I have managed to generate cave walls the way I like, by using the similar code to the code used to generate water. However I would like the cave walls to only be placed on the surfaces that I create. Right now I'm using the autoplace property in data.lua on my cave wall tile, but now it gets placed on all surfaces. A dirty workaround that kind of works was to modify the map gen presets to set the probability of cave wall to -1000 in all presets and manually override it on my own surfaces when creating them. But that doesn't really work since you can't change the default preset and it doesn't look like a very clean way to do it. Is there a better way of doing this?

I'm also a bit confused by all the different concepts like noise expressions, noise layers, autoplace controls, autoplace settings, property expression names, etc.

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by PyroFire »

No matter what you do with noise expressions, you cannot restrict your autoplacements to a specific surface.
You can only do that during the control stage, and careful manipulation of the map_gen_settings.

I have several mods that relies on this very functionality.

Particularly this one: https://mods.factorio.com/mod/planetorio
See: https://mods.factorio.com/mod/stacktorio for a mod that actually makes use of planetorio.

Warptorio has the planets system built-in (because this is where planetorio came from): https://mods.factorio.com/mod/warptorio2
Danacus wrote:
Fri Dec 20, 2019 9:07 am
A dirty workaround that kind of works was to modify the map gen presets to set the probability of cave wall to -1000 in all presets and manually override it on my own surfaces when creating them.
That's exactly what you need to do if you want anything to have a noise expression, but is only placed on specific surfaces.

You're welcome to depend on planetorio to do most of the "dirty work" for you (and it gives me an extra planet), though keep in mind things are still changing and planetorio is not 100% finished.

Danacus
Inserter
Inserter
Posts: 29
Joined: Sun Sep 18, 2016 5:25 pm
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by Danacus »

Actually, I was working on a library to create different surfaces and creating them as "layers" of a planet, for example a cave surface for a planet.

Now that I look at Planetorio, it seems like your goals might be similar, so it might make more sense to use Planetorio instead of my own library.

Maybe I could even build a library on to of yours that just handles the linking surfaces to a layer of a certain planet part?

Thanks for telling me about your mod!

Danacus
Inserter
Inserter
Posts: 29
Joined: Sun Sep 18, 2016 5:25 pm
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by Danacus »

I think I have found a reasonable way to fix my problem. I figured out it is possible to define new autoplace controls ("sliders in the menu") and assign them to the autoplace property of my tiles. That way I can remove these properties from specific surfaces and make sure to set "default_enable_all_autoplace_controls" to false.

This looks like a better, more reliable way to disable autoplace instead of setting probability to -1000. It is also very easy to disable all other autoplace properties for a surface this way, by simply replacing the whole autoplace_controls of the map gen settings.

Danacus
Inserter
Inserter
Posts: 29
Joined: Sun Sep 18, 2016 5:25 pm
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by Danacus »

Another update. If you don't want to have tiles placed automatically, you can set the "default_enabled" property of the autoplace specification to false. This way you no longer have to hack other surfaces. However, changing the autoplace_controls in the map gen settings to include these tiles, does not have any effect. What does work is putting them in the autoplace_settings. I have no idea what the difference between autoplace controls and settings is. Maybe it's a temporary thing and they plan to move it all into autoplace_settings?

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by PyroFire »

Danacus wrote:
Sat Dec 21, 2019 12:57 pm
That way I can remove these properties from specific surfaces and make sure to set "default_enable_all_autoplace_controls" to false.
This is not neccessarily a good way to setup your map gen settings.
This will prevent any undefined autoplace controls from spawning (e.g. iron-ore), and will force you to define them all manually (which planetorio does - it's somewhat cleaner for me to do it this way).

But i didn't make planetorio to make a single planet / map generator like you are.
I made planetorio so i could have lots of them, and from multiple mods without conflicting with eachother.
So we're coming from wildly different angles.
Danacus wrote:
Sat Dec 21, 2019 1:30 pm
I have no idea what the difference between autoplace controls and settings is.
An autoplace control is something that is defined with autoplacements but controlled by a single "autoplace control name", e.g. "trees" can be used to place tree-01 ... tree-09.
An autoplace setting is used to control the frequency/size/richness values for individual "things".
E.g. i can set the "tree" autoplace control to 1000,1000,1000 but then set autoplace_settings.entity.settings.tree-01 to 0,0,0. This should give me normal trees, but never tree-01.
This is why some things can appear both the autoplace controls and autoplace settings.

Danacus
Inserter
Inserter
Posts: 29
Joined: Sun Sep 18, 2016 5:25 pm
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by Danacus »

That makes sense, thanks for your reply and sorry for the late response.

In my case setting "default_enable_all_autoplace_controls" to false makes sense, but I understand that it's often not what you want and it would be a hassle to enable everything manually.

Honktown
Smart Inserter
Smart Inserter
Posts: 1037
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Question about Noise Expressions and autoplacing new tiles

Post by Honktown »

https://lua-api.factorio.com/latest/Con ... cification

Code: Select all

default_enabled :: boolean
Have you seen what that does? Try false and only adding the resource to your map_gen_settings.autoplace_controls when you're making your surface to see if that'd enable it

Noise expressions are the pseudo-math that pushes the buttons on the noise-expression calculator to make it give you back a value, which the engine turns into a yes/no/richness/etc. I've noticed there is another step, probably part of the deterministic noise/random process, which actually decides if the probability of the value is "enough" to turn it into an is/isnt. Not sure where that is, but the probability function returns a value, and it IS NOT that over some value like 1 makes something, and less than that to 0 doesn't. Negative values don't make stuff, so that's a reliable cut-off, and likewise, over 1 seems to be a 100% guarantee. In-between 0 and 1, no idea.

I was playing with noise expressions, and some don't like variables:

Edit: had wrong code section

Code: Select all

data:extend{
  {  
    type = "noise-expression",
    name = "evat",
    intended_property = "elevation",
    expression = {
      type = "if-else-chain",
      arguments = {
        {
          arguments = {
            x = {
              --literal_value = -120,
              --type = "literal-number"
              type = "variable",
              variable_name = "x"
              
            },
            {
              literal_value = 20,
              type = "literal-number"
            }
          },
          --literal_value = true,
          function_name = "add",
          type = "function-application"
        },
        {
          literal_value = -100,
          type = "literal-number"
        },
        {
          literal_value = 100,
          type = "literal-number"
        }
      }
    }
  }
}
end
If you do that, you get an error, but if you comment the variable part and put in the literal number, it works fine. I don't know if I had made a mistake, but it looks like that code should work, but it doesn't. I tried the noise.define_noise_expression function, and putting x for the first value to clamp also throws an error, while a number doesn't.

I think intended property refers to the properties in these:
https://lua-api.factorio.com/latest/Con ... enSettings
property_expression_names :: dictionary string → string: Overrides for tile property value generators. Values either name a NamedNoiseExpression or can be literal numbers, stored as strings (e.g. "5"). All other controls can be overridden by a property expression names. Notable properties:
moisture - a value between 0 and 1 that determines whether a tile becomes sandy (low moisture) or grassy (high moisture).
aux - a value between 0 and 1 that determines whether low-moisture tiles become sand or red desert.
temperature - provides a value (vaguely representing degrees Celsius, varying between -20 and 50) that is used (together with moisture and aux) as part of tree and decorative placement.
elevation - tiles values less than zero become water. Cliffs are placed along certain contours according to CliffPlacementSettings.
cliffiness - determines whether (when >0.5) or not (when <0.5) a cliff will be placed at an otherwise suitable (according to CliffPlacementSettings) location.
enemy-base-intensity - a number that is referenced by both enemy-base-frequency and enemy-base-radius. i.e. if this is overridden, enemy base frequency and size will both be affected and do something reasonable. By default, this expression returns a value proportional to distance from any starting point, clamped at about 7.
enemy-base-frequency - a number representing average number of enemy bases per tile for a region, by default in terms of enemy-base-intensity.
enemy-base-radius - a number representing the radius of an enemy base, if one were to be placed on the given tile, by default proportional to a constant plus enemy-base-intensity.
Looking there, there might be something VERY USEFUL!
All other MapGenSettings feed into named noise expressions, and therefore placement can be overridden by including the name of a property in this dictionary. The probability and richness functions for placing specific tiles, entities, and decoratives can be overridden by including an entry named {tile|entity|decorative}:(prototype name):{probability|richness}.

Code: Select all

local surface = game.player.surface
local mgs = surface.map_gen_settings
mgs.property_expression_names["tile:grass1:probability"] = "my-alternate-grass1-probability"
surface.map_gen_settings = mgs
We could try setting the default resource's probability expression to one that does nothing if default_enabled doesn't work in a useful (to us) way, and then try entity:myresource:probability to whatever noise expression we want (either or both probability/richness)

Edit: see code section, had wrong stuff copied
I have mods! I guess!
Link

Post Reply

Return to “Modding help”