1
0
forked from mirrors/0ad
Commit Graph

66 Commits

Author SHA1 Message Date
phosit df5cdbe8f1 Load map scripts as modules
Because its a function `GenerateMap` is renamed to `generateMap`.

Allows to rewrite the libraries as modules and to remove the costum
`Engine.LoadLibrary` mechanism in the future.
2025-06-14 09:10:47 +02:00
Ralph Sennhauser 76a50d1828 Fix eslint rule 'no-floating-decimal'
eslint --no-config-lookup --fix --rule '"no-floating-decimal": 1'

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-13 14:09:58 +02:00
real_tabasco_sauce fe16b919fe add placement options for many maps 2024-10-23 18:37:35 +02:00
phosit a0a4ca56a5 Remove setSelectedBiome
Since Atlas now supports biomes, defaulting the biome isn't required
anymore.
2024-09-26 19:47:36 +02:00
phosit e01ea16ae5 Adopt the generator based interface by generated maps
- Adding the function signature
- Changing `g_Map.ExportMap()` to `return g_Map`
- Changing `Engine.SetProgress(NN)` to `yield NN`
- Changing `const g_Map = ...` to `globalThis.g_Map = ...`
- On some maps using the argument `mapSettings`

Comments By: @asterix, @sera, @Stan
Differential Revision: https://code.wildfiregames.com/D5258
This was SVN commit r28119.
2024-06-21 15:19:13 +00:00
phosit a178b3fcb3 Add scope in map generation scripts
Summary:
Preparation to use the generator based interface.

Removes many globals. (but doesn't reduce their scope by much)
Refs: #4964

Comments By: @sera @elexis
Differential Revision: https://code.wildfiregames.com/D5285
This was SVN commit r28117.
2024-06-18 16:26:36 +00:00
marder 04ce68f42e rmgen: var -> let -> const
One should always use the variable declaration with the least possible
scope.
This patch cleans up many (but not all) of the `var` in rmgen and
replaces them with `let` or `const`.
The same is done for `let` -> `const`.

comments by: @sera @Stan
Differential revision: https://code.wildfiregames.com/D5214
This was SVN commit r28036.
2024-02-17 11:13:52 +00:00
Freagarach 73f732dc30 Replace chicken in the random maps folder with startingAnimal.
Which is more generic. It means we don't have `chicken = oPeacock` and
the like anymore.
It adds a default scaling function such that people replacing the
animals are puzzled by the different number of starting animals./To keep
the amount of food roughly equal to the amount standard provide by
chicken.

Patch by: @marder
Differential revision: https://code.wildfiregames.com/D4472
Comments by: @smiley, @Stan
This was SVN commit r26381.
2022-02-15 07:04:49 +00:00
elexis e5349abdcd Separate object-oriented random map generation core library "rmgen" from miscellaneous helper procedures which are moved to a new library "rmgen-common", refs #4804, #5042.
This way mods can use the placement and painting prototypes while
excluding any common 0ad code.

This was SVN commit r21289.
2018-02-20 19:39:04 +00:00
elexis 833ab874a9 Let SimpleObject also avoid other SimpleObjects within the same SimpleGroup following 0e0ed94926, refs #6.
Fixes unreachable small stone mines inside large stone mines.
Fixes #4338.

Differential Revision: https://code.wildfiregames.com/D189
Credit rapidelectron for working out the two main issues (refs
63e77de94e) and providing a similar patch.

This was SVN commit r21283.
2018-02-20 03:44:17 +00:00
elexis cacbdf7b1a Pass Infinity to the ChainPlacer if failed tiles should be ignored, rather than different numbers above 1 that have the same effect, refs #4805.
This was SVN commit r21141.
2018-02-07 16:39:36 +00:00
elexis a6e4c5142a On Persian Highlands, allow players to chose the summer or spring variant in the gamesetup, refs #4954.
Add Hannibal_Barca's biome descriptions on Gulf Of Bothnia and Persian
Highlands.

This was SVN commit r21090.
2018-01-31 19:51:23 +00:00
elexis b5b384da48 Implement rmgen JS logger that measures the time for each procedure and prints logmessages to stdout, fixes #4950.
Allows to identify performance bottlenecks quickly and provides a better
sense of progress when viewing stdout.

This was SVN commit r21073.
2018-01-30 00:11:11 +00:00
elexis f27743348e Delete good old paintClass and unPaintClass proxies and create the painters directly, like we do with the other painters too.
This was SVN commit r21001.
2018-01-24 05:11:52 +00:00
elexis 2177a2dca7 Delete createTileClass proxy, refs #4964.
Even though it prolongs the code, OOP should be prefered.

This was SVN commit r21000.
2018-01-24 05:02:49 +00:00
elexis d662ab5a0f Move getMapSize to the RandomMap object, refs #4964.
This was SVN commit r20997.
2018-01-24 04:28:30 +00:00
elexis 1242356f95 Move getMapCenter and getMapBounds to the RandomMap object, refs #4964.
The reference to the global should not be hidden behind a proxy function
and
object orientation is preferable over procedural code in general.

This was SVN commit r20996.
2018-01-24 04:21:22 +00:00
elexis b11563ddff Delete InitMap and ExportMap proxies and let the random map define the RandomMap object, refs #4804.
Eventually there should be no direct reference to g_Map in the library,
refs #4964.

This was SVN commit r20995.
2018-01-24 04:10:00 +00:00
elexis 6550d3a71c Pass vectors to the ChainPlacer instead of the components individually, refs #4992, #4845.
Support non-integer numbers.

This was SVN commit r20974.
2018-01-23 03:40:39 +00:00
elexis c5b7ecefa1 Delete BaseHeight property from random map JSON files and rmgen library, refs #6, #4973, 9ee44bd9b8, 0e0ed94926.
The height is only a concern to the random map script, not the rmgen
library, nor the gamesetup, nor the simulation.

Reveals the actual initial elevation to the random map script author
without looking up the JSON file.
Group and rename all height constants of random maps below the template
names.
Rename waterHeight to heightSeaGround to prevent confusion with the
actual waterlevel.
Remove useless paintTerrainBasedOnHeight calls on African Plains and
Polar Sea.

This was SVN commit r20904.
2018-01-18 13:57:11 +00:00
elexis 1ad10e5999 Merge InitMap, initTerrain and resetTerrain successors from 6d33c2eab7.
Lets the random map script decide which baseTerrain and baseHeight it
wants to use before initializing the map,
rather than painting what is in the JSON file, then changing ones mind
and painting something else on top of it.
This cleaner heightmap initialization incidentally addresses the
uninitialized border of the heightmap in that commit (excluding the
Unknown).

This was SVN commit r20900.
2018-01-17 23:27:06 +00:00
elexis 4263fae6c2 Don't call it centerOfMap, center, mid, centerX, centerZ, fractionToTiles(0.5), Math.round(fractionToTiles(0.5)), mapSize / 2, mapSize * 0.5, but just mapCenter everywhere and get it from the library.
Fixes #4854, refs #4845.

This was SVN commit r20892.
2018-01-17 01:55:45 +00:00
elexis 442c9848b8 Merge all playerX and playerZ arrays into one array of Vector2D items.
This way random map scripts can do vector math and pass the result to
library functions that do further vector math on them and leave shorter
code, refs #4845.
Pass tilegrid coordinates rather than percent numbers to the playerbase
functions too, refs #4939.
Some more mapCenter calls, refs #4854.

This was SVN commit r20882.
2018-01-16 04:39:31 +00:00
elexis c74bd3425f Nomad mode on all random map scripts (except Survival of the Fittest), fixes #3591.
Fine-tune random map scripts if nomad mode is enabled by omitting gaia
attackers and vast voids.
Fix nomad units on the Unknown sometimes being stuck on mountains or
tiny islands, refs #3140.

Discussed with: bb

This was SVN commit r20866.
2018-01-14 00:59:06 +00:00
elexis b838e57770 Clean some random map script comments.
This was SVN commit r20852.
2018-01-13 21:16:27 +00:00
elexis 08f561c02d Remove Math.sin, cos and PI proxy functions from rmgen. Fixes #4933.
This was SVN commit r20816.
2018-01-11 03:16:31 +00:00
elexis 921850cdef Implement random map script playerbase function.
Unifies 54 variants of the rmgen playerbase code, fixes #4805.

Add retry loops to prevent collisions of starting resources, fixes #4600
and
resources placed outside of the map area, fixes #4796.

Lays the foundation to test for collisions with Iberian walls, refs
#2192 and
allows to rearrange the starting resources on all random maps without
being confronted with code.

Delete remains of misc.js, leaving the rmgen files sorted by logic,
fixes #4804.
Concludes what was started in 5f1736cbd4, f98100bdaf, specifically the
82 rmgen commits starting f2550705d3, 376d8b3d1e.
Uses vector algebra, refs #4845.
Removes many Math proxy calls, refs #4933.
Removes 35 unused elevation and 24 unused cliffRadius variables,
demonstrating the copy&paste antipattern.
Reduce iberian-wall hardcoding to one line, refs #4940.

This was SVN commit r20815.
2018-01-11 00:35:01 +00:00
elexis 2414e4946e Replace TWO_PI with 2 * Math.PI, refs #4933.
This was SVN commit r20798.
2018-01-07 20:32:43 +00:00
elexis 4bc8dc9ed4 Remove rmgen Math.round proxy, refs #4933.
This was SVN commit r20796.
2018-01-07 20:18:31 +00:00
elexis a554a7c1ed Remove rmgen Math.abs proxy, refs #4933.
This was SVN commit r20795.
2018-01-07 19:57:30 +00:00
elexis 92fe7445e4 Remove rmgen Math.floor proxy, refs #4933.
This was SVN commit r20794.
2018-01-07 19:45:48 +00:00
elexis 69b7f39bf1 Rename RMS to Engine.
This was SVN commit r20525.
2017-11-25 22:17:01 +00:00
elexis ac8f4f49fc Delete the remains of rmgen/utilityfunctions.js, refs #4804 by
cleaning up the createForests function.

Remove g_numStragglerTrees and clForest references from the rmgen
library.
Compute the number of forest- and straggler trees in a new function
instead of hiding it and obstructing the placement code.
Remove unused numMultiplier argument.

Replace duplication of these three functions with calls to them, refs
#4805.
Remove duplicate random biome JSON constants of the Islands, Migration
and Snowflake Searocks map.
There is significant partial createForests duplication that should be
unified eventually.

This was SVN commit r20406.
2017-11-04 13:04:54 +00:00
elexis 376d8b3d1e Cleanup most createArea and some createObjectGroup calls in random map scripts.
Inline the placer, terrainPainter, elevationPainter, group and sizes
helper variables that are used only once.
Thus do not hoist variable declarations from unrelated scopes.
Remove few dozens of painters that are overpainted by the
paintBasedOnTerrainHeight call afterwards.
Remove 334 noisy misaligned code comments (// terrains // widths //
blend radius and // some variation).
Label the createArea calls so that the reader knows what they do.
Remove unbenefitial Math.PI/8 grass min/max angle limitation.
Use height variables for the SmoothElevationPainter calls so that levels
can be modified more easily.
Use Math prototype functions instead of the unfortunate rmgen proxies.
Does not touch starting base code, Unknown maps, Snowflake Searocks and
Corsica & Sardinia which need special treatment.

This was SVN commit r20301.
2017-10-15 17:53:12 +00:00
elexis 6656ec6de6 Remove about 360 unused variables in random map scripts, refs #4805.
Remove unused hasTextureInRadius from 9016b8d866.

This was SVN commit r20294.
2017-10-14 14:25:53 +00:00
elexis 635e608776 Unify 36 copies of the radial playerplacement loop of random mapscripts.
Trim unused PlayerAngle, StartAngle and baseRadius variables.

This was SVN commit r20149.
2017-09-09 19:12:28 +00:00
elexis 4477bcfb7e Replace 55 playerarray sorting loops copies with calls to two random mapgen helper functions.
Rename randomizePlayers as it paradoxically called sortPlayers on the
result.

This was SVN commit r20148.
2017-09-09 16:49:35 +00:00
elexis 45bb3d2a43 Remove 23 copies of the random mapgen terrain init loop (including 16 copies of unused x and z vars).
This was SVN commit r20146.
2017-09-09 15:30:44 +00:00
elexis ba36f233fa Remove 1400 useless random map script comments.
This was SVN commit r20144.
2017-09-09 14:41:50 +00:00
Imarok a639050a41 Fix SimpleGroup and RandomGroup placement retries
Reviewed by: FeXoR. Fixes: #4294
Differential Revision: https://code.wildfiregames.com/D249
This was SVN commit r19929.
2017-07-29 21:02:09 +00:00
elexis 175cded64a Replace deprecated randInt calls (besides those in the Unknown maps).
Differential Revision: https://code.wildfiregames.com/D278
Patch By: bb
Refs #4326

This was SVN commit r19443.
2017-04-21 21:45:00 +00:00
elexis da2b89583a Replace many deprecated randInt calls with randBool.
Add optional probability to randBool to receive true and use where
applicable.

Patch By: bb
Differential Revision: https://code.wildfiregames.com/D235
Refs #4326 D121

This was SVN commit r19355.
2017-03-28 04:28:55 +00:00
elexis 944ba16eb4 End source files with a newline.
This was SVN commit r18988.
2016-11-23 11:27:54 +00:00
elexis d999fc4be5 Prevent collisions of straggler trees with mines. Reviewed by FeXoR on 2016-10-29.
This was SVN commit r18953.
2016-11-16 13:57:04 +00:00
elexis f92279bbef Remove unused clWater and clRiver tile class from maps that don't have water nor rivers.
Remove pointless restraint checks on clWater on oasis before the water
is painted.

This was SVN commit r18872.
2016-10-27 12:20:54 +00:00
elexis 15dd804112 Remove trailing whitespace of all map scripts (as in all whitespace that doesn't come before any non-whitespace character on the same line).
This was SVN commit r18840.
2016-10-18 13:08:01 +00:00
elexis f24fd75577 Add missing semicolons found with jshint to all map scripts.
This was SVN commit r18839.
2016-10-18 12:52:00 +00:00
elexis 5f1736cbd4 Don't place chicken inside civic centers and unify chicken placement code. Reviewed by FeXoR, fixes #3836.
This was SVN commit r18816.
2016-10-09 15:07:48 +00:00
FeXoR 1c5a7f6267 Moved BUILDING_ANGlE from the maps to BUILDING_ORIENTATION in a random map lib. Made some arguments optional with the default set to that constant, renamed some arguments and moved "orientation" in placeCivDefaultEntities to kwargs. Removed unneeded comments. Fixes #3988
This was SVN commit r18198.
2016-05-19 14:48:21 +00:00
leper 072afdcede Fix line endings for random maps.
This was SVN commit r16476.
2015-03-30 23:41:12 +00:00