Skip to content

Commit b632c72

Browse files
authored
Update props.cpp Improved autoclose
Detect marines near doors and stops doors from auto closing if near
1 parent 59ef355 commit b632c72

1 file changed

Lines changed: 53 additions & 21 deletions

File tree

src/game/server/props.cpp

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
#include "GameStats.h"
4444
#include "vehicle_base.h"
4545
#include "tier0/icommandline.h"
46+
//includes used for improved autoclose
47+
#include "asw_gameresource.h"
48+
#include "asw_marine_resource.h"
49+
#include "asw_marine.h"
50+
4651

4752

4853

@@ -4690,28 +4695,55 @@ void CBasePropDoor::DoorOpenMoveDone(void)
46904695
//-----------------------------------------------------------------------------
46914696
// Purpose: Think function that tries to close the door. Used for autoreturn.
46924697
//-----------------------------------------------------------------------------
4693-
void CBasePropDoor::DoorAutoCloseThink(void)
4694-
{
4695-
// When autoclosing, we check both sides so that we don't close in the player's
4696-
// face, or in an NPC's face for that matter, because they might be shooting
4697-
// through the doorway.
4698-
if ( !DoorCanClose( true ) )
4699-
{
4700-
if (m_flAutoReturnDelay == -1)
4701-
{
4702-
SetNextThink( TICK_NEVER_THINK );
4703-
}
4704-
else
4705-
{
4706-
// In flWait seconds, DoorClose will fire, unless wait is -1, then door stays open
4707-
SetMoveDoneTime(m_flAutoReturnDelay + 0.1);
4708-
SetMoveDone(&CBasePropDoor::DoorAutoCloseThink);
4709-
}
4710-
4711-
return;
4712-
}
4698+
void CASW_Door::DoorAutoCloseThink()
4699+
{
4700+
//aprox distance of bigger then jags ff with gl plus a safety marign
4701+
const float CLOSE_DIST = 350.0f;
4702+
bool bMarineNearby = false;
4703+
4704+
if (ASWGameResource())
4705+
{
4706+
for (int i = 0; i < ASWGameResource()->GetMaxMarineResources(); i++)
4707+
{
4708+
CASW_Marine_Resource *pMR = ASWGameResource()->GetMarineResource(i);
4709+
CASW_Marine *pMarine = pMR ? pMR->GetMarineEntity() : NULL;
4710+
if (pMarine && pMarine->GetHealth() > 0)
4711+
{
4712+
float dist = (pMarine->GetAbsOrigin() - GetAbsOrigin()).Length();
4713+
if (dist < CLOSE_DIST)
4714+
{
4715+
bMarineNearby = true;
4716+
break;
4717+
}
4718+
}
4719+
}
4720+
}
4721+
4722+
if (bMarineNearby)
4723+
{
4724+
// Don't auto-close if a marine is nearby. Try again soon.
4725+
SetNextThink(gpGlobals->curtime + 0.1);
4726+
return;
4727+
}
4728+
4729+
if ( !DoorCanClose( true ) )
4730+
{
4731+
if (m_flAutoReturnDelay == -1)
4732+
{
4733+
SetNextThink( TICK_NEVER_THINK );
4734+
}
4735+
else
4736+
{
4737+
// In flWait seconds, DoorClose will fire, unless wait is -1, then door stays open
4738+
SetMoveDoneTime(m_flAutoReturnDelay + 0.1);
4739+
SetMoveDone(&CBasePropDoor::DoorAutoCloseThink);
4740+
}
4741+
4742+
return;
4743+
}
4744+
4745+
DoorClose();
47134746

4714-
DoorClose();
47154747
}
47164748

47174749

0 commit comments

Comments
 (0)