@korial29/tiny-fps 0.194.0 → 0.196.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/dist/index.js +44 -44
- package/dist/local.js +1 -1
- package/dist/server.js +835 -376
- package/dist/types/shared/bot.d.ts +49 -6
- package/dist/types/shared/nav.d.ts +55 -22
- package/dist/types/shared/room.d.ts +4 -0
- package/package.json +2 -1
|
@@ -9,6 +9,8 @@ export interface Seen {
|
|
|
9
9
|
id: number;
|
|
10
10
|
team: number;
|
|
11
11
|
state: PlayerState;
|
|
12
|
+
/** A bot: one the team's roles are handed out to (squad()). */
|
|
13
|
+
bot?: boolean;
|
|
12
14
|
}
|
|
13
15
|
/** What a bot knows each tick. */
|
|
14
16
|
export interface Sight {
|
|
@@ -22,6 +24,10 @@ export interface Sight {
|
|
|
22
24
|
errand?: Errand;
|
|
23
25
|
/** The numbers of its class (kit.ts): the marine's when absent. */
|
|
24
26
|
kit?: Kit;
|
|
27
|
+
/** The health packs there now, not taken. */
|
|
28
|
+
packs?: readonly Vec3[];
|
|
29
|
+
/** The bots that shot to hit each enemy last tick, by the enemy's id (Bot.hunting): TOKENS of them hit, the others miss. */
|
|
30
|
+
hunters?: ReadonlyMap<number, readonly number[]>;
|
|
25
31
|
}
|
|
26
32
|
export type Intent = {
|
|
27
33
|
keys: number;
|
|
@@ -62,20 +68,41 @@ export interface Persona {
|
|
|
62
68
|
strafe: number;
|
|
63
69
|
/** Its chance of dashing out of the way of a ball coming at it. */
|
|
64
70
|
duck: number;
|
|
71
|
+
/** Shots it fires past a new target before it shoots to hit. */
|
|
72
|
+
warn: number;
|
|
73
|
+
/** Radians its aim wanders about the target, about. */
|
|
74
|
+
shake: number;
|
|
75
|
+
/** The share of a target's flight time it leads him by. */
|
|
76
|
+
lead: number;
|
|
77
|
+
/** The share of a target's change of speed it catches up with a tick. */
|
|
78
|
+
track: number;
|
|
65
79
|
}
|
|
66
80
|
/** The character of the bot `id` in a room of this skill. */
|
|
67
81
|
export declare const personaOf: (id: number, skill?: number) => Persona;
|
|
82
|
+
/** What a bot of a team does, handed out by squad(). */
|
|
83
|
+
type Role = 'chase' | 'return' | 'escort' | 'help' | 'guard' | 'attack';
|
|
84
|
+
/**
|
|
85
|
+
* The roles of a team's bots this tick, the same in every bot's head (they see the same team):
|
|
86
|
+
* the nearest to each job takes it, the most pressing jobs first. Half the team or more chase the
|
|
87
|
+
* enemy who has the flag (all but an escort when ours has theirs too: no capture till ours is
|
|
88
|
+
* home), one or two return a lying flag, two escort the carrier, one goes to a teammate an enemy
|
|
89
|
+
* is on while he is low, one guards home in a squad of three or more, and the rest attack.
|
|
90
|
+
*/
|
|
91
|
+
export declare const squad: (team: number, players: readonly Seen[], flags: readonly FlagState[], world: World) => {
|
|
92
|
+
roles: Map<number, Role>;
|
|
93
|
+
trouble?: Seen;
|
|
94
|
+
};
|
|
68
95
|
export declare class Bot {
|
|
69
96
|
readonly id: number;
|
|
70
97
|
/** The route it prefers, an index of nav.ts's ROUTES. */
|
|
71
98
|
private prefer;
|
|
72
|
-
|
|
73
|
-
private
|
|
99
|
+
/** Its way: the points it goes through, walking or on a leg; the last is its goal or as near as it gets. */
|
|
100
|
+
private steps;
|
|
74
101
|
/** The goal of the way, and the tick it was planned. */
|
|
75
102
|
private goal;
|
|
76
103
|
private planned;
|
|
77
|
-
/**
|
|
78
|
-
private
|
|
104
|
+
/** The step it is on; steps.length once there. */
|
|
105
|
+
private step;
|
|
79
106
|
private flight;
|
|
80
107
|
/** The best distance to the point it walks to, and the tick it was last bettered. */
|
|
81
108
|
private best;
|
|
@@ -86,6 +113,18 @@ export declare class Bot {
|
|
|
86
113
|
private pitch;
|
|
87
114
|
private foe;
|
|
88
115
|
private since;
|
|
116
|
+
/** Its aim's wander off the target, yaw and pitch, and the target's speed as it has made it out. */
|
|
117
|
+
private err;
|
|
118
|
+
private errUp;
|
|
119
|
+
private speed;
|
|
120
|
+
/** Its shot count when it met the target, the shots it fires past him first, and to which side. */
|
|
121
|
+
private shot;
|
|
122
|
+
private warned;
|
|
123
|
+
private past;
|
|
124
|
+
/** The tick it last fought each enemy, by id. */
|
|
125
|
+
private met;
|
|
126
|
+
/** The enemy it shot to hit this tick, -1 for none: the room hands it to the others as `hunters`. */
|
|
127
|
+
hunting: number;
|
|
89
128
|
private last;
|
|
90
129
|
private world;
|
|
91
130
|
/** Where it looks walking, turned a little each tick; the side of its last detour; its last dash. */
|
|
@@ -138,8 +177,6 @@ export declare class Bot {
|
|
|
138
177
|
/** Where it wants to be. */
|
|
139
178
|
private goalOf;
|
|
140
179
|
private plan;
|
|
141
|
-
/** The point it walks straight to now: the entry, a walk's end, or the goal past the last edge. */
|
|
142
|
-
private target;
|
|
143
180
|
/**
|
|
144
181
|
* The keys and yaw of the move, whether the bot may look away from it to shoot, and whether the
|
|
145
182
|
* yaw must be kept to the letter (a leg of a route, as the tests fly it).
|
|
@@ -165,6 +202,11 @@ export declare class Bot {
|
|
|
165
202
|
private unstick;
|
|
166
203
|
/** One step of a leg of a route, the way test/routes.ts flies it. */
|
|
167
204
|
private fly;
|
|
205
|
+
/**
|
|
206
|
+
* FORWARD or BACK in the air to come down on (x, y, z) facing it: will the flight carry it past
|
|
207
|
+
* the point, or short of it, by the time it is down at its height? 0 when it will land there.
|
|
208
|
+
*/
|
|
209
|
+
private alight;
|
|
168
210
|
/** Whether the edge after this one is a jump that wants the run-up of this one. */
|
|
169
211
|
private leapNext;
|
|
170
212
|
/** A leg is over: on to the next on its roof, else a new way from where the bot came down. */
|
|
@@ -172,3 +214,4 @@ export declare class Bot {
|
|
|
172
214
|
/** The look and the trigger at the enemy to fight now, if any. */
|
|
173
215
|
private fight;
|
|
174
216
|
}
|
|
217
|
+
export {};
|
|
@@ -1,42 +1,75 @@
|
|
|
1
1
|
import type { Leg } from './routes';
|
|
2
2
|
import type { World } from './world';
|
|
3
3
|
export type Vec3 = [number, number, number];
|
|
4
|
-
|
|
4
|
+
type Rect = [x0: number, z0: number, x1: number, z1: number];
|
|
5
|
+
/** A rectangle of floor at the height `y`, or on the relief's ground when `r`. */
|
|
6
|
+
export interface Poly {
|
|
7
|
+
q: Rect;
|
|
8
|
+
y: number;
|
|
9
|
+
r?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** How a body goes through a portal: walks either way, drops down it, or jumps up onto a box. */
|
|
12
|
+
export declare const PASS: {
|
|
13
|
+
readonly WALK: 0;
|
|
14
|
+
readonly DROP: 1;
|
|
15
|
+
readonly HOP: 2;
|
|
16
|
+
};
|
|
17
|
+
/** A way out of a rectangle: through a portal (from `a` to `b` on the line between the two), or a link of legs. */
|
|
5
18
|
export interface Edge {
|
|
6
19
|
to: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
20
|
+
a?: [number, number];
|
|
21
|
+
b?: [number, number];
|
|
22
|
+
pass?: number;
|
|
23
|
+
/** A link: where its first leg starts, where its last ends, its legs and the route it is a leg of (-1 none). */
|
|
24
|
+
from?: Vec3;
|
|
25
|
+
end?: Vec3;
|
|
26
|
+
legs?: Leg[];
|
|
27
|
+
route?: number;
|
|
28
|
+
/** Seconds, about, past the walk to it: a link's own. */
|
|
11
29
|
cost: number;
|
|
30
|
+
/** How often a bot came down off this link: each makes it dearer for the room's life. */
|
|
31
|
+
fails?: number;
|
|
32
|
+
/** The first link of a crossing (the moon's): AREA more for a bot that prefers another route. */
|
|
33
|
+
toll?: boolean;
|
|
12
34
|
}
|
|
13
35
|
export interface Nav {
|
|
14
|
-
|
|
15
|
-
/** The ways out of each node. */
|
|
36
|
+
polys: Poly[];
|
|
16
37
|
out: Edge[][];
|
|
17
|
-
/**
|
|
18
|
-
|
|
38
|
+
/** Cell key to the rectangles that touch the cell, PORTAL metres round included. */
|
|
39
|
+
grid: Map<number, number[]>;
|
|
40
|
+
/** The route each rectangle is a crossing of, an index of ROUTES; -1 for none. */
|
|
41
|
+
route: Int8Array;
|
|
42
|
+
}
|
|
43
|
+
/** A point a bot goes to: walking, or flying a leg there (`edge` the link of the leg). */
|
|
44
|
+
export interface Step {
|
|
45
|
+
to: Vec3;
|
|
46
|
+
leg?: Leg;
|
|
47
|
+
edge?: Edge;
|
|
19
48
|
}
|
|
20
49
|
/** The routes, fastest first: the Spine, Midtown, the Lowline. */
|
|
21
50
|
export declare const ROUTES: import("./routes").Route[];
|
|
51
|
+
/** Where a leg ends: a jump steers for its `to`, which is on the roof it lands on. */
|
|
52
|
+
export declare const end: (l: Leg) => Vec3;
|
|
53
|
+
/** The height of a rectangle's floor at (x, z). */
|
|
54
|
+
export declare const heightAt: (w: World, p: Poly, x: number, z: number) => number;
|
|
22
55
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* or the head from the height of a.
|
|
56
|
+
* The rectangle a body at `v` stands on, or the nearest one within NEAR metres, at most ABOVE over
|
|
57
|
+
* it and BELOW under it, as (index, the point of it to walk to); -1 when none.
|
|
26
58
|
*/
|
|
27
|
-
export declare const
|
|
59
|
+
export declare const locate: (nav: Nav, w: World, v: Vec3) => [number, Vec3];
|
|
28
60
|
/** Whether the bots' map of a world is built. */
|
|
29
61
|
export declare const navBuilt: (w: World) => boolean;
|
|
30
62
|
/** The bots' map of a world, built once per world. */
|
|
31
63
|
export declare const navOf: (w: World) => Nav;
|
|
32
|
-
/** A way across the map: walk straight to `entry`, follow the edges, then walk straight to the goal. */
|
|
33
|
-
export interface Way {
|
|
34
|
-
entry?: Vec3;
|
|
35
|
-
edges: Edge[];
|
|
36
|
-
}
|
|
37
64
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
|
|
65
|
+
* The corners of the shortest line from `s` to `t` through the portals, each [left, right] as one
|
|
66
|
+
* goes (the simple stupid funnel algorithm), `t` last.
|
|
67
|
+
*/
|
|
68
|
+
export declare const funnel: (s: number[], ports: [number[], number[]][], t: number[]) => number[][];
|
|
69
|
+
/**
|
|
70
|
+
* The points a bot goes through from `a` to `b`, the last `b` or, when no way gets there, the
|
|
71
|
+
* nearest point it can get to. The links of the routes other than `prefer` (an index of ROUTES)
|
|
72
|
+
* cost more, so bots that prefer different ones spread over the map. Off the mesh, `b` alone.
|
|
41
73
|
*/
|
|
42
|
-
export declare const path: (nav: Nav, w: World, a: Vec3, b: Vec3, prefer?: number) =>
|
|
74
|
+
export declare const path: (nav: Nav, w: World, a: Vec3, b: Vec3, prefer?: number) => Step[];
|
|
75
|
+
export {};
|
|
@@ -31,6 +31,8 @@ export declare class Room {
|
|
|
31
31
|
private mapName;
|
|
32
32
|
/** The map the host picked for the next match, when it is another one. */
|
|
33
33
|
private next;
|
|
34
|
+
/** The next map's world, built with the bots' mesh while the end screen runs rather than in the tick that starts the match. */
|
|
35
|
+
private ready;
|
|
34
36
|
/** Joins so far: each player's `since`. */
|
|
35
37
|
private joins;
|
|
36
38
|
/** Ids of bots let go this tick, not given again before the next: the person who takes a bot's place would be drawn where it stood. */
|
|
@@ -53,6 +55,8 @@ export declare class Room {
|
|
|
53
55
|
private host;
|
|
54
56
|
/** The map the host picked, from now on: a new world and a new match, the players in it. */
|
|
55
57
|
private load;
|
|
58
|
+
/** The next map's world and the bots' mesh of it, built ahead (Tranquility's mesh takes some 30 ms). */
|
|
59
|
+
private prepare;
|
|
56
60
|
/** Number of joined players, the bots left out: a room of bots alone is empty. */
|
|
57
61
|
get size(): number;
|
|
58
62
|
/** A peer opened. Nothing is sent until it joins. */
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.196.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"format": "npm run format:prettier && npm run format:eslint",
|
|
69
69
|
"test": "vitest run --coverage",
|
|
70
70
|
"test:ci": "vitest run --maxWorkers=100% --passWithNoTests",
|
|
71
|
+
"botmatch": "BOTMATCH=${BOTMATCH:-24} vitest run src/shared/botmatch.test.ts",
|
|
71
72
|
"test:durations": "vitest run --reporter=json --outputFile=node_modules/.cache/vitest-report.json && node scripts/durations.mjs node_modules/.cache/vitest-report.json",
|
|
72
73
|
"test:watch": "vitest --watch"
|
|
73
74
|
},
|