Source code

Revision control

1
/***
2
*
3
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
4
*
5
* This product contains software technology licensed from Id
6
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
7
* All Rights Reserved.
8
*
9
* Use, distribution, and modification of this source code and/or resulting
10
* object code is restricted to non-commercial enhancements to products from
11
* Valve LLC. All other use, distribution, or modification is prohibited
12
* without written permission from Valve LLC.
13
*
14
****/
15
/*
16
17
Class Hierachy
18
19
CBaseEntity
20
CBaseDelay
21
CBaseToggle
22
CBaseItem
23
CBaseMonster
24
CBaseCycler
25
CBasePlayer
26
CBaseGroup
27
*/
28
29
#define MAX_PATH_SIZE 10 // max number of nodes available for a path.
30
31
// These are caps bits to indicate what an object's capabilities (currently used for save/restore and level transitions)
32
#define FCAP_CUSTOMSAVE 0x00000001
33
#define FCAP_ACROSS_TRANSITION 0x00000002 // should transfer between transitions
34
#define FCAP_MUST_SPAWN 0x00000004 // Spawn after restore
35
#define FCAP_DONT_SAVE 0x80000000 // Don't save this
36
#define FCAP_IMPULSE_USE 0x00000008 // can be used by the player
37
#define FCAP_CONTINUOUS_USE 0x00000010 // can be used by the player
38
#define FCAP_ONOFF_USE 0x00000020 // can be used by the player
39
#define FCAP_DIRECTIONAL_USE 0x00000040 // Player sends +/- 1 when using (currently only tracktrains)
40
#define FCAP_MASTER 0x00000080 // Can be used to "master" other entities (like multisource)
41
42
// UNDONE: This will ignore transition volumes (trigger_transition), but not the PVS!!!
43
#define FCAP_FORCE_TRANSITION 0x00000080 // ALWAYS goes across transitions
44
45
#include "archtypes.h" // DAL
46
#include "saverestore.h"
47
#include "schedule.h"
48
49
#ifndef MONSTEREVENT_H
50
#include "monsterevent.h"
51
#endif
52
53
// C functions for external declarations that call the appropriate C++ methods
54
55
#ifndef CBASE_DLLEXPORT
56
#ifdef _WIN32
57
#define CBASE_DLLEXPORT _declspec( dllexport )
58
#else
59
#define CBASE_DLLEXPORT __attribute__ ((visibility("default")))
60
#endif
61
#endif
62
63
#define EXPORT CBASE_DLLEXPORT
64
65
extern "C" CBASE_DLLEXPORT int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion );
66
extern "C" CBASE_DLLEXPORT int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion );
67
68
extern int DispatchSpawn( edict_t *pent );
69
extern void DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd );
70
extern void DispatchTouch( edict_t *pentTouched, edict_t *pentOther );
71
extern void DispatchUse( edict_t *pentUsed, edict_t *pentOther );
72
extern void DispatchThink( edict_t *pent );
73
extern void DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther );
74
extern void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData );
75
extern int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity );
76
extern void DispatchObjectCollsionBox( edict_t *pent );
77
extern void SaveWriteFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
78
extern void SaveReadFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
79
extern void SaveGlobalState( SAVERESTOREDATA *pSaveData );
80
extern void RestoreGlobalState( SAVERESTOREDATA *pSaveData );
81
extern void ResetGlobalState( void );
82
83
typedef enum { USE_OFF = 0, USE_ON = 1, USE_SET = 2, USE_TOGGLE = 3 } USE_TYPE;
84
85
extern void FireTargets( const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
86
87
typedef void (CBaseEntity::*BASEPTR)(void);
88
typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther );
89
typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
90
91
// For CLASSIFY
92
#define CLASS_NONE 0
93
#define CLASS_MACHINE 1
94
#define CLASS_PLAYER 2
95
#define CLASS_HUMAN_PASSIVE 3
96
#define CLASS_HUMAN_MILITARY 4
97
#define CLASS_ALIEN_MILITARY 5
98
#define CLASS_ALIEN_PASSIVE 6
99
#define CLASS_ALIEN_MONSTER 7
100
#define CLASS_ALIEN_PREY 8
101
#define CLASS_ALIEN_PREDATOR 9
102
#define CLASS_INSECT 10
103
#define CLASS_PLAYER_ALLY 11
104
#define CLASS_PLAYER_BIOWEAPON 12 // hornets and snarks.launched by players
105
#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks.launched by the alien menace
106
#define CLASS_BARNACLE 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures.
107
108
class CBaseEntity;
109
class CBaseMonster;
110
class CBasePlayerItem;
111
class CSquadMonster;
112
113
114
#define SF_NORESPAWN ( 1 << 30 )// !!!set this bit on guns and stuff that should never respawn.
115
116
//
117
// EHANDLE. Safe way to point to CBaseEntities who may die between frames
118
//
119
class EHANDLE
120
{
121
private:
122
edict_t *m_pent;
123
int m_serialnumber;
124
public:
125
edict_t *Get( void );
126
edict_t *Set( edict_t *pent );
127
128
operator int ();
129
130
operator CBaseEntity *();
131
132
CBaseEntity * operator = (CBaseEntity *pEntity);
133
CBaseEntity * operator ->();
134
};
135
136
137
//
138
// Base Entity. All entity types derive from this
139
//
140
class CBaseEntity
141
{
142
public:
143
// Constructor. Set engine to use C/C++ callback functions
144
// pointers to engine data
145
entvars_t *pev; // Don't need to save/restore this pointer, the engine resets it
146
147
// path corners
148
CBaseEntity *m_pGoalEnt;// path corner we are heading towards
149
CBaseEntity *m_pLink;// used for temporary link-list operations.
150
151
// initialization functions
152
virtual void Spawn( void ) { return; }
153
virtual void Precache( void ) { return; }
154
virtual void KeyValue( KeyValueData* pkvd) { pkvd->fHandled = FALSE; }
155
virtual int Save( CSave &save );
156
virtual int Restore( CRestore &restore );
157
virtual int ObjectCaps( void ) { return FCAP_ACROSS_TRANSITION; }
158
virtual void Activate( void ) {}
159
160
// Setup the object->object collision box (pev->mins / pev->maxs is the object->world collision box)
161
virtual void SetObjectCollisionBox( void );
162
163
// Classify - returns the type of group (i.e, "houndeye", or "human military" so that monsters with different classnames
164
// still realize that they are teammates. (overridden for monsters that form groups)
165
virtual int Classify ( void ) { return CLASS_NONE; };
166
virtual void DeathNotice ( entvars_t *pevChild ) {}// monster maker children use this to tell the monster maker that they have died.
167
168
169
static TYPEDESCRIPTION m_SaveData[];
170
171
virtual void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
172
virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
173
virtual int TakeHealth( float flHealth, int bitsDamageType );
174
virtual void Killed( entvars_t *pevAttacker, int iGib );
175
virtual int BloodColor( void ) { return DONT_BLEED; }
176
virtual void TraceBleed( float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
177
virtual BOOL IsTriggered( CBaseEntity *pActivator ) {return TRUE;}
178
virtual CBaseMonster *MyMonsterPointer( void ) { return NULL;}
179
virtual CSquadMonster *MySquadMonsterPointer( void ) { return NULL;}
180
virtual int GetToggleState( void ) { return TS_AT_TOP; }
181
virtual void AddPoints( int score, BOOL bAllowNegativeScore ) {}
182
virtual void AddPointsToTeam( int score, BOOL bAllowNegativeScore ) {}
183
virtual BOOL AddPlayerItem( CBasePlayerItem *pItem ) { return 0; }
184
virtual BOOL RemovePlayerItem( CBasePlayerItem *pItem ) { return 0; }
185
virtual int GiveAmmo( int iAmount, const char *szName, int iMax ) { return -1; };
186
virtual float GetDelay( void ) { return 0; }
187
virtual int IsMoving( void ) { return pev->velocity != g_vecZero; }
188
virtual void OverrideReset( void ) {}
189
virtual int DamageDecal( int bitsDamageType );
190
// This is ONLY used by the node graph to test movement through a door
191
virtual void SetToggleState( int state ) {}
192
virtual void StartSneaking( void ) {}
193
virtual void StopSneaking( void ) {}
194
virtual BOOL OnControls( entvars_t *pev ) { return FALSE; }
195
virtual BOOL IsSneaking( void ) { return FALSE; }
196
virtual BOOL IsAlive( void ) { return (pev->deadflag == DEAD_NO) && pev->health > 0; }
197
virtual BOOL IsBSPModel( void ) { return pev->solid == SOLID_BSP || pev->movetype == MOVETYPE_PUSHSTEP; }
198
virtual BOOL ReflectGauss( void ) { return ( IsBSPModel() && !pev->takedamage ); }
199
virtual BOOL HasTarget( string_t targetname ) { return FStrEq(STRING(targetname), STRING(pev->targetname) ); }
200
virtual BOOL IsInWorld( void );
201
virtual BOOL IsPlayer( void ) { return FALSE; }
202
virtual BOOL IsNetClient( void ) { return FALSE; }
203
virtual const char *TeamID( void ) { return ""; }
204
205
206
// virtual void SetActivator( CBaseEntity *pActivator ) {}
207
virtual CBaseEntity *GetNextTarget( void );
208
209
// fundamental callbacks
210
void (CBaseEntity ::*m_pfnThink)(void);
211
void (CBaseEntity ::*m_pfnTouch)( CBaseEntity *pOther );
212
void (CBaseEntity ::*m_pfnUse)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
213
void (CBaseEntity ::*m_pfnBlocked)( CBaseEntity *pOther );
214
215
virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)(); };
216
virtual void Touch( CBaseEntity *pOther ) { if (m_pfnTouch) (this->*m_pfnTouch)( pOther ); };
217
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
218
{
219
if (m_pfnUse)
220
(this->*m_pfnUse)( pActivator, pCaller, useType, value );
221
}
222
virtual void Blocked( CBaseEntity *pOther ) { if (m_pfnBlocked) (this->*m_pfnBlocked)( pOther ); };
223
224
// allow engine to allocate instance data
225
void *operator new( size_t stAllocateBlock, entvars_t *pev )
226
{
227
return (void *)ALLOC_PRIVATE(ENT(pev), stAllocateBlock);
228
};
229
230
// don't use this.
231
#if defined(_MSC_VER) && _MSC_VER >= 1200 // only build this code if MSVC++ 6.0 or higher
232
void operator delete(void *pMem, entvars_t *pev)
233
{
234
pev->flags |= FL_KILLME;
235
};
236
#endif
237
238
void UpdateOnRemove( void );
239
240
// common member functions
241
void EXPORT SUB_Remove( void );
242
void EXPORT SUB_DoNothing( void );
243
void EXPORT SUB_StartFadeOut ( void );
244
void EXPORT SUB_FadeOut ( void );
245
void EXPORT SUB_CallUseToggle( void ) { this->Use( this, this, USE_TOGGLE, 0 ); }
246
int ShouldToggle( USE_TYPE useType, BOOL currentState );
247
void FireBullets( ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq = 4, int iDamage = 0, entvars_t *pevAttacker = NULL );
248
Vector FireBulletsPlayer( ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq = 4, int iDamage = 0, entvars_t *pevAttacker = NULL, int shared_rand = 0 );
249
250
virtual CBaseEntity *Respawn( void ) { return NULL; }
251
252
void SUB_UseTargets( CBaseEntity *pActivator, USE_TYPE useType, float value );
253
// Do the bounding boxes of these two intersect?
254
int Intersects( CBaseEntity *pOther );
255
void MakeDormant( void );
256
int IsDormant( void );
257
BOOL IsLockedByMaster( void ) { return FALSE; }
258
259
static CBaseEntity *Instance( edict_t *pent )
260
{
261
if ( !pent )
262
pent = ENT(0);
263
CBaseEntity *pEnt = (CBaseEntity *)GET_PRIVATE(pent);
264
return pEnt;
265
}
266
267
static CBaseEntity *Instance( entvars_t *pev ) { return Instance( ENT( pev ) ); }
268
static CBaseEntity *Instance( int eoffset) { return Instance( ENT( eoffset) ); }
269
270
CBaseMonster *GetMonsterPointer( entvars_t *pevMonster )
271
{
272
CBaseEntity *pEntity = Instance( pevMonster );
273
if ( pEntity )
274
return pEntity->MyMonsterPointer();
275
return NULL;
276
}
277
CBaseMonster *GetMonsterPointer( edict_t *pentMonster )
278
{
279
CBaseEntity *pEntity = Instance( pentMonster );
280
if ( pEntity )
281
return pEntity->MyMonsterPointer();
282
return NULL;
283
}
284
285
286
// Ugly code to lookup all functions to make sure they are exported when set.
287
#ifdef _DEBUG
288
void FunctionCheck( void *pFunction, char *name )
289
{
290
if (pFunction && !NAME_FOR_FUNCTION((uint32)pFunction) )
291
ALERT( at_error, "No EXPORT: %s:%s (%08lx)\n", STRING(pev->classname), name, (uint32)pFunction );
292
}
293
294
BASEPTR ThinkSet( BASEPTR func, char *name )
295
{
296
m_pfnThink = func;
297
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnThink)))), name );
298
return func;
299
}
300
ENTITYFUNCPTR TouchSet( ENTITYFUNCPTR func, char *name )
301
{
302
m_pfnTouch = func;
303
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnTouch)))), name );
304
return func;
305
}
306
USEPTR UseSet( USEPTR func, char *name )
307
{
308
m_pfnUse = func;
309
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnUse)))), name );
310
return func;
311
}
312
ENTITYFUNCPTR BlockedSet( ENTITYFUNCPTR func, char *name )
313
{
314
m_pfnBlocked = func;
315
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnBlocked)))), name );
316
return func;
317
}
318
319
#endif
320
321
322
// virtual functions used by a few classes
323
324
// used by monsters that are created by the MonsterMaker
325
virtual void UpdateOwner( void ) { return; };
326
327
328
//
329
static CBaseEntity *Create( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner = NULL );
330
331
virtual BOOL FBecomeProne( void ) {return FALSE;};
332
edict_t *edict() { return ENT( pev ); };
333
EOFFSET eoffset( ) { return OFFSET( pev ); };
334
int entindex( ) { return ENTINDEX( edict() ); };
335
336
virtual Vector Center( ) { return (pev->absmax + pev->absmin) * 0.5; }; // center point of entity
337
virtual Vector EyePosition( ) { return pev->origin + pev->view_ofs; }; // position of eyes
338
virtual Vector EarPosition( ) { return pev->origin + pev->view_ofs; }; // position of ears
339
virtual Vector BodyTarget( const Vector &posSrc ) { return Center( ); }; // position to shoot at
340
341
virtual int Illumination( ) { return GETENTITYILLUM( ENT( pev ) ); };
342
343
virtual BOOL FVisible ( CBaseEntity *pEntity );
344
virtual BOOL FVisible ( const Vector &vecOrigin );
345
346
//We use this variables to store each ammo count.
347
int ammo_9mm;
348
int ammo_357;
349
int ammo_bolts;
350
int ammo_buckshot;
351
int ammo_rockets;
352
int ammo_uranium;
353
int ammo_hornets;
354
int ammo_argrens;
355
//Special stuff for grenades and satchels.
356
float m_flStartThrow;
357
float m_flReleaseThrow;
358
int m_chargeReady;
359
int m_fInAttack;
360
361
enum EGON_FIRESTATE { FIRE_OFF, FIRE_CHARGE };
362
int m_fireState;
363
};
364
365
366
367
// Ugly technique to override base member functions
368
// Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
369
// member function of a base class. static_cast is a sleezy way around that problem.
370
371
#ifdef _DEBUG
372
373
#define SetThink( a ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), #a )
374
#define SetTouch( a ) TouchSet( static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a), #a )
375
#define SetUse( a ) UseSet( static_cast <void (CBaseEntity::*)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )> (a), #a )
376
#define SetBlocked( a ) BlockedSet( static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a), #a )
377
378
#else
379
380
#define SetThink( a ) m_pfnThink = static_cast <void (CBaseEntity::*)(void)> (a)
381
#define SetTouch( a ) m_pfnTouch = static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a)
382
#define SetUse( a ) m_pfnUse = static_cast <void (CBaseEntity::*)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )> (a)
383
#define SetBlocked( a ) m_pfnBlocked = static_cast <void (CBaseEntity::*)(CBaseEntity *)> (a)
384
385
#endif
386
387
388
class CPointEntity : public CBaseEntity
389
{
390
public:
391
void Spawn( void );
392
virtual int ObjectCaps( void ) { return CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
393
private:
394
};
395
396
397
typedef struct locksounds // sounds that doors and buttons make when locked/unlocked
398
{
399
string_t sLockedSound; // sound a door makes when it's locked
400
string_t sLockedSentence; // sentence group played when door is locked
401
string_t sUnlockedSound; // sound a door makes when it's unlocked
402
string_t sUnlockedSentence; // sentence group played when door is unlocked
403
404
int iLockedSentence; // which sentence in sentence group to play next
405
int iUnlockedSentence; // which sentence in sentence group to play next
406
407
float flwaitSound; // time delay between playing consecutive 'locked/unlocked' sounds
408
float flwaitSentence; // time delay between playing consecutive sentences
409
BYTE bEOFLocked; // true if hit end of list of locked sentences
410
BYTE bEOFUnlocked; // true if hit end of list of unlocked sentences
411
} locksound_t;
412
413
void PlayLockSounds(entvars_t *pev, locksound_t *pls, int flocked, int fbutton);
414
415
//
416
// MultiSouce
417
//
418
419
#define MAX_MULTI_TARGETS 16 // maximum number of targets a single multi_manager entity may be assigned.
420
#define MS_MAX_TARGETS 32
421
422
class CMultiSource : public CPointEntity
423
{
424
public:
425
void Spawn( );
426
void KeyValue( KeyValueData *pkvd );
427
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
428
int ObjectCaps( void ) { return (CPointEntity::ObjectCaps() | FCAP_MASTER); }
429
BOOL IsTriggered( CBaseEntity *pActivator );
430
void EXPORT Register( void );
431
virtual int Save( CSave &save );
432
virtual int Restore( CRestore &restore );
433
434
static TYPEDESCRIPTION m_SaveData[];
435
436
EHANDLE m_rgEntities[MS_MAX_TARGETS];
437
int m_rgTriggered[MS_MAX_TARGETS];
438
439
int m_iTotal;
440
string_t m_globalstate;
441
};
442
443
444
//
445
// generic Delay entity.
446
//
447
class CBaseDelay : public CBaseEntity
448
{
449
public:
450
float m_flDelay;
451
int m_iszKillTarget;
452
453
virtual void KeyValue( KeyValueData* pkvd);
454
virtual int Save( CSave &save );
455
virtual int Restore( CRestore &restore );
456
457
static TYPEDESCRIPTION m_SaveData[];
458
// common member functions
459
void SUB_UseTargets( CBaseEntity *pActivator, USE_TYPE useType, float value );
460
void EXPORT DelayThink( void );
461
};
462
463
464
class CBaseAnimating : public CBaseDelay
465
{
466
public:
467
virtual int Save( CSave &save );
468
virtual int Restore( CRestore &restore );
469
470
static TYPEDESCRIPTION m_SaveData[];
471
472
// Basic Monster Animation functions
473
float StudioFrameAdvance( float flInterval = 0.0 ); // accumulate animation frame time from last time called until now
474
int GetSequenceFlags( void );
475
int LookupActivity ( int activity );
476
int LookupActivityHeaviest ( int activity );
477
int LookupSequence ( const char *label );
478
void ResetSequenceInfo ( );
479
void DispatchAnimEvents ( float flFutureInterval = 0.1 ); // Handle events that have happend since last time called up until X seconds into the future
480
virtual void HandleAnimEvent( MonsterEvent_t *pEvent ) { return; };
481
float SetBoneController ( int iController, float flValue );
482
void InitBoneControllers ( void );
483
float SetBlending ( int iBlender, float flValue );
484
void GetBonePosition ( int iBone, Vector &origin, Vector &angles );
485
void GetAutomovement( Vector &origin, Vector &angles, float flInterval = 0.1 );
486
int FindTransition( int iEndingSequence, int iGoalSequence, int *piDir );
487
void GetAttachment ( int iAttachment, Vector &origin, Vector &angles );
488
void SetBodygroup( int iGroup, int iValue );
489
int GetBodygroup( int iGroup );
490
int ExtractBbox( int sequence, float *mins, float *maxs );
491
void SetSequenceBox( void );
492
493
// animation needs
494
float m_flFrameRate; // computed FPS for current sequence
495
float m_flGroundSpeed; // computed linear movement rate for current sequence
496
float m_flLastEventCheck; // last time the event list was checked
497
BOOL m_fSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry
498
BOOL m_fSequenceLoops; // true if the sequence loops
499
};
500
501
502
//
503
// generic Toggle entity.
504
//
505
#define SF_ITEM_USE_ONLY 256 // ITEM_USE_ONLY = BUTTON_USE_ONLY = DOOR_USE_ONLY!!!
506
507
class CBaseToggle : public CBaseAnimating
508
{
509
public:
510
void KeyValue( KeyValueData *pkvd );
511
512
TOGGLE_STATE m_toggle_state;
513
float m_flActivateFinished;//like attack_finished, but for doors
514
float m_flMoveDistance;// how far a door should slide or rotate
515
float m_flWait;
516
float m_flLip;
517
float m_flTWidth;// for plats
518
float m_flTLength;// for plats
519
520
Vector m_vecPosition1;
521
Vector m_vecPosition2;
522
Vector m_vecAngle1;
523
Vector m_vecAngle2;
524
525
int m_cTriggersLeft; // trigger_counter only, # of activations remaining
526
float m_flHeight;
527
EHANDLE m_hActivator;
528
void (CBaseToggle::*m_pfnCallWhenMoveDone)(void);
529
Vector m_vecFinalDest;
530
Vector m_vecFinalAngle;
531
532
int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does
533
534
virtual int Save( CSave &save );
535
virtual int Restore( CRestore &restore );
536
537
static TYPEDESCRIPTION m_SaveData[];
538
539
virtual int GetToggleState( void ) { return m_toggle_state; }
540
virtual float GetDelay( void ) { return m_flWait; }
541
542
// common member functions
543
void LinearMove( Vector vecDest, float flSpeed );
544
void EXPORT LinearMoveDone( void );
545
void AngularMove( Vector vecDestAngle, float flSpeed );
546
void EXPORT AngularMoveDone( void );
547
BOOL IsLockedByMaster( void );
548
549
static float AxisValue( int flags, const Vector &angles );
550
static void AxisDir( entvars_t *pev );
551
static float AxisDelta( int flags, const Vector &angle1, const Vector &angle2 );
552
553
string_t m_sMaster; // If this button has a master switch, this is the targetname.
554
// A master switch must be of the multisource type. If all
555
// of the switches in the multisource have been triggered, then
556
// the button will be allowed to operate. Otherwise, it will be
557
// deactivated.
558
};
559
#define SetMoveDone( a ) m_pfnCallWhenMoveDone = static_cast <void (CBaseToggle::*)(void)> (a)
560
561
562
// people gib if their health is <= this at the time of death
563
#define GIB_HEALTH_VALUE -30
564
565
#define ROUTE_SIZE 8 // how many waypoints a monster can store at one time
566
#define MAX_OLD_ENEMIES 4 // how many old enemies to remember
567
568
#define bits_CAP_DUCK ( 1 << 0 )// crouch
569
#define bits_CAP_JUMP ( 1 << 1 )// jump/leap
570
#define bits_CAP_STRAFE ( 1 << 2 )// strafe ( walk/run sideways)
571
#define bits_CAP_SQUAD ( 1 << 3 )// can form squads
572
#define bits_CAP_SWIM ( 1 << 4 )// proficiently navigate in water
573
#define bits_CAP_CLIMB ( 1 << 5 )// climb ladders/ropes
574
#define bits_CAP_USE ( 1 << 6 )// open doors/push buttons/pull levers
575
#define bits_CAP_HEAR ( 1 << 7 )// can hear forced sounds
576
#define bits_CAP_AUTO_DOORS ( 1 << 8 )// can trigger auto doors
577
#define bits_CAP_OPEN_DOORS ( 1 << 9 )// can open manual doors
578
#define bits_CAP_TURN_HEAD ( 1 << 10)// can turn head, always bone controller 0
579
580
#define bits_CAP_RANGE_ATTACK1 ( 1 << 11)// can do a range attack 1
581
#define bits_CAP_RANGE_ATTACK2 ( 1 << 12)// can do a range attack 2
582
#define bits_CAP_MELEE_ATTACK1 ( 1 << 13)// can do a melee attack 1
583
#define bits_CAP_MELEE_ATTACK2 ( 1 << 14)// can do a melee attack 2
584
585
#define bits_CAP_FLY ( 1 << 15)// can fly, move all around
586
587
#define bits_CAP_DOORS_GROUP (bits_CAP_USE | bits_CAP_AUTO_DOORS | bits_CAP_OPEN_DOORS)
588
589
// used by suit voice to indicate damage sustained and repaired type to player
590
591
// instant damage
592
593
#define DMG_GENERIC 0 // generic damage was done
594
#define DMG_CRUSH (1 << 0) // crushed by falling or moving object
595
#define DMG_BULLET (1 << 1) // shot
596
#define DMG_SLASH (1 << 2) // cut, clawed, stabbed
597
#define DMG_BURN (1 << 3) // heat burned
598
#define DMG_FREEZE (1 << 4) // frozen
599
#define DMG_FALL (1 << 5) // fell too far
600
#define DMG_BLAST (1 << 6) // explosive blast damage
601
#define DMG_CLUB (1 << 7) // crowbar, punch, headbutt
602
#define DMG_SHOCK (1 << 8) // electric shock
603
#define DMG_SONIC (1 << 9) // sound pulse shockwave
604
#define DMG_ENERGYBEAM (1 << 10) // laser or other high energy beam
605
#define DMG_NEVERGIB (1 << 12) // with this bit OR'd in, no damage type will be able to gib victims upon death
606
#define DMG_ALWAYSGIB (1 << 13) // with this bit OR'd in, any damage type can be made to gib victims upon death.
607
#define DMG_DROWN (1 << 14) // Drowning
608
// time-based damage
609
#define DMG_TIMEBASED (~(0x3fff)) // mask for time-based damage
610
611
#define DMG_PARALYZE (1 << 15) // slows affected creature down
612
#define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad
613
#define DMG_POISON (1 << 17) // blood poisioning
614
#define DMG_RADIATION (1 << 18) // radiation exposure
615
#define DMG_DROWNRECOVER (1 << 19) // drowning recovery
616
#define DMG_ACID (1 << 20) // toxic chemicals or acid burns
617
#define DMG_SLOWBURN (1 << 21) // in an oven
618
#define DMG_SLOWFREEZE (1 << 22) // in a subzero freezer
619
#define DMG_MORTAR (1 << 23) // Hit by air raid (done to distinguish grenade from mortar)
620
621
// these are the damage types that are allowed to gib corpses
622
#define DMG_GIB_CORPSE ( DMG_CRUSH | DMG_FALL | DMG_BLAST | DMG_SONIC | DMG_CLUB )
623
624
// these are the damage types that have client hud art
625
#define DMG_SHOWNHUD (DMG_POISON | DMG_ACID | DMG_FREEZE | DMG_SLOWFREEZE | DMG_DROWN | DMG_BURN | DMG_SLOWBURN | DMG_NERVEGAS | DMG_RADIATION | DMG_SHOCK)
626
627
// NOTE: tweak these values based on gameplay feedback:
628
629
#define PARALYZE_DURATION 2 // number of 2 second intervals to take damage
630
#define PARALYZE_DAMAGE 1.0 // damage to take each 2 second interval
631
632
#define NERVEGAS_DURATION 2
633
#define NERVEGAS_DAMAGE 5.0
634
635
#define POISON_DURATION 5
636
#define POISON_DAMAGE 2.0
637
638
#define RADIATION_DURATION 2
639
#define RADIATION_DAMAGE 1.0
640
641
#define ACID_DURATION 2
642
#define ACID_DAMAGE 5.0
643
644
#define SLOWBURN_DURATION 2
645
#define SLOWBURN_DAMAGE 1.0
646
647
#define SLOWFREEZE_DURATION 2
648
#define SLOWFREEZE_DAMAGE 1.0
649
650
651
#define itbd_Paralyze 0
652
#define itbd_NerveGas 1
653
#define itbd_Poison 2
654
#define itbd_Radiation 3
655
#define itbd_DrownRecover 4
656
#define itbd_Acid 5
657
#define itbd_SlowBurn 6
658
#define itbd_SlowFreeze 7
659
#define CDMG_TIMEBASED 8
660
661
// when calling KILLED(), a value that governs gib behavior is expected to be
662
// one of these three values
663
#define GIB_NORMAL 0// gib if entity was overkilled
664
#define GIB_NEVER 1// never gib, no matter how much death damage is done ( freezing, etc )
665
#define GIB_ALWAYS 2// always gib ( Houndeye Shock, Barnacle Bite )
666
667
class CBaseMonster;
668
class CCineMonster;
669
class CSound;
670
671
#include "basemonster.h"
672
673
674
const char *ButtonSound( int sound ); // get string of button sound number
675
676
677
//
678
// Generic Button
679
//
680
class CBaseButton : public CBaseToggle
681
{
682
public:
683
void Spawn( void );
684
virtual void Precache( void );
685
void RotSpawn( void );
686
virtual void KeyValue( KeyValueData* pkvd);
687
688
void ButtonActivate( );
689
void SparkSoundCache( void );
690
691
void EXPORT ButtonShot( void );
692
void EXPORT ButtonTouch( CBaseEntity *pOther );
693
void EXPORT ButtonSpark ( void );
694
void EXPORT TriggerAndWait( void );
695
void EXPORT ButtonReturn( void );
696
void EXPORT ButtonBackHome( void );
697
void EXPORT ButtonUse ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
698
virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
699
virtual int Save( CSave &save );
700
virtual int Restore( CRestore &restore );
701
702
enum BUTTON_CODE { BUTTON_NOTHING, BUTTON_ACTIVATE, BUTTON_RETURN };
703
BUTTON_CODE ButtonResponseToTouch( void );
704
705
static TYPEDESCRIPTION m_SaveData[];
706
// Buttons that don't take damage can be IMPULSE used
707
virtual int ObjectCaps( void ) { return (CBaseToggle:: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | (pev->takedamage?0:FCAP_IMPULSE_USE); }
708
709
BOOL m_fStayPushed; // button stays pushed in until touched again?
710
BOOL m_fRotating; // a rotating button? default is a sliding button.
711
712
string_t m_strChangeTarget; // if this field is not null, this is an index into the engine string array.
713
// when this button is touched, it's target entity's TARGET field will be set
714
// to the button's ChangeTarget. This allows you to make a func_train switch paths, etc.
715
716
locksound_t m_ls; // door lock sounds
717
718
BYTE m_bLockedSound; // ordinals from entity selection
719
BYTE m_bLockedSentence;
720
BYTE m_bUnlockedSound;
721
BYTE m_bUnlockedSentence;
722
int m_sounds;
723
};
724
725
//
726
// Weapons
727
//
728
729
#define BAD_WEAPON 0x00007FFF
730
731
//
732
// Converts a entvars_t * to a class pointer
733
// It will allocate the class and entity if necessary
734
//
735
template <class T> T * GetClassPtr( T *a )
736
{
737
entvars_t *pev = (entvars_t *)a;
738
739
// allocate entity if necessary
740
if (pev == NULL)
741
pev = VARS(CREATE_ENTITY());
742
743
// get the private data
744
a = (T *)GET_PRIVATE(ENT(pev));
745
746
if (a == NULL)
747
{
748
// allocate private data
749
a = new(pev) T;
750
a->pev = pev;
751
}
752
return a;
753
}
754
755
756
/*
757
bit_PUSHBRUSH_DATA | bit_TOGGLE_DATA
758
bit_MONSTER_DATA
759
bit_DELAY_DATA
760
bit_TOGGLE_DATA | bit_DELAY_DATA | bit_MONSTER_DATA
761
bit_PLAYER_DATA | bit_MONSTER_DATA
762
bit_MONSTER_DATA | CYCLER_DATA
763
bit_LIGHT_DATA
764
path_corner_data
765
bit_MONSTER_DATA | wildcard_data
766
bit_MONSTER_DATA | bit_GROUP_DATA
767
boid_flock_data
768
boid_data
769
CYCLER_DATA
770
bit_ITEM_DATA
771
bit_ITEM_DATA | func_hud_data
772
bit_TOGGLE_DATA | bit_ITEM_DATA
773
EOFFSET
774
env_sound_data
775
env_sound_data
776
push_trigger_data
777
*/
778
779
#define TRACER_FREQ 4 // Tracers fire every 4 bullets
780
781
typedef struct _SelAmmo
782
{
783
BYTE Ammo1Type;
784
BYTE Ammo1;
785
BYTE Ammo2Type;
786
BYTE Ammo2;
787
} SelAmmo;
788
789
790
// this moved here from world.cpp, to allow classes to be derived from it
791
//=======================
792
// CWorld
793
//
794
// This spawns first when each level begins.
795
//=======================
796
class CWorld : public CBaseEntity
797
{
798
public:
799
void Spawn( void );
800
void Precache( void );
801
void KeyValue( KeyValueData *pkvd );
802
};