@adatechnology/game-crowd 0.4.7 → 0.5.1
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 +93 -41
- package/dist/index.global.js +148 -15
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +148 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
+
## Furniture the agents shove
|
|
63
|
+
|
|
64
|
+
`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
|
|
65
|
+
stops at its face and, going into it, leans `numbers.shoveForce` newtons (by its build) on it, with the arms out and the body forward (`store.shoveX`/`shoveZ`, read by the
|
|
66
|
+
look of `game-crowd-three`). The forces of the agents on the same piece add up, once per agent and update: `crowd.shoves` lists, after each `update`, the summed force, its
|
|
67
|
+
direction and how many push. The host decides whether the piece moves (its mass and friction) and moves it. Civilians do not shove: `crowd.movableAt(x, z, radius)` tells them a piece is ahead, and they walk round it along its face, always turning the same way.
|
|
68
|
+
|
|
62
69
|
## Civilians, herds, flocks and the region model
|
|
63
70
|
|
|
64
71
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ var numbers = {
|
|
|
33
33
|
limpSpeed: 0.5,
|
|
34
34
|
separation: 0.31,
|
|
35
35
|
separationPush: 2.2,
|
|
36
|
+
shoveForce: 450,
|
|
36
37
|
doorDamage: 10,
|
|
37
38
|
doorMessageDistance: 25,
|
|
38
39
|
skullMinDamage: 20,
|
|
@@ -463,6 +464,9 @@ declare const createStore: (capacity: number) => {
|
|
|
463
464
|
wounds: Uint16Array<ArrayBuffer>;
|
|
464
465
|
leanX: Float32Array<ArrayBuffer>;
|
|
465
466
|
leanZ: Float32Array<ArrayBuffer>;
|
|
467
|
+
/** The way the body leans its force on a movable piece this update (unit, or 0): the push pose. */
|
|
468
|
+
shoveX: Float32Array<ArrayBuffer>;
|
|
469
|
+
shoveZ: Float32Array<ArrayBuffer>;
|
|
466
470
|
thrown: Int8Array<ArrayBuffer>;
|
|
467
471
|
prevX: Float32Array<ArrayBuffer>;
|
|
468
472
|
prevZ: Float32Array<ArrayBuffer>;
|
|
@@ -470,7 +474,7 @@ declare const createStore: (capacity: number) => {
|
|
|
470
474
|
};
|
|
471
475
|
type CrowdStore = ReturnType<typeof createStore>;
|
|
472
476
|
/** The one-per-agent fields (G 66733 `FIELDS`): what a removal copies from the last agent. */
|
|
473
|
-
declare const AGENT_FIELDS: readonly ["x", "z", "vx", "vz", "yaw", "phase", "type", "age", "outfit", "height", "build", "chaseSpeed", "wanderSpeed", "hp", "hpMax", "headHp", "missing", "helmet", "state", "stateTimer", "lost", "attackTimer", "band", "next", "wx", "wz", "crawl", "limp", "color", "skin", "alertIn", "cooldown", "y", "floor", "floorLocked", "vy", "abilityTimer", "eaten", "stuck", "stepCell", "burn", "hunts", "named", "dvx", "dvz", "steering", "renderYaw", "renderSpeed", "pause", "lod", "variant", "attackPose", "arms", "stepDir", "pushX", "pushZ", "mass", "pressure", "field", "fieldPrev", "aimX", "aimZ", "directShove", "blastStep", "balance", "balanceTimer", "fallCause", "identity", "stability", "tripFactor", "driveFactor", "reaction", "cadenceFactor", "aggression", "idle", "gaitStyle", "wounds", "leanX", "leanZ", "thrown", "prevX", "prevZ", "prevY"];
|
|
477
|
+
declare const AGENT_FIELDS: readonly ["x", "z", "vx", "vz", "yaw", "phase", "type", "age", "outfit", "height", "build", "chaseSpeed", "wanderSpeed", "hp", "hpMax", "headHp", "missing", "helmet", "state", "stateTimer", "lost", "attackTimer", "band", "next", "wx", "wz", "crawl", "limp", "color", "skin", "alertIn", "cooldown", "y", "floor", "floorLocked", "vy", "abilityTimer", "eaten", "stuck", "stepCell", "burn", "hunts", "named", "dvx", "dvz", "steering", "renderYaw", "renderSpeed", "pause", "lod", "variant", "attackPose", "arms", "stepDir", "pushX", "pushZ", "mass", "pressure", "field", "fieldPrev", "aimX", "aimZ", "directShove", "blastStep", "balance", "balanceTimer", "fallCause", "identity", "stability", "tripFactor", "driveFactor", "reaction", "cadenceFactor", "aggression", "idle", "gaitStyle", "wounds", "leanX", "leanZ", "shoveX", "shoveZ", "thrown", "prevX", "prevZ", "prevY"];
|
|
474
478
|
|
|
475
479
|
/** What an agent is doing (G 66724 and 67180-67183): the store keeps the number. */
|
|
476
480
|
declare const STATE: {
|
|
@@ -976,6 +980,85 @@ type ThrownPool = {
|
|
|
976
980
|
active(): number;
|
|
977
981
|
};
|
|
978
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Furniture the agents bump into and may shove: the host lists the boxes on the floor (a sofa, a wardrobe), an agent walking into one stops at its face and, when it
|
|
985
|
+
* was going into it, leans its force on it. The forces of the agents on the same piece add up; the host reads them (`flush`) and decides whether and how far it moves.
|
|
986
|
+
*/
|
|
987
|
+
/** A box on the floor, in the crowd's metres. `top` is its height: an agent above it (on a pile, in the air) goes over. */
|
|
988
|
+
type CrowdMovable = {
|
|
989
|
+
readonly id: string;
|
|
990
|
+
readonly minX: number;
|
|
991
|
+
readonly minZ: number;
|
|
992
|
+
readonly maxX: number;
|
|
993
|
+
readonly maxZ: number;
|
|
994
|
+
readonly top: number;
|
|
995
|
+
};
|
|
996
|
+
/** What the agents did to one piece in the last update: the sum of their forces, its direction on the floor and how many leaned on it. */
|
|
997
|
+
type CrowdShove = {
|
|
998
|
+
readonly id: string;
|
|
999
|
+
readonly dirX: number;
|
|
1000
|
+
readonly dirZ: number;
|
|
1001
|
+
readonly forceN: number;
|
|
1002
|
+
readonly pushers: number;
|
|
1003
|
+
};
|
|
1004
|
+
type MovableHit = {
|
|
1005
|
+
readonly index: number;
|
|
1006
|
+
readonly intoX: number;
|
|
1007
|
+
readonly intoZ: number;
|
|
1008
|
+
};
|
|
1009
|
+
interface MovableContacts {
|
|
1010
|
+
readonly list: readonly CrowdMovable[];
|
|
1011
|
+
set(list: readonly CrowdMovable[]): void;
|
|
1012
|
+
/** The piece whose box (grown by the body's `radius`) holds `(x, z)` for a body at height `y`, or null. */
|
|
1013
|
+
at(x: number, z: number, y: number, radius: number): MovableHit | null;
|
|
1014
|
+
/** Agent `agent` leans `forceN` along `(dirX, dirZ)` on piece `index`; once per agent and update, the strongest kept. */
|
|
1015
|
+
lean(index: number, agent: number, dirX: number, dirZ: number, forceN: number): void;
|
|
1016
|
+
/** The shoves of this update, and a fresh start for the next. */
|
|
1017
|
+
flush(): CrowdShove[];
|
|
1018
|
+
}
|
|
1019
|
+
declare function createMovableContacts(): MovableContacts;
|
|
1020
|
+
/** Whether a walk along `(walkX, walkZ)` goes into the face whose inward normal is `(intoX, intoZ)` (a body inside the box always pushes). */
|
|
1021
|
+
declare const walksInto: (walkX: number, walkZ: number, hit: MovableHit) => boolean;
|
|
1022
|
+
|
|
1023
|
+
type CrowdView = {
|
|
1024
|
+
readonly x: number;
|
|
1025
|
+
readonly z: number;
|
|
1026
|
+
readonly yaw: number;
|
|
1027
|
+
readonly far: number;
|
|
1028
|
+
};
|
|
1029
|
+
type CrowdUpdateContext = {
|
|
1030
|
+
readonly target?: CrowdTarget | null;
|
|
1031
|
+
/** 0 day, 1 night: sight drops by 40% at night. */
|
|
1032
|
+
readonly nightFactor?: number;
|
|
1033
|
+
/** Where the flow field converges (the target by default; the foot of a ladder when the target is on a roof). */
|
|
1034
|
+
readonly flowTarget?: readonly [number, number];
|
|
1035
|
+
/** Where the viewer looks (yaw: forward is `(-sin, -cos)`); the stalker wakes when the target turns its back. Default: the target's view. */
|
|
1036
|
+
readonly viewYaw?: number;
|
|
1037
|
+
/** Centre of the relevance bands, for scenes without a player near the agents (tests, benches, cutscenes). Default: the target, or `flowTarget` without one. */
|
|
1038
|
+
readonly bandCentre?: readonly [number, number];
|
|
1039
|
+
};
|
|
1040
|
+
/** The same shape as `game-player`'s `PlayerCrowd` (structural, no dependency). */
|
|
1041
|
+
type PlayerCrowdLike = {
|
|
1042
|
+
count(): number;
|
|
1043
|
+
active(i: number): boolean;
|
|
1044
|
+
x(i: number): number;
|
|
1045
|
+
z(i: number): number;
|
|
1046
|
+
y(i: number): number;
|
|
1047
|
+
floor(i: number): number;
|
|
1048
|
+
chasing(i: number): boolean;
|
|
1049
|
+
down(i: number): boolean;
|
|
1050
|
+
panicWeight(i: number): number;
|
|
1051
|
+
hold(i: number, x: number, z: number, k: number, lookX: number, lookZ: number): void;
|
|
1052
|
+
stun(i: number, seconds: number, vx: number, vz: number): void;
|
|
1053
|
+
chase(i: number, cooldown: number): void;
|
|
1054
|
+
damage(i: number, hit: {
|
|
1055
|
+
region: number;
|
|
1056
|
+
amount: number;
|
|
1057
|
+
distance: number;
|
|
1058
|
+
cut: number;
|
|
1059
|
+
}): void;
|
|
1060
|
+
};
|
|
1061
|
+
|
|
979
1062
|
type CrowdNumbers = typeof defaults.numbers;
|
|
980
1063
|
type CrowdBand = {
|
|
981
1064
|
readonly max: number;
|
|
@@ -1032,23 +1115,6 @@ type CrowdOptions = {
|
|
|
1032
1115
|
/** Contact, pressure, balance, mounds, thrown bodies and personality: all off by default, and then the horde is the game's, bit for bit. */
|
|
1033
1116
|
readonly physics?: CrowdPhysicsOptions;
|
|
1034
1117
|
};
|
|
1035
|
-
type CrowdView = {
|
|
1036
|
-
readonly x: number;
|
|
1037
|
-
readonly z: number;
|
|
1038
|
-
readonly yaw: number;
|
|
1039
|
-
readonly far: number;
|
|
1040
|
-
};
|
|
1041
|
-
type CrowdUpdateContext = {
|
|
1042
|
-
readonly target?: CrowdTarget | null;
|
|
1043
|
-
/** 0 day, 1 night: sight drops by 40% at night. */
|
|
1044
|
-
readonly nightFactor?: number;
|
|
1045
|
-
/** Where the flow field converges (the target by default; the foot of a ladder when the target is on a roof). */
|
|
1046
|
-
readonly flowTarget?: readonly [number, number];
|
|
1047
|
-
/** Where the viewer looks (yaw: forward is `(-sin, -cos)`); the stalker wakes when the target turns its back. Default: the target's view. */
|
|
1048
|
-
readonly viewYaw?: number;
|
|
1049
|
-
/** Centre of the relevance bands, for scenes without a player near the agents (tests, benches, cutscenes). Default: the target, or `flowTarget` without one. */
|
|
1050
|
-
readonly bandCentre?: readonly [number, number];
|
|
1051
|
-
};
|
|
1052
1118
|
type Crowd = {
|
|
1053
1119
|
readonly store: CrowdStore;
|
|
1054
1120
|
readonly pack: CrowdPack;
|
|
@@ -1111,31 +1177,16 @@ type Crowd = {
|
|
|
1111
1177
|
setHunt(hunt: ((i: number, tdt: number) => boolean) | null): void;
|
|
1112
1178
|
/** The chase speed of agent `i` now (the stalker's sprint, the drowned in water; G 67343 `zChaseSpeed`). */
|
|
1113
1179
|
chaseSpeed(i: number): number;
|
|
1180
|
+
/** The furniture the agents bump into and may shove (`CrowdMovable`): the host sets it when it changes, the agents stop at its faces. */
|
|
1181
|
+
setMovables(list: readonly CrowdMovable[]): void;
|
|
1182
|
+
/** What the agents leaned on each movable in the last update, their forces added: the host moves the piece if the sum beats its friction. */
|
|
1183
|
+
readonly shoves: readonly CrowdShove[];
|
|
1184
|
+
/** The movable piece a body of `radius` at `(x, z)` stands in, or null: what walks round furniture without shoving it (civilians) asks this. */
|
|
1185
|
+
movableAt(x: number, z: number, radius: number): CrowdMovable | null;
|
|
1114
1186
|
/** The interface `game-player` uses to push, cut and be held by the agents. */
|
|
1115
1187
|
asPlayerCrowd(): PlayerCrowdLike;
|
|
1116
1188
|
on<K extends CrowdEventName>(event: K, listener: (event: CrowdEventMap[K]) => void): () => void;
|
|
1117
1189
|
};
|
|
1118
|
-
/** The same shape as `game-player`'s `PlayerCrowd` (structural, no dependency). */
|
|
1119
|
-
type PlayerCrowdLike = {
|
|
1120
|
-
count(): number;
|
|
1121
|
-
active(i: number): boolean;
|
|
1122
|
-
x(i: number): number;
|
|
1123
|
-
z(i: number): number;
|
|
1124
|
-
y(i: number): number;
|
|
1125
|
-
floor(i: number): number;
|
|
1126
|
-
chasing(i: number): boolean;
|
|
1127
|
-
down(i: number): boolean;
|
|
1128
|
-
panicWeight(i: number): number;
|
|
1129
|
-
hold(i: number, x: number, z: number, k: number, lookX: number, lookZ: number): void;
|
|
1130
|
-
stun(i: number, seconds: number, vx: number, vz: number): void;
|
|
1131
|
-
chase(i: number, cooldown: number): void;
|
|
1132
|
-
damage(i: number, hit: {
|
|
1133
|
-
region: number;
|
|
1134
|
-
amount: number;
|
|
1135
|
-
distance: number;
|
|
1136
|
-
cut: number;
|
|
1137
|
-
}): void;
|
|
1138
|
-
};
|
|
1139
1190
|
/**
|
|
1140
1191
|
* The crowd: a literal port of the team game's horde (`jogo.js` G 66714-67430). One struct of arrays, relevance bands R0-R3 with hysteresis, perception
|
|
1141
1192
|
* by sight, hearing and smell, the sliced flow field, the spatial hash, separation, six attack slots, chain alerts, doors, piles against walls, the
|
|
@@ -1221,6 +1272,8 @@ type CivilianNumbers = {
|
|
|
1221
1272
|
readonly doorProbe: number;
|
|
1222
1273
|
readonly steer: number;
|
|
1223
1274
|
readonly bodyHeight: number;
|
|
1275
|
+
/** Half the width of the body on the floor, metres: how far from a piece of furniture a civilian keeps when walking round it. */
|
|
1276
|
+
readonly bodyRadius: number;
|
|
1224
1277
|
readonly patrolChance: number;
|
|
1225
1278
|
readonly childHeight: number;
|
|
1226
1279
|
readonly childBuild: number;
|
|
@@ -1233,7 +1286,6 @@ type CivilianNumbers = {
|
|
|
1233
1286
|
readonly sidewalk: number;
|
|
1234
1287
|
readonly houseOffset: number;
|
|
1235
1288
|
};
|
|
1236
|
-
/** The game's numbers (`jogo.js` G 69960-70175). */
|
|
1237
1289
|
declare const CIVILIAN_DEFAULTS: CivilianNumbers;
|
|
1238
1290
|
type CivilianEventMap = {
|
|
1239
1291
|
bitten: {
|
|
@@ -1548,4 +1600,4 @@ type WorkerPort = {
|
|
|
1548
1600
|
*/
|
|
1549
1601
|
declare function attachPhysicsWorker(port: WorkerPort): void;
|
|
1550
1602
|
|
|
1551
|
-
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 CrowdNumbers, type CrowdOptions, type CrowdOutfit, type CrowdPack, type CrowdPersonalityOptions, type CrowdPhysicsOptions, type CrowdPlayerPressureOptions, type CrowdPlugin, type CrowdPressureOptions, 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, type Herd, type HerdAnimal, type HerdAnimalSpec, type HerdEventMap, type HerdEventName, type HerdNumbers, type HerdOptions, type HerdRole, type InfectionBinding, type InfectionBindingOptions, type InfectionModelLike, MISSING, type MigrationOptions, 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, createCrowd, createDoors, createFlock, createHerd, createNavGrid, createRng, createStore, identityOf, mix32, resolvePhysics, unit };
|
|
1603
|
+
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 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, type Herd, type HerdAnimal, type HerdAnimalSpec, type HerdEventMap, type HerdEventName, type HerdNumbers, type HerdOptions, type HerdRole, 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, createCrowd, createDoors, createFlock, createHerd, createMovableContacts, createNavGrid, createRng, createStore, identityOf, mix32, resolvePhysics, unit, walksInto };
|
package/dist/index.global.js
CHANGED
|
@@ -43,13 +43,15 @@ var GameCrowd = (() => {
|
|
|
43
43
|
createDoors: () => createDoors,
|
|
44
44
|
createFlock: () => createFlock,
|
|
45
45
|
createHerd: () => createHerd,
|
|
46
|
+
createMovableContacts: () => createMovableContacts,
|
|
46
47
|
createNavGrid: () => createNavGrid,
|
|
47
48
|
createRng: () => createRng,
|
|
48
49
|
createStore: () => createStore,
|
|
49
50
|
identityOf: () => identityOf,
|
|
50
51
|
mix32: () => mix32,
|
|
51
52
|
resolvePhysics: () => resolvePhysics,
|
|
52
|
-
unit: () => unit
|
|
53
|
+
unit: () => unit,
|
|
54
|
+
walksInto: () => walksInto
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
// ../game-contracts/dist/index.js
|
|
@@ -1502,6 +1504,7 @@ var GameCrowd = (() => {
|
|
|
1502
1504
|
limpSpeed: 0.5,
|
|
1503
1505
|
separation: 0.31,
|
|
1504
1506
|
separationPush: 2.2,
|
|
1507
|
+
shoveForce: 450,
|
|
1505
1508
|
doorDamage: 10,
|
|
1506
1509
|
doorMessageDistance: 25,
|
|
1507
1510
|
skullMinDamage: 20,
|
|
@@ -3633,6 +3636,9 @@ var GameCrowd = (() => {
|
|
|
3633
3636
|
wounds: new Uint16Array(capacity),
|
|
3634
3637
|
leanX: f32(),
|
|
3635
3638
|
leanZ: f32(),
|
|
3639
|
+
/** The way the body leans its force on a movable piece this update (unit, or 0): the push pose. */
|
|
3640
|
+
shoveX: f32(),
|
|
3641
|
+
shoveZ: f32(),
|
|
3636
3642
|
thrown: new Int8Array(capacity),
|
|
3637
3643
|
prevX: f32(),
|
|
3638
3644
|
prevZ: f32(),
|
|
@@ -3719,12 +3725,92 @@ var GameCrowd = (() => {
|
|
|
3719
3725
|
"wounds",
|
|
3720
3726
|
"leanX",
|
|
3721
3727
|
"leanZ",
|
|
3728
|
+
"shoveX",
|
|
3729
|
+
"shoveZ",
|
|
3722
3730
|
"thrown",
|
|
3723
3731
|
"prevX",
|
|
3724
3732
|
"prevZ",
|
|
3725
3733
|
"prevY"
|
|
3726
3734
|
];
|
|
3727
3735
|
|
|
3736
|
+
// src/movables.ts
|
|
3737
|
+
var INTO_MIN = 0.3;
|
|
3738
|
+
var TOUCH = 1e-6;
|
|
3739
|
+
function createMovableContacts() {
|
|
3740
|
+
let list = [];
|
|
3741
|
+
let sums = [];
|
|
3742
|
+
return {
|
|
3743
|
+
get list() {
|
|
3744
|
+
return list;
|
|
3745
|
+
},
|
|
3746
|
+
set(next) {
|
|
3747
|
+
list = next;
|
|
3748
|
+
sums = next.map(() => ({ x: 0, z: 0, agents: /* @__PURE__ */ new Map() }));
|
|
3749
|
+
},
|
|
3750
|
+
at(x, z, y, radius) {
|
|
3751
|
+
for (let k = 0; k < list.length; k++) {
|
|
3752
|
+
const m = list[k];
|
|
3753
|
+
if (y >= m.top || x <= m.minX - radius + TOUCH || x >= m.maxX + radius - TOUCH || z <= m.minZ - radius + TOUCH || z >= m.maxZ + radius - TOUCH) continue;
|
|
3754
|
+
const cx = Math.max(m.minX, Math.min(m.maxX, x)) - x;
|
|
3755
|
+
const cz = Math.max(m.minZ, Math.min(m.maxZ, z)) - z;
|
|
3756
|
+
const d = Math.hypot(cx, cz);
|
|
3757
|
+
return d < 1e-6 ? { index: k, intoX: 0, intoZ: 0 } : { index: k, intoX: cx / d, intoZ: cz / d };
|
|
3758
|
+
}
|
|
3759
|
+
return null;
|
|
3760
|
+
},
|
|
3761
|
+
lean(index, agent, dirX, dirZ, forceN) {
|
|
3762
|
+
const sum = sums[index];
|
|
3763
|
+
if (!sum) return;
|
|
3764
|
+
const length = Math.hypot(dirX, dirZ);
|
|
3765
|
+
if (length < 1e-6) return;
|
|
3766
|
+
const fx = dirX / length * forceN;
|
|
3767
|
+
const fz = dirZ / length * forceN;
|
|
3768
|
+
const before = sum.agents.get(agent);
|
|
3769
|
+
if (before) {
|
|
3770
|
+
if (Math.hypot(before[0], before[1]) >= forceN) return;
|
|
3771
|
+
sum.x -= before[0];
|
|
3772
|
+
sum.z -= before[1];
|
|
3773
|
+
}
|
|
3774
|
+
sum.agents.set(agent, [fx, fz]);
|
|
3775
|
+
sum.x += fx;
|
|
3776
|
+
sum.z += fz;
|
|
3777
|
+
},
|
|
3778
|
+
flush() {
|
|
3779
|
+
const out = [];
|
|
3780
|
+
for (let k = 0; k < sums.length; k++) {
|
|
3781
|
+
const sum = sums[k];
|
|
3782
|
+
if (sum.agents.size === 0) continue;
|
|
3783
|
+
const force = Math.hypot(sum.x, sum.z);
|
|
3784
|
+
if (force > 1e-6) out.push({ id: list[k].id, dirX: sum.x / force, dirZ: sum.z / force, forceN: force, pushers: sum.agents.size });
|
|
3785
|
+
sum.x = 0;
|
|
3786
|
+
sum.z = 0;
|
|
3787
|
+
sum.agents.clear();
|
|
3788
|
+
}
|
|
3789
|
+
return out;
|
|
3790
|
+
}
|
|
3791
|
+
};
|
|
3792
|
+
}
|
|
3793
|
+
var walksInto = (walkX, walkZ, hit) => {
|
|
3794
|
+
if (hit.intoX === 0 && hit.intoZ === 0) return true;
|
|
3795
|
+
const length = Math.hypot(walkX, walkZ);
|
|
3796
|
+
return length > 1e-6 && (walkX * hit.intoX + walkZ * hit.intoZ) / length > INTO_MIN;
|
|
3797
|
+
};
|
|
3798
|
+
function shoveStep(contacts, r) {
|
|
3799
|
+
const hit = contacts.at(r.nx, r.nz, r.y, r.radius);
|
|
3800
|
+
if (!hit) return null;
|
|
3801
|
+
let leanX = 0;
|
|
3802
|
+
let leanZ = 0;
|
|
3803
|
+
if (walksInto(r.walkX, r.walkZ, hit)) {
|
|
3804
|
+
const length = Math.hypot(r.walkX, r.walkZ) || 1;
|
|
3805
|
+
contacts.lean(hit.index, r.agent, r.walkX, r.walkZ, r.forceN);
|
|
3806
|
+
leanX = r.walkX / length;
|
|
3807
|
+
leanZ = r.walkZ / length;
|
|
3808
|
+
}
|
|
3809
|
+
if (!contacts.at(r.nx, r.z, r.y, r.radius) && !r.blocked(r.nx, r.z)) return { x: r.nx, z: r.z, leanX, leanZ };
|
|
3810
|
+
if (!contacts.at(r.x, r.nz, r.y, r.radius) && !r.blocked(r.x, r.nz)) return { x: r.x, z: r.nz, leanX, leanZ };
|
|
3811
|
+
return { x: r.x, z: r.z, leanX, leanZ };
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3728
3814
|
// src/crowd.ts
|
|
3729
3815
|
var CROWD_DEFAULTS = {
|
|
3730
3816
|
sources: defaults_default.sources,
|
|
@@ -3746,6 +3832,8 @@ var GameCrowd = (() => {
|
|
|
3746
3832
|
const grid = options.grid ?? createNavGrid();
|
|
3747
3833
|
const doors = options.doors ?? createDoors(grid, { random });
|
|
3748
3834
|
const water = options.water ?? (() => false);
|
|
3835
|
+
const movables = createMovableContacts();
|
|
3836
|
+
let shoves = [];
|
|
3749
3837
|
const plugins = options.plugins ?? [];
|
|
3750
3838
|
const clock = options.flow?.clock ?? (() => typeof performance === "undefined" ? Date.now() : performance.now());
|
|
3751
3839
|
const FLOW_R = options.flow?.radius ?? N.flowRadius;
|
|
@@ -4803,16 +4891,27 @@ var GameCrowd = (() => {
|
|
|
4803
4891
|
}
|
|
4804
4892
|
const nx = Z.x[i] + (Z.vx[i] + Z.pushX[i]) * dt;
|
|
4805
4893
|
const nz = Z.z[i] + (Z.vz[i] + Z.pushZ[i]) * dt;
|
|
4894
|
+
const walkX = Z.dvx[i];
|
|
4895
|
+
const walkZ = Z.dvz[i];
|
|
4806
4896
|
let hitCell = -1;
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4897
|
+
const shove = movables.list.length > 0 && Z.state[i] !== STATE.AIRBORNE && movables.at(nx, nz, Z.y[i], N.separation * Z.build[i]) ? shoveStep(movables, { agent: i, x: Z.x[i], z: Z.z[i], nx, nz, y: Z.y[i], radius: N.separation * Z.build[i], walkX, walkZ, forceN: N.shoveForce * Z.build[i], blocked: (x, z) => blockedAt(i, x, z) }) : null;
|
|
4898
|
+
Z.shoveX[i] = shove?.leanX ?? 0;
|
|
4899
|
+
Z.shoveZ[i] = shove?.leanZ ?? 0;
|
|
4900
|
+
if (shove) {
|
|
4901
|
+
Z.x[i] = shove.x;
|
|
4902
|
+
Z.z[i] = shove.z;
|
|
4903
|
+
Z.vx[i] = Z.vz[i] = Z.pushX[i] = Z.pushZ[i] = 0;
|
|
4904
|
+
} else {
|
|
4905
|
+
if (!blockedAt(i, nx, Z.z[i])) Z.x[i] = nx;
|
|
4906
|
+
else {
|
|
4907
|
+
if (Z.state[i] !== STATE.AIRBORNE) Z.vx[i] = Z.pushX[i] = 0;
|
|
4908
|
+
hitCell = cellOf(nx, Z.z[i]);
|
|
4909
|
+
}
|
|
4910
|
+
if (!blockedAt(i, Z.x[i], nz)) Z.z[i] = nz;
|
|
4911
|
+
else {
|
|
4912
|
+
if (Z.state[i] !== STATE.AIRBORNE) Z.vz[i] = Z.pushZ[i] = 0;
|
|
4913
|
+
hitCell = cellOf(Z.x[i], nz);
|
|
4914
|
+
}
|
|
4816
4915
|
}
|
|
4817
4916
|
if (hitCell >= 0 && Z.state[i] === STATE.CHASE && b === 0) {
|
|
4818
4917
|
const vl = tr.vaultsLow;
|
|
@@ -4842,7 +4941,7 @@ var GameCrowd = (() => {
|
|
|
4842
4941
|
Z.renderSpeed[i] += (spd - Z.renderSpeed[i]) * Math.min(1, dt * 6);
|
|
4843
4942
|
if (Z.band[i] <= 1) {
|
|
4844
4943
|
const s = Z.state[i];
|
|
4845
|
-
let goal = s === STATE.CHASE || s === STATE.GRAB || s === STATE.PILE_STEP ? 1 : 0;
|
|
4944
|
+
let goal = s === STATE.CHASE || s === STATE.GRAB || s === STATE.PILE_STEP || Z.shoveX[i] !== 0 || Z.shoveZ[i] !== 0 ? 1 : 0;
|
|
4846
4945
|
if (goal && solidAt(Z.x[i] + Math.sin(Z.renderYaw[i]) * 0.62, Z.z[i] + Math.cos(Z.renderYaw[i]) * 0.62, 1)) goal = 0.1;
|
|
4847
4946
|
Z.arms[i] += (goal - Z.arms[i]) * Math.min(1, dt * (goal > Z.arms[i] ? 3 : 5));
|
|
4848
4947
|
}
|
|
@@ -4857,6 +4956,7 @@ var GameCrowd = (() => {
|
|
|
4857
4956
|
Z.renderYaw[i] += dy * Math.min(1, dt * (Z.state[i] === STATE.AIRBORNE ? 20 : 9));
|
|
4858
4957
|
}
|
|
4859
4958
|
engine.endStep();
|
|
4959
|
+
shoves = movables.flush();
|
|
4860
4960
|
if (pileColumns.length) collapsePileColumns(Z, pileColumns, FW * FW, stepRelease);
|
|
4861
4961
|
killQFlush();
|
|
4862
4962
|
noises.length = 0;
|
|
@@ -4987,6 +5087,11 @@ var GameCrowd = (() => {
|
|
|
4987
5087
|
hunt = next;
|
|
4988
5088
|
},
|
|
4989
5089
|
chaseSpeed,
|
|
5090
|
+
setMovables: (list) => movables.set(list),
|
|
5091
|
+
movableAt: (x, z, radius) => movables.list[movables.at(x, z, 0, radius)?.index ?? -1] ?? null,
|
|
5092
|
+
get shoves() {
|
|
5093
|
+
return shoves;
|
|
5094
|
+
},
|
|
4990
5095
|
asPlayerCrowd: () => ({
|
|
4991
5096
|
count: () => Z.n,
|
|
4992
5097
|
active: (i) => Z.band[i] === 0,
|
|
@@ -5026,6 +5131,7 @@ var GameCrowd = (() => {
|
|
|
5026
5131
|
}
|
|
5027
5132
|
|
|
5028
5133
|
// src/behaviours/civilians.ts
|
|
5134
|
+
var ROUND_TOWARD = 0.2;
|
|
5029
5135
|
var CIVILIAN_DEFAULTS = {
|
|
5030
5136
|
hpAdult: 100,
|
|
5031
5137
|
hpChild: 40,
|
|
@@ -5054,6 +5160,7 @@ var GameCrowd = (() => {
|
|
|
5054
5160
|
doorProbe: 0.6,
|
|
5055
5161
|
steer: 8,
|
|
5056
5162
|
bodyHeight: 0.4,
|
|
5163
|
+
bodyRadius: 0.3,
|
|
5057
5164
|
patrolChance: 0.2,
|
|
5058
5165
|
childHeight: 0.65,
|
|
5059
5166
|
childBuild: 0.7,
|
|
@@ -5233,6 +5340,29 @@ var GameCrowd = (() => {
|
|
|
5233
5340
|
Z.yaw[i] = Math.atan2(dx, dz);
|
|
5234
5341
|
return true;
|
|
5235
5342
|
});
|
|
5343
|
+
const blocked = (x, z) => grid.solidAt(x, z, N.bodyHeight) || crowd.movableAt(x, z, N.bodyRadius) !== null;
|
|
5344
|
+
const roundSides = /* @__PURE__ */ new WeakMap();
|
|
5345
|
+
const roundFurniture = (n, ax, az) => {
|
|
5346
|
+
const m = crowd.movableAt(n.x + ax * N.probe, n.z + az * N.probe, N.bodyRadius);
|
|
5347
|
+
if (!m) {
|
|
5348
|
+
roundSides.delete(n);
|
|
5349
|
+
return null;
|
|
5350
|
+
}
|
|
5351
|
+
let ox = n.x - Math.max(m.minX, Math.min(m.maxX, n.x));
|
|
5352
|
+
let oz = n.z - Math.max(m.minZ, Math.min(m.maxZ, n.z));
|
|
5353
|
+
const length = Math.hypot(ox, oz) || 1;
|
|
5354
|
+
ox /= length;
|
|
5355
|
+
oz /= length;
|
|
5356
|
+
let side = roundSides.get(n);
|
|
5357
|
+
if (side === void 0) {
|
|
5358
|
+
const toward = -oz * ax + ox * az;
|
|
5359
|
+
const plusEnd = Math.abs(oz) >= Math.abs(ox) ? -oz > 0 ? m.maxX - n.x : n.x - m.minX : ox > 0 ? m.maxZ - n.z : n.z - m.minZ;
|
|
5360
|
+
const minusEnd = Math.abs(oz) >= Math.abs(ox) ? -oz > 0 ? n.x - m.minX : m.maxX - n.x : ox > 0 ? n.z - m.minZ : m.maxZ - n.z;
|
|
5361
|
+
side = Math.abs(toward) > ROUND_TOWARD ? Math.sign(toward) : plusEnd <= minusEnd ? 1 : -1;
|
|
5362
|
+
roundSides.set(n, side);
|
|
5363
|
+
}
|
|
5364
|
+
return [-oz * side, ox * side];
|
|
5365
|
+
};
|
|
5236
5366
|
const move = (n, dt, tx, tz, sp) => {
|
|
5237
5367
|
const dx = tx - n.x;
|
|
5238
5368
|
const dz = tz - n.z;
|
|
@@ -5243,12 +5373,14 @@ var GameCrowd = (() => {
|
|
|
5243
5373
|
}
|
|
5244
5374
|
let ax = dx / d;
|
|
5245
5375
|
let az = dz / d;
|
|
5246
|
-
|
|
5376
|
+
const round = roundFurniture(n, ax, az);
|
|
5377
|
+
if (round) [ax, az] = round;
|
|
5378
|
+
else for (const a of N.whiskers) {
|
|
5247
5379
|
const c2 = Math.cos(a);
|
|
5248
5380
|
const s = Math.sin(a);
|
|
5249
5381
|
const bx = ax * c2 - az * s;
|
|
5250
5382
|
const bz = ax * s + az * c2;
|
|
5251
|
-
if (!
|
|
5383
|
+
if (!blocked(n.x + bx * N.probe, n.z + bz * N.probe)) {
|
|
5252
5384
|
ax = bx;
|
|
5253
5385
|
az = bz;
|
|
5254
5386
|
break;
|
|
@@ -5267,8 +5399,8 @@ var GameCrowd = (() => {
|
|
|
5267
5399
|
n.vz = lerp(n.vz, az * sp, Math.min(1, dt * N.steer));
|
|
5268
5400
|
const nx = n.x + n.vx * dt;
|
|
5269
5401
|
const nz = n.z + n.vz * dt;
|
|
5270
|
-
if (!
|
|
5271
|
-
if (!
|
|
5402
|
+
if (!blocked(nx, n.z)) n.x = nx;
|
|
5403
|
+
if (!blocked(n.x, nz)) n.z = nz;
|
|
5272
5404
|
n.yaw = Math.atan2(n.vx, n.vz);
|
|
5273
5405
|
return false;
|
|
5274
5406
|
};
|
|
@@ -5371,6 +5503,7 @@ var GameCrowd = (() => {
|
|
|
5371
5503
|
n.state = "fleeing";
|
|
5372
5504
|
n.path = path.map(([x, z]) => [x, z]);
|
|
5373
5505
|
n.pathIndex = 0;
|
|
5506
|
+
n.stuckTimer = 0;
|
|
5374
5507
|
},
|
|
5375
5508
|
route(from, to) {
|
|
5376
5509
|
return rota(casaDe(from), casaDe(to));
|