| 4265 | } |
| 4266 | |
| 4267 | void OperateTrap(Object &trap) |
| 4268 | { |
| 4269 | if (!UpdateTrapState(trap)) |
| 4270 | return; |
| 4271 | |
| 4272 | // default to firing at the trigger object |
| 4273 | Point triggerPosition = { trap._oVar1, trap._oVar2 }; |
| 4274 | Point target = triggerPosition; |
| 4275 | |
| 4276 | auto searchArea = PointsInRectangle(Rectangle { target, 1 }); |
| 4277 | // look for a player near the trigger (using a reverse search to match vanilla behaviour) |
| 4278 | auto foundPosition = std::find_if(searchArea.crbegin(), searchArea.crend(), [](Point testPosition) { return InDungeonBounds(testPosition) && dPlayer[testPosition.x][testPosition.y] != 0; }); |
| 4279 | if (foundPosition != searchArea.crend()) { |
| 4280 | // if a player is standing near the trigger then target them instead |
| 4281 | target = *foundPosition; |
| 4282 | } |
| 4283 | |
| 4284 | Direction dir = GetDirection(trap.position, target); |
| 4285 | AddMissile(trap.position, target, dir, static_cast<MissileID>(trap._oVar3), TARGET_PLAYERS, -1, 0, 0); |
| 4286 | PlaySfxLoc(IS_TRAP, triggerPosition); |
| 4287 | } |
| 4288 | |
| 4289 | void ProcessObjects() |
| 4290 | { |
no test coverage detected