@adatechnology/game-crowd 0.6.2 → 0.7.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 +7 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.global.js +109 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +109 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -59,6 +59,13 @@ crowd.damage(i, { region: 0, amount: 35, distance: 12, caliber: { id: '9x19', cl
|
|
|
59
59
|
crowd.store.x[i] // the struct of arrays: x, z, y, yaw, state, hp, missing, band, variant...
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
## Walls, doors and gates of the world
|
|
63
|
+
|
|
64
|
+
`bindNavObstacles(crowd, source)` writes into the crowd's grid and doors what an SDK publishes as a `NavObstacleSource` of `game-contracts` (the houses of
|
|
65
|
+
`game-floorplan-three` with `createHouseNavObstacles`): each solid is a wall (a stub of a cut wall under 1.2 m a low wall the agents climb), each door or gate a crowd
|
|
66
|
+
door the agents push against and hit until it breaks, and the source is told (`breakDoor`, the house swings it open). Call `binding.sync()` once per fixed step before
|
|
67
|
+
`crowd.update`: a door that opened or closed and a wall a blast cut change only their own cells, from what was under them and the solids still standing there.
|
|
68
|
+
|
|
62
69
|
## Furniture the agents shove
|
|
63
70
|
|
|
64
71
|
`crowd.setMovables([{ id, minX, minZ, maxX, maxZ, top }])` lists the pieces on the floor the host lets the agents push (a sofa, a wardrobe). An agent walking into one
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CorpseLedger } from '@adatechnology/game-characters';
|
|
2
|
-
import { BlastShoveOptions, WorkerCoordinator, ResidentKind, SimModule } from '@adatechnology/game-contracts';
|
|
2
|
+
import { BlastShoveOptions, WorkerCoordinator, NavObstacleSource, ResidentKind, SimModule } from '@adatechnology/game-contracts';
|
|
3
3
|
|
|
4
4
|
var numbers = {
|
|
5
5
|
capacity: 6000,
|
|
@@ -1205,6 +1205,29 @@ type Crowd = {
|
|
|
1205
1205
|
*/
|
|
1206
1206
|
declare function createCrowd(options: CrowdOptions): Crowd;
|
|
1207
1207
|
|
|
1208
|
+
type NavObstacleBindingOptions = {
|
|
1209
|
+
/** Height (m) from which a box is a solid instead of a low wall (default 1.2). */
|
|
1210
|
+
readonly lowWallMaxHeight?: number;
|
|
1211
|
+
};
|
|
1212
|
+
type NavObstacleBinding = {
|
|
1213
|
+
/** Applies what changed in the source since the last call (a door opened or closed, a wall cut or gone): call it once per fixed step, before the crowd's. */
|
|
1214
|
+
sync(): void;
|
|
1215
|
+
/** The crowd door an obstacle door became, -1 for none. */
|
|
1216
|
+
doorOf(id: string): number;
|
|
1217
|
+
/** Stops following the source (the grid keeps what it has). */
|
|
1218
|
+
dispose(): void;
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Writes the obstacles an SDK publishes (`NavObstacleSource` of `game-contracts`: the houses' walls, lot walls, fences, doors and gates) into the crowd's grid and doors,
|
|
1222
|
+
* and keeps them there: a solid is a wall (or a low wall, when only a stub of it stands), a door a crowd door that agents push against and hit until it breaks
|
|
1223
|
+
* (then the source is told, and shows it open); a door the source opens or closes, and a wall a blast cuts, change the cells at the next `sync`.
|
|
1224
|
+
* Only the cells of what changed are written again, from what was under them before the binding and every solid still standing there.
|
|
1225
|
+
*/
|
|
1226
|
+
declare function bindNavObstacles(target: {
|
|
1227
|
+
readonly grid: NavGrid;
|
|
1228
|
+
readonly doors: Doors;
|
|
1229
|
+
}, source: NavObstacleSource, options?: NavObstacleBindingOptions): NavObstacleBinding;
|
|
1230
|
+
|
|
1208
1231
|
/** Deterministic mulberry32 generator; returns floats in [0, 1). */
|
|
1209
1232
|
declare function createRng(seed: number): () => number;
|
|
1210
1233
|
|
|
@@ -1765,4 +1788,4 @@ type WorkerPort = {
|
|
|
1765
1788
|
*/
|
|
1766
1789
|
declare function attachPhysicsWorker(port: WorkerPort): void;
|
|
1767
1790
|
|
|
1768
|
-
export { AGENT_FIELDS, BALANCE, CELL, CIVILIAN_DEFAULTS, CROWD_DEFAULTS, CROWD_PHYSICS_DEFAULTS, type Civilian, type CivilianBuilding, type CivilianEventMap, type CivilianEventName, type CivilianNumbers, type CivilianOptions, type CivilianSpec, type CivilianState, type Civilians, type ContactParams, type ContactResult, type ContactView, type Corpse, type Crowd, type CrowdAge, type CrowdBalanceOptions, type CrowdBalanceTraits, type CrowdBand, type CrowdBlast, type CrowdBlastOptions, type CrowdCaliber, type CrowdContactOptions, type CrowdDamageResult, type CrowdDensityOptions, type CrowdEffectId, type CrowdEventMap, type CrowdEventName, type CrowdHit, type CrowdMessageId, type CrowdMoundOptions, type CrowdMovable, type CrowdNumbers, type CrowdOptions, type CrowdOutfit, type CrowdPack, type CrowdPersonalityOptions, type CrowdPhysicsInit, type CrowdPhysicsOptions, type CrowdPlayerPressureOptions, type CrowdPlugin, type CrowdPressureOptions, type CrowdShove, type CrowdSoundId, type CrowdStore, type CrowdTarget, type CrowdThrownOptions, type CrowdTraits, type CrowdType, type CrowdUpdateContext, type CrowdView, DOOR_DEFAULTS, type Door, type DoorEventMap, type DoorEventName, type DoorNumbers, type Doors, FALL_CAUSE, type Flock, type FlockBird, type FlockMode, type FlockOptions, HERD_DEFAULTS, HERD_ROLES, HORDE_COMMAND, HORDE_SIM_ID, type Herd, type HerdAnimal, type HerdAnimalSpec, type HerdEventMap, type HerdEventName, type HerdNumbers, type HerdOptions, type HerdRole, type HordeSimInit, type HordeThreadLike, type InfectionBinding, type InfectionBindingOptions, type InfectionModelLike, MISSING, type MigrationOptions, type MovableContacts, type MovableHit, type NavGrid, type NavGridOptions, type OffloadTransport, type PhysicsStats, type PhysicsWorkerFactory, type PhysicsWorkerHandle, type PlayerCrowdLike, type Region, type ResolvedPhysics, STATE, type ThrownPool, type WorkerPort, attachPhysicsWorker, bindInfection, carrionCenter, contactStep, createCivilians, createContactView, createCoordinatorRunner, createCrowd, createDoors, createFlock, createHerd, createHordeCrowd, createMovableContacts, createNavGrid, createRng, createStore, crowdPhysicsKind, hordeSimModule, hordeSnapshotBytes, hordeSnapshotLayout, identityOf, mix32, readHordeSnapshot, resolvePhysics, unit, walksInto, writeHordeSnapshot };
|
|
1791
|
+
export { AGENT_FIELDS, BALANCE, CELL, CIVILIAN_DEFAULTS, CROWD_DEFAULTS, CROWD_PHYSICS_DEFAULTS, type Civilian, type CivilianBuilding, type CivilianEventMap, type CivilianEventName, type CivilianNumbers, type CivilianOptions, type CivilianSpec, type CivilianState, type Civilians, type ContactParams, type ContactResult, type ContactView, type Corpse, type Crowd, type CrowdAge, type CrowdBalanceOptions, type CrowdBalanceTraits, type CrowdBand, type CrowdBlast, type CrowdBlastOptions, type CrowdCaliber, type CrowdContactOptions, type CrowdDamageResult, type CrowdDensityOptions, type CrowdEffectId, type CrowdEventMap, type CrowdEventName, type CrowdHit, type CrowdMessageId, type CrowdMoundOptions, type CrowdMovable, type CrowdNumbers, type CrowdOptions, type CrowdOutfit, type CrowdPack, type CrowdPersonalityOptions, type CrowdPhysicsInit, type CrowdPhysicsOptions, type CrowdPlayerPressureOptions, type CrowdPlugin, type CrowdPressureOptions, type CrowdShove, type CrowdSoundId, type CrowdStore, type CrowdTarget, type CrowdThrownOptions, type CrowdTraits, type CrowdType, type CrowdUpdateContext, type CrowdView, DOOR_DEFAULTS, type Door, type DoorEventMap, type DoorEventName, type DoorNumbers, type Doors, FALL_CAUSE, type Flock, type FlockBird, type FlockMode, type FlockOptions, HERD_DEFAULTS, HERD_ROLES, HORDE_COMMAND, HORDE_SIM_ID, type Herd, type HerdAnimal, type HerdAnimalSpec, type HerdEventMap, type HerdEventName, type HerdNumbers, type HerdOptions, type HerdRole, type HordeSimInit, type HordeThreadLike, type InfectionBinding, type InfectionBindingOptions, type InfectionModelLike, MISSING, type MigrationOptions, type MovableContacts, type MovableHit, type NavGrid, type NavGridOptions, type NavObstacleBinding, type NavObstacleBindingOptions, type OffloadTransport, type PhysicsStats, type PhysicsWorkerFactory, type PhysicsWorkerHandle, type PlayerCrowdLike, type Region, type ResolvedPhysics, STATE, type ThrownPool, type WorkerPort, attachPhysicsWorker, bindInfection, bindNavObstacles, carrionCenter, contactStep, createCivilians, createContactView, createCoordinatorRunner, createCrowd, createDoors, createFlock, createHerd, createHordeCrowd, createMovableContacts, createNavGrid, createRng, createStore, crowdPhysicsKind, hordeSimModule, hordeSnapshotBytes, hordeSnapshotLayout, identityOf, mix32, readHordeSnapshot, resolvePhysics, unit, walksInto, writeHordeSnapshot };
|
package/dist/index.global.js
CHANGED
|
@@ -37,6 +37,7 @@ var GameCrowd = (() => {
|
|
|
37
37
|
STATE: () => STATE,
|
|
38
38
|
attachPhysicsWorker: () => attachPhysicsWorker,
|
|
39
39
|
bindInfection: () => bindInfection,
|
|
40
|
+
bindNavObstacles: () => bindNavObstacles,
|
|
40
41
|
carrionCenter: () => carrionCenter,
|
|
41
42
|
contactStep: () => contactStep,
|
|
42
43
|
createCivilians: () => createCivilians,
|
|
@@ -146,6 +147,7 @@ var GameCrowd = (() => {
|
|
|
146
147
|
[DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
|
|
147
148
|
};
|
|
148
149
|
var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
|
|
150
|
+
var NAV_OBSTACLE_KIND = { SOLID: "solid", DOOR: "door" };
|
|
149
151
|
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
150
152
|
var GAIT_IDS = ["walk", "run"];
|
|
151
153
|
var LANDING_IDS = ["light", "heavy"];
|
|
@@ -5310,6 +5312,113 @@ var GameCrowd = (() => {
|
|
|
5310
5312
|
return crowd;
|
|
5311
5313
|
}
|
|
5312
5314
|
|
|
5315
|
+
// src/obstacles.ts
|
|
5316
|
+
var LOW_WALL_MAX_HEIGHT = 1.2;
|
|
5317
|
+
var rangeOf = (grid, rect) => [
|
|
5318
|
+
Math.max(0, Math.floor((rect[0] + grid.half) / grid.cell)),
|
|
5319
|
+
Math.max(0, Math.floor((rect[1] + grid.half) / grid.cell)),
|
|
5320
|
+
Math.min(grid.n, Math.ceil((rect[2] + grid.half) / grid.cell)),
|
|
5321
|
+
Math.min(grid.n, Math.ceil((rect[3] + grid.half) / grid.cell))
|
|
5322
|
+
];
|
|
5323
|
+
var covers = (range, gx, gz) => gx >= range[0] && gx < range[2] && gz >= range[1] && gz < range[3];
|
|
5324
|
+
function bindNavObstacles(target, source, options = {}) {
|
|
5325
|
+
const { grid, doors } = target;
|
|
5326
|
+
const lowMax = options.lowWallMaxHeight ?? LOW_WALL_MAX_HEIGHT;
|
|
5327
|
+
const solids = /* @__PURE__ */ new Map();
|
|
5328
|
+
const doorIndex = /* @__PURE__ */ new Map();
|
|
5329
|
+
const doorId = [];
|
|
5330
|
+
const baseKind = /* @__PURE__ */ new Map();
|
|
5331
|
+
const baseHeight = /* @__PURE__ */ new Map();
|
|
5332
|
+
const writeCell = (cell, kind, height) => {
|
|
5333
|
+
if (!baseKind.has(cell)) {
|
|
5334
|
+
baseKind.set(cell, grid.occ[cell]);
|
|
5335
|
+
baseHeight.set(cell, grid.occH[cell]);
|
|
5336
|
+
}
|
|
5337
|
+
const x = cell % grid.n * grid.cell - grid.half;
|
|
5338
|
+
const z = Math.floor(cell / grid.n) * grid.cell - grid.half;
|
|
5339
|
+
grid.fillRect(x, z, x + grid.cell, z + grid.cell, kind, height);
|
|
5340
|
+
};
|
|
5341
|
+
const kindOf = (height) => height >= lowMax ? CELL.SOLID : CELL.LOW_WALL;
|
|
5342
|
+
const stampBox = (box) => {
|
|
5343
|
+
const [gx0, gz0, gx1, gz1] = rangeOf(grid, box.rect);
|
|
5344
|
+
for (let gz = gz0; gz < gz1; gz++)
|
|
5345
|
+
for (let gx = gx0; gx < gx1; gx++) {
|
|
5346
|
+
const cell = gz * grid.n + gx;
|
|
5347
|
+
if (doors.at(cell) >= 0) continue;
|
|
5348
|
+
const height = baseKind.has(cell) ? Math.max(grid.occH[cell], box.height) : box.height;
|
|
5349
|
+
writeCell(cell, kindOf(height), height);
|
|
5350
|
+
}
|
|
5351
|
+
};
|
|
5352
|
+
const addDoor = (obstacle) => {
|
|
5353
|
+
const box = obstacle.boxes[0];
|
|
5354
|
+
if (!box) return;
|
|
5355
|
+
const [x0, z0, x1, z1] = box.rect;
|
|
5356
|
+
const alongX = x1 - x0 >= z1 - z0;
|
|
5357
|
+
const index = doors.add((x0 + x1) / 2, (z0 + z1) / 2, alongX ? "x" : "z", alongX ? x1 - x0 : z1 - z0, { obstacle: obstacle.id });
|
|
5358
|
+
doorIndex.set(obstacle.id, index);
|
|
5359
|
+
doorId[index] = obstacle.id;
|
|
5360
|
+
for (let board = 0; board < obstacle.boards; board++) doors.plank(index);
|
|
5361
|
+
if (obstacle.open) doors.set(index, true);
|
|
5362
|
+
};
|
|
5363
|
+
const restamp = (ranges) => {
|
|
5364
|
+
if (ranges.length === 0) return;
|
|
5365
|
+
const bound = [Infinity, Infinity, -Infinity, -Infinity];
|
|
5366
|
+
for (const range of ranges) {
|
|
5367
|
+
bound[0] = Math.min(bound[0], range[0]);
|
|
5368
|
+
bound[1] = Math.min(bound[1], range[1]);
|
|
5369
|
+
bound[2] = Math.max(bound[2], range[2]);
|
|
5370
|
+
bound[3] = Math.max(bound[3], range[3]);
|
|
5371
|
+
}
|
|
5372
|
+
const near = [];
|
|
5373
|
+
for (const boxes of solids.values())
|
|
5374
|
+
for (const box of boxes) {
|
|
5375
|
+
const range = rangeOf(grid, box.rect);
|
|
5376
|
+
if (range[2] > bound[0] && range[0] < bound[2] && range[3] > bound[1] && range[1] < bound[3]) near.push({ range, height: box.height });
|
|
5377
|
+
}
|
|
5378
|
+
for (const range of ranges)
|
|
5379
|
+
for (let gz = range[1]; gz < range[3]; gz++)
|
|
5380
|
+
for (let gx = range[0]; gx < range[2]; gx++) {
|
|
5381
|
+
const cell = gz * grid.n + gx;
|
|
5382
|
+
if (doors.at(cell) >= 0) continue;
|
|
5383
|
+
let height = 0;
|
|
5384
|
+
for (const box of near) if (covers(box.range, gx, gz)) height = Math.max(height, box.height);
|
|
5385
|
+
if (height > 0) writeCell(cell, kindOf(height), height);
|
|
5386
|
+
else if (baseKind.has(cell)) writeCell(cell, baseKind.get(cell), baseHeight.get(cell));
|
|
5387
|
+
}
|
|
5388
|
+
};
|
|
5389
|
+
for (const obstacle of source.obstacles()) {
|
|
5390
|
+
if (obstacle.kind !== NAV_OBSTACLE_KIND.SOLID) continue;
|
|
5391
|
+
solids.set(obstacle.id, obstacle.boxes);
|
|
5392
|
+
for (const box of obstacle.boxes) stampBox(box);
|
|
5393
|
+
}
|
|
5394
|
+
for (const obstacle of source.obstacles()) if (obstacle.kind === NAV_OBSTACLE_KIND.DOOR) addDoor(obstacle);
|
|
5395
|
+
const offBroken = doors.on("broken", (event) => {
|
|
5396
|
+
const id = doorId[event.door];
|
|
5397
|
+
if (id !== void 0) source.breakDoor(id);
|
|
5398
|
+
});
|
|
5399
|
+
return {
|
|
5400
|
+
sync() {
|
|
5401
|
+
const changed = source.changes();
|
|
5402
|
+
if (changed.length === 0) return;
|
|
5403
|
+
const ranges = [];
|
|
5404
|
+
for (const obstacle of changed) {
|
|
5405
|
+
if (obstacle.kind === NAV_OBSTACLE_KIND.DOOR) {
|
|
5406
|
+
const index = doorIndex.get(obstacle.id);
|
|
5407
|
+
if (index === void 0) addDoor(obstacle);
|
|
5408
|
+
else doors.set(index, obstacle.open);
|
|
5409
|
+
continue;
|
|
5410
|
+
}
|
|
5411
|
+
for (const box of solids.get(obstacle.id) ?? []) ranges.push(rangeOf(grid, box.rect));
|
|
5412
|
+
for (const box of obstacle.boxes) ranges.push(rangeOf(grid, box.rect));
|
|
5413
|
+
solids.set(obstacle.id, obstacle.boxes);
|
|
5414
|
+
}
|
|
5415
|
+
restamp(ranges);
|
|
5416
|
+
},
|
|
5417
|
+
doorOf: (id) => doorIndex.get(id) ?? -1,
|
|
5418
|
+
dispose: offBroken
|
|
5419
|
+
};
|
|
5420
|
+
}
|
|
5421
|
+
|
|
5313
5422
|
// src/behaviours/civilians.ts
|
|
5314
5423
|
var ROUND_TOWARD = 0.2;
|
|
5315
5424
|
var CIVILIAN_DEFAULTS = {
|