Index: binaries/data/mods/public/maps/random/rmgen-common/player.js =================================================================== --- binaries/data/mods/public/maps/random/rmgen-common/player.js +++ binaries/data/mods/public/maps/random/rmgen-common/player.js @@ -244,7 +244,6 @@ function placePlayerBaseStartingAnimal(args) { const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args); - const template = get("template", "gaia/fauna_chicken"); const count = template === "gaia/fauna_chicken" ? 5 : Math.round(5 * (Engine.GetTemplate("gaia/fauna_chicken").ResourceSupply.Max / Engine.GetTemplate(get("template")).ResourceSupply.Max)); @@ -252,28 +251,34 @@ for (let i = 0; i < get("groupCount", 2); ++i) { let success = false; - for (let tries = 0; tries < get("maxTries", 30); ++tries) + for (let radius = get("minRadius", 5); radius < get("maxRadius", 13); ++radius) { - const position = new Vector2D(0, get("distance", 9)).rotate(randomAngle()).add(basePosition); - if (createObjectGroup( - new SimpleGroup( - [ - new SimpleObject( - template, - get("minGroupCount", count), - get("maxGroupCount", count), - get("minGroupDistance", 0), - get("maxGroupDistance", 2)) - ], - true, - args.BaseResourceClass, - position), - 0, - baseResourceConstraint)) + const startAngle = randomAngle(); + for (let angle = 0; angle < 360; angle += get("angleStep", 15)) { - success = true; - break; + const position = new Vector2D(0, get("radius", radius)).rotate(startAngle + incremental * Math.PI / 180).add(basePosition) + if (createObjectGroup( + new SimpleGroup( + [ + new SimpleObject( + template, + get("minGroupCount", count), + get("maxGroupCount", count), + get("minGroupDistance", 0), + get("maxGroupDistance", 2)) + ], + true, + args.BaseResourceClass, + position), + 0, + baseResourceConstraint)) + { + success = true; + break; + } } + if (success) + break; } if (!success) @@ -284,22 +289,28 @@ } } + function placePlayerBaseBerries(args) { - const [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args); - for (let tries = 0; tries < get("maxTries", 30); ++tries) - { - const position = new Vector2D(0, get("distance", 12)).rotate(randomAngle()).add(basePosition); - if (createObjectGroup( - new SimpleGroup( - [new SimpleObject(args.template, get("minCount", 5), get("maxCount", 5), get("maxDist", 1), get("maxDist", 3))], - true, - args.BaseResourceClass, - position), - 0, - baseResourceConstraint)) - return; - } + let [get, basePosition, baseResourceConstraint] = getPlayerBaseArgs(args); + let success = false; + for (let radius = get("maxRadius", 12); radius > get("minRadius", 7); --radius) + { + const startAngle = randomAngle(); + for (let angle = 0; angle < 360; angle += get("angleStep", 15)) + { + let position = new Vector2D(0, get("radius", radius)).rotate(startAngle + incremental * Math.PI / 180).add(basePosition) + if (createObjectGroup( + new SimpleGroup( + [new SimpleObject(args.template, get("minCount", 5), get("maxCount", 5), get("maxDist", 1), get("maxDist", 3))], + true, + args.BaseResourceClass, + position), + 0, + baseResourceConstraint)) + return; + } + } error("Could not place berries for player " + args.playerID); } @@ -315,44 +326,47 @@ if (args.groupElements) groupElements = groupElements.concat(args.groupElements); - for (let tries = 0; tries < get("maxTries", 75); ++tries) + for (let radius = get("maxRadius", 12); radius > get("minRadius", 7); --radius) { - // First find a place where all mines can be placed - let pos = []; const startAngle = randomAngle(); - for (let i = 0; i < mineCount; ++i) + for (let angle = 0; angle < 360; angle =+ get("angleStep", 15)) { - const angle = startAngle + angleBetweenMines * (i + (mineCount - 1) / 2); - pos[i] = new Vector2D(0, get("distance", 12)).rotate(angle).add(basePosition).round(); - if (!g_Map.validTilePassable(pos[i]) || !baseResourceConstraint.allows(pos[i])) + // First find a place where all mines can be placed + let pos = []; + for (let i = 0; i < mineCount; ++i) { - pos = undefined; - break; + const angle2 = startAngle + angleBetweenMines * (i + (mineCount - 1) / 2); + pos[i] = new Vector2D(0, get("radius", radius)).rotate(angle2 + angle * Math.PI /180).add(basePosition).round(); + if (!g_Map.validTilePassable(pos[i]) || !baseResourceConstraint.allows(pos[i])) + { + pos = undefined; + break; + } } - } - if (!pos) - continue; + if (!pos) + continue; - // Place the mines - for (let i = 0; i < mineCount; ++i) - { - if (args.types[i].type && args.types[i].type == "stone_formation") + // Place the mines + for (let i = 0; i < mineCount; ++i) { - createStoneMineFormation(pos[i], args.types[i].template, args.types[i].terrain); - args.BaseResourceClass.add(pos[i]); - continue; - } + if (args.types[i].type && args.types[i].type == "stone_formation") + { + createStoneMineFormation(pos[i], args.types[i].template, args.types[i].terrain); + args.BaseResourceClass.add(pos[i]); + continue; + } - createObjectGroup( - new SimpleGroup( - [new SimpleObject(args.types[i].template, 1, 1, 0, 0)].concat(groupElements), - true, - args.BaseResourceClass, - pos[i]), - 0); + createObjectGroup( + new SimpleGroup( + [new SimpleObject(args.types[i].template, 1, 1, 0, 0)].concat(groupElements), + true, + args.BaseResourceClass, + pos[i]), + 0); + } + return; } - return; } error("Could not place mines for player " + args.playerID);