@adatechnology/game-crowd 0.6.1 → 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/dist/index.js
CHANGED
|
@@ -3762,6 +3762,114 @@ function createCrowd(options) {
|
|
|
3762
3762
|
return crowd;
|
|
3763
3763
|
}
|
|
3764
3764
|
|
|
3765
|
+
// src/obstacles.ts
|
|
3766
|
+
import { NAV_OBSTACLE_KIND } from "@adatechnology/game-contracts";
|
|
3767
|
+
var LOW_WALL_MAX_HEIGHT = 1.2;
|
|
3768
|
+
var rangeOf = (grid, rect) => [
|
|
3769
|
+
Math.max(0, Math.floor((rect[0] + grid.half) / grid.cell)),
|
|
3770
|
+
Math.max(0, Math.floor((rect[1] + grid.half) / grid.cell)),
|
|
3771
|
+
Math.min(grid.n, Math.ceil((rect[2] + grid.half) / grid.cell)),
|
|
3772
|
+
Math.min(grid.n, Math.ceil((rect[3] + grid.half) / grid.cell))
|
|
3773
|
+
];
|
|
3774
|
+
var covers = (range, gx, gz) => gx >= range[0] && gx < range[2] && gz >= range[1] && gz < range[3];
|
|
3775
|
+
function bindNavObstacles(target, source, options = {}) {
|
|
3776
|
+
const { grid, doors } = target;
|
|
3777
|
+
const lowMax = options.lowWallMaxHeight ?? LOW_WALL_MAX_HEIGHT;
|
|
3778
|
+
const solids = /* @__PURE__ */ new Map();
|
|
3779
|
+
const doorIndex = /* @__PURE__ */ new Map();
|
|
3780
|
+
const doorId = [];
|
|
3781
|
+
const baseKind = /* @__PURE__ */ new Map();
|
|
3782
|
+
const baseHeight = /* @__PURE__ */ new Map();
|
|
3783
|
+
const writeCell = (cell, kind, height) => {
|
|
3784
|
+
if (!baseKind.has(cell)) {
|
|
3785
|
+
baseKind.set(cell, grid.occ[cell]);
|
|
3786
|
+
baseHeight.set(cell, grid.occH[cell]);
|
|
3787
|
+
}
|
|
3788
|
+
const x = cell % grid.n * grid.cell - grid.half;
|
|
3789
|
+
const z = Math.floor(cell / grid.n) * grid.cell - grid.half;
|
|
3790
|
+
grid.fillRect(x, z, x + grid.cell, z + grid.cell, kind, height);
|
|
3791
|
+
};
|
|
3792
|
+
const kindOf = (height) => height >= lowMax ? CELL.SOLID : CELL.LOW_WALL;
|
|
3793
|
+
const stampBox = (box) => {
|
|
3794
|
+
const [gx0, gz0, gx1, gz1] = rangeOf(grid, box.rect);
|
|
3795
|
+
for (let gz = gz0; gz < gz1; gz++)
|
|
3796
|
+
for (let gx = gx0; gx < gx1; gx++) {
|
|
3797
|
+
const cell = gz * grid.n + gx;
|
|
3798
|
+
if (doors.at(cell) >= 0) continue;
|
|
3799
|
+
const height = baseKind.has(cell) ? Math.max(grid.occH[cell], box.height) : box.height;
|
|
3800
|
+
writeCell(cell, kindOf(height), height);
|
|
3801
|
+
}
|
|
3802
|
+
};
|
|
3803
|
+
const addDoor = (obstacle) => {
|
|
3804
|
+
const box = obstacle.boxes[0];
|
|
3805
|
+
if (!box) return;
|
|
3806
|
+
const [x0, z0, x1, z1] = box.rect;
|
|
3807
|
+
const alongX = x1 - x0 >= z1 - z0;
|
|
3808
|
+
const index = doors.add((x0 + x1) / 2, (z0 + z1) / 2, alongX ? "x" : "z", alongX ? x1 - x0 : z1 - z0, { obstacle: obstacle.id });
|
|
3809
|
+
doorIndex.set(obstacle.id, index);
|
|
3810
|
+
doorId[index] = obstacle.id;
|
|
3811
|
+
for (let board = 0; board < obstacle.boards; board++) doors.plank(index);
|
|
3812
|
+
if (obstacle.open) doors.set(index, true);
|
|
3813
|
+
};
|
|
3814
|
+
const restamp = (ranges) => {
|
|
3815
|
+
if (ranges.length === 0) return;
|
|
3816
|
+
const bound = [Infinity, Infinity, -Infinity, -Infinity];
|
|
3817
|
+
for (const range of ranges) {
|
|
3818
|
+
bound[0] = Math.min(bound[0], range[0]);
|
|
3819
|
+
bound[1] = Math.min(bound[1], range[1]);
|
|
3820
|
+
bound[2] = Math.max(bound[2], range[2]);
|
|
3821
|
+
bound[3] = Math.max(bound[3], range[3]);
|
|
3822
|
+
}
|
|
3823
|
+
const near = [];
|
|
3824
|
+
for (const boxes of solids.values())
|
|
3825
|
+
for (const box of boxes) {
|
|
3826
|
+
const range = rangeOf(grid, box.rect);
|
|
3827
|
+
if (range[2] > bound[0] && range[0] < bound[2] && range[3] > bound[1] && range[1] < bound[3]) near.push({ range, height: box.height });
|
|
3828
|
+
}
|
|
3829
|
+
for (const range of ranges)
|
|
3830
|
+
for (let gz = range[1]; gz < range[3]; gz++)
|
|
3831
|
+
for (let gx = range[0]; gx < range[2]; gx++) {
|
|
3832
|
+
const cell = gz * grid.n + gx;
|
|
3833
|
+
if (doors.at(cell) >= 0) continue;
|
|
3834
|
+
let height = 0;
|
|
3835
|
+
for (const box of near) if (covers(box.range, gx, gz)) height = Math.max(height, box.height);
|
|
3836
|
+
if (height > 0) writeCell(cell, kindOf(height), height);
|
|
3837
|
+
else if (baseKind.has(cell)) writeCell(cell, baseKind.get(cell), baseHeight.get(cell));
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
for (const obstacle of source.obstacles()) {
|
|
3841
|
+
if (obstacle.kind !== NAV_OBSTACLE_KIND.SOLID) continue;
|
|
3842
|
+
solids.set(obstacle.id, obstacle.boxes);
|
|
3843
|
+
for (const box of obstacle.boxes) stampBox(box);
|
|
3844
|
+
}
|
|
3845
|
+
for (const obstacle of source.obstacles()) if (obstacle.kind === NAV_OBSTACLE_KIND.DOOR) addDoor(obstacle);
|
|
3846
|
+
const offBroken = doors.on("broken", (event) => {
|
|
3847
|
+
const id = doorId[event.door];
|
|
3848
|
+
if (id !== void 0) source.breakDoor(id);
|
|
3849
|
+
});
|
|
3850
|
+
return {
|
|
3851
|
+
sync() {
|
|
3852
|
+
const changed = source.changes();
|
|
3853
|
+
if (changed.length === 0) return;
|
|
3854
|
+
const ranges = [];
|
|
3855
|
+
for (const obstacle of changed) {
|
|
3856
|
+
if (obstacle.kind === NAV_OBSTACLE_KIND.DOOR) {
|
|
3857
|
+
const index = doorIndex.get(obstacle.id);
|
|
3858
|
+
if (index === void 0) addDoor(obstacle);
|
|
3859
|
+
else doors.set(index, obstacle.open);
|
|
3860
|
+
continue;
|
|
3861
|
+
}
|
|
3862
|
+
for (const box of solids.get(obstacle.id) ?? []) ranges.push(rangeOf(grid, box.rect));
|
|
3863
|
+
for (const box of obstacle.boxes) ranges.push(rangeOf(grid, box.rect));
|
|
3864
|
+
solids.set(obstacle.id, obstacle.boxes);
|
|
3865
|
+
}
|
|
3866
|
+
restamp(ranges);
|
|
3867
|
+
},
|
|
3868
|
+
doorOf: (id) => doorIndex.get(id) ?? -1,
|
|
3869
|
+
dispose: offBroken
|
|
3870
|
+
};
|
|
3871
|
+
}
|
|
3872
|
+
|
|
3765
3873
|
// src/behaviours/civilians.ts
|
|
3766
3874
|
var ROUND_TOWARD = 0.2;
|
|
3767
3875
|
var CIVILIAN_DEFAULTS = {
|
|
@@ -4618,6 +4726,7 @@ export {
|
|
|
4618
4726
|
STATE,
|
|
4619
4727
|
attachPhysicsWorker,
|
|
4620
4728
|
bindInfection,
|
|
4729
|
+
bindNavObstacles,
|
|
4621
4730
|
carrionCenter,
|
|
4622
4731
|
contactStep,
|
|
4623
4732
|
createCivilians,
|