|
| 1 | +# Resources |
| 2 | + |
| 3 | +- data/core/lualib/resource-autoplace.lua |
| 4 | +- https://github.com/wube/factorio-data/blob/2b18d0a/core/lualib/resource-autoplace.lua |
| 5 | +- https://lua-api.factorio.com/1.0.0/Concepts.html#AutoplaceSpecification |
| 6 | + |
| 7 | +# Notes on how stuff works |
| 8 | + |
| 9 | +``` |
| 10 | +return |
| 11 | +{ |
| 12 | + initialize_patch_set = initialize_patch_set, |
| 13 | + resource_autoplace_settings = resource_autoplace_settings |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +`initialize_patch_set` defines spots that resources can spawn on. |
| 18 | +If omitted, it doesn't initially change anything it seems. |
| 19 | + |
| 20 | +However, if the `probability_expression` is changesd, the probability applies to the entire map instead of just some |
| 21 | +blobs. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +``` |
| 26 | +local ret = |
| 27 | +{ |
| 28 | + order = order, |
| 29 | + control = autoplace_control_name, |
| 30 | + probability_expression = probability_expression, |
| 31 | + richness_expression = probability_expression * 100 -- noise.random(800) + 400 |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +`probability_expression` is a value between 0 and 1, indicating the chance that a particular tile will have a resource |
| 36 | +to begin with. If the chance is not actually 0 or 1, but something in between, resources patches will have empty tiles |
| 37 | +scatted across them. |
| 38 | + |
| 39 | +`richness_expression` returns the exact amount of ore for a particular tile. Though I'm not sure how exactly this |
| 40 | +converts to yielding resources, e.g. oil patches. |
| 41 | +- tne(10000) -> 3% |
| 42 | +- tne(100000) -> 33% |
| 43 | +- tne(1000000) -> 333% |
| 44 | + |
| 45 | +Note that this value must be at least 2. The tile won't spawn if it has a richness of less than that. |
| 46 | +Though it will still show up on the preview for map generation if the value is greater than 0. |
| 47 | +Floating point numbers are floored. |
| 48 | + |
| 49 | +Both these values must be noise expressions, a regular number is not enough. You can use the `tne()` that is used in |
| 50 | +this file to convert numbers "To Noise Expression"s. |
| 51 | + |
| 52 | +`noise.delimit_procedure(expression)` doesn't really do anything. |
| 53 | +It only causes outputs by `dump_expression(expression)` to be trimmed as not to clutter the output with a wall of math. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +``` |
| 58 | +{ |
| 59 | + type = "function-application", |
| 60 | + function_name = "random-penalty", |
| 61 | + arguments = |
| 62 | + { |
| 63 | + source = tne(10), |
| 64 | + x = noise.var("x"), |
| 65 | + y = noise.var("y"), |
| 66 | + amplitude = tne(8) |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +`source` is the base value. |
| 72 | + |
| 73 | +`amplitude` is the maximum deviation from that base value. |
| 74 | +In the above example, the effective value is in the range 2..10 |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +``` |
| 79 | +{ |
| 80 | + type = "function-application", |
| 81 | + function_name = "spot-noise", |
| 82 | + arguments = |
| 83 | + { |
| 84 | + x = noise.var("x"), |
| 85 | + y = noise.var("y"), |
| 86 | + seed0 = noise.var("map_seed"), |
| 87 | + seed1 = tne(seed1+1), |
| 88 | + density_expression = litexp(1000), -- litexp(starting_density * starting_modulation_richness), |
| 89 | + spot_quantity_expression = litexp(starting_area_spot_quantity), |
| 90 | + spot_radius_expression = litexp(starting_rq_factor * starting_area_spot_quantity ^ (onethird)), |
| 91 | + spot_favorability_expression = litexp( |
| 92 | + starting_feasibility_richness * 2 - |
| 93 | + 1 * distance / starting_resource_placement_radius + |
| 94 | + noise.random(0.5) |
| 95 | + ), |
| 96 | + basement_value = basement_value, |
| 97 | + maximum_spot_basement_radius = tne(128) -- does making this huge make a difference? |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +`density_expression` seems to practically determine the max distance at which a resource can spawn. |
| 103 | + |
| 104 | +# Variables |
| 105 | + |
| 106 | +The returned expressions can contain variables that will be replaced somewhere in the C++ core I assume. |
| 107 | +These can be included by calling `noise.var("variableName")`. |
| 108 | + |
| 109 | +Known variables: |
| 110 | +- `x`: X coordinate in tiles on the map |
| 111 | +- `y`: Y coordinate in tiles on the map |
| 112 | +- `distance`: Distance in tiles from the center of the map |
| 113 | +- `elevation`: Height of a specific tile |
| 114 | +- `map_seed`: Seed of the map |
| 115 | +- `regular-resource-patch-set-count`: ??? |
| 116 | +- `starting-resource-patch-set-count`: ??? |
0 commit comments