As soon as you can read a unit's coordinates you need angles and distances - which way to send something, how far apart two units are. All of it already exists as functions.
| atan2(y, x) | Angle from coordinates, 0 to 360. |
|---|---|
| lengthdir(length, angle) | x and y from an angle and a length - the inverse of atan2. |
| sqrt(n) | Square root. A distance is sqrt(x*x + y*y). |
atan2_256 changed behaviour in euddraft 0.9.9.8. The official example checks atan2_256(10, 10) >= 90 once to work out which side of that it is on and swaps the argument order accordingly. If you lift someone's code and your angles are ninety degrees out, this is why.
Binary search is the more interesting one. When a condition only answers true or false but you need a number - how many units are in a location - people write code that narrows it a bit at a time. There is already a function for that.
function helperFunc(x) {
const location = getcurpl() + ($L("P1 Area") + 1);
return l2v(Bring(P8, AtLeast, x, "Men", location));
}
// 조건을 만족하는 가장 큰 x = 그 로케이션의 유닛 수
const count = EUDBinaryMax(helperFunc, 0, 200);Narrowing the range is not free of consequence. The default is 0 to 0xFFFFFFFF, so for something with a known ceiling like a unit count, pass that ceiling - it takes the search from 32 steps down to about 8.
