({ zapTargetPosSrc, zapTargetPosNew, thangsSrc, thangsNew, processedPositions, visitedPositions, actionSrc, actionNew })
| 1430 | } |
| 1431 | |
| 1432 | function processExplosiveChain ({ zapTargetPosSrc, zapTargetPosNew, thangsSrc, thangsNew, processedPositions, visitedPositions, actionSrc, actionNew }) { |
| 1433 | const directions = [ |
| 1434 | new Direction('up'), |
| 1435 | new Direction('right'), |
| 1436 | new Direction('down'), |
| 1437 | new Direction('left'), |
| 1438 | { name: 'upleft', vector: new Vector(-1, 1) }, |
| 1439 | { name: 'upright', vector: new Vector(1, 1) }, |
| 1440 | { name: 'downleft', vector: new Vector(-1, -1) }, |
| 1441 | { name: 'downright', vector: new Vector(1, -1) } |
| 1442 | ] |
| 1443 | |
| 1444 | for (const direction of directions) { |
| 1445 | const nearbyPosSrc = zapTargetPosSrc.copy().add(direction.vector) |
| 1446 | const posKey = `${nearbyPosSrc.x},${nearbyPosSrc.y}` |
| 1447 | |
| 1448 | if (processedPositions.has(posKey)) continue |
| 1449 | processedPositions.add(posKey) |
| 1450 | |
| 1451 | const nearbyThangSrc = findThangAt(nearbyPosSrc, thangsSrc) |
| 1452 | const nearbySpriteName = thangTypesToSpriteNames[nearbyThangSrc?.thangType] |
| 1453 | |
| 1454 | if (nearbyThangSrc && hittableSpriteNames.includes(nearbySpriteName)) { |
| 1455 | const zapDirectionRelationship = actionNew.direction.getRelationship(actionSrc.direction) |
| 1456 | const directionNew = new Vector(direction.vector.x, direction.vector.y) |
| 1457 | |
| 1458 | if (zapDirectionRelationship === 'backward') { |
| 1459 | directionNew.multiply(-1) |
| 1460 | } else if (zapDirectionRelationship === 'turn') { |
| 1461 | const rotationFactor = actionNew.direction.vector.x * actionSrc.direction.vector.y - actionNew.direction.vector.y * actionSrc.direction.vector.x > 0 ? 1 : -1 |
| 1462 | directionNew.rotate(Math.PI / 2 * rotationFactor) |
| 1463 | } |
| 1464 | |
| 1465 | const nearbyPosNew = zapTargetPosNew.copy().add(directionNew) |
| 1466 | visitedPositions.push(nearbyPosNew.copy()) |
| 1467 | |
| 1468 | if (!moveThang({ at: nearbyPosSrc, to: nearbyPosNew, thangsSrc, thangsNew })) { |
| 1469 | actionNew.invalid = true |
| 1470 | } |
| 1471 | |
| 1472 | if (nearbySpriteName === 'Explosive Junior') { |
| 1473 | // console.log('Processing explosive chain', nearbyThangSrc, posKey) |
| 1474 | processExplosiveChain({ zapTargetPosSrc: nearbyPosSrc, zapTargetPosNew: nearbyPosNew, thangsSrc, thangsNew, processedPositions, visitedPositions, actionSrc, actionNew }) |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | function repositionFriendsAndExplosives ({ thangsSrc, thangsNew, visitedPositions }) { |
| 1481 | // Find any TNT or chickens that weren't moved into position (x == y == placeholderPosition), and try to put them where they might go |
no test coverage detected