@korial29/tiny-fps 0.138.0 → 0.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +3 -1
- package/dist/index.js +15 -15
- package/dist/local.js +1 -1
- package/dist/server.js +475 -236
- package/dist/types/client/body.d.ts +17 -1
- package/dist/types/client/limbs.d.ts +7 -2
- package/dist/types/client/skin.d.ts +5 -4
- package/dist/types/client/soldier.d.ts +9 -0
- package/dist/types/shared/bot.d.ts +71 -4
- package/dist/types/shared/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -4477,7 +4477,7 @@ var DROP$1 = 2;
|
|
|
4477
4477
|
* fails most, a stair all), how far above it may be (up a stair, or a ledge to climb) and how far
|
|
4478
4478
|
* below: a drop that does not hurt at full gravity.
|
|
4479
4479
|
*/
|
|
4480
|
-
var NEAR =
|
|
4480
|
+
var NEAR = 20;
|
|
4481
4481
|
var ABOVE = 2.2;
|
|
4482
4482
|
/** Two points of the routes this close (metres, and in height) are one. */
|
|
4483
4483
|
var SAME = .6;
|
|
@@ -4859,32 +4859,253 @@ var path = (nav, w, a, b, prefer = -1) => {
|
|
|
4859
4859
|
edges
|
|
4860
4860
|
};
|
|
4861
4861
|
};
|
|
4862
|
+
// src/shared/plasma.ts
|
|
4863
|
+
/** Metres a ball flies in a tick, and an arc. */
|
|
4864
|
+
var PLASMA_STEP = 40 / 60;
|
|
4865
|
+
var ARC_STEP = ARC_SPEED / 60;
|
|
4866
|
+
/** How far shot `n` of the laser rifle drifts off the look, yaw and pitch: a pattern within RIFLE_DRIFT, the same for the host and every client. */
|
|
4867
|
+
var drift = (n) => [RIFLE_DRIFT * Math.sin(n * 2.4), RIFLE_DRIFT * Math.cos(n * 1.7)];
|
|
4868
|
+
/**
|
|
4869
|
+
* The ball of the shot `p` has just fired (`p` is the state after the step that fired): from the
|
|
4870
|
+
* eye of the mode along the look, GUN_RANGE metres to go, named by his `shots` count, as strong
|
|
4871
|
+
* as the shot (`power`). The laser rifle's (the user, 2026-11-08: the gun's balls, in red) has
|
|
4872
|
+
* power 0, RIFLE_RANGE to go, and leaves along the look drifted by its shot's pattern.
|
|
4873
|
+
*/
|
|
4874
|
+
var launch$1 = (p, team = 0) => {
|
|
4875
|
+
const [dy, dp] = p.rifled ? drift(p.shots) : [0, 0];
|
|
4876
|
+
const [yaw, pitch] = [p.yaw + dy, p.pitch + dp];
|
|
4877
|
+
const [sy, cy, sp, cp] = [
|
|
4878
|
+
Math.sin(yaw),
|
|
4879
|
+
Math.cos(yaw),
|
|
4880
|
+
Math.sin(pitch),
|
|
4881
|
+
Math.cos(pitch)
|
|
4882
|
+
];
|
|
4883
|
+
return {
|
|
4884
|
+
id: p.shots,
|
|
4885
|
+
by: p.id,
|
|
4886
|
+
team,
|
|
4887
|
+
x: p.x,
|
|
4888
|
+
y: p.y + eyeHeight(p),
|
|
4889
|
+
z: p.z,
|
|
4890
|
+
dx: -sy * cp,
|
|
4891
|
+
dy: sp,
|
|
4892
|
+
dz: -cy * cp,
|
|
4893
|
+
left: p.rifled ? 60 : 80,
|
|
4894
|
+
burst: false,
|
|
4895
|
+
power: p.rifled ? 0 : p.power ?? 1
|
|
4896
|
+
};
|
|
4897
|
+
};
|
|
4898
|
+
/**
|
|
4899
|
+
* The arc of energy the ARC cut of `p` throws at its strike (`p` the state after that step): from
|
|
4900
|
+
* the eye along the look like a ball, ARC_RANGE metres to go, its CUT in `arc`. Its id is the
|
|
4901
|
+
* `shots` count with the top bit turned, apart from his balls' (one arc is gone before the next).
|
|
4902
|
+
*/
|
|
4903
|
+
var wave = (p, team = 0) => ({
|
|
4904
|
+
...launch$1(p, team),
|
|
4905
|
+
id: p.shots ^ 128,
|
|
4906
|
+
left: ARC_RANGE,
|
|
4907
|
+
power: 1,
|
|
4908
|
+
arc: p.cut
|
|
4909
|
+
});
|
|
4910
|
+
/** Metres the flight `b` goes in a tick. */
|
|
4911
|
+
var stepOf = (b) => b.arc ? ARC_STEP : b.power === 6 ? 2 : PLASMA_STEP;
|
|
4912
|
+
/**
|
|
4913
|
+
* Distance at which the ray from `o` along the unit `d` enters the upright cylinder of radius `r`
|
|
4914
|
+
* on `c`'s feet, `h` tall; Infinity on a miss.
|
|
4915
|
+
*/
|
|
4916
|
+
var cylinder = (o, d, c, r, h) => {
|
|
4917
|
+
const [px, pz] = [o[0] - c.x, o[2] - c.z];
|
|
4918
|
+
const a = d[0] * d[0] + d[2] * d[2];
|
|
4919
|
+
const b = px * d[0] + pz * d[2];
|
|
4920
|
+
const q = b * b - a * (px * px + pz * pz - r * r);
|
|
4921
|
+
let [lo, hi] = [0, Infinity];
|
|
4922
|
+
if (a > 1e-12) {
|
|
4923
|
+
if (q < 0) return Infinity;
|
|
4924
|
+
[lo, hi] = [(-b - Math.sqrt(q)) / a, (-b + Math.sqrt(q)) / a];
|
|
4925
|
+
} else if (px * px + pz * pz > r * r) return Infinity;
|
|
4926
|
+
const [y0, y1] = [c.y - o[1], c.y + h - o[1]];
|
|
4927
|
+
if (d[1]) [lo, hi] = [Math.max(lo, Math.min(y0 / d[1], y1 / d[1])), Math.min(hi, Math.max(y0 / d[1], y1 / d[1]))];
|
|
4928
|
+
else if (y0 > 0 || y1 < 0) return Infinity;
|
|
4929
|
+
return lo <= hi && hi >= 0 ? Math.max(lo, 0) : Infinity;
|
|
4930
|
+
};
|
|
4931
|
+
/**
|
|
4932
|
+
* Flies `b` on by `m` metres (at most what it has left) as a sphere of PLASMA_R: it stops and
|
|
4933
|
+
* bursts on the first brush, or on the first of `foes` whose body (a cylinder PLASMA_R wider, ARC_R
|
|
4934
|
+
* for an arc) it enters. Returns the foe it burst on.
|
|
4935
|
+
*/
|
|
4936
|
+
var fly = (w, b, m, foes) => {
|
|
4937
|
+
const o = [
|
|
4938
|
+
b.x,
|
|
4939
|
+
b.y,
|
|
4940
|
+
b.z
|
|
4941
|
+
];
|
|
4942
|
+
const d = [
|
|
4943
|
+
b.dx,
|
|
4944
|
+
b.dy,
|
|
4945
|
+
b.dz
|
|
4946
|
+
];
|
|
4947
|
+
const go = Math.min(m, b.left);
|
|
4948
|
+
let t = ray(w, o, d, go, PLASMA_R);
|
|
4949
|
+
let hit;
|
|
4950
|
+
for (const f of foes) {
|
|
4951
|
+
const u = cylinder(o, d, f, PLAYER_R + (b.arc ? ARC_R : PLASMA_R), heightOf(f));
|
|
4952
|
+
if (u < t) [t, hit] = [u, f];
|
|
4953
|
+
}
|
|
4954
|
+
b.burst = t < go;
|
|
4955
|
+
b.left -= t;
|
|
4956
|
+
[b.x, b.y, b.z] = [
|
|
4957
|
+
o[0] + d[0] * t,
|
|
4958
|
+
o[1] + d[1] * t,
|
|
4959
|
+
o[2] + d[2] * t
|
|
4960
|
+
];
|
|
4961
|
+
return hit;
|
|
4962
|
+
};
|
|
4963
|
+
/**
|
|
4964
|
+
* The grenade `p` has just launched (`p` the state after that step): from the eye along the look,
|
|
4965
|
+
* with no drift, at NADE_SPEED, NADE_RANGE metres of flight to go. Named by his `shots` like a ball.
|
|
4966
|
+
*/
|
|
4967
|
+
var lob = (p, team = 0) => ({
|
|
4968
|
+
...launch$1({
|
|
4969
|
+
...p,
|
|
4970
|
+
rifled: false
|
|
4971
|
+
}, team),
|
|
4972
|
+
left: 150,
|
|
4973
|
+
power: 7,
|
|
4974
|
+
v: 36
|
|
4975
|
+
});
|
|
4976
|
+
/**
|
|
4977
|
+
* One tick of the grenade `b`: the map's gravity bends its flight, then it flies on as a ball
|
|
4978
|
+
* (fly()) and bursts on the first brush or foe, or at the end of its range. Float32, so the
|
|
4979
|
+
* shooter's client flies the same one.
|
|
4980
|
+
*/
|
|
4981
|
+
var toss = (w, b, foes) => {
|
|
4982
|
+
const f = Math.fround;
|
|
4983
|
+
const [vx, vy, vz] = [
|
|
4984
|
+
b.dx * b.v,
|
|
4985
|
+
b.dy * b.v - gravity(w) / 60,
|
|
4986
|
+
b.dz * b.v
|
|
4987
|
+
];
|
|
4988
|
+
const v = Math.sqrt(vx * vx + vy * vy + vz * vz) || 1;
|
|
4989
|
+
[b.dx, b.dy, b.dz, b.v] = [
|
|
4990
|
+
f(vx / v),
|
|
4991
|
+
f(vy / v),
|
|
4992
|
+
f(vz / v),
|
|
4993
|
+
f(v)
|
|
4994
|
+
];
|
|
4995
|
+
const hit = fly(w, b, b.v / 60, foes);
|
|
4996
|
+
[b.x, b.y, b.z, b.left] = [
|
|
4997
|
+
f(b.x),
|
|
4998
|
+
f(b.y),
|
|
4999
|
+
f(b.z),
|
|
5000
|
+
f(b.left)
|
|
5001
|
+
];
|
|
5002
|
+
b.burst ||= b.left <= 0;
|
|
5003
|
+
return hit;
|
|
5004
|
+
};
|
|
5005
|
+
/**
|
|
5006
|
+
* The health a grenade bursting at `c` takes from `p`: NADE_HP at the body, less with the distance
|
|
5007
|
+
* to its nearest point (the axis, feet to head), nothing from NADE_R on, rounded up. Nothing when
|
|
5008
|
+
* a brush hides both that point and the chest.
|
|
5009
|
+
*/
|
|
5010
|
+
var blast = (w, c, p) => {
|
|
5011
|
+
const h = heightOf(p);
|
|
5012
|
+
const near = [
|
|
5013
|
+
p.x,
|
|
5014
|
+
Math.max(p.y, Math.min(p.y + h, c[1])),
|
|
5015
|
+
p.z
|
|
5016
|
+
];
|
|
5017
|
+
const [dx, dy, dz] = [
|
|
5018
|
+
near[0] - c[0],
|
|
5019
|
+
near[1] - c[1],
|
|
5020
|
+
near[2] - c[2]
|
|
5021
|
+
];
|
|
5022
|
+
const d = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
5023
|
+
return d >= 5 || hidden(w, c, near) && hidden(w, c, [
|
|
5024
|
+
p.x,
|
|
5025
|
+
p.y + .7 * h,
|
|
5026
|
+
p.z
|
|
5027
|
+
]) ? 0 : Math.ceil(5 * (1 - d / 5));
|
|
5028
|
+
};
|
|
4862
5029
|
// src/shared/bot.ts
|
|
4863
5030
|
var { FORWARD, BACK, LEFT, RIGHT, JUMP, SPRINT, DASH, CROUCH, FIRE, RELOAD } = KEY;
|
|
4864
5031
|
/** How far a bot shoots, metres, and how far it sees an enemy to fight. */
|
|
4865
5032
|
var RANGE = 35;
|
|
4866
|
-
/**
|
|
4867
|
-
var REACT = 15;
|
|
4868
|
-
/** The most a bot turns its aim in a tick, radians (6 rad/s). */
|
|
4869
|
-
var TURN$1 = .1;
|
|
4870
|
-
/** Radians off the target a bot still shoots, and the error its aim starts with on a new target. */
|
|
5033
|
+
/** Radians off the target a bot still shoots. */
|
|
4871
5034
|
var CONE = .06;
|
|
4872
|
-
|
|
4873
|
-
|
|
5035
|
+
/** A number in [0, 1) that looks random, the same for the same n. */
|
|
5036
|
+
var frac = (n) => {
|
|
5037
|
+
const s = Math.sin(n * 12.9898) * 43758.5453;
|
|
5038
|
+
return s - Math.floor(s);
|
|
5039
|
+
};
|
|
5040
|
+
/** The character of the bot `id` in a room of this skill. */
|
|
5041
|
+
var personaOf = (id, skill = 4) => {
|
|
5042
|
+
const r = (k) => frac((id + 1) * 7.31 + k);
|
|
5043
|
+
const s = Math.max(0, Math.min(7, skill)) / 7;
|
|
5044
|
+
return {
|
|
5045
|
+
miss: (.3 - .22 * s) * (.75 + .5 * r(1)),
|
|
5046
|
+
react: Math.round((36 - 28 * s) * (.75 + .5 * r(2))),
|
|
5047
|
+
turn: .05 + .09 * s,
|
|
5048
|
+
jumpy: .003 + .012 * r(3),
|
|
5049
|
+
strafe: Math.round(25 + 45 * r(4)),
|
|
5050
|
+
duck: .15 + .75 * s
|
|
5051
|
+
};
|
|
5052
|
+
};
|
|
5053
|
+
/** One jump in DASHY that a fighting bot makes is a dash aside instead; metres it wants open for it. */
|
|
5054
|
+
var DASHY = 2;
|
|
5055
|
+
var ASIDE = 3;
|
|
5056
|
+
/** Seconds ahead a bot looks for a ball coming at it, and how close it must pass, metres, to dash. */
|
|
5057
|
+
var WARN = .5;
|
|
5058
|
+
var CLOSE = 1.3;
|
|
5059
|
+
/** Ticks without a metre of progress before a point close by counts as reached, and before a new way. */
|
|
4874
5060
|
var STUCK_JUMP = 45;
|
|
4875
5061
|
var STUCK_PLAN = 180;
|
|
4876
|
-
/**
|
|
5062
|
+
/**
|
|
5063
|
+
* Ticks a straight run to a goal is kept before a way is looked for again, and the metres the goal
|
|
5064
|
+
* may move before a new way: DRIFT, or that share of the way to it when it is farther.
|
|
5065
|
+
*/
|
|
4877
5066
|
var REPLAN = 120;
|
|
4878
5067
|
var DRIFT = 4;
|
|
5068
|
+
var SHARE = .25;
|
|
5069
|
+
/** Metres over the floor under a player in the air past which he is over a gap, not jumping on a roof. */
|
|
5070
|
+
var HOVER = 4;
|
|
4879
5071
|
/** Metres from the enemy carrier a bot dashes into him: the tackle. */
|
|
4880
5072
|
var TACKLE = 4;
|
|
4881
5073
|
/** Metres a bot without a gun goes out of its way to the rack. */
|
|
4882
5074
|
var ARM = 30;
|
|
4883
|
-
/**
|
|
5075
|
+
/**
|
|
5076
|
+
* Metres ahead a walking bot looks for a wall or a drop, the seconds of its speed it looks for the
|
|
5077
|
+
* floor further on (it does not stop at once), and the share of the drop that hurts it will walk into.
|
|
5078
|
+
*/
|
|
4884
5079
|
var AHEAD = 1.5;
|
|
5080
|
+
var BRAKE = .3;
|
|
4885
5081
|
var SAFE = .8;
|
|
4886
|
-
/**
|
|
4887
|
-
var
|
|
5082
|
+
/** The turns off its way a walking bot tries round a wall or a drop, radians, nearest first: back a little, last. */
|
|
5083
|
+
var DETOURS = [
|
|
5084
|
+
0,
|
|
5085
|
+
.5,
|
|
5086
|
+
-.5,
|
|
5087
|
+
1,
|
|
5088
|
+
-1,
|
|
5089
|
+
1.5,
|
|
5090
|
+
-1.5,
|
|
5091
|
+
2,
|
|
5092
|
+
-2
|
|
5093
|
+
];
|
|
5094
|
+
/** The highest box a bot jumps onto on its way, metres (a standing jump lands on 1.7 m), and the floor it wants behind its edge. */
|
|
5095
|
+
var HOP = 1.6;
|
|
5096
|
+
var HOP_DEPTH = 2.5;
|
|
5097
|
+
/** The most a walking bot turns in a tick (12 rad/s), and the turn past which it stops sprinting to strafe. */
|
|
5098
|
+
var WALK_TURN = .2;
|
|
5099
|
+
var SWING = .6;
|
|
5100
|
+
/** Metres of open floor a bot wants ahead to dash, the least way left to bother, and ticks between two of its dashes. */
|
|
5101
|
+
var DASH_RUN = 7;
|
|
5102
|
+
/** Metres more a dash on a route's run wants before the run's end: its speed takes that to fall back. */
|
|
5103
|
+
var LEG_ROOM = 6;
|
|
5104
|
+
/** Metres of floor a dash wants each side of its run. */
|
|
5105
|
+
var WIDE = 1.2;
|
|
5106
|
+
var DASH_FAR = 8;
|
|
5107
|
+
var DASH_GAP = 120;
|
|
5108
|
+
/** Metres of floor a bot wants on the side it strafes to. */
|
|
4888
5109
|
var SIDE = 1.5;
|
|
4889
5110
|
/** The bots whose id is GUARD - 1 modulo GUARD stay home. */
|
|
4890
5111
|
var GUARD = 8;
|
|
@@ -4943,9 +5164,28 @@ var Bot = class {
|
|
|
4943
5164
|
0
|
|
4944
5165
|
];
|
|
4945
5166
|
world;
|
|
4946
|
-
|
|
5167
|
+
/** Where it looks walking, turned a little each tick; the side of its last detour; its last dash. */
|
|
5168
|
+
look = 0;
|
|
5169
|
+
side = 1;
|
|
5170
|
+
dashed = -120;
|
|
5171
|
+
persona;
|
|
5172
|
+
/** Its own random numbers, seeded by its id: the same match plays the same on every host. */
|
|
5173
|
+
seed;
|
|
5174
|
+
/** The way it strafes in a fight (1 left, -1 right) and the tick it may turn back. */
|
|
5175
|
+
strafing = 1;
|
|
5176
|
+
turnBack = 0;
|
|
5177
|
+
/** The balls it has weighed, by shooter and count: it decides once whether to get out of the way. */
|
|
5178
|
+
weighed = /* @__PURE__ */ new Set();
|
|
5179
|
+
constructor(id, skill = 4) {
|
|
4947
5180
|
this.id = id;
|
|
4948
5181
|
this.prefer = id % ROUTES.length;
|
|
5182
|
+
this.persona = personaOf(id, skill);
|
|
5183
|
+
this.seed = id * 2654435761 + 1;
|
|
5184
|
+
}
|
|
5185
|
+
/** A number in [0, 1) from its own sequence. */
|
|
5186
|
+
rnd() {
|
|
5187
|
+
this.seed = Math.imul(this.seed, 1664525) + 1013904223 >>> 0;
|
|
5188
|
+
return this.seed / 2 ** 32;
|
|
4949
5189
|
}
|
|
4950
5190
|
/** The input of this tick. */
|
|
4951
5191
|
think(s) {
|
|
@@ -4969,40 +5209,112 @@ var Bot = class {
|
|
|
4969
5209
|
yaw: p.yaw,
|
|
4970
5210
|
pitch: 0
|
|
4971
5211
|
};
|
|
4972
|
-
if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > DRIFT || !this.way.edges.length && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
|
|
5212
|
+
if (p.ground && (!this.goal || flat(goal[0], goal[2], this.goal[0], this.goal[2]) > Math.max(DRIFT, SHARE * flat(p.x, p.z, goal[0], goal[2])) || !this.way.edges.length && t - this.planned > REPLAN)) this.plan(s.world, p, goal);
|
|
4973
5213
|
const move = this.pilot(p);
|
|
4974
5214
|
const fight = this.fight(s, move.free);
|
|
4975
5215
|
const reload = p.ammo > 0 && !p.mag && !p.reload && t & 1 ? RELOAD : 0;
|
|
4976
5216
|
if (!fight) {
|
|
4977
|
-
this.aim = move.yaw;
|
|
4978
5217
|
this.pitch = 0;
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
5218
|
+
const runs = s.flags[1 - s.me.team].state === FLAG$1.CARRIED && s.flags[1 - s.me.team].by === s.me.id;
|
|
5219
|
+
if (move.exact || runs) {
|
|
5220
|
+
this.look = this.aim = move.yaw;
|
|
5221
|
+
return this.evade(s, {
|
|
5222
|
+
keys: move.keys | reload,
|
|
5223
|
+
yaw: move.yaw,
|
|
5224
|
+
pitch: 0
|
|
5225
|
+
}, move.exact);
|
|
5226
|
+
}
|
|
5227
|
+
const off = turn(this.look, move.yaw);
|
|
5228
|
+
this.look = this.aim = norm(this.look + Math.max(-.2, Math.min(WALK_TURN, off)));
|
|
5229
|
+
const keys = Math.abs(off) > SWING && move.keys & FORWARD ? move.keys & ~(FORWARD | SPRINT | DASH) | keysFor(this.look, move.yaw) : move.keys;
|
|
5230
|
+
return this.evade(s, {
|
|
5231
|
+
keys: keys | reload,
|
|
5232
|
+
yaw: this.look,
|
|
4982
5233
|
pitch: 0
|
|
4983
|
-
};
|
|
5234
|
+
}, false);
|
|
4984
5235
|
}
|
|
5236
|
+
this.look = this.aim;
|
|
4985
5237
|
if (fight.keys & DASH) return {
|
|
4986
5238
|
keys: fight.keys,
|
|
4987
5239
|
yaw: this.aim,
|
|
4988
5240
|
pitch: 0
|
|
4989
5241
|
};
|
|
4990
5242
|
const keys = move.keys & ~(FORWARD | BACK | LEFT | RIGHT | SPRINT);
|
|
4991
|
-
|
|
5243
|
+
const out = {
|
|
4992
5244
|
keys: (move.keys & FORWARD ? keysFor(this.aim, move.yaw) : 0) & ~(LEFT | RIGHT) | this.dodge(s.world, p) | keys | fight.keys | reload,
|
|
4993
5245
|
yaw: this.aim,
|
|
4994
5246
|
pitch: this.pitch
|
|
4995
5247
|
};
|
|
5248
|
+
return this.evade(s, out, false);
|
|
4996
5249
|
}
|
|
4997
|
-
/**
|
|
5250
|
+
/**
|
|
5251
|
+
* How it moves while it fights, as UT2004's bots do: it strafes, one way for a while then the
|
|
5252
|
+
* other, never toward a drop, and now and then jumps or dashes aside (its Jumpiness).
|
|
5253
|
+
*/
|
|
4998
5254
|
dodge(w, p) {
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5255
|
+
if (this.ticks >= this.turnBack) {
|
|
5256
|
+
this.strafing = -this.strafing;
|
|
5257
|
+
this.turnBack = this.ticks + this.persona.strafe + Math.floor(this.rnd() * this.persona.strafe);
|
|
5258
|
+
}
|
|
5259
|
+
for (const k of [this.strafing, -this.strafing]) {
|
|
5260
|
+
const yaw = norm(this.aim + k * (Math.PI / 2));
|
|
5261
|
+
const [x, z] = forward(yaw);
|
|
5262
|
+
if (floorAt(w, p.x + x * SIDE, p.z + z * SIDE, p.y + .5) <= p.y - .5) continue;
|
|
5263
|
+
this.strafing = k;
|
|
5264
|
+
const side = k > 0 ? LEFT : RIGHT;
|
|
5265
|
+
if (!p.ground || this.rnd() >= this.persona.jumpy) return side;
|
|
5266
|
+
if (this.rnd() * DASHY < 1 && !(p.held & DASH) && this.ticks - this.dashed > DASH_GAP && this.open(w, p, yaw, ASIDE) === "open") {
|
|
5267
|
+
this.dashed = this.ticks;
|
|
5268
|
+
return side | DASH;
|
|
5269
|
+
}
|
|
5270
|
+
return p.held & JUMP ? side : side | JUMP;
|
|
5003
5271
|
}
|
|
5004
5272
|
return 0;
|
|
5005
5273
|
}
|
|
5274
|
+
/**
|
|
5275
|
+
* Out of the way of a ball coming at it, as UT2004's bots dodge a rocket: an enemy ball that will
|
|
5276
|
+
* pass within CLOSE of its chest in the next WARN seconds is weighed once, and with the bot's
|
|
5277
|
+
* chance it dashes aside, across the ball's way and away from it, where the floor is open.
|
|
5278
|
+
* Not on a leg of a route, nor in the air.
|
|
5279
|
+
*/
|
|
5280
|
+
evade(s, out, exact) {
|
|
5281
|
+
const p = s.me.state;
|
|
5282
|
+
if (exact || !p.ground || p.held & DASH || !s.balls?.length) return out;
|
|
5283
|
+
const chest = p.y + 1.1;
|
|
5284
|
+
for (const b of s.balls) {
|
|
5285
|
+
if (b.team === s.me.team || b.burst || b.v !== void 0) continue;
|
|
5286
|
+
const [ox, oy, oz] = [
|
|
5287
|
+
p.x - b.x,
|
|
5288
|
+
chest - b.y,
|
|
5289
|
+
p.z - b.z
|
|
5290
|
+
];
|
|
5291
|
+
const along = ox * b.dx + oy * b.dy + oz * b.dz;
|
|
5292
|
+
const [mx, my, mz] = [
|
|
5293
|
+
ox - b.dx * along,
|
|
5294
|
+
oy - b.dy * along,
|
|
5295
|
+
oz - b.dz * along
|
|
5296
|
+
];
|
|
5297
|
+
if (!(along > 0 && along / (stepOf(b) * 60) < WARN) || mx * mx + my * my + mz * mz > CLOSE * CLOSE) continue;
|
|
5298
|
+
const key = b.by * 256 + b.id;
|
|
5299
|
+
if (this.weighed.has(key)) continue;
|
|
5300
|
+
if (this.weighed.size > 64) this.weighed.clear();
|
|
5301
|
+
this.weighed.add(key);
|
|
5302
|
+
if (this.rnd() >= this.persona.duck) continue;
|
|
5303
|
+
const first = mx * -b.dz + mz * b.dx >= 0 ? 1 : -1;
|
|
5304
|
+
for (const k of [first, -first]) {
|
|
5305
|
+
const yaw = norm(Math.atan2(k * b.dz, -k * b.dx));
|
|
5306
|
+
if (this.open(s.world, p, yaw, ASIDE) === "open") {
|
|
5307
|
+
this.dashed = this.ticks;
|
|
5308
|
+
const keys = out.keys & ~(FORWARD | BACK | LEFT | RIGHT | SPRINT | JUMP);
|
|
5309
|
+
return {
|
|
5310
|
+
...out,
|
|
5311
|
+
keys: keys | keysFor(out.yaw, yaw) | DASH
|
|
5312
|
+
};
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5316
|
+
return out;
|
|
5317
|
+
}
|
|
5006
5318
|
/** Where it wants to be. */
|
|
5007
5319
|
goalOf(s) {
|
|
5008
5320
|
const { me, others, flags, world } = s;
|
|
@@ -5010,12 +5322,20 @@ var Bot = class {
|
|
|
5010
5322
|
const { team } = me;
|
|
5011
5323
|
const home = world.def.teams[team];
|
|
5012
5324
|
const [mine, theirs] = [flags[team], flags[1 - team]];
|
|
5013
|
-
const holder = (f) =>
|
|
5325
|
+
const holder = (f) => {
|
|
5326
|
+
const h = others.find((o) => o.id === f.by)?.state;
|
|
5327
|
+
const y = h && floorAt(world, h.x, h.z, h.y + .5);
|
|
5328
|
+
return h && [
|
|
5329
|
+
h.x,
|
|
5330
|
+
y > h.y - HOVER ? y : h.y,
|
|
5331
|
+
h.z
|
|
5332
|
+
];
|
|
5333
|
+
};
|
|
5014
5334
|
if (theirs.state === FLAG$1.CARRIED && theirs.by === me.id) return home.base;
|
|
5015
5335
|
if (p.ammo < 0 && home.rack && flat(p.x, p.z, home.rack[0], home.rack[2]) < ARM) return home.rack;
|
|
5016
5336
|
if (mine.state === FLAG$1.CARRIED) {
|
|
5017
5337
|
const h = holder(mine);
|
|
5018
|
-
if (h) return
|
|
5338
|
+
if (h) return h;
|
|
5019
5339
|
}
|
|
5020
5340
|
if (mine.state === FLAG$1.DROPPED) return [
|
|
5021
5341
|
mine.x,
|
|
@@ -5025,7 +5345,7 @@ var Bot = class {
|
|
|
5025
5345
|
if (this.id % GUARD === 7) return home.base;
|
|
5026
5346
|
if (theirs.state === FLAG$1.CARRIED) {
|
|
5027
5347
|
const h = holder(theirs);
|
|
5028
|
-
if (h) return
|
|
5348
|
+
if (h) return h;
|
|
5029
5349
|
}
|
|
5030
5350
|
if (theirs.state === FLAG$1.DROPPED) return [
|
|
5031
5351
|
theirs.x,
|
|
@@ -5051,7 +5371,10 @@ var Bot = class {
|
|
|
5051
5371
|
const e = edges[this.leg];
|
|
5052
5372
|
return e ? this.nav.nodes[e.to] : this.goal;
|
|
5053
5373
|
}
|
|
5054
|
-
/**
|
|
5374
|
+
/**
|
|
5375
|
+
* The keys and yaw of the move, whether the bot may look away from it to shoot, and whether the
|
|
5376
|
+
* yaw must be kept to the letter (a leg of a route, as the tests fly it).
|
|
5377
|
+
*/
|
|
5055
5378
|
pilot(p) {
|
|
5056
5379
|
const e = this.leg >= 0 ? this.way.edges[this.leg] : void 0;
|
|
5057
5380
|
if (e?.leg) return this.fly(p, e.leg);
|
|
@@ -5066,42 +5389,108 @@ var Bot = class {
|
|
|
5066
5389
|
return {
|
|
5067
5390
|
keys: 0,
|
|
5068
5391
|
yaw: this.aim,
|
|
5069
|
-
free: true
|
|
5392
|
+
free: true,
|
|
5393
|
+
exact: false
|
|
5070
5394
|
};
|
|
5071
5395
|
}
|
|
5072
|
-
|
|
5073
|
-
|
|
5396
|
+
this.unstick(d);
|
|
5397
|
+
return this.walk(p, toward$1(p.x, p.z, x, z), d);
|
|
5398
|
+
}
|
|
5399
|
+
/**
|
|
5400
|
+
* A straight walk toward `want`: round a wall or a drop that hurts by the nearest turn that is open
|
|
5401
|
+
* (on the side it last went round, first), up a box low enough to jump onto, and a dash when the
|
|
5402
|
+
* way ahead is long, straight and open. It steps down onto a lower roof.
|
|
5403
|
+
*/
|
|
5404
|
+
walk(p, want, d) {
|
|
5074
5405
|
const w = this.world;
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5406
|
+
let yaw = want;
|
|
5407
|
+
let hop = false;
|
|
5408
|
+
let shut = true;
|
|
5409
|
+
for (const a of DETOURS) {
|
|
5410
|
+
const way = this.open(w, p, norm(want + a * this.side), AHEAD);
|
|
5411
|
+
if (way) {
|
|
5412
|
+
yaw = norm(want + a * this.side);
|
|
5413
|
+
hop = way === "hop";
|
|
5414
|
+
shut = false;
|
|
5415
|
+
if (a) this.side = Math.sign(a * this.side);
|
|
5416
|
+
break;
|
|
5417
|
+
}
|
|
5083
5418
|
}
|
|
5419
|
+
if (shut && p.ground) return {
|
|
5420
|
+
keys: 0,
|
|
5421
|
+
yaw,
|
|
5422
|
+
free: true,
|
|
5423
|
+
exact: false
|
|
5424
|
+
};
|
|
5425
|
+
let keys = FORWARD | SPRINT;
|
|
5426
|
+
if (p.ground && hop && !(p.held & JUMP)) keys |= JUMP;
|
|
5427
|
+
if (Math.abs(turn(this.look, yaw)) < .15 && !this.way.edges[this.leg + 1]?.leg) keys |= this.dash(w, p, yaw, d);
|
|
5084
5428
|
return {
|
|
5085
|
-
keys
|
|
5429
|
+
keys,
|
|
5086
5430
|
yaw,
|
|
5087
|
-
free: true
|
|
5431
|
+
free: true,
|
|
5432
|
+
exact: false
|
|
5088
5433
|
};
|
|
5089
5434
|
}
|
|
5435
|
+
/** DASH when the way ahead is long, open and wide and the last dash is a while back, else 0. */
|
|
5436
|
+
dash(w, p, yaw, d) {
|
|
5437
|
+
if (p.ground && d > DASH_FAR && !(p.held & DASH) && this.ticks - this.dashed > DASH_GAP + this.id % 4 * 15 && this.open(w, p, yaw, DASH_RUN) === "open" && this.wide(w, p, yaw)) {
|
|
5438
|
+
this.dashed = this.ticks;
|
|
5439
|
+
return DASH;
|
|
5440
|
+
}
|
|
5441
|
+
return 0;
|
|
5442
|
+
}
|
|
5443
|
+
/** Whether the floor of a dash's run is wide: a metre each side of it, all along, no edge or beam. */
|
|
5444
|
+
wide(w, p, yaw) {
|
|
5445
|
+
const [fx, fz] = forward(yaw);
|
|
5446
|
+
for (let t = 1; t <= DASH_RUN; t++) for (const s of [-1.2, WIDE]) if (floorAt(w, p.x + fx * t - fz * s, p.z + fz * t + fx * s, p.y + .5) < p.y - .5) return false;
|
|
5447
|
+
return true;
|
|
5448
|
+
}
|
|
5449
|
+
/**
|
|
5450
|
+
* Whether a body may walk `ahead` metres along `yaw` from where it stands: 'open', 'hop' over a box
|
|
5451
|
+
* it can jump onto, or false at a wall, the void or a drop that hurts.
|
|
5452
|
+
*/
|
|
5453
|
+
open(w, p, yaw, ahead) {
|
|
5454
|
+
const [fx, fz] = forward(yaw);
|
|
5455
|
+
const hurts = SAFE * 400 / (2 * gravity(w));
|
|
5456
|
+
const far = Math.max(ahead, AHEAD + BRAKE * Math.sqrt(p.vx ** 2 + p.vz ** 2));
|
|
5457
|
+
for (let t = .5; t <= far; t += .5) if (floorAt(w, p.x + fx * t, p.z + fz * t, p.y + HOP) < p.y - hurts) return false;
|
|
5458
|
+
const reach = Math.min(ahead, AHEAD);
|
|
5459
|
+
if (ray(w, [
|
|
5460
|
+
p.x,
|
|
5461
|
+
p.y + 1.9,
|
|
5462
|
+
p.z
|
|
5463
|
+
], [
|
|
5464
|
+
fx,
|
|
5465
|
+
0,
|
|
5466
|
+
fz
|
|
5467
|
+
], reach) < reach) return false;
|
|
5468
|
+
if (ray(w, [
|
|
5469
|
+
p.x,
|
|
5470
|
+
p.y + .5 + .1,
|
|
5471
|
+
p.z
|
|
5472
|
+
], [
|
|
5473
|
+
fx,
|
|
5474
|
+
0,
|
|
5475
|
+
fz
|
|
5476
|
+
], ahead) >= ahead) return "open";
|
|
5477
|
+
if (ahead !== AHEAD) return false;
|
|
5478
|
+
for (let t = 1; t <= HOP_DEPTH; t += .5) if (floorAt(w, p.x + fx * t, p.z + fz * t, p.y + HOP) < p.y - .5) return false;
|
|
5479
|
+
return "hop";
|
|
5480
|
+
}
|
|
5090
5481
|
next() {
|
|
5091
5482
|
this.leg++;
|
|
5092
5483
|
this.flight = void 0;
|
|
5093
5484
|
this.best = Infinity;
|
|
5094
5485
|
this.better = this.ticks;
|
|
5095
5486
|
}
|
|
5096
|
-
/**
|
|
5097
|
-
unstick(
|
|
5487
|
+
/** Counts the progress toward the point it goes to: a new way when there has been none for a while. */
|
|
5488
|
+
unstick(d) {
|
|
5098
5489
|
if (d < this.best - 1) [this.best, this.better] = [d, this.ticks];
|
|
5099
|
-
|
|
5100
|
-
if (idle > STUCK_PLAN) {
|
|
5490
|
+
if (this.ticks - this.better > STUCK_PLAN) {
|
|
5101
5491
|
this.goal = void 0;
|
|
5102
|
-
|
|
5492
|
+
this.side = -this.side;
|
|
5103
5493
|
}
|
|
5104
|
-
return idle > STUCK_JUMP && p.mode !== MODE.HANG && idle % 30 === 0 ? keys | JUMP : keys;
|
|
5105
5494
|
}
|
|
5106
5495
|
/** One step of a leg of a route, the way test/routes.ts flies it. */
|
|
5107
5496
|
fly(p, leg) {
|
|
@@ -5113,22 +5502,31 @@ var Bot = class {
|
|
|
5113
5502
|
};
|
|
5114
5503
|
const go = (x, z, r, keys) => {
|
|
5115
5504
|
const d = flat(p.x, p.z, x, z);
|
|
5116
|
-
|
|
5117
|
-
|
|
5505
|
+
if (d < r || d < 2 && this.ticks - this.better > STUCK_JUMP) return;
|
|
5506
|
+
this.unstick(d);
|
|
5507
|
+
return {
|
|
5508
|
+
keys,
|
|
5118
5509
|
yaw: toward$1(p.x, p.z, x, z),
|
|
5119
|
-
free: false
|
|
5510
|
+
free: false,
|
|
5511
|
+
exact: true
|
|
5120
5512
|
};
|
|
5121
5513
|
};
|
|
5122
5514
|
if (leg.k === "go") {
|
|
5123
5515
|
const run = go(leg.to[0], leg.to[1], leg.sprint ? .4 : .15, FORWARD | (leg.sprint ? SPRINT : 0));
|
|
5124
|
-
if (run)
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5516
|
+
if (run) {
|
|
5517
|
+
const next = this.way.edges[this.leg + 1]?.leg;
|
|
5518
|
+
const dash = leg.sprint && next?.k !== "leap" ? this.dash(this.world, p, run.yaw, flat(p.x, p.z, ...leg.to) - LEG_ROOM) : 0;
|
|
5519
|
+
return {
|
|
5520
|
+
...run,
|
|
5521
|
+
keys: run.keys | dash,
|
|
5522
|
+
free: !this.leapNext()
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5128
5525
|
if (!p.ground) return {
|
|
5129
5526
|
keys: 0,
|
|
5130
5527
|
yaw: p.yaw,
|
|
5131
|
-
free: false
|
|
5528
|
+
free: false,
|
|
5529
|
+
exact: true
|
|
5132
5530
|
};
|
|
5133
5531
|
return this.landed(p, leg);
|
|
5134
5532
|
}
|
|
@@ -5144,7 +5542,8 @@ var Bot = class {
|
|
|
5144
5542
|
return p.ground ? this.landed(p, leg) : {
|
|
5145
5543
|
keys: 0,
|
|
5146
5544
|
yaw: p.yaw,
|
|
5147
|
-
free: false
|
|
5545
|
+
free: false,
|
|
5546
|
+
exact: true
|
|
5148
5547
|
};
|
|
5149
5548
|
}
|
|
5150
5549
|
const keys = FORWARD | (leg.sprint ? SPRINT : 0);
|
|
@@ -5156,7 +5555,8 @@ var Bot = class {
|
|
|
5156
5555
|
return {
|
|
5157
5556
|
keys: keys | JUMP,
|
|
5158
5557
|
yaw,
|
|
5159
|
-
free: false
|
|
5558
|
+
free: false,
|
|
5559
|
+
exact: true
|
|
5160
5560
|
};
|
|
5161
5561
|
}
|
|
5162
5562
|
if (p.ground) return this.landed(p, leg);
|
|
@@ -5172,14 +5572,16 @@ var Bot = class {
|
|
|
5172
5572
|
return {
|
|
5173
5573
|
keys: v * t < d - .3 ? FORWARD : v * t > d + .3 ? BACK : 0,
|
|
5174
5574
|
yaw,
|
|
5175
|
-
free: false
|
|
5575
|
+
free: false,
|
|
5576
|
+
exact: true
|
|
5176
5577
|
};
|
|
5177
5578
|
}
|
|
5178
5579
|
const n = leg.run ? f.ended < 0 ? -1 : f.k - f.ended : f.k;
|
|
5179
5580
|
return {
|
|
5180
5581
|
keys: (n === leg.dash ? keys | DASH : keys) | (n === leg.double ? JUMP : 0),
|
|
5181
5582
|
yaw,
|
|
5182
|
-
free: false
|
|
5583
|
+
free: false,
|
|
5584
|
+
exact: true
|
|
5183
5585
|
};
|
|
5184
5586
|
}
|
|
5185
5587
|
/** Whether the edge after this one is a jump that wants the run-up of this one. */
|
|
@@ -5194,7 +5596,8 @@ var Bot = class {
|
|
|
5194
5596
|
return {
|
|
5195
5597
|
keys: 0,
|
|
5196
5598
|
yaw: p.yaw,
|
|
5197
|
-
free: false
|
|
5599
|
+
free: false,
|
|
5600
|
+
exact: true
|
|
5198
5601
|
};
|
|
5199
5602
|
}
|
|
5200
5603
|
this.next();
|
|
@@ -5236,7 +5639,8 @@ var Bot = class {
|
|
|
5236
5639
|
if (foe.id !== this.foe) {
|
|
5237
5640
|
this.foe = foe.id;
|
|
5238
5641
|
this.since = this.ticks;
|
|
5239
|
-
|
|
5642
|
+
const miss = this.persona.miss;
|
|
5643
|
+
this.aim = norm(p.yaw + (this.rnd() < .5 ? miss : -miss));
|
|
5240
5644
|
}
|
|
5241
5645
|
const d = flat(p.x, p.z, q.x, q.z);
|
|
5242
5646
|
const lead = d / 40;
|
|
@@ -5246,9 +5650,10 @@ var Bot = class {
|
|
|
5246
5650
|
q.z + q.vz * lead
|
|
5247
5651
|
];
|
|
5248
5652
|
const want = toward$1(p.x, p.z, tx, tz);
|
|
5249
|
-
|
|
5653
|
+
const rate = this.persona.turn;
|
|
5654
|
+
this.aim = norm(this.aim + Math.max(-rate, Math.min(rate, turn(this.aim, want))));
|
|
5250
5655
|
this.pitch = Math.atan2(ty - eye[1], Math.max(d, .1));
|
|
5251
|
-
const ready = this.ticks - this.since >
|
|
5656
|
+
const ready = this.ticks - this.since > this.persona.react && Math.abs(turn(this.aim, want)) < CONE;
|
|
5252
5657
|
if (foe.id === carrier && d < TACKLE && p.ground && !(p.held & DASH)) return { keys: FORWARD | DASH };
|
|
5253
5658
|
const armed = p.ammo > 0 && (p.mag ?? 0) > 0 && !p.wield;
|
|
5254
5659
|
return { keys: ready && (armed && d < RANGE || !armed && d < 1.4) && this.ticks & 1 ? FIRE : 0 };
|
|
@@ -5530,7 +5935,7 @@ var within = (p, at, r) => {
|
|
|
5530
5935
|
* The start of a cut that moves the body, from a floor only: the lunge throws him along the look at
|
|
5531
5936
|
* LUNGE_SPEED for the burst of a dash, and spends the dash; the leap jumps him LEAP_SPEED up.
|
|
5532
5937
|
*/
|
|
5533
|
-
var launch
|
|
5938
|
+
var launch = (p) => {
|
|
5534
5939
|
if (p.mode !== MODE.GROUND) return;
|
|
5535
5940
|
if (p.cut === CUT.LUNGE) {
|
|
5536
5941
|
const [fx, fz] = forward(p.yaw);
|
|
@@ -5700,7 +6105,7 @@ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
|
|
|
5700
6105
|
} else if (p.wield && (!p.swing || special)) {
|
|
5701
6106
|
p.cut = cutOf(i.keys) + (special ? 4 : 0);
|
|
5702
6107
|
[p.swing, p.charge] = [CUTS[p.cut].ticks, 0];
|
|
5703
|
-
launch
|
|
6108
|
+
launch(p);
|
|
5704
6109
|
} else if (p.rifled) {
|
|
5705
6110
|
if (!p.cool && p.clip && !p.reload) {
|
|
5706
6111
|
p.rifle--;
|
|
@@ -5762,173 +6167,6 @@ var MAPS = {
|
|
|
5762
6167
|
var mapOf = (key) => key !== void 0 && MAPS[key] || HIGHLINE;
|
|
5763
6168
|
/** The key of a known map, else 'highline'. */
|
|
5764
6169
|
var mapKey = (key) => key !== void 0 && Object.hasOwn(MAPS, key) ? key : "highline";
|
|
5765
|
-
// src/shared/plasma.ts
|
|
5766
|
-
/** Metres a ball flies in a tick, and an arc. */
|
|
5767
|
-
var PLASMA_STEP = 40 / 60;
|
|
5768
|
-
var ARC_STEP = ARC_SPEED / 60;
|
|
5769
|
-
/** How far shot `n` of the laser rifle drifts off the look, yaw and pitch: a pattern within RIFLE_DRIFT, the same for the host and every client. */
|
|
5770
|
-
var drift = (n) => [RIFLE_DRIFT * Math.sin(n * 2.4), RIFLE_DRIFT * Math.cos(n * 1.7)];
|
|
5771
|
-
/**
|
|
5772
|
-
* The ball of the shot `p` has just fired (`p` is the state after the step that fired): from the
|
|
5773
|
-
* eye of the mode along the look, GUN_RANGE metres to go, named by his `shots` count, as strong
|
|
5774
|
-
* as the shot (`power`). The laser rifle's (the user, 2026-11-08: the gun's balls, in red) has
|
|
5775
|
-
* power 0, RIFLE_RANGE to go, and leaves along the look drifted by its shot's pattern.
|
|
5776
|
-
*/
|
|
5777
|
-
var launch = (p, team = 0) => {
|
|
5778
|
-
const [dy, dp] = p.rifled ? drift(p.shots) : [0, 0];
|
|
5779
|
-
const [yaw, pitch] = [p.yaw + dy, p.pitch + dp];
|
|
5780
|
-
const [sy, cy, sp, cp] = [
|
|
5781
|
-
Math.sin(yaw),
|
|
5782
|
-
Math.cos(yaw),
|
|
5783
|
-
Math.sin(pitch),
|
|
5784
|
-
Math.cos(pitch)
|
|
5785
|
-
];
|
|
5786
|
-
return {
|
|
5787
|
-
id: p.shots,
|
|
5788
|
-
by: p.id,
|
|
5789
|
-
team,
|
|
5790
|
-
x: p.x,
|
|
5791
|
-
y: p.y + eyeHeight(p),
|
|
5792
|
-
z: p.z,
|
|
5793
|
-
dx: -sy * cp,
|
|
5794
|
-
dy: sp,
|
|
5795
|
-
dz: -cy * cp,
|
|
5796
|
-
left: p.rifled ? 60 : 80,
|
|
5797
|
-
burst: false,
|
|
5798
|
-
power: p.rifled ? 0 : p.power ?? 1
|
|
5799
|
-
};
|
|
5800
|
-
};
|
|
5801
|
-
/**
|
|
5802
|
-
* The arc of energy the ARC cut of `p` throws at its strike (`p` the state after that step): from
|
|
5803
|
-
* the eye along the look like a ball, ARC_RANGE metres to go, its CUT in `arc`. Its id is the
|
|
5804
|
-
* `shots` count with the top bit turned, apart from his balls' (one arc is gone before the next).
|
|
5805
|
-
*/
|
|
5806
|
-
var wave = (p, team = 0) => ({
|
|
5807
|
-
...launch(p, team),
|
|
5808
|
-
id: p.shots ^ 128,
|
|
5809
|
-
left: ARC_RANGE,
|
|
5810
|
-
power: 1,
|
|
5811
|
-
arc: p.cut
|
|
5812
|
-
});
|
|
5813
|
-
/** Metres the flight `b` goes in a tick. */
|
|
5814
|
-
var stepOf = (b) => b.arc ? ARC_STEP : b.power === 6 ? 2 : PLASMA_STEP;
|
|
5815
|
-
/**
|
|
5816
|
-
* Distance at which the ray from `o` along the unit `d` enters the upright cylinder of radius `r`
|
|
5817
|
-
* on `c`'s feet, `h` tall; Infinity on a miss.
|
|
5818
|
-
*/
|
|
5819
|
-
var cylinder = (o, d, c, r, h) => {
|
|
5820
|
-
const [px, pz] = [o[0] - c.x, o[2] - c.z];
|
|
5821
|
-
const a = d[0] * d[0] + d[2] * d[2];
|
|
5822
|
-
const b = px * d[0] + pz * d[2];
|
|
5823
|
-
const q = b * b - a * (px * px + pz * pz - r * r);
|
|
5824
|
-
let [lo, hi] = [0, Infinity];
|
|
5825
|
-
if (a > 1e-12) {
|
|
5826
|
-
if (q < 0) return Infinity;
|
|
5827
|
-
[lo, hi] = [(-b - Math.sqrt(q)) / a, (-b + Math.sqrt(q)) / a];
|
|
5828
|
-
} else if (px * px + pz * pz > r * r) return Infinity;
|
|
5829
|
-
const [y0, y1] = [c.y - o[1], c.y + h - o[1]];
|
|
5830
|
-
if (d[1]) [lo, hi] = [Math.max(lo, Math.min(y0 / d[1], y1 / d[1])), Math.min(hi, Math.max(y0 / d[1], y1 / d[1]))];
|
|
5831
|
-
else if (y0 > 0 || y1 < 0) return Infinity;
|
|
5832
|
-
return lo <= hi && hi >= 0 ? Math.max(lo, 0) : Infinity;
|
|
5833
|
-
};
|
|
5834
|
-
/**
|
|
5835
|
-
* Flies `b` on by `m` metres (at most what it has left) as a sphere of PLASMA_R: it stops and
|
|
5836
|
-
* bursts on the first brush, or on the first of `foes` whose body (a cylinder PLASMA_R wider, ARC_R
|
|
5837
|
-
* for an arc) it enters. Returns the foe it burst on.
|
|
5838
|
-
*/
|
|
5839
|
-
var fly = (w, b, m, foes) => {
|
|
5840
|
-
const o = [
|
|
5841
|
-
b.x,
|
|
5842
|
-
b.y,
|
|
5843
|
-
b.z
|
|
5844
|
-
];
|
|
5845
|
-
const d = [
|
|
5846
|
-
b.dx,
|
|
5847
|
-
b.dy,
|
|
5848
|
-
b.dz
|
|
5849
|
-
];
|
|
5850
|
-
const go = Math.min(m, b.left);
|
|
5851
|
-
let t = ray(w, o, d, go, PLASMA_R);
|
|
5852
|
-
let hit;
|
|
5853
|
-
for (const f of foes) {
|
|
5854
|
-
const u = cylinder(o, d, f, PLAYER_R + (b.arc ? ARC_R : PLASMA_R), heightOf(f));
|
|
5855
|
-
if (u < t) [t, hit] = [u, f];
|
|
5856
|
-
}
|
|
5857
|
-
b.burst = t < go;
|
|
5858
|
-
b.left -= t;
|
|
5859
|
-
[b.x, b.y, b.z] = [
|
|
5860
|
-
o[0] + d[0] * t,
|
|
5861
|
-
o[1] + d[1] * t,
|
|
5862
|
-
o[2] + d[2] * t
|
|
5863
|
-
];
|
|
5864
|
-
return hit;
|
|
5865
|
-
};
|
|
5866
|
-
/**
|
|
5867
|
-
* The grenade `p` has just launched (`p` the state after that step): from the eye along the look,
|
|
5868
|
-
* with no drift, at NADE_SPEED, NADE_RANGE metres of flight to go. Named by his `shots` like a ball.
|
|
5869
|
-
*/
|
|
5870
|
-
var lob = (p, team = 0) => ({
|
|
5871
|
-
...launch({
|
|
5872
|
-
...p,
|
|
5873
|
-
rifled: false
|
|
5874
|
-
}, team),
|
|
5875
|
-
left: 150,
|
|
5876
|
-
power: 7,
|
|
5877
|
-
v: 36
|
|
5878
|
-
});
|
|
5879
|
-
/**
|
|
5880
|
-
* One tick of the grenade `b`: the map's gravity bends its flight, then it flies on as a ball
|
|
5881
|
-
* (fly()) and bursts on the first brush or foe, or at the end of its range. Float32, so the
|
|
5882
|
-
* shooter's client flies the same one.
|
|
5883
|
-
*/
|
|
5884
|
-
var toss = (w, b, foes) => {
|
|
5885
|
-
const f = Math.fround;
|
|
5886
|
-
const [vx, vy, vz] = [
|
|
5887
|
-
b.dx * b.v,
|
|
5888
|
-
b.dy * b.v - gravity(w) / 60,
|
|
5889
|
-
b.dz * b.v
|
|
5890
|
-
];
|
|
5891
|
-
const v = Math.sqrt(vx * vx + vy * vy + vz * vz) || 1;
|
|
5892
|
-
[b.dx, b.dy, b.dz, b.v] = [
|
|
5893
|
-
f(vx / v),
|
|
5894
|
-
f(vy / v),
|
|
5895
|
-
f(vz / v),
|
|
5896
|
-
f(v)
|
|
5897
|
-
];
|
|
5898
|
-
const hit = fly(w, b, b.v / 60, foes);
|
|
5899
|
-
[b.x, b.y, b.z, b.left] = [
|
|
5900
|
-
f(b.x),
|
|
5901
|
-
f(b.y),
|
|
5902
|
-
f(b.z),
|
|
5903
|
-
f(b.left)
|
|
5904
|
-
];
|
|
5905
|
-
b.burst ||= b.left <= 0;
|
|
5906
|
-
return hit;
|
|
5907
|
-
};
|
|
5908
|
-
/**
|
|
5909
|
-
* The health a grenade bursting at `c` takes from `p`: NADE_HP at the body, less with the distance
|
|
5910
|
-
* to its nearest point (the axis, feet to head), nothing from NADE_R on, rounded up. Nothing when
|
|
5911
|
-
* a brush hides both that point and the chest.
|
|
5912
|
-
*/
|
|
5913
|
-
var blast = (w, c, p) => {
|
|
5914
|
-
const h = heightOf(p);
|
|
5915
|
-
const near = [
|
|
5916
|
-
p.x,
|
|
5917
|
-
Math.max(p.y, Math.min(p.y + h, c[1])),
|
|
5918
|
-
p.z
|
|
5919
|
-
];
|
|
5920
|
-
const [dx, dy, dz] = [
|
|
5921
|
-
near[0] - c[0],
|
|
5922
|
-
near[1] - c[1],
|
|
5923
|
-
near[2] - c[2]
|
|
5924
|
-
];
|
|
5925
|
-
const d = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
5926
|
-
return d >= 5 || hidden(w, c, near) && hidden(w, c, [
|
|
5927
|
-
p.x,
|
|
5928
|
-
p.y + .7 * h,
|
|
5929
|
-
p.z
|
|
5930
|
-
]) ? 0 : Math.ceil(5 * (1 - d / 5));
|
|
5931
|
-
};
|
|
5932
6170
|
/** A rover's floats, in wire order. */
|
|
5933
6171
|
var ROVER_F = [...[
|
|
5934
6172
|
"x",
|
|
@@ -7855,7 +8093,7 @@ var Room = class {
|
|
|
7855
8093
|
* against the others as they are now. Past PLASMA_MAX balls in flight, the oldest bursts. A
|
|
7856
8094
|
* grenade (lob()) is flown on the same way, a tick of its arc at a time.
|
|
7857
8095
|
*/
|
|
7858
|
-
shoot(p, view = 0, b = launch(p.state, p.info.team)) {
|
|
8096
|
+
shoot(p, view = 0, b = launch$1(p.state, p.info.team)) {
|
|
7859
8097
|
const lag = (this.ticks - view + 65536) % 65536;
|
|
7860
8098
|
this.balls.push(b);
|
|
7861
8099
|
const ticks = Math.min(lag < 32768 ? lag : 0, 12);
|
|
@@ -8454,7 +8692,8 @@ var Room = class {
|
|
|
8454
8692
|
me,
|
|
8455
8693
|
others: others.filter((o) => o !== me),
|
|
8456
8694
|
flags: this.ctf.flags,
|
|
8457
|
-
world: this.world
|
|
8695
|
+
world: this.world,
|
|
8696
|
+
balls: this.balls
|
|
8458
8697
|
});
|
|
8459
8698
|
p.seq = (p.seq ?? -1) + 1 & 65535;
|
|
8460
8699
|
this.apply(p, onWire({
|
|
@@ -8524,7 +8763,7 @@ var Room = class {
|
|
|
8524
8763
|
by: 0,
|
|
8525
8764
|
tackled: -30,
|
|
8526
8765
|
run: -SPLAT_COOLDOWN,
|
|
8527
|
-
...bot ? { bot: new Bot(id) } : {}
|
|
8766
|
+
...bot ? { bot: new Bot(id, this.rules.botSkill) } : {}
|
|
8528
8767
|
};
|
|
8529
8768
|
this.peers.set(conn, player);
|
|
8530
8769
|
this.ctf.join(id, team, player.state);
|