Skip to content

Commit 805e14d

Browse files
authored
Update asw_door.cpp added improved auto close function
Made Doors not automatically close in peoples faces via detecting marines near doors and reschedule closing if there is
1 parent 8c4c971 commit 805e14d

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/game/server/swarm/asw_door.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "cvisibilitymonitor.h"
1919
#include "soundent.h"
2020
#include "asw_util_shared.h"
21+
#include "asw_gameresource.h"
2122

2223
// memdbgon must be the last include file in a .cpp file!!!
2324
#include "tier0/memdbgon.h"
@@ -436,6 +437,57 @@ void CASW_Door::OnDoorClosed( void )
436437
}
437438
}
438439

440+
// Purpose: Check if a marine is close to a door and if so prevent it from closing
441+
void CASW_Door::DoorAutoCloseThink()
442+
{
443+
444+
const float CLOSE_DIST = 350.0f;
445+
bool bMarineNearby = false;
446+
447+
if (ASWGameResource())
448+
{
449+
for (int i = 0; i < ASWGameResource()->GetMaxMarineResources(); i++)
450+
{
451+
CASW_Marine_Resource *pMR = ASWGameResource()->GetMarineResource(i);
452+
CASW_Marine *pMarine = pMR ? pMR->GetMarineEntity() : NULL;
453+
if (pMarine && pMarine->GetHealth() > 0)
454+
{
455+
float dist = (pMarine->GetAbsOrigin() - GetAbsOrigin()).Length();
456+
if (dist < CLOSE_DIST)
457+
{
458+
bMarineNearby = true;
459+
break;
460+
}
461+
}
462+
}
463+
}
464+
465+
if (bMarineNearby)
466+
{
467+
// Don't auto-close if a marine is nearby. Try again soon.
468+
SetNextThink(gpGlobals->curtime + 0.1);
469+
return;
470+
}
471+
472+
if ( !DoorCanClose( true ) )
473+
{
474+
if (m_flAutoReturnDelay == -1)
475+
{
476+
SetNextThink( TICK_NEVER_THINK );
477+
}
478+
else
479+
{
480+
// In flWait seconds, DoorClose will fire, unless wait is -1, then door stays open
481+
SetMoveDoneTime(m_flAutoReturnDelay + 0.1);
482+
SetMoveDone(&CBasePropDoor::DoorAutoCloseThink);
483+
}
484+
485+
return;
486+
}
487+
488+
DoorClose();
489+
490+
}
439491

440492
//-----------------------------------------------------------------------------
441493
// Purpose: Returns whether the way is clear for the door to close.

0 commit comments

Comments
 (0)