|
18 | 18 | #include "cvisibilitymonitor.h" |
19 | 19 | #include "soundent.h" |
20 | 20 | #include "asw_util_shared.h" |
| 21 | +#include "asw_gameresource.h" |
21 | 22 |
|
22 | 23 | // memdbgon must be the last include file in a .cpp file!!! |
23 | 24 | #include "tier0/memdbgon.h" |
@@ -436,6 +437,57 @@ void CASW_Door::OnDoorClosed( void ) |
436 | 437 | } |
437 | 438 | } |
438 | 439 |
|
| 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 | +} |
439 | 491 |
|
440 | 492 | //----------------------------------------------------------------------------- |
441 | 493 | // Purpose: Returns whether the way is clear for the door to close. |
|
0 commit comments