-
Notifications
You must be signed in to change notification settings - Fork 638
/
Copy pathcontroller.cpp
1427 lines (1169 loc) · 33.6 KB
/
controller.cpp
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
/***
*
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
//=========================================================
// CONTROLLER
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "effects.h"
#include "schedule.h"
#include "weapons.h"
#include "squadmonster.h"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define CONTROLLER_AE_HEAD_OPEN 1
#define CONTROLLER_AE_BALL_SHOOT 2
#define CONTROLLER_AE_SMALL_SHOOT 3
#define CONTROLLER_AE_POWERUP_FULL 4
#define CONTROLLER_AE_POWERUP_HALF 5
#define CONTROLLER_FLINCH_DELAY 2 // at most one flinch every n secs
class CController : public CSquadMonster
{
public:
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
int Classify ( void );
void HandleAnimEvent( MonsterEvent_t *pEvent );
void RunAI( void );
BOOL CheckRangeAttack1 ( float flDot, float flDist ); // balls
BOOL CheckRangeAttack2 ( float flDot, float flDist ); // head
BOOL CheckMeleeAttack1 ( float flDot, float flDist ); // block, throw
Schedule_t* GetSchedule ( void );
Schedule_t* GetScheduleOfType ( int Type );
void StartTask ( Task_t *pTask );
void RunTask ( Task_t *pTask );
CUSTOM_SCHEDULES;
void Stop( void );
void Move ( float flInterval );
int CheckLocalMove ( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist );
void MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval );
void SetActivity ( Activity NewActivity );
BOOL ShouldAdvanceRoute( float flWaypointDist );
int LookupFloat( );
float m_flNextFlinch;
float m_flShootTime;
float m_flShootEnd;
void PainSound( void );
void AlertSound( void );
void IdleSound( void );
void AttackSound( void );
void DeathSound( void );
static const char *pAttackSounds[];
static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pPainSounds[];
static const char *pDeathSounds[];
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
CSprite *m_pBall[2]; // hand balls
int m_iBall[2]; // how bright it should be
float m_iBallTime[2]; // when it should be that color
int m_iBallCurrent[2]; // current brightness
Vector m_vecEstVelocity;
Vector m_velocity;
int m_fInCombat;
};
LINK_ENTITY_TO_CLASS( monster_alien_controller, CController );
TYPEDESCRIPTION CController::m_SaveData[] =
{
DEFINE_ARRAY( CController, m_pBall, FIELD_CLASSPTR, 2 ),
DEFINE_ARRAY( CController, m_iBall, FIELD_INTEGER, 2 ),
DEFINE_ARRAY( CController, m_iBallTime, FIELD_TIME, 2 ),
DEFINE_ARRAY( CController, m_iBallCurrent, FIELD_INTEGER, 2 ),
DEFINE_FIELD( CController, m_vecEstVelocity, FIELD_VECTOR ),
};
IMPLEMENT_SAVERESTORE( CController, CSquadMonster );
const char *CController::pAttackSounds[] =
{
"controller/con_attack1.wav",
"controller/con_attack2.wav",
"controller/con_attack3.wav",
};
const char *CController::pIdleSounds[] =
{
"controller/con_idle1.wav",
"controller/con_idle2.wav",
"controller/con_idle3.wav",
"controller/con_idle4.wav",
"controller/con_idle5.wav",
};
const char *CController::pAlertSounds[] =
{
"controller/con_alert1.wav",
"controller/con_alert2.wav",
"controller/con_alert3.wav",
};
const char *CController::pPainSounds[] =
{
"controller/con_pain1.wav",
"controller/con_pain2.wav",
"controller/con_pain3.wav",
};
const char *CController::pDeathSounds[] =
{
"controller/con_die1.wav",
"controller/con_die2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
int CController :: Classify ( void )
{
return CLASS_ALIEN_MILITARY;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
void CController :: SetYawSpeed ( void )
{
int ys;
ys = 120;
#if 0
switch ( m_Activity )
{
}
#endif
pev->yaw_speed = ys;
}
int CController :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
// HACK HACK -- until we fix this.
if ( IsAlive() )
PainSound();
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
void CController::Killed( entvars_t *pevAttacker, int iGib )
{
// shut off balls
/*
m_iBall[0] = 0;
m_iBallTime[0] = gpGlobals->time + 4.0;
m_iBall[1] = 0;
m_iBallTime[1] = gpGlobals->time + 4.0;
*/
// fade balls
if (m_pBall[0])
{
m_pBall[0]->SUB_StartFadeOut();
m_pBall[0] = NULL;
}
if (m_pBall[1])
{
m_pBall[1]->SUB_StartFadeOut();
m_pBall[1] = NULL;
}
CSquadMonster::Killed( pevAttacker, iGib );
}
void CController::GibMonster( void )
{
// delete balls
if (m_pBall[0])
{
UTIL_Remove( m_pBall[0] );
m_pBall[0] = NULL;
}
if (m_pBall[1])
{
UTIL_Remove( m_pBall[1] );
m_pBall[1] = NULL;
}
CSquadMonster::GibMonster( );
}
void CController :: PainSound( void )
{
if (RANDOM_LONG(0,5) < 2)
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pPainSounds );
}
void CController :: AlertSound( void )
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAlertSounds );
}
void CController :: IdleSound( void )
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pIdleSounds );
}
void CController :: AttackSound( void )
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAttackSounds );
}
void CController :: DeathSound( void )
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pDeathSounds );
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CController :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
switch( pEvent->event )
{
case CONTROLLER_AE_HEAD_OPEN:
{
Vector vecStart, angleGun;
GetAttachment( 0, vecStart, angleGun );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
WRITE_SHORT( entindex( ) + 0x1000 ); // entity, attachment
WRITE_COORD( vecStart.x ); // origin
WRITE_COORD( vecStart.y );
WRITE_COORD( vecStart.z );
WRITE_COORD( 1 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 20 ); // life * 10
WRITE_COORD( -32 ); // decay
MESSAGE_END();
m_iBall[0] = 192;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 255;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_BALL_SHOOT:
{
Vector vecStart, angleGun;
GetAttachment( 0, vecStart, angleGun );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
WRITE_SHORT( entindex( ) + 0x1000 ); // entity, attachment
WRITE_COORD( 0 ); // origin
WRITE_COORD( 0 );
WRITE_COORD( 0 );
WRITE_COORD( 32 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 32 ); // decay
MESSAGE_END();
CBaseMonster *pBall = (CBaseMonster*)Create( "controller_head_ball", vecStart, pev->angles, edict() );
pBall->pev->velocity = Vector( 0, 0, 32 );
pBall->m_hEnemy = m_hEnemy;
m_iBall[0] = 0;
m_iBall[1] = 0;
}
break;
case CONTROLLER_AE_SMALL_SHOOT:
{
AttackSound( );
m_flShootTime = gpGlobals->time;
m_flShootEnd = m_flShootTime + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_POWERUP_FULL:
{
m_iBall[0] = 255;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 255;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_POWERUP_HALF:
{
m_iBall[0] = 192;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 192;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
void CController :: Spawn()
{
Precache( );
SET_MODEL(ENT(pev), "models/controller.mdl");
UTIL_SetSize( pev, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ));
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_FLY;
pev->flags |= FL_FLY;
m_bloodColor = BLOOD_COLOR_GREEN;
pev->health = gSkillData.controllerHealth;
pev->view_ofs = Vector( 0, 0, -2 );// position of the eyes relative to monster's origin.
m_flFieldOfView = VIEW_FIELD_FULL;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
void CController :: Precache()
{
PRECACHE_MODEL("models/controller.mdl");
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pIdleSounds );
PRECACHE_SOUND_ARRAY( pAlertSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
PRECACHE_MODEL( "sprites/xspark4.spr");
UTIL_PrecacheOther( "controller_energy_ball" );
UTIL_PrecacheOther( "controller_head_ball" );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
// Chase enemy schedule
Task_t tlControllerChaseEnemy[] =
{
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
};
Schedule_t slControllerChaseEnemy[] =
{
{
tlControllerChaseEnemy,
ARRAYSIZE ( tlControllerChaseEnemy ),
bits_COND_NEW_ENEMY |
bits_COND_TASK_FAILED,
0,
"ControllerChaseEnemy"
},
};
Task_t tlControllerStrafe[] =
{
{ TASK_WAIT, (float)0.2 },
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
};
Schedule_t slControllerStrafe[] =
{
{
tlControllerStrafe,
ARRAYSIZE ( tlControllerStrafe ),
bits_COND_NEW_ENEMY,
0,
"ControllerStrafe"
},
};
Task_t tlControllerTakeCover[] =
{
{ TASK_WAIT, (float)0.2 },
{ TASK_FIND_COVER_FROM_ENEMY, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
};
Schedule_t slControllerTakeCover[] =
{
{
tlControllerTakeCover,
ARRAYSIZE ( tlControllerTakeCover ),
bits_COND_NEW_ENEMY,
0,
"ControllerTakeCover"
},
};
Task_t tlControllerFail[] =
{
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 },
{ TASK_WAIT_PVS, (float)0 },
};
Schedule_t slControllerFail[] =
{
{
tlControllerFail,
ARRAYSIZE ( tlControllerFail ),
0,
0,
"ControllerFail"
},
};
DEFINE_CUSTOM_SCHEDULES( CController )
{
slControllerChaseEnemy,
slControllerStrafe,
slControllerTakeCover,
slControllerFail,
};
IMPLEMENT_CUSTOM_SCHEDULES( CController, CSquadMonster );
//=========================================================
// StartTask
//=========================================================
void CController :: StartTask ( Task_t *pTask )
{
switch ( pTask->iTask )
{
case TASK_RANGE_ATTACK1:
CSquadMonster :: StartTask ( pTask );
break;
case TASK_GET_PATH_TO_ENEMY_LKP:
{
if (BuildNearestRoute( m_vecEnemyLKP, pev->view_ofs, pTask->flData, (m_vecEnemyLKP - pev->origin).Length() + 1024 ))
{
TaskComplete();
}
else
{
// no way to get there =(
ALERT ( at_aiconsole, "GetPathToEnemyLKP failed!!\n" );
TaskFail();
}
break;
}
case TASK_GET_PATH_TO_ENEMY:
{
CBaseEntity *pEnemy = m_hEnemy;
if ( pEnemy == NULL )
{
TaskFail();
return;
}
if (BuildNearestRoute( pEnemy->pev->origin, pEnemy->pev->view_ofs, pTask->flData, (pEnemy->pev->origin - pev->origin).Length() + 1024 ))
{
TaskComplete();
}
else
{
// no way to get there =(
ALERT ( at_aiconsole, "GetPathToEnemy failed!!\n" );
TaskFail();
}
break;
}
default:
CSquadMonster :: StartTask ( pTask );
break;
}
}
Vector Intersect( Vector vecSrc, Vector vecDst, Vector vecMove, float flSpeed )
{
Vector vecTo = vecDst - vecSrc;
float a = DotProduct( vecMove, vecMove ) - flSpeed * flSpeed;
float b = 0 * DotProduct(vecTo, vecMove); // why does this work?
float c = DotProduct( vecTo, vecTo );
float t;
if (a == 0)
{
t = c / (flSpeed * flSpeed);
}
else
{
t = b * b - 4 * a * c;
t = sqrt( t ) / (2.0 * a);
float t1 = -b +t;
float t2 = -b -t;
if (t1 < 0 || t2 < t1)
t = t2;
else
t = t1;
}
// ALERT( at_console, "Intersect %f\n", t );
if (t < 0.1)
t = 0.1;
if (t > 10.0)
t = 10.0;
Vector vecHit = vecTo + vecMove * t;
return vecHit.Normalize( ) * flSpeed;
}
int CController::LookupFloat( )
{
if (m_velocity.Length( ) < 32.0)
{
return LookupSequence( "up" );
}
UTIL_MakeAimVectors( pev->angles );
float x = DotProduct( gpGlobals->v_forward, m_velocity );
float y = DotProduct( gpGlobals->v_right, m_velocity );
float z = DotProduct( gpGlobals->v_up, m_velocity );
if (fabs(x) > fabs(y) && fabs(x) > fabs(z))
{
if (x > 0)
return LookupSequence( "forward");
else
return LookupSequence( "backward");
}
else if (fabs(y) > fabs(z))
{
if (y > 0)
return LookupSequence( "right");
else
return LookupSequence( "left");
}
else
{
if (z > 0)
return LookupSequence( "up");
else
return LookupSequence( "down");
}
}
//=========================================================
// RunTask
//=========================================================
void CController :: RunTask ( Task_t *pTask )
{
if (m_flShootEnd > gpGlobals->time)
{
Vector vecHand, vecAngle;
GetAttachment( 2, vecHand, vecAngle );
while (m_flShootTime < m_flShootEnd && m_flShootTime < gpGlobals->time)
{
Vector vecSrc = vecHand + pev->velocity * (m_flShootTime - gpGlobals->time);
Vector vecDir;
if (m_hEnemy != NULL)
{
if (HasConditions( bits_COND_SEE_ENEMY ))
{
m_vecEstVelocity = m_vecEstVelocity * 0.5 + m_hEnemy->pev->velocity * 0.5;
}
else
{
m_vecEstVelocity = m_vecEstVelocity * 0.8;
}
vecDir = Intersect( vecSrc, m_hEnemy->BodyTarget( pev->origin ), m_vecEstVelocity, gSkillData.controllerSpeedBall );
float delta = 0.03490; // +-2 degree
vecDir = vecDir + Vector( RANDOM_FLOAT( -delta, delta ), RANDOM_FLOAT( -delta, delta ), RANDOM_FLOAT( -delta, delta ) ) * gSkillData.controllerSpeedBall;
vecSrc = vecSrc + vecDir * (gpGlobals->time - m_flShootTime);
CBaseMonster *pBall = (CBaseMonster*)Create( "controller_energy_ball", vecSrc, pev->angles, edict() );
pBall->pev->velocity = vecDir;
}
m_flShootTime += 0.2;
}
if (m_flShootTime > m_flShootEnd)
{
m_iBall[0] = 64;
m_iBallTime[0] = m_flShootEnd;
m_iBall[1] = 64;
m_iBallTime[1] = m_flShootEnd;
m_fInCombat = FALSE;
}
}
switch ( pTask->iTask )
{
case TASK_WAIT_FOR_MOVEMENT:
case TASK_WAIT:
case TASK_WAIT_FACE_ENEMY:
case TASK_WAIT_PVS:
MakeIdealYaw( m_vecEnemyLKP );
ChangeYaw( pev->yaw_speed );
if (m_fSequenceFinished)
{
m_fInCombat = FALSE;
}
CSquadMonster :: RunTask ( pTask );
if (!m_fInCombat)
{
if (HasConditions ( bits_COND_CAN_RANGE_ATTACK1 ))
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK1 );
pev->frame = 0;
ResetSequenceInfo( );
m_fInCombat = TRUE;
}
else if (HasConditions ( bits_COND_CAN_RANGE_ATTACK2 ))
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK2 );
pev->frame = 0;
ResetSequenceInfo( );
m_fInCombat = TRUE;
}
else
{
int iFloat = LookupFloat( );
if (m_fSequenceFinished || iFloat != pev->sequence)
{
pev->sequence = iFloat;
pev->frame = 0;
ResetSequenceInfo( );
}
}
}
break;
default:
CSquadMonster :: RunTask ( pTask );
break;
}
}
//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
Schedule_t *CController :: GetSchedule ( void )
{
switch ( m_MonsterState )
{
case MONSTERSTATE_IDLE:
break;
case MONSTERSTATE_ALERT:
break;
case MONSTERSTATE_COMBAT:
{
Vector vecTmp = Intersect( Vector( 0, 0, 0 ), Vector( 100, 4, 7 ), Vector( 2, 10, -3 ), 20.0 );
// dead enemy
if ( HasConditions ( bits_COND_LIGHT_DAMAGE ) )
{
// m_iFrustration++;
}
if ( HasConditions ( bits_COND_HEAVY_DAMAGE ) )
{
// m_iFrustration++;
}
}
break;
}
return CSquadMonster :: GetSchedule();
}
//=========================================================
//=========================================================
Schedule_t* CController :: GetScheduleOfType ( int Type )
{
// ALERT( at_console, "%d\n", m_iFrustration );
switch ( Type )
{
case SCHED_CHASE_ENEMY:
return slControllerChaseEnemy;
case SCHED_RANGE_ATTACK1:
return slControllerStrafe;
case SCHED_RANGE_ATTACK2:
case SCHED_MELEE_ATTACK1:
case SCHED_MELEE_ATTACK2:
case SCHED_TAKE_COVER_FROM_ENEMY:
return slControllerTakeCover;
case SCHED_FAIL:
return slControllerFail;
}
return CBaseMonster :: GetScheduleOfType( Type );
}
//=========================================================
// CheckRangeAttack1 - shoot a bigass energy ball out of their head
//
//=========================================================
BOOL CController :: CheckRangeAttack1 ( float flDot, float flDist )
{
if ( flDot > 0.5 && flDist > 256 && flDist <= 2048 )
{
return TRUE;
}
return FALSE;
}
BOOL CController :: CheckRangeAttack2 ( float flDot, float flDist )
{
if ( flDot > 0.5 && flDist > 64 && flDist <= 2048 )
{
return TRUE;
}
return FALSE;
}
BOOL CController :: CheckMeleeAttack1 ( float flDot, float flDist )
{
return FALSE;
}
void CController :: SetActivity ( Activity NewActivity )
{
CBaseMonster::SetActivity( NewActivity );
switch ( m_Activity)
{
case ACT_WALK:
m_flGroundSpeed = 100;
break;
default:
m_flGroundSpeed = 100;
break;
}
}
//=========================================================
// RunAI
//=========================================================
void CController :: RunAI( void )
{
CBaseMonster :: RunAI();
Vector vecStart, angleGun;
if ( HasMemory( bits_MEMORY_KILLED ) )
return;
for (int i = 0; i < 2; i++)
{
if (m_pBall[i] == NULL)
{
m_pBall[i] = CSprite::SpriteCreate( "sprites/xspark4.spr", pev->origin, TRUE );
m_pBall[i]->SetTransparency( kRenderGlow, 255, 255, 255, 255, kRenderFxNoDissipation );
m_pBall[i]->SetAttachment( edict(), (i + 3) );
m_pBall[i]->SetScale( 1.0 );
}
float t = m_iBallTime[i] - gpGlobals->time;
if (t > 0.1)
t = 0.1 / t;
else
t = 1.0;
m_iBallCurrent[i] += (m_iBall[i] - m_iBallCurrent[i]) * t;
m_pBall[i]->SetBrightness( m_iBallCurrent[i] );
GetAttachment( i + 2, vecStart, angleGun );
UTIL_SetOrigin( m_pBall[i]->pev, vecStart );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
WRITE_SHORT( entindex( ) + 0x1000 * (i + 3) ); // entity, attachment
WRITE_COORD( vecStart.x ); // origin
WRITE_COORD( vecStart.y );
WRITE_COORD( vecStart.z );
WRITE_COORD( m_iBallCurrent[i] / 8 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 5 ); // life * 10
WRITE_COORD( 0 ); // decay
MESSAGE_END();
}
}
extern void DrawRoute( entvars_t *pev, WayPoint_t *m_Route, int m_iRouteIndex, int r, int g, int b );
void CController::Stop( void )
{
m_IdealActivity = GetStoppedActivity();
}
#define DIST_TO_CHECK 200
void CController :: Move ( float flInterval )
{
float flWaypointDist;
float flCheckDist;
float flDist;// how far the lookahead check got before hitting an object.
float flMoveDist;
Vector vecDir;
Vector vecApex;
CBaseEntity *pTargetEnt;
// Don't move if no valid route
if ( FRouteClear() )
{
ALERT( at_aiconsole, "Tried to move with no route!\n" );
TaskFail();
return;
}
if ( m_flMoveWaitFinished > gpGlobals->time )
return;
// Debug, test movement code
#if 0
// if ( CVAR_GET_FLOAT("stopmove" ) != 0 )
{
if ( m_movementGoal == MOVEGOAL_ENEMY )
RouteSimplify( m_hEnemy );
else
RouteSimplify( m_hTargetEnt );
FRefreshRoute();
return;
}
#else
// Debug, draw the route
// DrawRoute( pev, m_Route, m_iRouteIndex, 0, 0, 255 );
#endif
// if the monster is moving directly towards an entity (enemy for instance), we'll set this pointer
// to that entity for the CheckLocalMove and Triangulate functions.
pTargetEnt = NULL;
if (m_flGroundSpeed == 0)
{
m_flGroundSpeed = 100;
// TaskFail( );
// return;
}
flMoveDist = m_flGroundSpeed * flInterval;
do
{
// local move to waypoint.
vecDir = ( m_Route[ m_iRouteIndex ].vecLocation - pev->origin ).Normalize();
flWaypointDist = ( m_Route[ m_iRouteIndex ].vecLocation - pev->origin ).Length();
// MakeIdealYaw ( m_Route[ m_iRouteIndex ].vecLocation );
// ChangeYaw ( pev->yaw_speed );
// if the waypoint is closer than CheckDist, CheckDist is the dist to waypoint
if ( flWaypointDist < DIST_TO_CHECK )
{
flCheckDist = flWaypointDist;
}
else
{
flCheckDist = DIST_TO_CHECK;
}
if ( (m_Route[ m_iRouteIndex ].iType & (~bits_MF_NOT_TO_MASK)) == bits_MF_TO_ENEMY )
{
// only on a PURE move to enemy ( i.e., ONLY MF_TO_ENEMY set, not MF_TO_ENEMY and DETOUR )
pTargetEnt = m_hEnemy;
}
else if ( (m_Route[ m_iRouteIndex ].iType & ~bits_MF_NOT_TO_MASK) == bits_MF_TO_TARGETENT )
{
pTargetEnt = m_hTargetEnt;
}
// !!!BUGBUG - CheckDist should be derived from ground speed.
// If this fails, it should be because of some dynamic entity blocking this guy.
// We've already checked this path, so we should wait and time out if the entity doesn't move
flDist = 0;
if ( CheckLocalMove ( pev->origin, pev->origin + vecDir * flCheckDist, pTargetEnt, &flDist ) != LOCALMOVE_VALID )
{
CBaseEntity *pBlocker;
// Can't move, stop
Stop();
// Blocking entity is in global trace_ent
pBlocker = CBaseEntity::Instance( gpGlobals->trace_ent );
if (pBlocker)
{
DispatchBlocked( edict(), pBlocker->edict() );
}
if ( pBlocker && m_moveWaitTime > 0 && pBlocker->IsMoving() && !pBlocker->IsPlayer() && (gpGlobals->time-m_flMoveWaitFinished) > 3.0 )
{
// Can we still move toward our target?
if ( flDist < m_flGroundSpeed )
{
// Wait for a second
m_flMoveWaitFinished = gpGlobals->time + m_moveWaitTime;
// ALERT( at_aiconsole, "Move %s!!!\n", STRING( pBlocker->pev->classname ) );
return;
}