(state: State, tank: TankRecord, threshhold = -0.01)
| 96 | } |
| 97 | |
| 98 | export default function canTankMove(state: State, tank: TankRecord, threshhold = -0.01) { |
| 99 | const { |
| 100 | tanks, |
| 101 | map: { bricks, steels, rivers, eagle, restrictedAreas }, |
| 102 | } = state |
| 103 | const tankRect = asRect(tank) |
| 104 | |
| 105 | // 判断是否位于战场内 |
| 106 | if (!isInField(tankRect)) { |
| 107 | return false |
| 108 | } |
| 109 | |
| 110 | // 判断是否与地形相碰撞 |
| 111 | if (isTankCollidedWithEagle(eagle, tankRect, threshhold)) { |
| 112 | return false |
| 113 | } |
| 114 | if (isTankCollidedWithBricks(bricks, tankRect, threshhold)) { |
| 115 | return false |
| 116 | } |
| 117 | if (isTankCollidedWithSteels(steels, tankRect, threshhold)) { |
| 118 | return false |
| 119 | } |
| 120 | if (isTankCollidedWithRivers(rivers, tankRect, threshhold)) { |
| 121 | return false |
| 122 | } |
| 123 | |
| 124 | // 判断是否与保留区域有碰撞 |
| 125 | if (isTankCollidedWithRestrictedAreas(restrictedAreas, tankRect, threshhold)) { |
| 126 | return false |
| 127 | } |
| 128 | |
| 129 | // 判断是否与其他坦克相碰撞 |
| 130 | const activeTanks = tanks.filter(t => t.alive) |
| 131 | if (isTankCollidedWithOtherTanks(activeTanks, tank, tankRect, threshhold)) { |
| 132 | return false |
| 133 | } |
| 134 | |
| 135 | // 与其他物品都没有相撞, 则表示可以进行移动 |
| 136 | return true |
| 137 | } |
nothing calls this directly
no test coverage detected