MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / OperateTrap

Function OperateTrap

Source/objects.cpp:4267–4287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4265}
4266
4267void 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
4289void ProcessObjects()
4290{

Callers 1

ProcessObjectsFunction · 0.85

Calls 8

UpdateTrapStateFunction · 0.85
PointsInRectangleFunction · 0.85
InDungeonBoundsFunction · 0.85
GetDirectionFunction · 0.85
AddMissileFunction · 0.85
PlaySfxLocFunction · 0.70
crbeginMethod · 0.45
crendMethod · 0.45

Tested by

no test coverage detected