-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_door.cpp
More file actions
2003 lines (1703 loc) · 57.6 KB
/
asw_door.cpp
File metadata and controls
2003 lines (1703 loc) · 57.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "cbase.h"
#include "asw_door.h"
#include "asw_door_padding.h"
#include "doors.h"
#include "asw_trace_filter_door_crush.h"
#include "eventqueue.h"
#include "func_asw_fade.h"
#include "prop_asw_fade.h"
#include "asw_marine.h"
#include "asw_marine_speech.h"
#include "asw_marine_resource.h"
#include "asw_player.h"
#include "asw_weapon_sniper_rifle.h"
#include "asw_fail_advice.h"
#include "asw_gamerules.h"
#include "asw_generic_emitter_entity.h"
#include "vcollide_parse.h"
#include "cvisibilitymonitor.h"
#include "soundent.h"
#include "asw_util_shared.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_DATADESC( CASW_Door )
DEFINE_KEYFIELD( m_eSpawnPosition, FIELD_INTEGER, "spawnpos" ),
DEFINE_KEYFIELD( m_flDistance, FIELD_FLOAT, "distance" ),
DEFINE_KEYFIELD( m_angSlideAngle, FIELD_VECTOR, "slideangle" ),
DEFINE_KEYFIELD( m_flTotalSealTime, FIELD_FLOAT, "totalsealtime" ),
DEFINE_KEYFIELD( m_flCurrentSealTime, FIELD_FLOAT, "currentsealtime" ),
DEFINE_KEYFIELD( m_iDoorType, FIELD_INTEGER, "doortype" ),
DEFINE_KEYFIELD( m_iCustomMaxHealth, FIELD_INTEGER, "CustomMaxHealth" ),
DEFINE_KEYFIELD( m_DentAmount, FIELD_INTEGER, "dentamount" ),
DEFINE_KEYFIELD( m_flCustomDentPercentage, FIELD_FLOAT, "CustomDentPercentage" ),
DEFINE_KEYFIELD( m_bShowsOnScanner, FIELD_BOOLEAN, "showsonscanner" ),
DEFINE_KEYFIELD( m_bAutoOpen, FIELD_BOOLEAN, "autoopen" ),
DEFINE_KEYFIELD( m_bCanCloseToWeld, FIELD_BOOLEAN, "CanCloseToWeld" ),
DEFINE_KEYFIELD( m_bCanPlayerWeld, FIELD_BOOLEAN, "CanPlayerWeld" ),
DEFINE_KEYFIELD( m_bDoCutShout, FIELD_BOOLEAN, "DoCutShout" ),
DEFINE_KEYFIELD( m_bDoBreachedShout, FIELD_BOOLEAN, "DoBreachedShout" ),
DEFINE_KEYFIELD( m_bDoAutoShootChatter, FIELD_BOOLEAN, "DoAutoShootChatter" ),
DEFINE_FIELD( m_bBashable, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bShootable, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vecGoal, FIELD_VECTOR ),
DEFINE_FIELD( m_hDoorBlocker, FIELD_EHANDLE ),
DEFINE_FIELD( m_hDoorPadding, FIELD_EHANDLE ),
DEFINE_FIELD( m_fClosingToWeldTime, FIELD_FLOAT ),
DEFINE_FIELD( m_bHasBeenWelded, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bFlipped, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bSetSide, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vecOpenPosition, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecClosedPosition, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecBoundsMin, FIELD_VECTOR ),
DEFINE_FIELD( m_vecBoundsMax, FIELD_VECTOR ),
DEFINE_FIELD( m_fLastMarineShootTime, FIELD_TIME ),
DEFINE_FIELD( m_fMarineShootCounter, FIELD_FLOAT ),
DEFINE_FIELD( m_bDoneDoorShout, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fLastMomentFlipDamage, FIELD_FLOAT ),
DEFINE_FIELD( m_fSkillMarineHelping, FIELD_TIME ),
DEFINE_FIELD( m_bSkillMarineHelping, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bDoorFallen, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bRecommendedSeal, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bWasWeldedByMarine, FIELD_BOOLEAN ),
DEFINE_FIELD( m_iszDoorHitSound, FIELD_SOUNDNAME ),
DEFINE_FIELD( m_iszDoorDentSound, FIELD_SOUNDNAME ),
DEFINE_THINKFUNC( RunAnimation ),
DEFINE_INPUTFUNC( FIELD_VOID, "NPCNear", InputNPCNear ),
DEFINE_INPUTFUNC( FIELD_VOID, "EnableAutoOpen", InputEnableAutoOpen ),
DEFINE_INPUTFUNC( FIELD_VOID, "DisableAutoOpen", InputDisableAutoOpen ),
DEFINE_INPUTFUNC( FIELD_VOID, "RecommendWeld", InputRecommendWeld ),
DEFINE_OUTPUT( m_OnFullySealed, "OnFullySealed" ),
DEFINE_OUTPUT( m_OnFullyCut, "OnFullyCut" ),
DEFINE_OUTPUT( m_OnDestroyed, "OnDestroyed" ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CASW_Door, DT_ASW_Door )
SendPropFloat ( SENDINFO( m_flTotalSealTime ) ),
SendPropFloat ( SENDINFO( m_flCurrentSealTime ) ),
SendPropInt ( SENDINFO( m_iDoorStrength ) ),
SendPropInt ( SENDINFO( m_iDoorType ) ),
SendPropInt ( SENDINFO( m_iHealth ) ),
SendPropInt ( SENDINFO( m_lifeState ) ),
SendPropBool ( SENDINFO( m_bAutoOpen ) ),
SendPropBool ( SENDINFO( m_bBashable ) ),
SendPropBool ( SENDINFO( m_bShootable ) ),
SendPropBool ( SENDINFO( m_bCanCloseToWeld ) ),
SendPropBool ( SENDINFO( m_bCanPlayerWeld ) ),
SendPropBool ( SENDINFO( m_bRecommendedSeal ) ),
SendPropBool ( SENDINFO( m_bWasWeldedByMarine ) ),
SendPropFloat ( SENDINFO( m_fLastMomentFlipDamage ) ),
SendPropVector ( SENDINFO( m_vecClosedPosition ), -1, SPROP_COORD ),
SendPropBool ( SENDINFO( m_bSkillMarineHelping ) ),
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( asw_door, CASW_Door );
ConVar asw_door_drone_damage_scale( "asw_door_drone_damage_scale", "2.0f", FCVAR_CHEAT, "Damage scale for drones hitting doors" );
ConVar asw_door_seal_damage_reduction( "asw_door_seal_damage_reduction", "0.6f", FCVAR_CHEAT, "Alien damage scale when door is fully sealed" );
ConVar asw_door_physics( "asw_door_physics", "0", FCVAR_CHEAT, "If set, doors will turn into vphysics objects upon death." );
ConVar rd_door_melee_damage( "rd_door_melee_damage", "0", FCVAR_CHEAT, "Allow doors to take melee damage from marines." );
ConVar asw_door_damage_base( "asw_door_damage_base", "1000", FCVAR_CHEAT, "Damage being hit by a door does on Normal." );
ConVar asw_door_damage_step( "asw_door_damage_step", "0", FCVAR_CHEAT, "Increase/decrease in damage from being hit by a door for every mission difficulty above/below 5." );
ConVar asw_door_normal_health_base( "asw_door_normal_health_base", "1800", FCVAR_CHEAT | FCVAR_REPLICATED, "Base health for a non-reinforced door on Normal." );
ConVar asw_door_normal_health_step( "asw_door_normal_health_step", "0", FCVAR_CHEAT | FCVAR_REPLICATED, "Increase/decrease in health for a non-reinforced door on for every mission difficulty above/below 5." );
ConVar asw_door_reinforced_health_base( "asw_door_reinforced_health_base", "2400", FCVAR_CHEAT, "Base health for a reinforced door on Normal." );
ConVar asw_door_reinforced_health_step( "asw_door_reinforced_health_step", "0", FCVAR_CHEAT, "Increase/decrease in health for a reinforced door on for every mission difficulty above/below 5." );
ConVar rd_door_force_closed( "rd_door_force_closed", "1", FCVAR_CHEAT );
extern ConVar asw_debug_marine_chatter;
extern ConVar asw_difficulty_alien_damage_step;
static const char *s_pDoorAnimThink = "DoorAnimThink";
namespace
{
void UTIL_ComputeAABBForBounds( const Vector &mins1, const Vector &maxs1, const Vector &mins2, const Vector &maxs2, Vector *destMins, Vector *destMaxs )
{
// Find the minimum extents
( *destMins )[0] = MIN( mins1[0], mins2[0] );
( *destMins )[1] = MIN( mins1[1], mins2[1] );
( *destMins )[2] = MIN( mins1[2], mins2[2] );
// Find the maximum extents
( *destMaxs )[0] = MAX( maxs1[0], maxs2[0] );
( *destMaxs )[1] = MAX( maxs1[1], maxs2[1] );
( *destMaxs )[2] = MAX( maxs1[2], maxs2[2] );
}
}
CASW_Door::CASW_Door()
{
// compat for maps built before this key was added to hammer
m_bCanPlayerWeld = true;
}
CASW_Door::~CASW_Door( void )
{
// Remove our door blocker entity
if ( m_hDoorBlocker != NULL )
{
UTIL_Remove( m_hDoorBlocker );
}
if ( m_hDoorPadding != NULL )
{
UTIL_Remove( m_hDoorPadding );
}
}
void CASW_Door::Precache()
{
PrecacheScriptSound( "ASW_Welder.WeldDeny" );
BaseClass::Precache();
int iModelIndex = modelinfo->GetModelIndex( STRING( GetModelName() ) );
const model_t *pModel = modelinfo->GetModel( iModelIndex );
KeyValues::AutoDelete pKV( "" );
CUtlBuffer buf( 1024, 0, CUtlBuffer::TEXT_BUFFER );
if ( modelinfo->GetModelKeyValue( pModel, buf ) )
{
pKV->LoadFromBuffer( modelinfo->GetModelName( pModel ), buf );
}
m_iszDoorHitSound = AllocPooledString( pKV->GetString( "asw_door/hit_sound", "ASW_Door.MeleeHit" ) );
m_iszDoorDentSound = AllocPooledString( pKV->GetString( "asw_door/dent_sound", "ASW_Door.Dented" ) );
PrecacheScriptSound( STRING( m_iszDoorHitSound ) );
PrecacheScriptSound( STRING( m_iszDoorDentSound ) );
}
void CASW_Door::Spawn()
{
if ( m_flDistance == 0 )
{
m_flDistance = 90;
}
m_fLastMomentFlipDamage = 0;
m_iFallingStage = 0;
m_flDistance = fabs( m_flDistance );
// Calculate our closed and open positions
m_vecClosedPosition = GetAbsOrigin();
QAngle door_angle = GetLocalAngles();
door_angle += m_angSlideAngle;
Vector v( m_flDistance, 0, 0 );
matrix3x4_t door_angle_matrix;
Vector offset;
AngleMatrix( door_angle, door_angle_matrix );
VectorRotate( v, door_angle_matrix, offset );
m_vecOpenPosition = GetAbsOrigin() + offset;
m_fClosingToWeldTime = 0;
m_nHardwareType = -1; // Suppress base class warnings
m_nPhysicsMaterial = physprops->GetSurfaceIndex( "metal" );
// Call this last! It relies on stuff we calculated above.
BaseClass::Spawn();
// Figure out our volumes of movement as this door opens
CalculateDoorVolume( m_vecOpenPosition, m_vecClosedPosition, &m_vecBoundsMin, &m_vecBoundsMax );
if ( m_flTotalSealTime <= 0 )
m_flTotalSealTime = 10.0f;
// set door strength according to breakable or not:
switch ( m_iDoorType )
{
case ASWDT_NORMAL:
{
m_bBashable = true;
m_bShootable = true;
m_iDoorStrength = asw_door_normal_health_base.GetInt();
break;
}
case ASWDT_REINFORCED:
{
m_bBashable = true;
m_bShootable = true;
m_iDoorStrength = asw_door_reinforced_health_base.GetInt();
break;
}
case ASWDT_INDESTRUCTABLE:
{
m_bBashable = false;
m_bShootable = false;
m_iDoorStrength = 0;
break;
}
case ASWDT_CUSTOM:
{
m_bBashable = true;
m_bShootable = true;
m_iDoorStrength = m_iCustomMaxHealth <= 0 ? asw_door_normal_health_base.GetInt() : m_iCustomMaxHealth;
break;
}
}
m_bSetSide = false;
m_bFlipped = false;
m_bDoneChatter = false;
m_fChatterCounter = 0;
if ( m_DentAmount == ASWDD_PARTIAL_PREFLIP )
{
m_DentAmount = ASWDD_PARTIAL;
FlipDoor();
}
else if ( m_DentAmount == ASWDD_COMPLETE_PREFLIP )
{
m_DentAmount = ASWDD_COMPLETE;
FlipDoor();
}
if ( m_iDoorStrength > 0 )
{
m_takedamage = DAMAGE_YES;
m_iHealth = m_iDoorStrength;
if ( m_flCustomDentPercentage > 0.001f && m_flCustomDentPercentage < 1.0f )
{
m_iHealth = m_flCustomDentPercentage * m_iDoorStrength;
if ( m_iHealth == 0 )
m_iHealth = 1;
}
else
{
if ( m_DentAmount == ASWDD_PARTIAL )
{
m_iHealth = ASW_DOOR_PARTIAL_DENT_HEALTH * m_iDoorStrength;
}
else if ( m_DentAmount == ASWDD_COMPLETE )
{
m_iHealth = ASW_DOOR_COMPLETE_DENT_HEALTH * m_iDoorStrength;
}
}
SetDentSequence();
SetMaxHealth( m_iHealth );
}
else
{
m_takedamage = DAMAGE_YES; // has to receive damage events so marines can be informed they're shooting a junk item
m_iHealth = 1;
}
// if this door isn't sealed, we don't do cut shouting
if ( m_flCurrentSealTime <= 0 )
{
m_bDoCutShout = false;
}
m_fLastFullyWeldedSound = 0;
// create our padding:
m_hDoorPadding = CASW_Door_Padding::CreateDoorPadding( this );
if ( VPhysicsGetObject() )
{
VPhysicsGetObject()->SetMaterialIndex( physprops->GetSurfaceIndex( "metal" ) );
}
SetContextThink( &CASW_Door::RunAnimation, gpGlobals->curtime + 0.1f, s_pDoorAnimThink );
if ( m_flCurrentSealTime > 0.0f )
{
VisibilityMonitor_AddEntity( this, asw_visrange_generic.GetFloat() * 0.9f, &CASW_Door::WeldedVismonCallback, NULL );
}
else
{
VisibilityMonitor_AddEntity( this, asw_visrange_generic.GetFloat() * 0.9f, &CASW_Door::DestroyVismonCallback, &CASW_Door::DestroyVismonEvaluator );
}
}
bool CASW_Door::DestroyVismonEvaluator( CBaseEntity *pVisibleEntity, CBasePlayer *pViewingPlayer )
{
CASW_Door *pDoor = assert_cast< CASW_Door * >( pVisibleEntity );
if ( !pDoor->m_bShootable )
return false;
if ( pDoor->m_bDoAutoShootChatter )
return true;
if ( pDoor->m_iHealth <= 0 )
return false;
if ( float( pDoor->m_iHealth ) / pDoor->GetMaxHealth() > 0.4f )
return false;
return true;
}
bool CASW_Door::DestroyVismonCallback( CBaseEntity *pVisibleEntity, CBasePlayer *pViewingPlayer )
{
IGameEvent *event = gameeventmanager->CreateEvent( "door_recommend_destroy" );
if ( event )
{
event->SetInt( "userid", pViewingPlayer->GetUserID() );
event->SetInt( "entindex", pVisibleEntity->entindex() );
gameeventmanager->FireEvent( event );
}
return false;
}
bool CASW_Door::WeldedVismonCallback( CBaseEntity *pVisibleEntity, CBasePlayer *pViewingPlayer )
{
IGameEvent *event = gameeventmanager->CreateEvent( "door_welded_visible" );
if ( event )
{
event->SetInt( "userid", pViewingPlayer->GetUserID() );
event->SetInt( "subject", pVisibleEntity->entindex() );
event->SetString( "entityname", STRING( pVisibleEntity->GetEntityName() ) );
gameeventmanager->FireEvent( event );
}
return false;
}
void CASW_Door::RunAnimation()
{
m_flPlaybackRate = 1.0f;
StudioFrameAdvance();
DispatchAnimEvents( this );
SetContextThink( &CASW_Door::RunAnimation, gpGlobals->curtime + 0.1f, s_pDoorAnimThink );
m_bSkillMarineHelping = ( m_fSkillMarineHelping >= gpGlobals->curtime - 0.2f );
}
// is this door open or not?
bool CASW_Door::IsOpen( void )
{
//return ( m_vecGoal == m_vecOpenPosition );
Vector diff = GetAbsOrigin() - m_vecClosedPosition;
float dist = diff.LengthSqr();
return ( dist > 2 );
}
bool CASW_Door::IsMoving()
{
return GetLocalVelocity().LengthSqr() > 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::OnDoorOpened( void )
{
if ( m_hDoorBlocker != NULL )
{
// Allow passage through this blocker while open
m_hDoorBlocker->AddSolidFlags( FSOLID_NOT_SOLID );
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( GetAbsOrigin(), m_hDoorBlocker->CollisionProp()->OBBMins(), m_hDoorBlocker->CollisionProp()->OBBMaxs(), 0, 255, 0, true, 1.0f );
}
}
if ( m_hDoorPadding != NULL )
{
m_hDoorPadding->AddSolidFlags( FSOLID_NOT_SOLID );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::OnDoorClosed( void )
{
if ( m_hDoorBlocker != NULL )
{
// Destroy the blocker that was preventing NPCs from getting in our way.
UTIL_Remove( m_hDoorBlocker );
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( GetAbsOrigin(), m_hDoorBlocker->CollisionProp()->OBBMins(), m_hDoorBlocker->CollisionProp()->OBBMaxs(), 0, 255, 0, true, 1.0f );
}
}
if ( m_hDoorPadding != NULL )
{
m_hDoorPadding->RemoveSolidFlags( FSOLID_NOT_SOLID );
}
}
//-----------------------------------------------------------------------------
// Purpose: Returns whether the way is clear for the door to close.
// Input : state - Which sides to check, forward, backward, or both.
// Output : Returns true if the door can close, false if the way is blocked.
//-----------------------------------------------------------------------------
bool CASW_Door::DoorCanClose( bool bAutoClose )
{
if ( GetMaster() != NULL )
return GetMaster()->DoorCanClose( bAutoClose );
// Check all slaves
if ( HasSlaves() )
{
int numDoors = m_hDoorList.Count();
CASW_Door *pLinkedDoor = NULL;
// Check all links as well
CBasePropDoor *pBasePD;
for ( int i = 0; i < numDoors; i++ )
{
pBasePD = m_hDoorList[i].Get();
if ( pBasePD && pBasePD->Classify() == CLASS_ASW_DOOR )
{
pLinkedDoor = assert_cast< CASW_Door * >( pBasePD );
if ( !pLinkedDoor->CheckDoorClear() )
return false;
}
}
}
// See if our path of movement is clear to allow us to shut
return CheckDoorClear();
}
void CASW_Door::CalculateDoorVolume( Vector OpenPosition, Vector ClosedPosition, Vector *destMins, Vector *destMaxs )
{
// Save our current position and move to our start position
Vector savePosition = GetAbsOrigin();
SetAbsOrigin( ClosedPosition );
// Find our AABB at the closed state
Vector closedMins, closedMaxs;
CollisionProp()->WorldSpaceAABB( &closedMins, &closedMaxs );
SetAbsOrigin( OpenPosition );
// Find our AABB at the open state
Vector openMins, openMaxs;
CollisionProp()->WorldSpaceAABB( &openMins, &openMaxs );
// Reset our position to our starting position
SetAbsOrigin( savePosition );
// Find the minimum extents
UTIL_ComputeAABBForBounds( closedMins, closedMaxs, openMins, openMaxs, destMins, destMaxs );
// Move this back into local space
*destMins -= GetAbsOrigin();
*destMaxs -= GetAbsOrigin();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::OnRestore( void )
{
BaseClass::OnRestore();
// Figure out our volumes of movement as this door opens
CalculateDoorVolume( m_vecOpenPosition, m_vecClosedPosition, &m_vecBoundsMin, &m_vecBoundsMax );
}
class CASWTraceFilterDoor : public CTraceFilterEntitiesOnly
{
public:
// It does have a base, but we'll never network anything below here..
DECLARE_CLASS_NOBASE( CASWTraceFilterDoor );
CASWTraceFilterDoor( const IHandleEntity *pDoor, const IHandleEntity *passentity, int collisionGroup )
: m_pDoor( pDoor ), m_pPassEnt( passentity ), m_collisionGroup( collisionGroup )
{
}
virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
{
if ( !StandardFilterRules( pHandleEntity, contentsMask ) )
return false;
if ( !PassServerEntityFilter( pHandleEntity, m_pDoor ) )
return false;
if ( !PassServerEntityFilter( pHandleEntity, m_pPassEnt ) )
return false;
// Don't test if the game code tells us we should ignore this collision...
CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
if ( pEntity )
{
if ( dynamic_cast< CFunc_ASW_Fade * >( pEntity ) || dynamic_cast< CProp_ASW_Fade * >( pEntity ) )
return false;
if ( !pEntity->ShouldCollide( m_collisionGroup, contentsMask ) )
return false;
if ( !g_pGameRules->ShouldCollide( m_collisionGroup, pEntity->GetCollisionGroup() ) )
return false;
// If objects are small enough and can move, close on them
if ( pEntity->GetMoveType() == MOVETYPE_VPHYSICS )
{
IPhysicsObject *pPhysics = pEntity->VPhysicsGetObject();
Assert( pPhysics );
// Must either be squashable or very light
if ( pPhysics->IsMoveable() && pPhysics->GetMass() < 32 )
return false;
}
}
return true;
}
private:
const IHandleEntity *m_pDoor;
const IHandleEntity *m_pPassEnt;
int m_collisionGroup;
};
inline void TraceHull_Door( const CBasePropDoor *pDoor, const Vector &vecAbsStart, const Vector &vecAbsEnd, const Vector &hullMin,
const Vector &hullMax, unsigned int mask, const CBaseEntity *ignore,
int collisionGroup, trace_t *ptr )
{
Ray_t ray;
ray.Init( vecAbsStart, vecAbsEnd, hullMin, hullMax );
CASWTraceFilterDoor traceFilter( pDoor, ignore, collisionGroup );
enginetrace->TraceRay( ray, mask, &traceFilter, ptr );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : forward -
// mask -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CASW_Door::CheckDoorClear()
{
// Look for blocking entities, ignoring ourselves and the entity that opened us.
Vector vecClosed = m_vecClosedPosition;
trace_t tr;
TraceHull_Door( this, vecClosed, vecClosed, m_vecBoundsMin, m_vecBoundsMax, MASK_SOLID, GetActivator(), COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid || tr.startsolid )
{
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( vecClosed, m_vecBoundsMin, m_vecBoundsMax, 255, 0, 0, true, 10.0f );
if ( tr.m_pEnt )
{
NDebugOverlay::Box( tr.m_pEnt->GetAbsOrigin(), tr.m_pEnt->CollisionProp()->OBBMins(), tr.m_pEnt->CollisionProp()->OBBMaxs(), 220, 220, 0, true, 10.0f );
}
}
return false;
}
// dont try to close when an entity is standing inside any trigger_asw_door_area's that would make the door open
FOR_EACH_VEC( m_AttachedDoorAreas, i )
{
if ( m_AttachedDoorAreas[i]->GetNumTouching() != 0 )
return false;
}
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( vecClosed, m_vecBoundsMin, m_vecBoundsMax, 0, 255, 0, true, 10.0f );
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Puts the door in its appropriate position for spawning.
//-----------------------------------------------------------------------------
void CASW_Door::DoorTeleportToSpawnPosition()
{
Vector vecSpawn;
// The Start Open spawnflag trumps the choices field
if ( HasSpawnFlags( SF_DOOR_START_OPEN_OBSOLETE ) || m_eSpawnPosition == DOOR_SPAWN_OPEN )
{
vecSpawn = m_vecOpenPosition;
SetDoorState( DOOR_STATE_OPEN );
}
else if ( m_eSpawnPosition == DOOR_SPAWN_CLOSED )
{
vecSpawn = m_vecClosedPosition;
SetDoorState( DOOR_STATE_CLOSED );
}
else
{
// Bogus spawn position setting!
Assert( false );
vecSpawn = m_vecClosedPosition;
SetDoorState( DOOR_STATE_CLOSED );
}
SetAbsOrigin( vecSpawn );
// Doesn't relink; that's done in Spawn.
}
//-----------------------------------------------------------------------------
// Purpose: After moving, set position to the exact final position, call "move done" function.
//-----------------------------------------------------------------------------
void CASW_Door::MoveDone()
{
SetAbsOrigin( m_vecGoal );
SetLocalVelocity( vec3_origin );
SetMoveDoneTime( -1 );
BaseClass::MoveDone();
}
//-----------------------------------------------------------------------------
// Purpose: Calculate m_vecVelocity and m_flNextThink to reach vecDest from
// GetLocalOrigin() traveling at flSpeed. Just like LinearMove, but rotational.
// Input : vecDestPosition -
// flSpeed -
//-----------------------------------------------------------------------------
void CASW_Door::SlideMove( const Vector &vecDestPosition, float flSpeed )
{
ASSERTSZ( flSpeed != 0, "SlideMove: no speed is defined!" );
// no moving if our door is dead
//if (m_lifeState = LIFE_DEAD)
//{
//MoveDone();
//return;
//}
m_vecGoal = vecDestPosition;
// Already there?
if ( vecDestPosition == GetAbsOrigin() )
{
MoveDone();
return;
}
// Set destdelta to the vector needed to move.
Vector vecDestDelta = vecDestPosition - GetAbsOrigin();
// Divide by speed to get time to reach dest
float flTravelTime = vecDestDelta.Length() / flSpeed;
// Call MoveDone when destination position is reached.
SetMoveDoneTime( flTravelTime );
// Scale the destdelta vector by the time spent traveling to get velocity.
SetLocalVelocity( vecDestDelta * ( 1.0 / flTravelTime ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::BeginOpening( CBaseEntity *pOwner )
{
Vector vecOpen = m_vecOpenPosition;
// turn off our padding, so it doesn't drag marines along
if ( m_hDoorPadding != NULL )
{
m_hDoorPadding->AddSolidFlags( FSOLID_NOT_SOLID );
}
// Create the door blocker
Vector mins, maxs;
mins = m_vecBoundsMin;
maxs = m_vecBoundsMax;
if ( m_hDoorBlocker != NULL )
{
UTIL_Remove( m_hDoorBlocker );
}
// Create a blocking entity to keep random entities out of our movement path
m_hDoorBlocker = CEntityBlocker::Create( GetAbsOrigin(), mins, maxs, pOwner, false );
Vector volumeCenter = ( ( mins + maxs ) * 0.5f ) + GetAbsOrigin();
// Ignoring the Z
float volumeRadius = MAX( fabs( mins.x ), maxs.x );
volumeRadius = MAX( volumeRadius, MAX( fabs( mins.y ), maxs.y ) );
// Debug
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Cross3D( volumeCenter, -Vector( volumeRadius, volumeRadius, volumeRadius ), Vector( volumeRadius, volumeRadius, volumeRadius ), 255, 0, 0, true, 1.0f );
}
// Make respectful entities move away from our path
CSoundEnt::InsertSound( SOUND_MOVE_AWAY, volumeCenter, volumeRadius, 0.5f, pOwner );
// Do final setup
if ( m_hDoorBlocker != NULL )
{
// Only block NPCs
m_hDoorBlocker->SetCollisionGroup( COLLISION_GROUP_DOOR_BLOCKER );
// If we hit something while opening, just stay unsolid until we try again
if ( CheckDoorClear() == false )
{
m_hDoorBlocker->AddSolidFlags( FSOLID_NOT_SOLID );
}
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( GetAbsOrigin(), m_hDoorBlocker->CollisionProp()->OBBMins(), m_hDoorBlocker->CollisionProp()->OBBMaxs(), 255, 0, 0, true, 1.0f );
}
}
SlideMove( vecOpen, m_flSpeed );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::BeginClosing( void )
{
if ( m_hDoorBlocker != NULL )
{
// Become solid again unless we're already being blocked
if ( CheckDoorClear() )
{
m_hDoorBlocker->RemoveSolidFlags( FSOLID_NOT_SOLID );
}
if ( g_debug_doors.GetBool() )
{
NDebugOverlay::Box( GetAbsOrigin(), m_hDoorBlocker->CollisionProp()->OBBMins(), m_hDoorBlocker->CollisionProp()->OBBMaxs(), 255, 0, 0, true, 1.0f );
}
}
SlideMove( m_vecClosedPosition, m_flSpeed );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_Door::DoorStop( void )
{
SetLocalVelocity( vec3_origin );
SetMoveDoneTime( -1 );
}
//-----------------------------------------------------------------------------
// Purpose: Restart a door moving that was temporarily paused
//-----------------------------------------------------------------------------
void CASW_Door::DoorResume( void )
{
// Restart our linear movement
SlideMove( m_vecGoal, m_flSpeed );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : vecMoveDir -
// opendata -
//-----------------------------------------------------------------------------
void CASW_Door::GetNPCOpenData( CAI_BaseNPC *pNPC, opendata_t &opendata )
{
// dvs: TODO: finalize open position, direction, activity
Vector vecForward;
Vector vecRight;
AngleVectors( GetAbsAngles(), &vecForward, &vecRight, NULL );
//
// Figure out where the NPC should stand to open this door,
// and what direction they should face.
//
opendata.vecStandPos = GetAbsOrigin() - ( vecRight * 24 );
opendata.vecStandPos.z -= 54;
//Vector vecNPCOrigin = pNPC->GetAbsOrigin();
if ( pNPC->GetAbsOrigin().Dot( vecForward ) > GetAbsOrigin().Dot( vecForward ) )
{
// In front of the door relative to the door's forward vector.
opendata.vecStandPos += vecForward * 64;
opendata.vecFaceDir = -vecForward;
}
else
{
// Behind the door relative to the door's forward vector.
opendata.vecStandPos -= vecForward * 64;
opendata.vecFaceDir = vecForward;
}
opendata.eActivity = ACT_OPEN_DOOR;
}
//-----------------------------------------------------------------------------
// Purpose: Returns how long it will take this door to open.
//-----------------------------------------------------------------------------
float CASW_Door::GetOpenInterval()
{
// set destdelta to the vector needed to move
Vector vecDestDelta = m_vecOpenPosition - GetAbsOrigin();
// divide by speed to get time to reach dest
return vecDestDelta.Length() / m_flSpeed;
}
//-----------------------------------------------------------------------------
// Purpose: Draw any debug text overlays
// Output : Current text offset from the top
//-----------------------------------------------------------------------------
int CASW_Door::DrawDebugTextOverlays( void )
{
int text_offset = BaseClass::DrawDebugTextOverlays();
if ( m_debugOverlays & OVERLAY_TEXT_BIT )
{
char tempstr[512];
Q_snprintf( tempstr, sizeof( tempstr ), "Avelocity: %.2f %.2f %.2f", GetLocalVelocity().x, GetLocalVelocity().y, GetLocalVelocity().z );
NDebugOverlay::EntityText( entindex(), text_offset, tempstr, 0 );
text_offset++;
if ( IsDoorOpen() )
{
Q_strncpy( tempstr, "DOOR STATE: OPEN", sizeof( tempstr ) );
}
else if ( IsDoorClosed() )
{
Q_strncpy( tempstr, "DOOR STATE: CLOSED", sizeof( tempstr ) );
}
else if ( IsDoorOpening() )
{
Q_strncpy( tempstr, "DOOR STATE: OPENING", sizeof( tempstr ) );
}
else if ( IsDoorClosing() )
{
Q_strncpy( tempstr, "DOOR STATE: CLOSING", sizeof( tempstr ) );
}
else if ( IsDoorAjar() )
{
Q_strncpy( tempstr, "DOOR STATE: AJAR", sizeof( tempstr ) );
}
NDebugOverlay::EntityText( entindex(), text_offset, tempstr, 0 );
text_offset++;
}
return text_offset;
}
void CASW_Door::InputNPCNear( inputdata_t &inputdata )
{
// a marine or an alien has come near the door
Msg( "[S] NPC near door\n" );
}
// returns how sealed this door is, from 0 to 1.0
float CASW_Door::GetSealAmount()
{
if ( m_flTotalSealTime <= 0 )
return 0;
return ( m_flCurrentSealTime / m_flTotalSealTime );
}
void CASW_Door::SetCurrentSealTime( float fTime )
{
m_flCurrentSealTime = fTime;
}
void CASW_Door::SetTotalSealTime( float fTime )
{
m_flTotalSealTime = fTime;
}
bool CASW_Door::IsDoorLocked()
{
bool bDented = ( m_DentAmount > ASWDD_PARTIAL );
if ( !bDented && HasSlaves() )
{
int numDoors = m_hDoorList.Count();
CASW_Door *pSlave = NULL;
CBasePropDoor *pBasePD;
for ( int i = 0; i < numDoors; i++ )
{
pBasePD = m_hDoorList[i].Get();
if ( pBasePD && pBasePD->Classify() == CLASS_ASW_DOOR )
{
pSlave = assert_cast< CASW_Door * >( pBasePD );
if ( pSlave->m_DentAmount > ASWDD_PARTIAL )
{
bDented = true;
break;
}
}
}
}
return BaseClass::IsDoorLocked() || bDented || ( GetCurrentSealTime() > 0 );
}
void CASW_Door::WeldDoor( bool bSeal, float fAmount, CASW_Marine *pMarine )
{
if ( !pMarine )
return;
float fCurrentSealTime = GetCurrentSealTime();
if ( !bSeal )
{
fAmount = -fAmount;
}
else
{
m_bWasWeldedByMarine = true;
}
// once a door has been welded a bit, don't have anyone complain about it being sealed
m_bDoCutShout = false;
if ( m_fChatterCounter * fAmount < 0 ) // reset the chatter counter if we switch weld direction
{
m_fChatterCounter = 0;
m_bDoneChatter = false;
}
if ( !m_bDoneChatter )
{
m_fChatterCounter += fAmount;
if ( m_fChatterCounter > 1.0f )
{
pMarine->GetMarineSpeech()->Chatter( CHATTER_SEALING_DOOR );
m_bDoneChatter = true;
}
else if ( m_fChatterCounter < -1.0f )
{
pMarine->GetMarineSpeech()->Chatter( CHATTER_CUTTING_DOOR );
m_bDoneChatter = true;
}
}
float fNewTime = fCurrentSealTime + fAmount;
if ( fNewTime <= 0 )
{
if ( fCurrentSealTime > 0 )
{
m_OnFullyCut.FireOutput( pMarine, this );
// door completely opened