Index: binaries/data/mods/public/gui/session/input.js =================================================================== --- binaries/data/mods/public/gui/session/input.js +++ binaries/data/mods/public/gui/session/input.js @@ -63,6 +63,17 @@ const g_FreehandSelection_MinNumberOfUnits = 2; /** + * To change from FreehandSelection to freehandFormation function you need a minimum number of units. + * Minimum must be 5, for better performance you could set it higher. + */ +const g_FreehandFormation_MinNumberOfUnits = 5; + +/** + * Says how many units stand behind in a line. + */ +const g_FreehandFormation_DeepOfLine = 4; + +/** * Number of pixels the mouse can move before the action is considered a drag. */ const g_MaxDragDelta = 4; @@ -1193,10 +1204,24 @@ return !!action && doAction(action, ev); } + // Change to freehand formation position. + let freehandFormation = false; +// if (ev.button == ALT && selection.length >= g_FreehandFormation_MinNumberOfUnits) + freehandFormation = true; + // Even distribution of the units on the line. let p0 = inputLine[0]; let entityDistribution = [p0]; - let distanceBetweenEnts = lengthOfLine / (selection.length - 1); + let distanceBetweenEnts; + if (freehandFormation == true) + { + distanceBetweenEnts = lengthOfLine / (Math.ceil(selection.length / g_FreehandFormation_DeepOfLine) - 1); + let v0 = Vector2D.sub(inputLine[1], inputLine[0]).perpendicular().normalize().mult(3); + for (let i = 1; i < g_FreehandFormation_DeepOfLine; ++i) + entityDistribution.push(Vector2D.add(p0, Vector2D.mult(v0, i))); + } + else + distanceBetweenEnts = lengthOfLine / (selection.length - 1); let freeDist = -distanceBetweenEnts; for (let i = 1; i < inputLine.length; ++i) @@ -1209,11 +1234,23 @@ p0 = Vector2D.sub(p0, p1).normalize().mult(freeDist).add(p1); entityDistribution.push(p0); freeDist -= distanceBetweenEnts; + if (freehandFormation == true) + { + let v0 = Vector2D.sub(inputLine[i], inputLine[i - 1]).perpendicular().normalize().mult(3); + for (let j = 1; j < g_FreehandFormation_DeepOfLine; ++j) + entityDistribution.push(Vector2D.add(p0, Vector2D.mult(v0, j))); + } } } // Rounding errors can lead to missing or too many points. - entityDistribution.slice(0, selection.length); + if (freehandFormation == true) + { + let v0 = Vector2D.sub(inputLine[inputLine.length - 1], inputLine[inputLine.length - 1 - g_FreehandFormation_DeepOfLine]).perpendicular().normalize().mult(3); + for (let i = 0; i < g_FreehandFormation_DeepOfLine; ++i) + entityDistribution.push(Vector2D.add(inputLine[inputLine.length -1], Vector2D.mult(v0, i))); + } + entityDistribution = entityDistribution.slice(0, selection.length); entityDistribution = entityDistribution.concat(new Array(selection.length - entityDistribution.length).fill(inputLine[inputLine.length - 1])); if (Vector2D.from3D(GetEntityState(selection[0]).position).distanceTo(entityDistribution[0]) + @@ -1230,8 +1267,10 @@ "queued": Engine.HotkeyIsPressed("session.queue") }); - // Add target markers with a minimum distance of 5 to each other. + // Add target markers with a minimum distance of 5 to each other. Shows only markers in a line. let entitiesBetweenMarker = Math.ceil(5 / distanceBetweenEnts); + if (freehandFormation == true) + entitiesBetweenMarker *= g_FreehandFormation_DeepOfLine; for (let i = 0; i < entityDistribution.length; i += entitiesBetweenMarker) DrawTargetMarker({ "x": entityDistribution[i].x, "z": entityDistribution[i].y });