This will be used in a few places where we previously used a raw integer random to index into a local array for selection, simplifying that type of logic to a single statement.
Identified and removed an instance of Direction being used as an argument for a bool parameter
Removed a single-use temporary variable being cast from sprite frame to direction to size_t
Co-authored-by: Anders Jenbo <anders@jenbo.dk>
Fix alignment of WalkSettings array
Previously an improper check was being done to see if the player was
located on the 3 teleporting pads in the level. Even if fixng this the
spell would not work correctly if the layer was standing on the pads
when casting the spell.
Simply use TARGET_BOTH to indicate that it should not be random and send
the player to the given destination
Phasing could end up attempting to teleport to hunreds of random
location and still fail to find a valid target and send the player in to
a wall or outside the map.
This is fixed by first finding all valid locations within range and then
picking one of them at random.
Valid targets is a 13x13 area around the player minus the inner 7x7
In total there can be no more then 120 valid tiles and on average there
should be 75 avalible.
No idea why template deduction was failing on 3ds builds only... It was using the context of the return type to deduce what the template arguments should be? Hopefully specifying the template explicitly works.
This is mainly to help isolate functionality in the hopes of adding a specialised object class for this type of object as suggested by @julealgon in https://github.com/diasurgical/devilutionX/pull/2344#discussion_r667415019
For example, AddSCambBook performs almost the same logic but uses var6 instead of var8 for the trigger condition/identifier.
Due to the way this function is used it was easiest to also change ObjIndex to return a reference to the object instead of the index. Also added an explicit conversion from Size to Displacement to make one of the uses slightly cleaner to express.
Really blanking on a good name for that function. Might not even be necessary given I think the BreakCrux use is effectively dead code, it could be rolled back into SyncCrux.
Instead calling the function directly makes it easier to see common code patterns
DoorSet really only cares if the door opens to the left or the right
Can take a bool instead of the object type.
these two functions are always called together, can probably be combined or have a wrapper introduced
Move SyncL1Doors to near declarations of other SyncDoors functions
Simplify checks in SyncL3Doors
The function is only called with objects of type L3LDOOR or L3RDOOR so there's no real need to check again.
Take door by reference in SyncL3Doors
Removes one use of the Objects global.
Door by reference 2, SyncL2Doors
Simplify logic in SyncL2Doors to match L3Doors
Almost the same code, can probably be combined to a single function with appropriate parameters.
Use Point in DoorSet params
Use switch in DoorSet
Instead of a whole bunch of if statements where only one can be true
Replace object index with type in DoorSet
This function doesn't need any other object property. Still references the dPiece global unfortunately.
SyncL1Doors door by reference
Replace code that mutates a copy of door position with Direction
Inline if/else statement for L1LDOOR
Only difference is the value of the second parameter
Also updated declaration of temporary/local variables to match
convention. This includes inlining int oi in LoadMapObjects as this
matches the way SetOBjMapRange is called in other areas.