|
|
@@ -56,10 +56,12 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
e.CheckpointModel.peopleCount = peopleCount
|
|
|
const count = Math.ceil(peopleCount / 3)
|
|
|
const colorCount = this.distributePeopleToColorsByArray(peopleCount, levelColor)
|
|
|
- const { gridPositions, gridColors, subwayPositions, subwayColors, subwayOrientations } = this.distributeToGridAndSubwayWithOptimizedPlacement(gridRowCount, gridColCount, colorCount, levelColor, 24)
|
|
|
+ const { gridPositions, gridColors, subwayPositions, subwayColors, subwayOrientations, obstaclePositions } = this.distributeToGridAndSubwayWithOptimizedPlacement(gridRowCount, gridColCount, colorCount, levelColor, 18)
|
|
|
+ this.createObstacle(e, obstaclePositions)
|
|
|
this.createMan(e, gridPositions, gridColors, levelColor)
|
|
|
this.createSubway(e, subwayPositions, subwayOrientations, subwayColors, levelColor)
|
|
|
this.createStation(e, stationCount)
|
|
|
+ // const vColor = e.CheckpointModel.puppets.map(v=>levelColor.findIndex((c)=>c===v.PuppetModel?.color)+1)
|
|
|
this.createVehicle(e, count, [], colorCount, levelColor)
|
|
|
} else { // 依据配置生成
|
|
|
this.createObstacle(e, obstaclePosition)
|
|
|
@@ -75,7 +77,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
const colorArr = levelColor as number[]
|
|
|
|
|
|
let newPeoplePosition = []
|
|
|
- if (peoplePosition&&peoplePosition.length>0) {
|
|
|
+ if (peoplePosition && peoplePosition.length > 0) {
|
|
|
newPeoplePosition = [...peoplePosition]
|
|
|
} else {
|
|
|
e.CheckpointModel.cells?.forEach((v, xIndex) => {
|
|
|
@@ -146,9 +148,8 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
this.fillEmptyMapInfo(e)
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- e.add(VehicleOperationComp)
|
|
|
e.add(CheckpointPathTriggerComp)
|
|
|
+ e.add(VehicleOperationComp)
|
|
|
e.remove(InitCheckpointComp)
|
|
|
// 关闭加载界面
|
|
|
oops.gui.remove(UIID.Loading);
|
|
|
@@ -227,24 +228,44 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
}
|
|
|
|
|
|
|
|
|
- distributeToGridAndSubwayWithOptimizedPlacement(row: number, col: number, colorDistribution: any, colors: string[], subwayCapacity = 24) {
|
|
|
+ distributeToGridAndSubwayWithOptimizedPlacement(row: number, col: number, colorDistribution: any, colors: string[], subwayCapacity = 18) {
|
|
|
const grid = Array.from({ length: row }, () => Array(col).fill(null));
|
|
|
let freePositions = [];
|
|
|
- let freePositionsCopy = [];
|
|
|
+ // let freePositionsCopy = [];
|
|
|
+ const obstacleCount = Math.floor(Math.random() * 8); // 随机生成个数
|
|
|
for (let i = 0; i < row; i++) {
|
|
|
for (let j = 0; j < col; j++) {
|
|
|
freePositions.push([i, j]);
|
|
|
- freePositionsCopy.push([i, j]);
|
|
|
+ // freePositionsCopy.push([i, j]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const gridColors: number[] = []
|
|
|
const gridPositions: [x: number, y: number][] = []
|
|
|
+ // const obstaclePositions: [x: number, y: number][] = []
|
|
|
const subwayPositions: [x: number, y: number][] = [];
|
|
|
const subwayColors: number[][] = [];
|
|
|
const subwayOrientations: number[] = [];
|
|
|
const cellCount = row * col
|
|
|
|
|
|
+
|
|
|
+ // 打乱freePositions数组
|
|
|
+ this.shuffleArray(freePositions);
|
|
|
+ // this.shuffleArray(freePositions); // 再洗一次,洗乱点
|
|
|
+
|
|
|
+ // 从打乱后的数组中选择前 obstacleCount 个位置为障碍物位置
|
|
|
+ const obstaclePositions: [x: number, y: number][] = freePositions.slice(0, obstacleCount);
|
|
|
+
|
|
|
+ // 若需要,从 freePositions 中移除这些障碍物位置
|
|
|
+ freePositions = freePositions.slice(obstacleCount);
|
|
|
+
|
|
|
+ obstaclePositions.forEach(([x, y]) => {
|
|
|
+ grid[x][y] = 'obstacle'
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ let freePositionsCopy = [...freePositions];
|
|
|
+
|
|
|
// 创建颜色池
|
|
|
let colorPool: number[] = [];
|
|
|
colors.forEach((color, index) => {
|
|
|
@@ -266,22 +287,24 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
randColorPool.forEach((colorIndex) => {
|
|
|
// let people = colorDistribution[colors[colorIndex-1]];
|
|
|
if (freePositions.length > 0) {
|
|
|
- let randomIndex = Math.floor(Math.random() * freePositions.length);
|
|
|
- let [x, y] = freePositions[randomIndex];
|
|
|
+ // let randomIndex = Math.floor(Math.random() * freePositions.length);
|
|
|
+ // let [x, y] = freePositions[randomIndex];
|
|
|
+ let [x, y] = freePositions.shift();
|
|
|
grid[x][y] = colorIndex;
|
|
|
gridColors.push(colorIndex)
|
|
|
gridPositions.push([x, y])
|
|
|
- freePositions.splice(randomIndex, 1);
|
|
|
+ // freePositions.splice(randomIndex, 1);
|
|
|
} else {
|
|
|
|
|
|
if (!subwayColors[subwayColors.length - 1] || subwayColors[subwayColors.length - 1].length >= subwayCapacity) {
|
|
|
const orientation = getSubwayOrientation();
|
|
|
const filteredPositions = freePositionsCopy.filter(([x, y]) =>
|
|
|
- ((orientation === SubwayEnum.LEFT && y > 0) || (orientation === SubwayEnum.RIGHT && y < col - 1)) && grid[x][y] !== 'Subway' &&
|
|
|
- ((orientation === SubwayEnum.RIGHT && grid[x][y + 1] !== 'Subway') || (orientation === SubwayEnum.LEFT && grid[x][y - 1] !== 'Subway')));
|
|
|
+ ((orientation === SubwayEnum.LEFT && y > 0) || (orientation === SubwayEnum.RIGHT && y < col - 1)) && grid[x][y] !== 'Subway' && grid[x][y] !== 'obstacle' &&
|
|
|
+ ((orientation === SubwayEnum.RIGHT && grid[x][y + 1] !== 'Subway' && grid[x][y + 1] !== 'obstacle') || (orientation === SubwayEnum.LEFT && grid[x][y - 1] !== 'Subway' && grid[x][y - 1] !== 'obstacle')));
|
|
|
if (filteredPositions.length > 0) {
|
|
|
const index = Math.floor(Math.random() * filteredPositions.length);
|
|
|
const [subwayX, subwayY] = filteredPositions[index];
|
|
|
+ // let [subwayX, subwayY] = filteredPositions.shift();
|
|
|
const gridColor = grid[subwayX][subwayY]
|
|
|
subwayPositions.push([subwayX, subwayY]);
|
|
|
const existIndex = gridPositions.findIndex(val => {
|
|
|
@@ -309,7 +332,8 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
gridColors,
|
|
|
subwayPositions: subwayPositions.map(([x, y]) => [x + 1, y + 1]) as [x: number, y: number][],
|
|
|
subwayColors,
|
|
|
- subwayOrientations
|
|
|
+ subwayOrientations,
|
|
|
+ obstaclePositions:obstaclePositions.map(([x, y]) => [x + 1, y + 1]) as [x: number, y: number][],
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -333,12 +357,12 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
checkpoint_model.path_grid = Array.from({ length: row }, () => new Array(col).fill(null));
|
|
|
const width = 0.442;
|
|
|
const gap = 0.025;
|
|
|
- const start_point = row % 2 === 0 ? v3(-(row / 2 * (width + gap) - gap / 2)+0.08, 0, 2.7) : v3(-(Math.floor(row / 2) * (width+gap) + width / 2), 0, 2.7)
|
|
|
+ const start_point = row % 2 === 0 ? v3(-(row / 2 * (width + gap) - gap / 2) + 0.08, 0, 2.7) : v3(-(Math.floor(row / 2) * (width + gap) + width / 2), 0, 2.7)
|
|
|
for (let index = 0; index < row; index++) {
|
|
|
for (let j = 0; j < col; j++) {
|
|
|
const gridEnt = ecs.getEntity<Grid>(Grid);
|
|
|
// 添加关卡到场景
|
|
|
- const pos = v3(start_point.x + j * (width+gap), 0, start_point.z + index * (width+gap))
|
|
|
+ const pos = v3(start_point.x + j * (width + gap), 0, start_point.z + index * (width + gap))
|
|
|
gridEnt.load(checkpoint_root, pos);
|
|
|
e.addChild(gridEnt)
|
|
|
checkpoint_model.grids[index][j] = gridEnt
|
|
|
@@ -522,6 +546,51 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // // 生成交通工具
|
|
|
+ // createVehicleByReachColor(e: Checkpoint, count: number, pcolor: number[], colorCount: any, colors: string[]) {
|
|
|
+ // const copyColorCount = { ...colorCount }
|
|
|
+ // const checkpoint_root = e.CheckpointView.node
|
|
|
+ // const checkpoint_model = e.CheckpointModel
|
|
|
+ // const availablePositions = Array.from({ length: count }, (_, i) => i)
|
|
|
+ // checkpoint_model.vehicles = Array(count).fill(null)
|
|
|
+ // const start_point = v3(-6, 0, 0)
|
|
|
+ // pcolor?.forEach((v, i) => {
|
|
|
+ // const color = colors[pcolor[i] - 1]
|
|
|
+ // if (copyColorCount[color] > 0) {
|
|
|
+ // const vehicle = ecs.getEntity<Vehicle>(Vehicle);
|
|
|
+ // availablePositions.shift()
|
|
|
+ // copyColorCount[color] -= 3;
|
|
|
+ // // 添加车到场景
|
|
|
+ // vehicle.VehicleModel.color = color
|
|
|
+ // const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
|
|
|
+ // vehicle.load(checkpoint_root, color, start_point, vehicleType);
|
|
|
+ // e.addChild(vehicle)
|
|
|
+ // checkpoint_model.vehicles[i] = vehicle
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // while (availablePositions.length > 0) {
|
|
|
+ // let randomIndex = Math.floor(Math.random() * availablePositions.length);
|
|
|
+
|
|
|
+ // let colorIndex = Math.floor(Math.random() * colors.length);
|
|
|
+ // let color = colors[colorIndex];
|
|
|
+
|
|
|
+ // if (copyColorCount[color] > 0) {
|
|
|
+ // // if (randomIndex < pcolor.length) {
|
|
|
+ // // availablePositions.splice(randomIndex, 1);
|
|
|
+ // // }
|
|
|
+ // const vehicle = ecs.getEntity<Vehicle>(Vehicle);
|
|
|
+ // let index = availablePositions.splice(randomIndex, 1)[0];
|
|
|
+ // copyColorCount[color] -= 3;
|
|
|
+ // // 添加车到场景
|
|
|
+ // vehicle.VehicleModel.color = color
|
|
|
+ // const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
|
|
|
+ // vehicle.load(checkpoint_root, color, start_point, vehicleType);
|
|
|
+ // e.addChild(vehicle)
|
|
|
+ // checkpoint_model.vehicles[index] = vehicle
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
// 生成交通工具
|
|
|
createVehicle(e: Checkpoint, count: number, pcolor: number[], colorCount: any, colors: string[]) {
|
|
|
const copyColorCount = { ...colorCount }
|