Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen-common/player.js
Show First 20 Lines • Show All 462 Lines • ▼ Show 20 Lines | for (let i = 0; i < numPlayers; ++i) | ||||
// Add treasure if too few resources for a civic center | // Add treasure if too few resources for a civic center | ||||
let ccCost = Engine.GetTemplate("structures/" + getCivCode(playerIDs[i]) + "/civil_centre").Cost.Resources; | let ccCost = Engine.GetTemplate("structures/" + getCivCode(playerIDs[i]) + "/civil_centre").Cost.Resources; | ||||
for (let resourceType in ccCost) | for (let resourceType in ccCost) | ||||
{ | { | ||||
let treasureTemplate = g_NomadTreasureTemplates[resourceType]; | let treasureTemplate = g_NomadTreasureTemplates[resourceType]; | ||||
let count = Math.max(0, Math.ceil( | let count = Math.max(0, Math.ceil( | ||||
(ccCost[resourceType] - (g_MapSettings.StartingResources || 0)) / | (ccCost[resourceType] - (g_MapSettings.StartingResources || 0)) / | ||||
Engine.GetTemplate(treasureTemplate).ResourceSupply.Amount)); | Engine.GetTemplate(treasureTemplate).Treasure.Resources[resourceType])); | ||||
objects.push(new SimpleObject(treasureTemplate, count, count, 3, 5)); | objects.push(new SimpleObject(treasureTemplate, count, count, 3, 5)); | ||||
} | } | ||||
// Try place these entities at a random location | // Try place these entities at a random location | ||||
let group = new SimpleGroup(objects, true, playerClass); | let group = new SimpleGroup(objects, true, playerClass); | ||||
let success = false; | let success = false; | ||||
for (let distanceFactor of [1, 1/2, 1/4, 0]) | for (let distanceFactor of [1, 1/2, 1/4, 0]) | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | function partitionPlayers(playerIDs) | ||||
teams.sort((a, b) => b.length - a.length); | teams.sort((a, b) => b.length - a.length); | ||||
// Use the greedy algorithm: add the next team to the side with fewer players | // Use the greedy algorithm: add the next team to the side with fewer players | ||||
return teams.reduce(([east, west], team) => | return teams.reduce(([east, west], team) => | ||||
east.length > west.length ? | east.length > west.length ? | ||||
[east, west.concat(team)] : | [east, west.concat(team)] : | ||||
[east.concat(team), west], | [east.concat(team), west], | ||||
[[], []]); | [[], []]); | ||||
Lint: ESLintBear (indent): `Expected indentation of 1 tab but found 2.` | |||||
} | } | ||||
/** | /** | ||||
* Determine player starting positions on a circular pattern. | * Determine player starting positions on a circular pattern. | ||||
*/ | */ | ||||
function playerPlacementCircle(radius, startingAngle = undefined, center = undefined) | function playerPlacementCircle(radius, startingAngle = undefined, center = undefined) | ||||
{ | { | ||||
let startAngle = startingAngle !== undefined ? startingAngle : randomAngle(); | let startAngle = startingAngle !== undefined ? startingAngle : randomAngle(); | ||||
▲ Show 20 Lines • Show All 271 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Expected indentation of 1 tab but found 2.