Skip to content

Commit

Permalink
ElevatorMovers always move at approximately the same speed (#951)
Browse files Browse the repository at this point in the history
* elevators always move at approximately the same speed

* adjustments to elevator speed logic

* add ElevatorMover.Initialize()

* Update DXRFixes/DeusEx/Classes/ElevatorMover.uc

---------

Co-authored-by: Die4Ever <30947252+Die4Ever@users.noreply.github.com>
  • Loading branch information
MQDuck and Die4Ever authored Sep 19, 2024
1 parent 3810ac2 commit 40d970c
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions DXRFixes/DeusEx/Classes/ElevatorMover.uc
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
class ElevatorMover merges ElevatorMover;
// can't do injects because it uses a state

var float lastTime;
var float lastTime, moveSpeed, originalMoveTime;
var int numKeyPos;
var bool initialized;

function Initialize()
{
local SequenceTrigger st;
local float dist, maxDist, avgDist, distSum;
local int validKeyPos[8];
local int i, j;

if (initialized) return;

// calculate numKeyPos and make a list of valid KeyPos indices
foreach AllActors(class'SequenceTrigger', st) {
if (st.event != tag) continue;

// check if st.seqnum is already in the list
for (i = 0; i < numKeyPos; i++) {
if (validKeyPos[i] == st.seqnum) {
break;
}
}
// if not, add it and increment numKeyPos
if (i == numKeyPos) {
validKeyPos[numKeyPos++] = st.seqnum;
}
}

// do calculations using only valid KeyPos elements
for (i = 0; i < numKeyPos; i++) {
for (j = i + 1; j < numKeyPos; j++) {
dist = VSize(KeyPos[validKeyPos[i]] - KeyPos[validKeyPos[j]]);
maxDist = FMax(maxDist, dist);
distSum += dist;
}
}

avgDist = distSum / (numKeyPos * (numKeyPos - 1) / 2.0);
moveSpeed = (maxDist*0.33 + avgDist*0.67) / MoveTime;
originalMoveTime = MoveTime;

initialized = true;
}

function bool EncroachingOn( actor Other )
{
Expand All @@ -23,17 +66,23 @@ function SetSeq(int seqnum)
local int prevKeyNum;
local float dist;

if( MoveTime/2 < Level.TimeSeconds-lastTime )
Initialize();

if( MoveTime/10 < Level.TimeSeconds-lastTime )
oldSeq = true;

if ( bIsMoving && !oldSeq )
return;

dist = VSize(BasePos + KeyPos[seqnum] - Location);

if (numKeyPos > 2)
MoveTime = FMax(dist / moveSpeed, originalMoveTime / 2.5);

if (KeyNum != seqnum || oldSeq)
{
prevKeyNum = KeyNum;
KeyNum = seqnum;
dist = VSize(BasePos + KeyPos[seqnum] - Location);

GotoState('ElevatorMover', 'Next');

Expand Down

0 comments on commit 40d970c

Please sign in to comment.