diff --git a/dlls/activity.h b/dlls/activity.h index 6fd3a18..a34b76a 100644 --- a/dlls/activity.h +++ b/dlls/activity.h @@ -1,43 +1,56 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -#ifndef ACTIVITY_H -#define ACTIVITY_H +typedef enum Activity_s +{ + ACT_INVALID = -1, - -typedef enum { - ACT_RESET = 0, // Set m_Activity to this invalid value to force a reset to m_IdealActivity - ACT_IDLE = 1, + ACT_RESET = 0, // Set m_Activity to this invalid value to force a reset to m_IdealActivity + ACT_IDLE, ACT_GUARD, ACT_WALK, ACT_RUN, - ACT_FLY, // Fly (and flap if appropriate) + ACT_FLY, ACT_SWIM, - ACT_HOP, // vertical jump - ACT_LEAP, // long forward jump + ACT_HOP, + ACT_LEAP, ACT_FALL, ACT_LAND, ACT_STRAFE_LEFT, ACT_STRAFE_RIGHT, - ACT_ROLL_LEFT, // tuck and roll, left - ACT_ROLL_RIGHT, // tuck and roll, right - ACT_TURN_LEFT, // turn quickly left (stationary) - ACT_TURN_RIGHT, // turn quickly right (stationary) - ACT_CROUCH, // the act of crouching down from a standing position - ACT_CROUCHIDLE, // holding body in crouched position (loops) - ACT_STAND, // the act of standing from a crouched position + ACT_ROLL_LEFT, + ACT_ROLL_RIGHT, + ACT_TURN_LEFT, + ACT_TURN_RIGHT, + ACT_CROUCH, + ACT_CROUCHIDLE, + ACT_STAND, ACT_USE, ACT_SIGNAL1, ACT_SIGNAL2, @@ -51,43 +64,43 @@ typedef enum { ACT_MELEE_ATTACK1, ACT_MELEE_ATTACK2, ACT_RELOAD, - ACT_ARM, // pull out gun, for instance - ACT_DISARM, // reholster gun - ACT_EAT, // monster chowing on a large food item (loop) + ACT_ARM, + ACT_DISARM, + ACT_EAT, ACT_DIESIMPLE, ACT_DIEBACKWARD, ACT_DIEFORWARD, ACT_DIEVIOLENT, - ACT_BARNACLE_HIT, // barnacle tongue hits a monster - ACT_BARNACLE_PULL, // barnacle is lifting the monster ( loop ) - ACT_BARNACLE_CHOMP, // barnacle latches on to the monster - ACT_BARNACLE_CHEW, // barnacle is holding the monster in its mouth ( loop ) + ACT_BARNACLE_HIT, + ACT_BARNACLE_PULL, + ACT_BARNACLE_CHOMP, + ACT_BARNACLE_CHEW, ACT_SLEEP, - ACT_INSPECT_FLOOR, // for active idles, look at something on or near the floor - ACT_INSPECT_WALL, // for active idles, look at something directly ahead of you ( doesn't HAVE to be a wall or on a wall ) - ACT_IDLE_ANGRY, // alternate idle animation in which the monster is clearly agitated. (loop) - ACT_WALK_HURT, // limp (loop) - ACT_RUN_HURT, // limp (loop) - ACT_HOVER, // Idle while in flight - ACT_GLIDE, // Fly (don't flap) - ACT_FLY_LEFT, // Turn left in flight - ACT_FLY_RIGHT, // Turn right in flight - ACT_DETECT_SCENT, // this means the monster smells a scent carried by the air - ACT_SNIFF, // this is the act of actually sniffing an item in front of the monster - ACT_BITE, // some large monsters can eat small things in one bite. This plays one time, EAT loops. - ACT_THREAT_DISPLAY, // without attacking, monster demonstrates that it is angry. (Yell, stick out chest, etc ) - ACT_FEAR_DISPLAY, // monster just saw something that it is afraid of - ACT_EXCITED, // for some reason, monster is excited. Sees something he really likes to eat, or whatever. - ACT_SPECIAL_ATTACK1, // very monster specific special attacks. - ACT_SPECIAL_ATTACK2, - ACT_COMBAT_IDLE, // agitated idle. + ACT_INSPECT_FLOOR, + ACT_INSPECT_WALL, + ACT_IDLE_ANGRY, + ACT_WALK_HURT, + ACT_RUN_HURT, + ACT_HOVER, + ACT_GLIDE, + ACT_FLY_LEFT, + ACT_FLY_RIGHT, + ACT_DETECT_SCENT, + ACT_SNIFF, + ACT_BITE, + ACT_THREAT_DISPLAY, + ACT_FEAR_DISPLAY, + ACT_EXCITED, + ACT_SPECIAL_ATTACK1, + ACT_SPECIAL_ATTACK2, + ACT_COMBAT_IDLE, ACT_WALK_SCARED, ACT_RUN_SCARED, - ACT_VICTORY_DANCE, // killed a player, do a victory dance. - ACT_DIE_HEADSHOT, // die, hit in head. - ACT_DIE_CHESTSHOT, // die, hit in chest - ACT_DIE_GUTSHOT, // die, hit in gut - ACT_DIE_BACKSHOT, // die, hit in back + ACT_VICTORY_DANCE, + ACT_DIE_HEADSHOT, + ACT_DIE_CHESTSHOT, + ACT_DIE_GUTSHOT, + ACT_DIE_BACKSHOT, ACT_FLINCH_HEAD, ACT_FLINCH_CHEST, ACT_FLINCH_STOMACH, @@ -95,15 +108,38 @@ typedef enum { ACT_FLINCH_RIGHTARM, ACT_FLINCH_LEFTLEG, ACT_FLINCH_RIGHTLEG, + ACT_FLINCH, + ACT_LARGE_FLINCH, + ACT_HOLDBOMB, + ACT_IDLE_FIDGET, + ACT_IDLE_SCARED, + ACT_IDLE_SCARED_FIDGET, + ACT_FOLLOW_IDLE, + ACT_FOLLOW_IDLE_FIDGET, + ACT_FOLLOW_IDLE_SCARED, + ACT_FOLLOW_IDLE_SCARED_FIDGET, + ACT_CROUCH_IDLE, + ACT_CROUCH_IDLE_FIDGET, + ACT_CROUCH_IDLE_SCARED, + ACT_CROUCH_IDLE_SCARED_FIDGET, + ACT_CROUCH_WALK, + ACT_CROUCH_WALK_SCARED, + ACT_CROUCH_DIE, + ACT_WALK_BACK, + ACT_IDLE_SNEAKY, + ACT_IDLE_SNEAKY_FIDGET, + ACT_WALK_SNEAKY, + ACT_WAVE, + ACT_YES, + ACT_NO, + } Activity; - -typedef struct { - int type; +typedef struct +{ + int type; char *name; + } activity_map_t; extern activity_map_t activity_map[]; - - -#endif //ACTIVITY_H diff --git a/dlls/activitymap.h b/dlls/activitymap.h index 92cadae..cf5ddfc 100644 --- a/dlls/activitymap.h +++ b/dlls/activitymap.h @@ -1,97 +1,111 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ -#define _A( a ) { a, #a } +#define _A(a)\ + { a, #a } activity_map_t activity_map[] = { -_A( ACT_IDLE ), -_A( ACT_GUARD ), -_A( ACT_WALK ), -_A( ACT_RUN ), -_A( ACT_FLY ), -_A( ACT_SWIM ), -_A( ACT_HOP ), -_A( ACT_LEAP ), -_A( ACT_FALL ), -_A( ACT_LAND ), -_A( ACT_STRAFE_LEFT ), -_A( ACT_STRAFE_RIGHT ), -_A( ACT_ROLL_LEFT ), -_A( ACT_ROLL_RIGHT ), -_A( ACT_TURN_LEFT ), -_A( ACT_TURN_RIGHT ), -_A( ACT_CROUCH ), -_A( ACT_CROUCHIDLE ), -_A( ACT_STAND ), -_A( ACT_USE ), -_A( ACT_SIGNAL1 ), -_A( ACT_SIGNAL2 ), -_A( ACT_SIGNAL3 ), -_A( ACT_TWITCH ), -_A( ACT_COWER ), -_A( ACT_SMALL_FLINCH ), -_A( ACT_BIG_FLINCH ), -_A( ACT_RANGE_ATTACK1 ), -_A( ACT_RANGE_ATTACK2 ), -_A( ACT_MELEE_ATTACK1 ), -_A( ACT_MELEE_ATTACK2 ), -_A( ACT_RELOAD ), -_A( ACT_ARM ), -_A( ACT_DISARM ), -_A( ACT_EAT ), -_A( ACT_DIESIMPLE ), -_A( ACT_DIEBACKWARD ), -_A( ACT_DIEFORWARD ), -_A( ACT_DIEVIOLENT ), -_A( ACT_BARNACLE_HIT ), -_A( ACT_BARNACLE_PULL ), -_A( ACT_BARNACLE_CHOMP ), -_A( ACT_BARNACLE_CHEW ), -_A( ACT_SLEEP ), -_A( ACT_INSPECT_FLOOR ), -_A( ACT_INSPECT_WALL ), -_A( ACT_IDLE_ANGRY ), -_A( ACT_WALK_HURT ), -_A( ACT_RUN_HURT ), -_A( ACT_HOVER ), -_A( ACT_GLIDE ), -_A( ACT_FLY_LEFT ), -_A( ACT_FLY_RIGHT ), -_A( ACT_DETECT_SCENT ), -_A( ACT_SNIFF ), -_A( ACT_BITE ), -_A( ACT_THREAT_DISPLAY ), -_A( ACT_FEAR_DISPLAY ), -_A( ACT_EXCITED ), -_A( ACT_SPECIAL_ATTACK1 ), -_A( ACT_SPECIAL_ATTACK2 ), -_A( ACT_COMBAT_IDLE ), -_A( ACT_WALK_SCARED ), -_A( ACT_RUN_SCARED ), -_A( ACT_VICTORY_DANCE ), -_A( ACT_DIE_HEADSHOT ), -_A( ACT_DIE_CHESTSHOT ), -_A( ACT_DIE_GUTSHOT ), -_A( ACT_DIE_BACKSHOT ), -_A( ACT_FLINCH_HEAD ), -_A( ACT_FLINCH_CHEST ), -_A( ACT_FLINCH_STOMACH ), -_A( ACT_FLINCH_LEFTARM ), -_A( ACT_FLINCH_RIGHTARM ), -_A( ACT_FLINCH_LEFTLEG ), -_A( ACT_FLINCH_RIGHTLEG ), -0, NULL + _A(ACT_IDLE), + _A(ACT_GUARD), + _A(ACT_WALK), + _A(ACT_RUN), + _A(ACT_FLY), + _A(ACT_SWIM), + _A(ACT_HOP), + _A(ACT_LEAP), + _A(ACT_FALL), + _A(ACT_LAND), + _A(ACT_STRAFE_LEFT), + _A(ACT_STRAFE_RIGHT), + _A(ACT_ROLL_LEFT), + _A(ACT_ROLL_RIGHT), + _A(ACT_TURN_LEFT), + _A(ACT_TURN_RIGHT), + _A(ACT_CROUCH), + _A(ACT_CROUCHIDLE), + _A(ACT_STAND), + _A(ACT_USE), + _A(ACT_SIGNAL1), + _A(ACT_SIGNAL2), + _A(ACT_SIGNAL3), + _A(ACT_TWITCH), + _A(ACT_COWER), + _A(ACT_SMALL_FLINCH), + _A(ACT_BIG_FLINCH), + _A(ACT_RANGE_ATTACK1), + _A(ACT_RANGE_ATTACK2), + _A(ACT_MELEE_ATTACK1), + _A(ACT_MELEE_ATTACK2), + _A(ACT_RELOAD), + _A(ACT_ARM), + _A(ACT_DISARM), + _A(ACT_EAT), + _A(ACT_DIESIMPLE), + _A(ACT_DIEBACKWARD), + _A(ACT_DIEFORWARD), + _A(ACT_DIEVIOLENT), + _A(ACT_BARNACLE_HIT), + _A(ACT_BARNACLE_PULL), + _A(ACT_BARNACLE_CHOMP), + _A(ACT_BARNACLE_CHEW), + _A(ACT_SLEEP), + _A(ACT_INSPECT_FLOOR), + _A(ACT_INSPECT_WALL), + _A(ACT_IDLE_ANGRY), + _A(ACT_WALK_HURT), + _A(ACT_RUN_HURT), + _A(ACT_HOVER), + _A(ACT_GLIDE), + _A(ACT_FLY_LEFT), + _A(ACT_FLY_RIGHT), + _A(ACT_DETECT_SCENT), + _A(ACT_SNIFF), + _A(ACT_BITE), + _A(ACT_THREAT_DISPLAY), + _A(ACT_FEAR_DISPLAY), + _A(ACT_EXCITED), + _A(ACT_SPECIAL_ATTACK1), + _A(ACT_SPECIAL_ATTACK2), + _A(ACT_COMBAT_IDLE), + _A(ACT_WALK_SCARED), + _A(ACT_RUN_SCARED), + _A(ACT_VICTORY_DANCE), + _A(ACT_DIE_HEADSHOT), + _A(ACT_DIE_CHESTSHOT), + _A(ACT_DIE_GUTSHOT), + _A(ACT_DIE_BACKSHOT), + _A(ACT_FLINCH_HEAD), + _A(ACT_FLINCH_CHEST), + _A(ACT_FLINCH_STOMACH), + _A(ACT_FLINCH_LEFTARM), + _A(ACT_FLINCH_RIGHTARM), + _A(ACT_FLINCH_LEFTLEG), + _A(ACT_FLINCH_RIGHTLEG), + 0, NULL }; diff --git a/dlls/airtank.h b/dlls/airtank.h new file mode 100644 index 0000000..3f435a8 --- /dev/null +++ b/dlls/airtank.h @@ -0,0 +1,42 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CAirtank: public CGrenade { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Killed(entvars_t *pevAttacker, int iGib) = 0; + virtual int BloodColor() = 0; + + int GetState() const { return m_state; } +private: + int m_state; +}; diff --git a/dlls/ammo.h b/dlls/ammo.h new file mode 100644 index 0000000..4b22b9e --- /dev/null +++ b/dlls/ammo.h @@ -0,0 +1,98 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class C9MMAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class CBuckShotAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C556NatoAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C556NatoBoxAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C762NatoAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C45ACPAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C50AEAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C338MagnumAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C57MMAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; + +class C357SIGAmmo: public CBasePlayerAmmo { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL AddAmmo(CBaseEntity *pOther) = 0; +}; diff --git a/dlls/animation.h b/dlls/animation.h deleted file mode 100644 index 174bd71..0000000 --- a/dlls/animation.h +++ /dev/null @@ -1,47 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -#ifndef ANIMATION_H -#define ANIMATION_H - -#define ACTIVITY_NOT_AVAILABLE -1 - -#ifndef MONSTEREVENT_H -#include "monsterevent.h" -#endif - -extern int IsSoundEvent( int eventNumber ); - -int LookupActivity( void *pmodel, entvars_t *pev, int activity ); -int LookupActivityHeaviest( void *pmodel, entvars_t *pev, int activity ); -int LookupSequence( void *pmodel, const char *label ); -void GetSequenceInfo( void *pmodel, entvars_t *pev, float *pflFrameRate, float *pflGroundSpeed ); -int GetSequenceFlags( void *pmodel, entvars_t *pev ); -int LookupAnimationEvents( void *pmodel, entvars_t *pev, float flStart, float flEnd ); -float SetController( void *pmodel, entvars_t *pev, int iController, float flValue ); -float SetBlending( void *pmodel, entvars_t *pev, int iBlender, float flValue ); -void GetEyePosition( void *pmodel, float *vecEyePosition ); -void SequencePrecache( void *pmodel, const char *pSequenceName ); -int FindTransition( void *pmodel, int iEndingAnim, int iGoalAnim, int *piDir ); -void SetBodygroup( void *pmodel, entvars_t *pev, int iGroup, int iValue ); -int GetBodygroup( void *pmodel, entvars_t *pev, int iGroup ); - -int GetAnimationEvent( void *pmodel, entvars_t *pev, MonsterEvent_t *pMonsterEvent, float flStart, float flEnd, int index ); -int ExtractBbox( void *pmodel, int sequence, float *mins, float *maxs ); - -// From /engine/studio.h -#define STUDIO_LOOPING 0x0001 - - -#endif //ANIMATION_H diff --git a/dlls/basemonster.h b/dlls/basemonster.h index 43a2ed7..05cb5e3 100644 --- a/dlls/basemonster.h +++ b/dlls/basemonster.h @@ -1,94 +1,105 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef BASEMONSTER_H -#define BASEMONSTER_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -class CBaseMonster : public CBaseToggle +#include "activity.h" + +class EHANDLE; + +enum MONSTERSTATE { -public: - Activity m_Activity;// what the monster is doing (animation) - Activity m_IdealActivity;// monster should switch to this activity - int m_LastHitGroup; // the last body region that took damage - int m_bitsDamageType; // what types of damage has monster (player) taken - BYTE m_rgbTimeBasedDamage[CDMG_TIMEBASED]; - MONSTERSTATE m_MonsterState;// monster's current state - MONSTERSTATE m_IdealMonsterState;// monster should change to this state - int m_afConditions; - int m_afMemory; - float m_flNextAttack; // cannot attack again until this time - EHANDLE m_hEnemy; // the entity that the monster is fighting. - EHANDLE m_hTargetEnt; // the entity that the monster is trying to reach - float m_flFieldOfView;// width of monster's field of view ( dot product ) - int m_bloodColor; // color of blood particless - Vector m_HackedGunPos; // HACK until we can query end of gun - Vector m_vecEnemyLKP;// last known position of enemy. (enemy's origin) - - - void KeyValue( KeyValueData *pkvd ); - - void MakeIdealYaw( Vector vecTarget ); - virtual float ChangeYaw ( int speed ); - virtual BOOL HasHumanGibs( void ); - virtual BOOL HasAlienGibs( void ); - virtual void FadeMonster( void ); // Called instead of GibMonster() when gibs are disabled - virtual void GibMonster( void ); - virtual Activity GetDeathActivity ( void ); - Activity GetSmallFlinchActivity( void ); - virtual void BecomeDead( void ); - BOOL ShouldGibMonster( int iGib ); - void CallGibMonster( void ); - virtual BOOL ShouldFadeOnDeath( void ); - BOOL FCheckAITrigger( void );// checks and, if necessary, fires the monster's trigger target. - virtual int IRelationship ( CBaseEntity *pTarget ); - virtual int TakeHealth( float flHealth, int bitsDamageType ); - virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType); - int DeadTakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ); - float DamageForce( float damage ); - virtual void Killed( entvars_t *pevAttacker, int iGib ); - virtual void PainSound ( void ) { return; }; - - void RadiusDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int iClassIgnore, int bitsDamageType ); - void RadiusDamage(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int iClassIgnore, int bitsDamageType ); - - inline void SetConditions( int iConditions ) { m_afConditions |= iConditions; } - inline void ClearConditions( int iConditions ) { m_afConditions &= ~iConditions; } - inline BOOL HasConditions( int iConditions ) { if ( m_afConditions & iConditions ) return TRUE; return FALSE; } - inline BOOL HasAllConditions( int iConditions ) { if ( (m_afConditions & iConditions) == iConditions ) return TRUE; return FALSE; } - - inline void Remember( int iMemory ) { m_afMemory |= iMemory; } - inline void Forget( int iMemory ) { m_afMemory &= ~iMemory; } - inline BOOL HasMemory( int iMemory ) { if ( m_afMemory & iMemory ) return TRUE; return FALSE; } - inline BOOL HasAllMemories( int iMemory ) { if ( (m_afMemory & iMemory) == iMemory ) return TRUE; return FALSE; } - - // This will stop animation until you call ResetSequenceInfo() at some point in the future - inline void StopAnimation( void ) { pev->framerate = 0; } - - virtual void ReportAIState( void ); - virtual void MonsterInitDead( void ); // Call after animation/pose is set up - void EXPORT CorpseFallThink( void ); - - virtual void Look ( int iDistance );// basic sight function for monsters - virtual CBaseEntity* BestVisibleEnemy ( void );// finds best visible enemy for attack - CBaseEntity *CheckTraceHullAttack( float flDist, int iDamage, int iDmgType ); - virtual BOOL FInViewCone ( CBaseEntity *pEntity );// see if pEntity is in monster's view cone - virtual BOOL FInViewCone ( Vector *pOrigin );// see if given location is in monster's view cone - void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType); - void MakeDamageBloodDecal ( int cCount, float flNoise, TraceResult *ptr, const Vector &vecDir ); - virtual BOOL IsAlive( void ) { return (pev->deadflag != DEAD_DEAD); } - + MONSTERSTATE_NONE = 0, + MONSTERSTATE_IDLE, + MONSTERSTATE_COMBAT, + MONSTERSTATE_ALERT, + MONSTERSTATE_HUNT, + MONSTERSTATE_PRONE, + MONSTERSTATE_SCRIPT, + MONSTERSTATE_PLAYDEAD, + MONSTERSTATE_DEAD }; +class CBaseToggle; +class CBaseMonster: public CBaseToggle { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual BOOL TakeHealth(float flHealth, int bitsDamageType) = 0; + virtual void Killed(entvars_t *pevAttacker, int iGib) = 0; + virtual int BloodColor() = 0; + virtual BOOL IsAlive() = 0; + virtual float ChangeYaw(int speed) = 0; + virtual BOOL HasHumanGibs() = 0; + virtual BOOL HasAlienGibs() = 0; + virtual void FadeMonster() = 0; + virtual void GibMonster() = 0; + virtual Activity GetDeathActivity() = 0; + virtual void BecomeDead() = 0; + virtual BOOL ShouldFadeOnDeath() = 0; + virtual int IRelationship(CBaseEntity *pTarget) = 0; + virtual void PainSound() = 0; + virtual void ResetMaxSpeed() = 0; + virtual void ReportAIState() = 0; + virtual void MonsterInitDead() = 0; + virtual void Look(int iDistance) = 0; + virtual CBaseEntity *BestVisibleEnemy() = 0; + virtual BOOL FInViewCone(CBaseEntity *pEntity) = 0; + virtual BOOL FInViewCone(const Vector *pOrigin) = 0; +public: + void SetConditions(int iConditions) { m_afConditions |= iConditions; } + void ClearConditions(int iConditions) { m_afConditions &= ~iConditions; } + BOOL HasConditions(int iConditions) { return (m_afConditions & iConditions) ? TRUE : FALSE; } + BOOL HasAllConditions(int iConditions) { return ((m_afConditions & iConditions) == iConditions) ? TRUE : FALSE; } -#endif + void Remember(int iMemory) { m_afMemory |= iMemory; } + void Forget(int iMemory) { m_afMemory &= ~iMemory; } + BOOL HasMemory(int iMemory) { return (m_afMemory & iMemory) ? TRUE : FALSE; } + BOOL HasAllMemories(int iMemory) { return ((m_afMemory & iMemory) == iMemory) ? TRUE : FALSE; } + + void StopAnimation() { pev->framerate = 0.0f; } +public: + Activity m_Activity; // what the monster is doing (animation) + Activity m_IdealActivity; // monster should switch to this activity + int m_LastHitGroup; // the last body region that took damage + int m_bitsDamageType; // what types of damage has monster (player) taken + byte m_rgbTimeBasedDamage[8]; + + MONSTERSTATE m_MonsterState; // monster's current state + MONSTERSTATE m_IdealMonsterState; // monster should change to this state + int m_afConditions; + int m_afMemory; + + float m_flNextAttack; // cannot attack again until this time + EHANDLE m_hEnemy; // the entity that the monster is fighting. + EHANDLE m_hTargetEnt; // the entity that the monster is trying to reach + float m_flFieldOfView; // width of monster's field of view ( dot product ) + int m_bloodColor; // color of blood particless + Vector m_HackedGunPos; // HACK until we can query end of gun + Vector m_vecEnemyLKP; // last known position of enemy. (enemy's origin) +}; diff --git a/dlls/bmodels.h b/dlls/bmodels.h new file mode 100644 index 0000000..741ebc6 --- /dev/null +++ b/dlls/bmodels.h @@ -0,0 +1,131 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SF_PENDULUM_SWING 2 // spawnflag that makes a pendulum a rope swing. + +#define SF_BRUSH_ACCDCC 16 // brush should accelerate and decelerate when toggled +#define SF_BRUSH_HURT 32 // rotating brush that inflicts pain based on rotation speed +#define SF_ROTATING_NOT_SOLID 64 // some special rotating objects are not solid. + +#define SF_WALL_START_OFF 0x0001 + +#define SF_CONVEYOR_VISUAL 0x0001 +#define SF_CONVEYOR_NOTSOLID 0x0002 + +#define SF_WORLD_DARK 0x0001 // Fade from black at startup +#define SF_WORLD_TITLE 0x0002 // Display game title at startup +#define SF_WORLD_FORCETEAM 0x0004 // Force teams + +#define FANPITCHMIN 30 +#define FANPITCHMAX 100 + +// This is just a solid wall if not inhibited +class CFuncWall: public CBaseEntity { +public: + virtual void Spawn() = 0; + + // Bmodels don't go across transitions + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CFuncWallToggle: public CFuncWall { +public: + virtual void Spawn() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CFuncConveyor: public CFuncWall { +public: + virtual void Spawn() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +// A simple entity that looks solid but lets you walk through it. +class CFuncIllusionary: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int ObjectCaps() = 0; +}; + +// Monster only clip brush +// +// This brush will be solid for any entity who has the FL_MONSTERCLIP flag set +// in pev->flags +// +// otherwise it will be invisible and not solid. This can be used to keep +// specific monsters out of certain areas +class CFuncMonsterClip: public CFuncWall { +public: + virtual void Spawn() = 0; + + // Clear out func_wall's use function + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CFuncRotating: public CBaseEntity { +public: + // basic functions + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + + float m_flFanFriction; + float m_flAttenuation; + float m_flVolume; + float m_pitch; + int m_sounds; +}; + +class CPendulum: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + float m_accel; // Acceleration + float m_distance; + float m_time; + float m_damp; + float m_maxSpeed; + float m_dampSpeed; + + Vector m_center; + Vector m_start; +}; diff --git a/dlls/bot/cs_bot.h b/dlls/bot/cs_bot.h new file mode 100644 index 0000000..f9f30aa --- /dev/null +++ b/dlls/bot/cs_bot.h @@ -0,0 +1,641 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "bot/cs_gamestate.h" +#include "bot/cs_bot_manager.h" +#include "bot/cs_bot_chatter.h" + +#define PRIMARY_WEAPON_BUY_COUNT 13 +#define SECONDARY_WEAPON_BUY_COUNT 3 + +#define FLAG_PROGRESS_DRAW 0x0 // draw status bar progress +#define FLAG_PROGRESS_START 0x1 // init status bar progress +#define FLAG_PROGRESS_HIDE 0x2 // hide status bar progress + +#define HI_X 0x01 +#define LO_X 0x02 +#define HI_Y 0x04 +#define LO_Y 0x08 +#define HI_Z 0x10 +#define LO_Z 0x20 + +extern int _navAreaCount; +extern int _currentIndex; + +extern struct BuyInfo primaryWeaponBuyInfoCT[PRIMARY_WEAPON_BUY_COUNT]; +extern struct BuyInfo secondaryWeaponBuyInfoCT[SECONDARY_WEAPON_BUY_COUNT]; + +extern struct BuyInfo primaryWeaponBuyInfoT[PRIMARY_WEAPON_BUY_COUNT]; +extern struct BuyInfo secondaryWeaponBuyInfoT[SECONDARY_WEAPON_BUY_COUNT]; + +class CCSBot; +class BotChatterInterface; + +class BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const = 0; +}; + +class IdleState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual const char *GetName() const { return "Idle"; } +}; + +class HuntState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "Hunt"; } +public: + CNavArea *m_huntArea; +}; + +class AttackState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "Attack"; } +public: + enum DodgeStateType + { + STEADY_ON, + SLIDE_LEFT, + SLIDE_RIGHT, + JUMP, + NUM_ATTACK_STATES + } m_dodgeState; + + float m_nextDodgeStateTimestamp; + CountdownTimer m_repathTimer; + float m_scopeTimestamp; + bool m_haveSeenEnemy; + bool m_isEnemyHidden; + float m_reacquireTimestamp; + float m_shieldToggleTimestamp; + bool m_shieldForceOpen; + float m_pinnedDownTimestamp; + bool m_crouchAndHold; + bool m_didAmbushCheck; + bool m_dodge; + bool m_firstDodge; + bool m_isCoward; + CountdownTimer m_retreatTimer; +}; + +class InvestigateNoiseState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "InvestigateNoise"; } +private: + void AttendCurrentNoise(CCSBot *me); + Vector m_checkNoisePosition; +}; + +class BuyState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "Buy"; } +public: + bool m_isInitialDelay; + int m_prefRetries; + int m_prefIndex; + int m_retries; + bool m_doneBuying; + bool m_buyDefuseKit; + bool m_buyGrenade; + bool m_buyShield; + bool m_buyPistol; +}; + +class MoveToState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "MoveTo"; } + + void SetGoalPosition(const Vector &pos) { m_goalPosition = pos; } + void SetRouteType(RouteType route) { m_routeType = route; } + +private: + Vector m_goalPosition; + RouteType m_routeType; + bool m_radioedPlan; + bool m_askedForCover; +}; + +class FetchBombState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual const char *GetName() const { return "FetchBomb"; } +}; + +class PlantBombState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "PlantBomb"; } +}; + +class DefuseBombState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "DefuseBomb"; } +}; + +class HideState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "Hide"; } + +public: + void SetHidingSpot(const Vector &pos) { m_hidingSpot = pos; } + const Vector &GetHidingSpot() const { return m_hidingSpot; } + + void SetSearchArea(CNavArea *area) { m_searchFromArea = area; } + void SetSearchRange(float range) { m_range = range; } + + void SetDuration(float time) { m_duration = time; } + void SetHoldPosition(bool hold) { m_isHoldingPosition = hold; } + + bool IsAtSpot() const { return m_isAtSpot; } + +public: + CNavArea *m_searchFromArea; + float m_range; + + Vector m_hidingSpot; + bool m_isAtSpot; + float m_duration; + bool m_isHoldingPosition; + float m_holdPositionTime; + bool m_heardEnemy; + + float m_firstHeardEnemyTime; + int m_retry; + Vector m_leaderAnchorPos; +}; + +class EscapeFromBombState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "EscapeFromBomb"; } +}; + +class FollowState: public BotState +{ +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "Follow"; } + + void SetLeader(CBaseEntity *leader) { m_leader = leader; } + +public: + EHANDLE m_leader; + Vector m_lastLeaderPos; + bool m_isStopped; + float m_stoppedTimestamp; + + enum LeaderMotionStateType + { + INVALID, + STOPPED, + WALKING, + RUNNING + + } m_leaderMotionState; + + IntervalTimer m_leaderMotionStateTime; + + bool m_isSneaking; + float m_lastSawLeaderTime; + CountdownTimer m_repathInterval; + + IntervalTimer m_walkTime; + bool m_isAtWalkSpeed; + + float m_waitTime; + CountdownTimer m_idleTimer; +}; + +class UseEntityState: public BotState { +public: + virtual void OnEnter(CCSBot *me) {} + virtual void OnUpdate(CCSBot *me) {} + virtual void OnExit(CCSBot *me) {} + virtual const char *GetName() const { return "UseEntity"; } + + void SetEntity(CBaseEntity *entity) { m_entity = entity; } + +private: + EHANDLE m_entity; +}; + +// The Counter-strike Bot +class CCSBot: public CBot { +public: + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; // invoked when injured by something (EXTEND) - returns the amount of damage inflicted + virtual void Killed(entvars_t *pevAttacker, int iGib) = 0; // invoked when killed (EXTEND) + virtual void RoundRespawn() = 0; + virtual void Blind(float duration, float holdTime, float fadeTime, int alpha = 255) = 0; // player blinded by a flashbang + virtual void OnTouchingWeapon(CWeaponBox *box) = 0; // invoked when in contact with a CWeaponBox + + virtual bool Initialize(const BotProfile *profile) = 0; // (EXTEND) prepare bot for action + virtual void SpawnBot() = 0; // (EXTEND) spawn the bot into the game + + virtual void Upkeep() = 0; // lightweight maintenance, invoked frequently + virtual void Update() = 0; // heavyweight algorithms, invoked less often + + virtual void Walk() = 0; + virtual bool Jump(bool mustJump = false) = 0; // returns true if jump was started + + virtual void OnEvent(GameEventType event, CBaseEntity *entity = NULL, CBaseEntity *other = NULL) = 0; // invoked when event occurs in the game (some events have NULL entity) + + #define CHECK_FOV true + virtual bool IsVisible(const Vector *pos, bool testFOV = false) const = 0; // return true if we can see the point + virtual bool IsVisible(CBasePlayer *player, bool testFOV = false, unsigned char *visParts = NULL) const = 0; // return true if we can see any part of the player + + virtual bool IsEnemyPartVisible(VisiblePartType part) const = 0; // if enemy is visible, return the part we see for our current enemy + +public: + const Vector &GetEyePosition() const + { + m_eyePos = pev->origin + pev->view_ofs; + return m_eyePos; + } +public: + friend class CCSBotManager; + + // TODO: Get rid of these + friend class AttackState; + friend class BuyState; + + char m_name[64]; // copied from STRING(pev->netname) for debugging + + // behavior properties + float m_combatRange; // desired distance between us and them during gunplay + mutable bool m_isRogue; // if true, the bot is a "rogue" and listens to no-one + mutable CountdownTimer m_rogueTimer; + + enum MoraleType + { + TERRIBLE = -3, + BAD = -2, + NEGATIVE = -1, + NEUTRAL = 0, + POSITIVE = 1, + GOOD = 2, + EXCELLENT = 3, + }; + + MoraleType m_morale; // our current morale, based on our win/loss history + bool m_diedLastRound; // true if we died last round + float m_safeTime; // duration at the beginning of the round where we feel "safe" + bool m_wasSafe; // true if we were in the safe time last update + NavRelativeDirType m_blindMoveDir; // which way to move when we're blind + bool m_blindFire; // if true, fire weapon while blinded + + // TODO: implement through CountdownTimer + float m_surpriseDelay; // when we were surprised + float m_surpriseTimestamp; + + bool m_isFollowing; // true if we are following someone + EHANDLE m_leader; // the ID of who we are following + float m_followTimestamp; // when we started following + float m_allowAutoFollowTime; // time when we can auto follow + + CountdownTimer m_hurryTimer; // if valid, bot is in a hurry + + // instances of each possible behavior state, to avoid dynamic memory allocation during runtime + IdleState m_idleState; + HuntState m_huntState; + AttackState m_attackState; + InvestigateNoiseState m_investigateNoiseState; + BuyState m_buyState; + MoveToState m_moveToState; + FetchBombState m_fetchBombState; + PlantBombState m_plantBombState; + DefuseBombState m_defuseBombState; + HideState m_hideState; + EscapeFromBombState m_escapeFromBombState; + FollowState m_followState; + UseEntityState m_useEntityState; + + // TODO: Allow multiple simultaneous state machines (look around, etc) + BotState *m_state; // current behavior state + float m_stateTimestamp; // time state was entered + bool m_isAttacking; // if true, special Attack state is overriding the state machine + + // high-level tasks + enum TaskType + { + SEEK_AND_DESTROY, + PLANT_BOMB, + FIND_TICKING_BOMB, + DEFUSE_BOMB, + GUARD_TICKING_BOMB, + GUARD_BOMB_DEFUSER, + GUARD_LOOSE_BOMB, + GUARD_BOMB_ZONE, + ESCAPE_FROM_BOMB, + HOLD_POSITION, + FOLLOW, + VIP_ESCAPE, + GUARD_VIP_ESCAPE_ZONE, + COLLECT_HOSTAGES, + RESCUE_HOSTAGES, + GUARD_HOSTAGES, + GUARD_HOSTAGE_RESCUE_ZONE, + MOVE_TO_LAST_KNOWN_ENEMY_POSITION, + MOVE_TO_SNIPER_SPOT, + SNIPING, + + NUM_TASKS + }; + TaskType m_task; // our current task + EHANDLE m_taskEntity; // an entity used for our task + + // navigation + Vector m_goalPosition; + EHANDLE m_goalEntity; + + CNavArea *m_currentArea; // the nav area we are standing on + CNavArea *m_lastKnownArea; // the last area we were in + EHANDLE m_avoid; // higher priority player we need to make way for + float m_avoidTimestamp; + bool m_isJumpCrouching; + bool m_isJumpCrouched; + float m_jumpCrouchTimestamp; + + // path navigation data + enum { _MAX_PATH_LENGTH = 256 }; + struct ConnectInfo + { + CNavArea *area; // the area along the path + NavTraverseType how; // how to enter this area from the previous one + Vector pos; // our movement goal position at this point in the path + const CNavLadder *ladder; // if "how" refers to a ladder, this is it + } + m_path[_MAX_PATH_LENGTH]; + int m_pathLength; + int m_pathIndex; + float m_areaEnteredTimestamp; + + CountdownTimer m_repathTimer; // must have elapsed before bot can pathfind again + + mutable CountdownTimer m_avoidFriendTimer; // used to throttle how often we check for friends in our path + mutable bool m_isFriendInTheWay; // true if a friend is blocking our path + CountdownTimer m_politeTimer; // we'll wait for friend to move until this runs out + bool m_isWaitingBehindFriend; // true if we are waiting for a friend to move + + enum LadderNavState + { + APPROACH_ASCENDING_LADDER, // prepare to scale a ladder + APPROACH_DESCENDING_LADDER, // prepare to go down ladder + FACE_ASCENDING_LADDER, + FACE_DESCENDING_LADDER, + MOUNT_ASCENDING_LADDER, // move toward ladder until "on" it + MOUNT_DESCENDING_LADDER, // move toward ladder until "on" it + ASCEND_LADDER, // go up the ladder + DESCEND_LADDER, // go down the ladder + DISMOUNT_ASCENDING_LADDER, // get off of the ladder + DISMOUNT_DESCENDING_LADDER, // get off of the ladder + MOVE_TO_DESTINATION, // dismount ladder and move to destination area + } + m_pathLadderState; + bool m_pathLadderFaceIn; // if true, face towards ladder, otherwise face away + const CNavLadder *m_pathLadder; // the ladder we need to use to reach the next area + NavRelativeDirType m_pathLadderDismountDir; // which way to dismount + float m_pathLadderDismountTimestamp; // time when dismount started + float m_pathLadderEnd; // if ascending, z of top, if descending z of bottom + float m_pathLadderTimestamp; // time when we started using ladder - for timeout check + + CountdownTimer m_mustRunTimer; // if nonzero, bot cannot walk + + // game scenario mechanisms + CSGameState m_gameState; + + // hostages mechanism + byte m_hostageEscortCount; + float m_hostageEscortCountTimestamp; + bool m_isWaitingForHostage; + CountdownTimer m_inhibitWaitingForHostageTimer; + CountdownTimer m_waitForHostageTimer; + + // listening mechanism + Vector m_noisePosition; // position we last heard non-friendly noise + float m_noiseTimestamp; // when we heard it (can get zeroed) + CNavArea *m_noiseArea; // the nav area containing the noise + float m_noiseCheckTimestamp; + PriorityType m_noisePriority; // priority of currently heard noise + bool m_isNoiseTravelRangeChecked; + + // "looking around" mechanism + float m_lookAroundStateTimestamp; // time of next state change + float m_lookAheadAngle; // our desired forward look angle + float m_forwardAngle; // our current forward facing direction + float m_inhibitLookAroundTimestamp; // time when we can look around again + + enum LookAtSpotState + { + NOT_LOOKING_AT_SPOT, // not currently looking at a point in space + LOOK_TOWARDS_SPOT, // in the process of aiming at m_lookAtSpot + LOOK_AT_SPOT, // looking at m_lookAtSpot + NUM_LOOK_AT_SPOT_STATES + } + m_lookAtSpotState; + Vector m_lookAtSpot; // the spot we're currently looking at + PriorityType m_lookAtSpotPriority; + float m_lookAtSpotDuration; // how long we need to look at the spot + float m_lookAtSpotTimestamp; // when we actually began looking at the spot + float m_lookAtSpotAngleTolerance; // how exactly we must look at the spot + bool m_lookAtSpotClearIfClose; // if true, the look at spot is cleared if it gets close to us + const char *m_lookAtDesc; // for debugging + float m_peripheralTimestamp; + + enum { MAX_APPROACH_POINTS = 16 }; + Vector m_approachPoint[MAX_APPROACH_POINTS]; + unsigned char m_approachPointCount; + Vector m_approachPointViewPosition; // the position used when computing current approachPoint set + bool m_isWaitingToTossGrenade; // lining up throw + CountdownTimer m_tossGrenadeTimer; // timeout timer for grenade tossing + + SpotEncounter *m_spotEncounter; // the spots we will encounter as we move thru our current area + float m_spotCheckTimestamp; // when to check next encounter spot + + // TODO: Add timestamp for each possible client to hiding spots + enum { MAX_CHECKED_SPOTS = 64 }; + struct HidingSpotCheckInfo + { + HidingSpot *spot; + float timestamp; + } + m_checkedHidingSpot[MAX_CHECKED_SPOTS]; + int m_checkedHidingSpotCount; + + // view angle mechanism + float m_lookPitch; // our desired look pitch angle + float m_lookPitchVel; + float m_lookYaw; // our desired look yaw angle + float m_lookYawVel; + + // aim angle mechanism + mutable Vector m_eyePos; + Vector m_aimOffset; // current error added to victim's position to get actual aim spot + Vector m_aimOffsetGoal; // desired aim offset + float m_aimOffsetTimestamp; // time of next offset adjustment + float m_aimSpreadTimestamp; // time used to determine max spread as it begins to tighten up + Vector m_aimSpot; // the spot we are currently aiming to fire at + + // attack state data + // behavior modifiers + enum DispositionType + { + ENGAGE_AND_INVESTIGATE, // engage enemies on sight and investigate enemy noises + OPPORTUNITY_FIRE, // engage enemies on sight, but only look towards enemy noises, dont investigate + SELF_DEFENSE, // only engage if fired on, or very close to enemy + IGNORE_ENEMIES, // ignore all enemies - useful for ducking around corners, running away, etc + + NUM_DISPOSITIONS + }; + DispositionType m_disposition; // how we will react to enemies + CountdownTimer m_ignoreEnemiesTimer; // how long will we ignore enemies + mutable EHANDLE m_enemy; // our current enemy + bool m_isEnemyVisible; // result of last visibility test on enemy + unsigned char m_visibleEnemyParts; // which parts of the visible enemy do we see + Vector m_lastEnemyPosition; // last place we saw the enemy + float m_lastSawEnemyTimestamp; + float m_firstSawEnemyTimestamp; + float m_currentEnemyAcquireTimestamp; + float m_enemyDeathTimestamp; // if m_enemy is dead, this is when he died + bool m_isLastEnemyDead; // true if we killed or saw our last enemy die + int m_nearbyEnemyCount; // max number of enemies we've seen recently + unsigned int m_enemyPlace; // the location where we saw most of our enemies + + struct WatchInfo + { + float timestamp; + bool isEnemy; + } + m_watchInfo[MAX_CLIENTS]; + mutable EHANDLE m_bomber; // points to bomber if we can see him + + int m_nearbyFriendCount; // number of nearby teammates + mutable EHANDLE m_closestVisibleFriend; // the closest friend we can see + mutable EHANDLE m_closestVisibleHumanFriend; // the closest human friend we can see + + CBasePlayer *m_attacker; // last enemy that hurt us (may not be same as m_enemy) + float m_attackedTimestamp; // when we were hurt by the m_attacker + + int m_lastVictimID; // the entindex of the last victim we killed, or zero + bool m_isAimingAtEnemy; // if true, we are trying to aim at our enemy + bool m_isRapidFiring; // if true, RunUpkeep() will toggle our primary attack as fast as it can + IntervalTimer m_equipTimer; // how long have we had our current weapon equipped + float m_fireWeaponTimestamp; + + // reaction time system + enum { MAX_ENEMY_QUEUE = 20 }; + struct ReactionState + { + // NOTE: player position & orientation is not currently stored separately + EHANDLE player; + bool isReloading; + bool isProtectedByShield; + } + m_enemyQueue[MAX_ENEMY_QUEUE]; // round-robin queue for simulating reaction times + + byte m_enemyQueueIndex; + byte m_enemyQueueCount; + byte m_enemyQueueAttendIndex; // index of the timeframe we are "conscious" of + + // stuck detection + bool m_isStuck; + float m_stuckTimestamp; // time when we got stuck + Vector m_stuckSpot; // the location where we became stuck + NavRelativeDirType m_wiggleDirection; + float m_wiggleTimestamp; + float m_stuckJumpTimestamp; // time for next jump when stuck + + enum { MAX_VEL_SAMPLES = 5 }; + float m_avgVel[MAX_VEL_SAMPLES]; + int m_avgVelIndex; + int m_avgVelCount; + Vector m_lastOrigin; + + // chatter mechanism + GameEventType m_lastRadioCommand; // last radio command we recieved + + float m_lastRadioRecievedTimestamp; // time we recieved a radio message + float m_lastRadioSentTimestamp; // time when we send a radio message + EHANDLE m_radioSubject; // who issued the radio message + Vector m_radioPosition; // position referred to in radio message + float m_voiceFeedbackStartTimestamp; + float m_voiceFeedbackEndTimestamp; // new-style "voice" chatter gets voice feedback + BotChatterInterface m_chatter; + + // learn map mechanism + const CNavNode *m_navNodeList; + CNavNode *m_currentNode; + NavDirType m_generationDir; + NavAreaList::iterator m_analyzeIter; + + enum ProcessType + { + PROCESS_NORMAL, + PROCESS_LEARN, + PROCESS_ANALYZE_ALPHA, + PROCESS_ANALYZE_BETA, + PROCESS_SAVE, + } + m_processMode; + CountdownTimer m_mumbleTimer; + CountdownTimer m_booTimer; + CountdownTimer m_relocateTimer; +}; diff --git a/dlls/bot/cs_bot_chatter.h b/dlls/bot/cs_bot_chatter.h new file mode 100644 index 0000000..4f56b96 --- /dev/null +++ b/dlls/bot/cs_bot_chatter.h @@ -0,0 +1,337 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define UNDEFINED_COUNT 0xFFFF +#define MAX_PLACES_PER_MAP 64 +#define UNDEFINED_SUBJECT (-1) +#define COUNT_MANY 4 // equal to or greater than this is "many" + +class CCSBot; +class BotChatterInterface; + +typedef unsigned int PlaceCriteria; +typedef unsigned int CountCriteria; + +// A meme is a unit information that bots use to +// transmit information to each other via the radio +class BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const = 0; // cause the given bot to act on this meme +}; + +class BotAllHostagesGoneMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +}; + +class BotHostageBeingTakenMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +}; + +class BotHelpMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +public: + Place m_place; +}; + +class BotBombsiteStatusMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +public: + enum StatusType { CLEAR, PLANTED }; + int m_zoneIndex; // the bombsite + StatusType m_status; // whether it is cleared or the bomb is there (planted) +}; + +class BotBombStatusMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme + +public: + CSGameState::BombState m_state; + Vector m_pos; +}; + +class BotFollowMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +}; + +class BotDefendHereMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +public: + Vector m_pos; +}; + +class BotWhereBombMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +}; + +class BotRequestReportMeme: public BotMeme { +public: + virtual void Interpret(CCSBot *sender, CCSBot *receiver) const; // cause the given bot to act on this meme +}; + +enum BotStatementType +{ + REPORT_VISIBLE_ENEMIES, + REPORT_ENEMY_ACTION, + REPORT_MY_CURRENT_TASK, + REPORT_MY_INTENTION, + REPORT_CRITICAL_EVENT, + REPORT_REQUEST_HELP, + REPORT_REQUEST_INFORMATION, + REPORT_ROUND_END, + REPORT_MY_PLAN, + REPORT_INFORMATION, + REPORT_EMOTE, + REPORT_ACKNOWLEDGE, // affirmative or negative + REPORT_ENEMIES_REMAINING, + REPORT_FRIENDLY_FIRE, + REPORT_KILLED_FRIEND, + //REPORT_ENEMY_LOST + + NUM_BOT_STATEMENT_TYPES, +}; + +// BotSpeakables are the smallest unit of bot chatter. +// They represent a specific wav file of a phrase, and the criteria for which it is useful +class BotSpeakable { +public: + char *m_phrase; + float m_duration; + PlaceCriteria m_place; + CountCriteria m_count; +}; + +typedef std::vector BotSpeakableVector; +typedef std::vector BotVoiceBankVector; + +// The BotPhrase class is a collection of Speakables associated with a name, ID, and criteria +class BotPhrase { +public: + const char *GetName() const { return m_name; } + Place GetID() const { return m_id; } + GameEventType GetRadioEquivalent() const { return m_radioEvent; } + bool IsImportant() const { return m_isImportant; } // return true if this phrase is part of an important statement + bool IsPlace() const { return m_isPlace; } +public: + friend class BotPhraseManager; + char *m_name; + Place m_id; + bool m_isPlace; // true if this is a Place phrase + GameEventType m_radioEvent; + bool m_isImportant; // mission-critical statement + + mutable BotVoiceBankVector m_voiceBank; // array of voice banks (arrays of speakables) + std::vector m_count; // number of speakables + mutable std::vector< int > m_index; // index of next speakable to return + int m_numVoiceBanks; // number of voice banks that have been initialized + + mutable PlaceCriteria m_placeCriteria; + mutable CountCriteria m_countCriteria; +}; + +typedef std::list BotPhraseList; + +// The BotPhraseManager is a singleton that provides an interface to all BotPhrase collections +class BotPhraseManager { +public: + const BotPhraseList *GetPlaceList() const { return &m_placeList; } + + // return time last statement of given type was emitted by a teammate for the given place + float GetPlaceStatementInterval(Place place) const; + + // set time of last statement of given type was emitted by a teammate for the given place + void ResetPlaceStatementInterval(Place place) const; + +public: + int FindPlaceIndex(Place where) const; + + // master list of all phrase collections + BotPhraseList m_list; + + // master list of all Place phrases + BotPhraseList m_placeList; + + struct PlaceTimeInfo + { + Place placeID; + IntervalTimer timer; + }; + + mutable PlaceTimeInfo m_placeStatementHistory[MAX_PLACES_PER_MAP]; + mutable int m_placeCount; +}; + +inline int BotPhraseManager::FindPlaceIndex(Place where) const +{ + for (int i = 0; i < m_placeCount; ++i) + { + if (m_placeStatementHistory[i].placeID == where) + return i; + } + + if (m_placeCount < MAX_PLACES_PER_MAP) + { + m_placeStatementHistory[++m_placeCount].placeID = where; + m_placeStatementHistory[++m_placeCount].timer.Invalidate(); + return m_placeCount - 1; + } + + return -1; +} + +inline float BotPhraseManager::GetPlaceStatementInterval(Place place) const +{ + int index = FindPlaceIndex(place); + + if (index < 0) + return 999999.9f; + + if (index >= m_placeCount) + return 999999.9f; + + return m_placeStatementHistory[index].timer.GetElapsedTime(); +} + +inline void BotPhraseManager::ResetPlaceStatementInterval(Place place) const +{ + int index = FindPlaceIndex(place); + + if (index < 0) + return; + + if (index >= m_placeCount) + return; + + m_placeStatementHistory[index].timer.Reset(); +} + +// Statements are meaningful collections of phrases +class BotStatement { +public: + BotChatterInterface *GetChatter() const { return m_chatter; } + BotStatementType GetType() const { return m_type; } // return the type of statement this is + bool HasSubject() const { return (m_subject != UNDEFINED_SUBJECT); } + void SetSubject(int playerID) { m_subject = playerID; } // who this statement is about + int GetSubject() const { return m_subject; } // who this statement is about + void SetPlace(Place where) { m_place = where; } // explicitly set place + + void SetStartTime(float timestamp) { m_startTime = timestamp; } // define the earliest time this statement can be spoken + float GetStartTime() const { return m_startTime; } + bool IsSpeaking() const { return m_isSpeaking; } // return true if this statement is currently being spoken + float GetTimestamp() const { return m_timestamp; } // get time statement was created (but not necessarily started talking) + +public: + friend class BotChatterInterface; + + BotChatterInterface *m_chatter; // the chatter system this statement is part of + BotStatement *m_next, *m_prev; // linked list hooks + + BotStatementType m_type; // what kind of statement this is + int m_subject; // who this subject is about + Place m_place; // explicit place - note some phrases have implicit places as well + BotMeme *m_meme; // a statement can only have a single meme for now + + float m_timestamp; // time when message was created + float m_startTime; // the earliest time this statement can be spoken + float m_expireTime; // time when this statement is no longer valid + float m_speakTimestamp; // time when message began being spoken + bool m_isSpeaking; // true if this statement is current being spoken + + float m_nextTime; // time for next phrase to begin + + enum { MAX_BOT_PHRASES = 4 }; + enum ContextType + { + CURRENT_ENEMY_COUNT, + REMAINING_ENEMY_COUNT, + SHORT_DELAY, + LONG_DELAY, + ACCUMULATE_ENEMIES_DELAY, + }; + struct + { + bool isPhrase; + union + { + const BotPhrase *phrase; + ContextType context; + }; + + } + m_statement[MAX_BOT_PHRASES]; + + enum { MAX_BOT_CONDITIONS = 4 }; + enum ConditionType + { + IS_IN_COMBAT, + RADIO_SILENCE, + ENEMIES_REMAINING, + NUM_CONDITIONS, + }; + + ConditionType m_condition[MAX_BOT_CONDITIONS]; // conditions that must be true for the statement to be said + int m_conditionCount; + + int m_index; // m_index refers to the phrase currently being spoken, or -1 if we havent started yet + int m_count; +}; + +// This class defines the interface to the bot radio chatter system +class BotChatterInterface { +public: + CCSBot *GetOwner() const { return m_me; } + int GetPitch() const { return m_pitch; } + bool SeesAtLeastOneEnemy() const { return m_seeAtLeastOneEnemy; } +public: + BotStatement *m_statementList; // list of all active/pending messages for this bot + void ReportEnemies(); // track nearby enemy count and generate enemy activity statements + bool ShouldSpeak() const; // return true if we speaking makes sense now + CCSBot *m_me; // the bot this chatter is for + bool m_seeAtLeastOneEnemy; + float m_timeWhenSawFirstEnemy; + bool m_reportedEnemies; + bool m_requestedBombLocation; // true if we already asked where the bomb has been planted + int m_pitch; + IntervalTimer m_needBackupInterval; + IntervalTimer m_spottedBomberInterval; + IntervalTimer m_scaredInterval; + IntervalTimer m_planInterval; + CountdownTimer m_spottedLooseBombTimer; + CountdownTimer m_heardNoiseTimer; + CountdownTimer m_escortingHostageTimer; +}; + +extern BotPhraseManager *TheBotPhrases; diff --git a/dlls/bot/cs_bot_manager.h b/dlls/bot/cs_bot_manager.h new file mode 100644 index 0000000..38f3d60 --- /dev/null +++ b/dlls/bot/cs_bot_manager.h @@ -0,0 +1,145 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +extern CBotManager *TheBots; + +// The manager for Counter-Strike specific bots +class CCSBotManager: public CBotManager { +public: + virtual void ClientDisconnect(CBasePlayer *pPlayer) = 0; + virtual BOOL ClientCommand(CBasePlayer *pPlayer, const char *pcmd) = 0; + + virtual void ServerActivate() = 0; + virtual void ServerDeactivate() = 0; + + virtual void ServerCommand(const char *pcmd) = 0; + virtual void AddServerCommand(const char *cmd) = 0; + virtual void AddServerCommands() = 0; + + virtual void RestartRound() = 0; // (EXTEND) invoked when a new round begins + virtual void StartFrame() = 0; // (EXTEND) called each frame + + virtual void OnEvent(GameEventType event, CBaseEntity *entity = NULL, CBaseEntity *other = NULL) = 0; + virtual unsigned int GetPlayerPriority(CBasePlayer *player) const = 0; // return priority of player (0 = max pri) + virtual bool IsImportantPlayer(CBasePlayer *player) const = 0; // return true if player is important to scenario (VIP, bomb carrier, etc) + +public: + // the supported game scenarios + enum GameScenarioType + { + SCENARIO_DEATHMATCH, + SCENARIO_DEFUSE_BOMB, + SCENARIO_RESCUE_HOSTAGES, + SCENARIO_ESCORT_VIP + }; + GameScenarioType GetScenario() const { return m_gameScenario; } + + // "zones" + // depending on the game mode, these are bomb zones, rescue zones, etc. + enum { MAX_ZONES = 4 }; // max # of zones in a map + enum { MAX_ZONE_NAV_AREAS = 16 }; // max # of nav areas in a zone + struct Zone + { + CBaseEntity *m_entity; // the map entity + CNavArea *m_area[MAX_ZONE_NAV_AREAS]; // nav areas that overlap this zone + int m_areaCount; + Vector m_center; + bool m_isLegacy; // if true, use pev->origin and 256 unit radius as zone + int m_index; + Extent m_extent; + }; + + const Zone *GetZone(int i) const { return &m_zone[i]; } + int GetZoneCount() const { return m_zoneCount; } + + // pick a zone at random and return it + const Zone *GetRandomZone() const + { + if (!m_zoneCount) + return NULL; + + return &m_zone[RANDOM_LONG(0, m_zoneCount - 1)]; + } + + bool IsBombPlanted() const { return m_isBombPlanted; } // returns true if bomb has been planted + float GetBombPlantTimestamp() const { return m_bombPlantTimestamp; } // return time bomb was planted + bool IsTimeToPlantBomb() const { return (gpGlobals->time >= m_earliestBombPlantTimestamp); } // return true if it's ok to try to plant bomb + CBasePlayer *GetBombDefuser() const { return m_bombDefuser; } // return the player currently defusing the bomb, or NULL + CBaseEntity *GetLooseBomb() { return m_looseBomb; } // return the bomb if it is loose on the ground + CNavArea *GetLooseBombArea() const { return m_looseBombArea; } // return area that bomb is in/near + + float GetLastSeenEnemyTimestamp() const { return m_lastSeenEnemyTimestamp; } // return the last time anyone has seen an enemy + void SetLastSeenEnemyTimestamp() { m_lastSeenEnemyTimestamp = gpGlobals->time; } + + float GetRoundStartTime() const { return m_roundStartTimestamp; } + float GetElapsedRoundTime() const { return gpGlobals->time - m_roundStartTimestamp; } // return the elapsed time since the current round began + + bool IsDefenseRushing() const { return m_isDefenseRushing; } // returns true if defense team has "decided" to rush this round + bool IsRoundOver() const { return m_isRoundOver; } // return true if the round has ended + + unsigned int GetNavPlace() const { return m_navPlace; } + void SetNavPlace(unsigned int place) { m_navPlace = place; } + +public: + GameScenarioType m_gameScenario; // what kind of game are we playing + + Zone m_zone[MAX_ZONES]; + int m_zoneCount; + + bool m_isBombPlanted; // true if bomb has been planted + float m_bombPlantTimestamp; // time bomb was planted + float m_earliestBombPlantTimestamp; // don't allow planting until after this time has elapsed + CBasePlayer *m_bombDefuser; // the player currently defusing a bomb + EHANDLE m_looseBomb; // will be non-NULL if bomb is loose on the ground + CNavArea *m_looseBombArea; // area that bomb is is/near + + bool m_isRoundOver; // true if the round has ended + float m_radioMsgTimestamp[24][2]; + + float m_lastSeenEnemyTimestamp; + float m_roundStartTimestamp; // the time when the current round began + + bool m_isDefenseRushing; // whether defensive team is rushing this round or not + + unsigned int m_navPlace; + CountdownTimer m_respawnTimer; + bool m_isRespawnStarted; + bool m_canRespawn; + bool m_bServerActive; +}; + +inline int OtherTeam(int team) +{ + return (team == TERRORIST) ? CT : TERRORIST; +} + +inline CCSBotManager *TheCSBots() +{ + return reinterpret_cast(TheBots); +} diff --git a/dlls/bot/cs_gamestate.h b/dlls/bot/cs_gamestate.h new file mode 100644 index 0000000..769575f --- /dev/null +++ b/dlls/bot/cs_gamestate.h @@ -0,0 +1,90 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CCSBot; + +// This class represents the game state as known by a particular bot +class CSGameState { +public: + // bomb defuse scenario + enum BombState + { + MOVING, // being carried by a Terrorist + LOOSE, // loose on the ground somewhere + PLANTED, // planted and ticking + DEFUSED, // the bomb has been defused + EXPLODED, // the bomb has exploded + }; + + bool IsBombMoving() const { return (m_bombState == MOVING); } + bool IsBombLoose() const { return (m_bombState == LOOSE); } + bool IsBombPlanted() const { return (m_bombState == PLANTED); } + bool IsBombDefused() const { return (m_bombState == DEFUSED); } + bool IsBombExploded() const { return (m_bombState == EXPLODED); } + +public: + CCSBot *m_owner; // who owns this gamestate + bool m_isRoundOver; // true if round is over, but no yet reset + + // bomb defuse scenario + BombState GetBombState() { return m_bombState; } + BombState m_bombState; // what we think the bomb is doing + + IntervalTimer m_lastSawBomber; + Vector m_bomberPos; + + IntervalTimer m_lastSawLooseBomb; + Vector m_looseBombPos; + + bool m_isBombsiteClear[4]; // corresponds to zone indices in CCSBotManager + int m_bombsiteSearchOrder[4]; // randomized order of bombsites to search + int m_bombsiteCount; + int m_bombsiteSearchIndex; // the next step in the search + + int m_plantedBombsite; // zone index of the bombsite where the planted bomb is + + bool m_isPlantedBombPosKnown; // if true, we know the exact location of the bomb + Vector m_plantedBombPos; + + // hostage rescue scenario + struct HostageInfo + { + CHostage *hostage; + Vector knownPos; + bool isValid; + bool isAlive; + bool isFree; // not being escorted by a CT + } + m_hostage[MAX_HOSTAGES]; + int m_hostageCount; // number of hostages left in map + CountdownTimer m_validateInterval; + + bool m_allHostagesRescued; // if true, so every hostages been is rescued + bool m_haveSomeHostagesBeenTaken; // true if a hostage has been moved by a CT (and we've seen it) +}; diff --git a/dlls/buttons.h b/dlls/buttons.h new file mode 100644 index 0000000..087417a --- /dev/null +++ b/dlls/buttons.h @@ -0,0 +1,104 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SF_BUTTON_DONTMOVE 1 +#define SF_ROTBUTTON_NOTSOLID 1 +#define SF_BUTTON_TOGGLE 32 // button stays pushed until reactivated +#define SF_BUTTON_SPARK_IF_OFF 64 // button sparks in OFF state +#define SF_BUTTON_TOUCH_ONLY 256 // button only fires as a result of USE key. + +#define SF_GLOBAL_SET 1 // Set global state to initial state on spawn + +#define SF_MULTI_INIT 1 + +// Make this button behave like a door (HACKHACK) +// This will disable use and make the button solid +// rotating buttons were made SOLID_NOT by default since their were some +// collision problems with them... +#define SF_MOMENTARY_DOOR 0x0001 + +#define SF_SPARK_TOOGLE 32 +#define SF_SPARK_IF_OFF 64 + +#define SF_BTARGET_USE 0x0001 +#define SF_BTARGET_ON 0x0002 + +class CEnvGlobal: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + string_t m_globalstate; + int m_triggermode; + int m_initialstate; +}; + +class CRotButton: public CBaseButton { +public: + virtual void Spawn() = 0; +}; + +class CMomentaryRotButton: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_lastUsed; + int m_direction; + float m_returnSpeed; + Vector m_start; + Vector m_end; + int m_sounds; +}; + +class CEnvSpark: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; +public: + float m_flDelay; +}; + +class CButtonTarget: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int ObjectCaps() = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; diff --git a/dlls/cbase.h b/dlls/cbase.h index c5f8048..c785243 100644 --- a/dlls/cbase.h +++ b/dlls/cbase.h @@ -1,802 +1,379 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ /* - -Class Hierachy - -CBaseEntity - CBaseDelay - CBaseToggle - CBaseItem - CBaseMonster - CBaseCycler - CBasePlayer - CBaseGroup +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* */ +#pragma once -#define MAX_PATH_SIZE 10 // max number of nodes available for a path. - -// These are caps bits to indicate what an object's capabilities (currently used for save/restore and level transitions) -#define FCAP_CUSTOMSAVE 0x00000001 -#define FCAP_ACROSS_TRANSITION 0x00000002 // should transfer between transitions -#define FCAP_MUST_SPAWN 0x00000004 // Spawn after restore -#define FCAP_DONT_SAVE 0x80000000 // Don't save this -#define FCAP_IMPULSE_USE 0x00000008 // can be used by the player -#define FCAP_CONTINUOUS_USE 0x00000010 // can be used by the player -#define FCAP_ONOFF_USE 0x00000020 // can be used by the player -#define FCAP_DIRECTIONAL_USE 0x00000040 // Player sends +/- 1 when using (currently only tracktrains) -#define FCAP_MASTER 0x00000080 // Can be used to "master" other entities (like multisource) - -// UNDONE: This will ignore transition volumes (trigger_transition), but not the PVS!!! -#define FCAP_FORCE_TRANSITION 0x00000080 // ALWAYS goes across transitions - -#include "archtypes.h" // DAL -#include "saverestore.h" -#include "schedule.h" - -#ifndef MONSTEREVENT_H +#include "util.h" #include "monsterevent.h" -#endif - -// C functions for external declarations that call the appropriate C++ methods - -#ifndef CBASE_DLLEXPORT -#ifdef _WIN32 -#define CBASE_DLLEXPORT _declspec( dllexport ) -#else -#define CBASE_DLLEXPORT __attribute__ ((visibility("default"))) -#endif -#endif - -#define EXPORT CBASE_DLLEXPORT - -extern "C" CBASE_DLLEXPORT int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion ); -extern "C" CBASE_DLLEXPORT int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion ); - -extern int DispatchSpawn( edict_t *pent ); -extern void DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd ); -extern void DispatchTouch( edict_t *pentTouched, edict_t *pentOther ); -extern void DispatchUse( edict_t *pentUsed, edict_t *pentOther ); -extern void DispatchThink( edict_t *pent ); -extern void DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther ); -extern void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData ); -extern int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity ); -extern void DispatchObjectCollsionBox( edict_t *pent ); -extern void SaveWriteFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ); -extern void SaveReadFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ); -extern void SaveGlobalState( SAVERESTOREDATA *pSaveData ); -extern void RestoreGlobalState( SAVERESTOREDATA *pSaveData ); -extern void ResetGlobalState( void ); - -typedef enum { USE_OFF = 0, USE_ON = 1, USE_SET = 2, USE_TOGGLE = 3 } USE_TYPE; - -extern void FireTargets( const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - -typedef void (CBaseEntity::*BASEPTR)(void); -typedef void (CBaseEntity::*ENTITYFUNCPTR)(CBaseEntity *pOther ); -typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - -// For CLASSIFY -#define CLASS_NONE 0 -#define CLASS_MACHINE 1 -#define CLASS_PLAYER 2 -#define CLASS_HUMAN_PASSIVE 3 -#define CLASS_HUMAN_MILITARY 4 -#define CLASS_ALIEN_MILITARY 5 -#define CLASS_ALIEN_PASSIVE 6 -#define CLASS_ALIEN_MONSTER 7 -#define CLASS_ALIEN_PREY 8 -#define CLASS_ALIEN_PREDATOR 9 -#define CLASS_INSECT 10 -#define CLASS_PLAYER_ALLY 11 -#define CLASS_PLAYER_BIOWEAPON 12 // hornets and snarks.launched by players -#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks.launched by the alien menace -#define CLASS_BARNACLE 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures. +class CSave; +class CRestore; +class CBasePlayer; class CBaseEntity; class CBaseMonster; class CBasePlayerItem; class CSquadMonster; +class CCSEntity; - -#define SF_NORESPAWN ( 1 << 30 )// !!!set this bit on guns and stuff that should never respawn. - -// -// EHANDLE. Safe way to point to CBaseEntities who may die between frames -// -class EHANDLE -{ -private: - edict_t *m_pent; - int m_serialnumber; -public: - edict_t *Get( void ); - edict_t *Set( edict_t *pent ); - - operator int (); - - operator CBaseEntity *(); - - CBaseEntity * operator = (CBaseEntity *pEntity); - CBaseEntity * operator ->(); -}; - - -// -// Base Entity. All entity types derive from this -// -class CBaseEntity -{ +class CBaseEntity { public: // Constructor. Set engine to use C/C++ callback functions // pointers to engine data - entvars_t *pev; // Don't need to save/restore this pointer, the engine resets it + entvars_t *pev; // Don't need to save/restore this pointer, the engine resets it // path corners - CBaseEntity *m_pGoalEnt;// path corner we are heading towards - CBaseEntity *m_pLink;// used for temporary link-list operations. + CBaseEntity *m_pGoalEnt; // path corner we are heading towards + CBaseEntity *m_pLink; // used for temporary link-list operations. // initialization functions - virtual void Spawn( void ) { return; } - virtual void Precache( void ) { return; } - virtual void KeyValue( KeyValueData* pkvd) { pkvd->fHandled = FALSE; } - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - virtual int ObjectCaps( void ) { return FCAP_ACROSS_TRANSITION; } - virtual void Activate( void ) {} - + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Activate() = 0; + // Setup the object->object collision box (pev->mins / pev->maxs is the object->world collision box) - virtual void SetObjectCollisionBox( void ); + virtual void SetObjectCollisionBox() = 0; -// Classify - returns the type of group (i.e, "houndeye", or "human military" so that monsters with different classnames -// still realize that they are teammates. (overridden for monsters that form groups) - virtual int Classify ( void ) { return CLASS_NONE; }; - virtual void DeathNotice ( entvars_t *pevChild ) {}// monster maker children use this to tell the monster maker that they have died. + // Classify - returns the type of group (i.e, "houndeye", or "human military" so that monsters with different classnames + // still realize that they are teammates. (overridden for monsters that form groups) + virtual int Classify() = 0; + virtual void DeathNotice(entvars_t *pevChild) = 0; + virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual BOOL TakeHealth(float flHealth, int bitsDamageType) = 0; + virtual void Killed(entvars_t *pevAttacker, int iGib) = 0; + virtual int BloodColor() = 0; + virtual void TraceBleed(float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; + virtual BOOL IsTriggered(CBaseEntity *pActivator) = 0; + virtual CBaseMonster *MyMonsterPointer() = 0; + virtual CSquadMonster *MySquadMonsterPointer() = 0; + virtual int GetToggleState() = 0; + virtual void AddPoints(int score, BOOL bAllowNegativeScore) = 0; + virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0; + virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0; + virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0; + virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0; + virtual float GetDelay() = 0; + virtual int IsMoving() = 0; + virtual void OverrideReset() = 0; + virtual int DamageDecal(int bitsDamageType) = 0; - static TYPEDESCRIPTION m_SaveData[]; - - virtual void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType); - virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ); - virtual int TakeHealth( float flHealth, int bitsDamageType ); - virtual void Killed( entvars_t *pevAttacker, int iGib ); - virtual int BloodColor( void ) { return DONT_BLEED; } - virtual void TraceBleed( float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType ); - virtual BOOL IsTriggered( CBaseEntity *pActivator ) {return TRUE;} - virtual CBaseMonster *MyMonsterPointer( void ) { return NULL;} - virtual CSquadMonster *MySquadMonsterPointer( void ) { return NULL;} - virtual int GetToggleState( void ) { return TS_AT_TOP; } - virtual void AddPoints( int score, BOOL bAllowNegativeScore ) {} - virtual void AddPointsToTeam( int score, BOOL bAllowNegativeScore ) {} - virtual BOOL AddPlayerItem( CBasePlayerItem *pItem ) { return 0; } - virtual BOOL RemovePlayerItem( CBasePlayerItem *pItem ) { return 0; } - virtual int GiveAmmo( int iAmount, char *szName, int iMax ) { return -1; }; - virtual float GetDelay( void ) { return 0; } - virtual int IsMoving( void ) { return pev->velocity != g_vecZero; } - virtual void OverrideReset( void ) {} - virtual int DamageDecal( int bitsDamageType ); // This is ONLY used by the node graph to test movement through a door - virtual void SetToggleState( int state ) {} - virtual void StartSneaking( void ) {} - virtual void StopSneaking( void ) {} - virtual BOOL OnControls( entvars_t *pev ) { return FALSE; } - virtual BOOL IsSneaking( void ) { return FALSE; } - virtual BOOL IsAlive( void ) { return (pev->deadflag == DEAD_NO) && pev->health > 0; } - virtual BOOL IsBSPModel( void ) { return pev->solid == SOLID_BSP || pev->movetype == MOVETYPE_PUSHSTEP; } - virtual BOOL ReflectGauss( void ) { return ( IsBSPModel() && !pev->takedamage ); } - virtual BOOL HasTarget( string_t targetname ) { return FStrEq(STRING(targetname), STRING(pev->targetname) ); } - virtual BOOL IsInWorld( void ); - virtual BOOL IsPlayer( void ) { return FALSE; } - virtual BOOL IsNetClient( void ) { return FALSE; } - virtual const char *TeamID( void ) { return ""; } + virtual void SetToggleState(int state) = 0; + virtual void StartSneaking() = 0; + virtual void UpdateOnRemove() = 0; + virtual BOOL OnControls(entvars_t *onpev) = 0; + virtual BOOL IsSneaking() = 0; + virtual BOOL IsAlive() = 0; + virtual BOOL IsBSPModel() = 0; + virtual BOOL ReflectGauss() = 0; + virtual BOOL HasTarget(string_t targetname) = 0; + virtual BOOL IsInWorld() = 0; + virtual BOOL IsPlayer() = 0; + virtual BOOL IsNetClient() = 0; + virtual const char *TeamID() = 0; + virtual CBaseEntity *GetNextTarget() = 0; -// virtual void SetActivator( CBaseEntity *pActivator ) {} - virtual CBaseEntity *GetNextTarget( void ); - // fundamental callbacks - void (CBaseEntity ::*m_pfnThink)(void); - void (CBaseEntity ::*m_pfnTouch)( CBaseEntity *pOther ); - void (CBaseEntity ::*m_pfnUse)( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void (CBaseEntity ::*m_pfnBlocked)( CBaseEntity *pOther ); + void (CBaseEntity::*m_pfnThink)(); + void (CBaseEntity::*m_pfnTouch)(CBaseEntity *pOther); + void (CBaseEntity::*m_pfnUse)(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); + void (CBaseEntity::*m_pfnBlocked)(CBaseEntity *pOther); - virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)(); }; - virtual void Touch( CBaseEntity *pOther ) { if (m_pfnTouch) (this->*m_pfnTouch)( pOther ); }; - virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) - { - if (m_pfnUse) - (this->*m_pfnUse)( pActivator, pCaller, useType, value ); - } - virtual void Blocked( CBaseEntity *pOther ) { if (m_pfnBlocked) (this->*m_pfnBlocked)( pOther ); }; + virtual void Think() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType = USE_OFF, float value = 0.0f) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; - // allow engine to allocate instance data - void *operator new( size_t stAllocateBlock, entvars_t *pev ) - { - return (void *)ALLOC_PRIVATE(ENT(pev), stAllocateBlock); - }; + virtual CBaseEntity *Respawn() = 0; + virtual void UpdateOwner() = 0; + virtual BOOL FBecomeProne() = 0; - // don't use this. -#if _MSC_VER >= 1200 // only build this code if MSVC++ 6.0 or higher - void operator delete(void *pMem, entvars_t *pev) - { - pev->flags |= FL_KILLME; - }; -#endif + virtual Vector Center() = 0; // center point of entity + virtual Vector EyePosition() = 0; // position of eyes + virtual Vector EarPosition() = 0; // position of ears + virtual Vector BodyTarget(const Vector &posSrc) = 0; // position to shoot at - void UpdateOnRemove( void ); + virtual int Illumination() = 0; + virtual BOOL FVisible(CBaseEntity *pEntity) = 0; + virtual BOOL FVisible(const Vector &vecOrigin) = 0; +public: + static CBaseEntity *Instance(edict_t *pent) { return (CBaseEntity *)GET_PRIVATE(pent ? pent : ENT(0)); } + static CBaseEntity *Instance(entvars_t *pev) { return Instance(ENT(pev)); } + static CBaseEntity *Instance(int offset) { return Instance(ENT(offset)); } - // common member functions - void EXPORT SUB_Remove( void ); - void EXPORT SUB_DoNothing( void ); - void EXPORT SUB_StartFadeOut ( void ); - void EXPORT SUB_FadeOut ( void ); - void EXPORT SUB_CallUseToggle( void ) { this->Use( this, this, USE_TOGGLE, 0 ); } - int ShouldToggle( USE_TYPE useType, BOOL currentState ); - void FireBullets( ULONG cShots, Vector vecSrc, Vector vecDirShooting, Vector vecSpread, float flDistance, int iBulletType, int iTracerFreq = 4, int iDamage = 0, entvars_t *pevAttacker = NULL ); - 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 ); + edict_t *edict() { return ENT(pev); } + EOFFSET eoffset() { return OFFSET(pev); } + int entindex() { return ENTINDEX(edict()); } + int IsDormant() { return (pev->flags & FL_DORMANT) == FL_DORMANT; } - virtual CBaseEntity *Respawn( void ) { return NULL; } +public: + CCSEntity *m_pEntity; // NOTE: it was replaced on member "int *current_ammo" because it is useless. - void SUB_UseTargets( CBaseEntity *pActivator, USE_TYPE useType, float value ); - // Do the bounding boxes of these two intersect? - int Intersects( CBaseEntity *pOther ); - void MakeDormant( void ); - int IsDormant( void ); - BOOL IsLockedByMaster( void ) { return FALSE; } - - static CBaseEntity *Instance( edict_t *pent ) - { - if ( !pent ) - pent = ENT(0); - CBaseEntity *pEnt = (CBaseEntity *)GET_PRIVATE(pent); - return pEnt; - } - - static CBaseEntity *Instance( entvars_t *pev ) { return Instance( ENT( pev ) ); } - static CBaseEntity *Instance( int eoffset) { return Instance( ENT( eoffset) ); } - - CBaseMonster *GetMonsterPointer( entvars_t *pevMonster ) - { - CBaseEntity *pEntity = Instance( pevMonster ); - if ( pEntity ) - return pEntity->MyMonsterPointer(); - return NULL; - } - CBaseMonster *GetMonsterPointer( edict_t *pentMonster ) - { - CBaseEntity *pEntity = Instance( pentMonster ); - if ( pEntity ) - return pEntity->MyMonsterPointer(); - return NULL; - } - - - // Ugly code to lookup all functions to make sure they are exported when set. -#ifdef _DEBUG - void FunctionCheck( void *pFunction, char *name ) - { - if (pFunction && !NAME_FOR_FUNCTION((uint32)pFunction) ) - ALERT( at_error, "No EXPORT: %s:%s (%08lx)\n", STRING(pev->classname), name, (uint32)pFunction ); - } - - BASEPTR ThinkSet( BASEPTR func, char *name ) - { - m_pfnThink = func; - FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnThink)))), name ); - return func; - } - ENTITYFUNCPTR TouchSet( ENTITYFUNCPTR func, char *name ) - { - m_pfnTouch = func; - FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnTouch)))), name ); - return func; - } - USEPTR UseSet( USEPTR func, char *name ) - { - m_pfnUse = func; - FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnUse)))), name ); - return func; - } - ENTITYFUNCPTR BlockedSet( ENTITYFUNCPTR func, char *name ) - { - m_pfnBlocked = func; - FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnBlocked)))), name ); - return func; - } - -#endif - - - // virtual functions used by a few classes - - // used by monsters that are created by the MonsterMaker - virtual void UpdateOwner( void ) { return; }; - - - // - static CBaseEntity *Create( char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner = NULL ); - - virtual BOOL FBecomeProne( void ) {return FALSE;}; - edict_t *edict() { return ENT( pev ); }; - EOFFSET eoffset( ) { return OFFSET( pev ); }; - int entindex( ) { return ENTINDEX( edict() ); }; - - virtual Vector Center( ) { return (pev->absmax + pev->absmin) * 0.5; }; // center point of entity - virtual Vector EyePosition( ) { return pev->origin + pev->view_ofs; }; // position of eyes - virtual Vector EarPosition( ) { return pev->origin + pev->view_ofs; }; // position of ears - virtual Vector BodyTarget( const Vector &posSrc ) { return Center( ); }; // position to shoot at - - virtual int Illumination( ) { return GETENTITYILLUM( ENT( pev ) ); }; - - virtual BOOL FVisible ( CBaseEntity *pEntity ); - virtual BOOL FVisible ( const Vector &vecOrigin ); - - //We use this variables to store each ammo count. - int ammo_9mm; - int ammo_357; - int ammo_bolts; + // We use this variables to store each ammo count. + float currentammo; + int maxammo_buckshot; int ammo_buckshot; - int ammo_rockets; - int ammo_uranium; - int ammo_hornets; - int ammo_argrens; - //Special stuff for grenades and satchels. + int maxammo_9mm; + int ammo_9mm; + int maxammo_556nato; + int ammo_556nato; + int maxammo_556natobox; + int ammo_556natobox; + int maxammo_762nato; + int ammo_762nato; + int maxammo_45acp; + int ammo_45acp; + int maxammo_50ae; + int ammo_50ae; + int maxammo_338mag; + int ammo_338mag; + int maxammo_57mm; + int ammo_57mm; + int maxammo_357sig; + int ammo_357sig; + + // Special stuff for grenades and knife. float m_flStartThrow; float m_flReleaseThrow; - int m_chargeReady; - int m_fInAttack; + int m_iSwing; - enum EGON_FIRESTATE { FIRE_OFF, FIRE_CHARGE }; - int m_fireState; + // client has left the game + bool has_disconnected; +}; + +class CPointEntity: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int ObjectCaps() = 0; }; - -// Ugly technique to override base member functions -// Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a -// member function of a base class. static_cast is a sleezy way around that problem. - -#ifdef _DEBUG - -#define SetThink( a ) ThinkSet( static_cast (a), #a ) -#define SetTouch( a ) TouchSet( static_cast (a), #a ) -#define SetUse( a ) UseSet( static_cast (a), #a ) -#define SetBlocked( a ) BlockedSet( static_cast (a), #a ) - -#else - -#define SetThink( a ) m_pfnThink = static_cast (a) -#define SetTouch( a ) m_pfnTouch = static_cast (a) -#define SetUse( a ) m_pfnUse = static_cast (a) -#define SetBlocked( a ) m_pfnBlocked = static_cast (a) - -#endif - - -class CPointEntity : public CBaseEntity -{ +// generic Delay entity +class CBaseDelay: public CBaseEntity { public: - void Spawn( void ); - virtual int ObjectCaps( void ) { return CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION; } -private: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; +public: + float m_flDelay; + int m_iszKillTarget; }; - -typedef struct locksounds // sounds that doors and buttons make when locked/unlocked -{ - string_t sLockedSound; // sound a door makes when it's locked - string_t sLockedSentence; // sentence group played when door is locked - string_t sUnlockedSound; // sound a door makes when it's unlocked - string_t sUnlockedSentence; // sentence group played when door is unlocked - - int iLockedSentence; // which sentence in sentence group to play next - int iUnlockedSentence; // which sentence in sentence group to play next - - float flwaitSound; // time delay between playing consecutive 'locked/unlocked' sounds - float flwaitSentence; // time delay between playing consecutive sentences - BYTE bEOFLocked; // true if hit end of list of locked sentences - BYTE bEOFUnlocked; // true if hit end of list of unlocked sentences -} locksound_t; - -void PlayLockSounds(entvars_t *pev, locksound_t *pls, int flocked, int fbutton); - -// -// MultiSouce -// - -#define MAX_MULTI_TARGETS 16 // maximum number of targets a single multi_manager entity may be assigned. -#define MS_MAX_TARGETS 32 - -class CMultiSource : public CPointEntity -{ +class CBaseAnimating: public CBaseDelay { public: - void Spawn( ); - void KeyValue( KeyValueData *pkvd ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - int ObjectCaps( void ) { return (CPointEntity::ObjectCaps() | FCAP_MASTER); } - BOOL IsTriggered( CBaseEntity *pActivator ); - void EXPORT Register( void ); - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; - - EHANDLE m_rgEntities[MS_MAX_TARGETS]; - int m_rgTriggered[MS_MAX_TARGETS]; - - int m_iTotal; - string_t m_globalstate; -}; - - -// -// generic Delay entity. -// -class CBaseDelay : public CBaseEntity -{ + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void HandleAnimEvent(MonsterEvent_t *pEvent) = 0; public: - float m_flDelay; - int m_iszKillTarget; - - virtual void KeyValue( KeyValueData* pkvd); - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; - // common member functions - void SUB_UseTargets( CBaseEntity *pActivator, USE_TYPE useType, float value ); - void EXPORT DelayThink( void ); -}; - - -class CBaseAnimating : public CBaseDelay -{ -public: - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; - - // Basic Monster Animation functions - float StudioFrameAdvance( float flInterval = 0.0 ); // accumulate animation frame time from last time called until now - int GetSequenceFlags( void ); - int LookupActivity ( int activity ); - int LookupActivityHeaviest ( int activity ); - int LookupSequence ( const char *label ); - void ResetSequenceInfo ( ); - void DispatchAnimEvents ( float flFutureInterval = 0.1 ); // Handle events that have happend since last time called up until X seconds into the future - virtual void HandleAnimEvent( MonsterEvent_t *pEvent ) { return; }; - float SetBoneController ( int iController, float flValue ); - void InitBoneControllers ( void ); - float SetBlending ( int iBlender, float flValue ); - void GetBonePosition ( int iBone, Vector &origin, Vector &angles ); - void GetAutomovement( Vector &origin, Vector &angles, float flInterval = 0.1 ); - int FindTransition( int iEndingSequence, int iGoalSequence, int *piDir ); - void GetAttachment ( int iAttachment, Vector &origin, Vector &angles ); - void SetBodygroup( int iGroup, int iValue ); - int GetBodygroup( int iGroup ); - int ExtractBbox( int sequence, float *mins, float *maxs ); - void SetSequenceBox( void ); - // animation needs - float m_flFrameRate; // computed FPS for current sequence - float m_flGroundSpeed; // computed linear movement rate for current sequence - float m_flLastEventCheck; // last time the event list was checked - BOOL m_fSequenceFinished;// flag set when StudioAdvanceFrame moves across a frame boundry - BOOL m_fSequenceLoops; // true if the sequence loops + float m_flFrameRate; // computed FPS for current sequence + float m_flGroundSpeed; // computed linear movement rate for current sequence + float m_flLastEventCheck; // last time the event list was checked + BOOL m_fSequenceFinished; // flag set when StudioAdvanceFrame moves across a frame boundry + BOOL m_fSequenceLoops; // true if the sequence loops }; - -// -// generic Toggle entity. -// -#define SF_ITEM_USE_ONLY 256 // ITEM_USE_ONLY = BUTTON_USE_ONLY = DOOR_USE_ONLY!!! - -class CBaseToggle : public CBaseAnimating -{ +// EHANDLE. Safe way to point to CBaseEntities who may die between frames +class EHANDLE { public: - void KeyValue( KeyValueData *pkvd ); + edict_t *Get(); + edict_t *Set(edict_t *pent); - TOGGLE_STATE m_toggle_state; - float m_flActivateFinished;//like attack_finished, but for doors - float m_flMoveDistance;// how far a door should slide or rotate - float m_flWait; - float m_flLip; - float m_flTWidth;// for plats - float m_flTLength;// for plats + operator int(); + operator CBaseEntity*(); + operator CBasePlayer*(); - Vector m_vecPosition1; - Vector m_vecPosition2; - Vector m_vecAngle1; - Vector m_vecAngle2; + CBaseEntity *operator=(CBaseEntity *pEntity); + CBaseEntity *operator->(); - int m_cTriggersLeft; // trigger_counter only, # of activations remaining - float m_flHeight; - EHANDLE m_hActivator; - void (CBaseToggle::*m_pfnCallWhenMoveDone)(void); - Vector m_vecFinalDest; - Vector m_vecFinalAngle; +private: + edict_t *m_pent; + int m_serialnumber; +}; - int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does +// generic Toggle entity. +class CBaseToggle: public CBaseAnimating { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int GetToggleState() = 0; + virtual float GetDelay() = 0; +public: + TOGGLE_STATE m_toggle_state; + float m_flActivateFinished; // like attack_finished, but for doors + float m_flMoveDistance; // how far a door should slide or rotate + float m_flWait; + float m_flLip; + float m_flTWidth; // for plats + float m_flTLength; // for plats - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); + Vector m_vecPosition1; + Vector m_vecPosition2; + Vector m_vecAngle1; + Vector m_vecAngle2; - static TYPEDESCRIPTION m_SaveData[]; + int m_cTriggersLeft; // trigger_counter only, # of activations remaining + float m_flHeight; + EHANDLE m_hActivator; + void (CBaseToggle::*m_pfnCallWhenMoveDone)(); + Vector m_vecFinalDest; + Vector m_vecFinalAngle; - virtual int GetToggleState( void ) { return m_toggle_state; } - virtual float GetDelay( void ) { return m_flWait; } - - // common member functions - void LinearMove( Vector vecDest, float flSpeed ); - void EXPORT LinearMoveDone( void ); - void AngularMove( Vector vecDestAngle, float flSpeed ); - void EXPORT AngularMoveDone( void ); - BOOL IsLockedByMaster( void ); - - static float AxisValue( int flags, const Vector &angles ); - static void AxisDir( entvars_t *pev ); - static float AxisDelta( int flags, const Vector &angle1, const Vector &angle2 ); + int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does string_t m_sMaster; // If this button has a master switch, this is the targetname. - // A master switch must be of the multisource type. If all - // of the switches in the multisource have been triggered, then - // the button will be allowed to operate. Otherwise, it will be - // deactivated. + // A master switch must be of the multisource type. If all + // of the switches in the multisource have been triggered, then + // the button will be allowed to operate. Otherwise, it will be + // deactivated. }; -#define SetMoveDone( a ) m_pfnCallWhenMoveDone = static_cast (a) - - -// people gib if their health is <= this at the time of death -#define GIB_HEALTH_VALUE -30 - -#define ROUTE_SIZE 8 // how many waypoints a monster can store at one time -#define MAX_OLD_ENEMIES 4 // how many old enemies to remember - -#define bits_CAP_DUCK ( 1 << 0 )// crouch -#define bits_CAP_JUMP ( 1 << 1 )// jump/leap -#define bits_CAP_STRAFE ( 1 << 2 )// strafe ( walk/run sideways) -#define bits_CAP_SQUAD ( 1 << 3 )// can form squads -#define bits_CAP_SWIM ( 1 << 4 )// proficiently navigate in water -#define bits_CAP_CLIMB ( 1 << 5 )// climb ladders/ropes -#define bits_CAP_USE ( 1 << 6 )// open doors/push buttons/pull levers -#define bits_CAP_HEAR ( 1 << 7 )// can hear forced sounds -#define bits_CAP_AUTO_DOORS ( 1 << 8 )// can trigger auto doors -#define bits_CAP_OPEN_DOORS ( 1 << 9 )// can open manual doors -#define bits_CAP_TURN_HEAD ( 1 << 10)// can turn head, always bone controller 0 - -#define bits_CAP_RANGE_ATTACK1 ( 1 << 11)// can do a range attack 1 -#define bits_CAP_RANGE_ATTACK2 ( 1 << 12)// can do a range attack 2 -#define bits_CAP_MELEE_ATTACK1 ( 1 << 13)// can do a melee attack 1 -#define bits_CAP_MELEE_ATTACK2 ( 1 << 14)// can do a melee attack 2 - -#define bits_CAP_FLY ( 1 << 15)// can fly, move all around - -#define bits_CAP_DOORS_GROUP (bits_CAP_USE | bits_CAP_AUTO_DOORS | bits_CAP_OPEN_DOORS) - -// used by suit voice to indicate damage sustained and repaired type to player - -// instant damage - -#define DMG_GENERIC 0 // generic damage was done -#define DMG_CRUSH (1 << 0) // crushed by falling or moving object -#define DMG_BULLET (1 << 1) // shot -#define DMG_SLASH (1 << 2) // cut, clawed, stabbed -#define DMG_BURN (1 << 3) // heat burned -#define DMG_FREEZE (1 << 4) // frozen -#define DMG_FALL (1 << 5) // fell too far -#define DMG_BLAST (1 << 6) // explosive blast damage -#define DMG_CLUB (1 << 7) // crowbar, punch, headbutt -#define DMG_SHOCK (1 << 8) // electric shock -#define DMG_SONIC (1 << 9) // sound pulse shockwave -#define DMG_ENERGYBEAM (1 << 10) // laser or other high energy beam -#define DMG_NEVERGIB (1 << 12) // with this bit OR'd in, no damage type will be able to gib victims upon death -#define DMG_ALWAYSGIB (1 << 13) // with this bit OR'd in, any damage type can be made to gib victims upon death. -#define DMG_DROWN (1 << 14) // Drowning -// time-based damage -#define DMG_TIMEBASED (~(0x3fff)) // mask for time-based damage - -#define DMG_PARALYZE (1 << 15) // slows affected creature down -#define DMG_NERVEGAS (1 << 16) // nerve toxins, very bad -#define DMG_POISON (1 << 17) // blood poisioning -#define DMG_RADIATION (1 << 18) // radiation exposure -#define DMG_DROWNRECOVER (1 << 19) // drowning recovery -#define DMG_ACID (1 << 20) // toxic chemicals or acid burns -#define DMG_SLOWBURN (1 << 21) // in an oven -#define DMG_SLOWFREEZE (1 << 22) // in a subzero freezer -#define DMG_MORTAR (1 << 23) // Hit by air raid (done to distinguish grenade from mortar) - -// these are the damage types that are allowed to gib corpses -#define DMG_GIB_CORPSE ( DMG_CRUSH | DMG_FALL | DMG_BLAST | DMG_SONIC | DMG_CLUB ) - -// these are the damage types that have client hud art -#define DMG_SHOWNHUD (DMG_POISON | DMG_ACID | DMG_FREEZE | DMG_SLOWFREEZE | DMG_DROWN | DMG_BURN | DMG_SLOWBURN | DMG_NERVEGAS | DMG_RADIATION | DMG_SHOCK) - -// NOTE: tweak these values based on gameplay feedback: - -#define PARALYZE_DURATION 2 // number of 2 second intervals to take damage -#define PARALYZE_DAMAGE 1.0 // damage to take each 2 second interval - -#define NERVEGAS_DURATION 2 -#define NERVEGAS_DAMAGE 5.0 - -#define POISON_DURATION 5 -#define POISON_DAMAGE 2.0 - -#define RADIATION_DURATION 2 -#define RADIATION_DAMAGE 1.0 - -#define ACID_DURATION 2 -#define ACID_DAMAGE 5.0 - -#define SLOWBURN_DURATION 2 -#define SLOWBURN_DAMAGE 1.0 - -#define SLOWFREEZE_DURATION 2 -#define SLOWFREEZE_DAMAGE 1.0 - - -#define itbd_Paralyze 0 -#define itbd_NerveGas 1 -#define itbd_Poison 2 -#define itbd_Radiation 3 -#define itbd_DrownRecover 4 -#define itbd_Acid 5 -#define itbd_SlowBurn 6 -#define itbd_SlowFreeze 7 -#define CDMG_TIMEBASED 8 - -// when calling KILLED(), a value that governs gib behavior is expected to be -// one of these three values -#define GIB_NORMAL 0// gib if entity was overkilled -#define GIB_NEVER 1// never gib, no matter how much death damage is done ( freezing, etc ) -#define GIB_ALWAYS 2// always gib ( Houndeye Shock, Barnacle Bite ) - -class CBaseMonster; -class CCineMonster; -class CSound; #include "basemonster.h" +#include "weapons.h" +#include "player.h" - -char *ButtonSound( int sound ); // get string of button sound number - - -// // Generic Button -// -class CBaseButton : public CBaseToggle -{ +class CBaseButton: public CBaseToggle { public: - void Spawn( void ); - virtual void Precache( void ); - void RotSpawn( void ); - virtual void KeyValue( KeyValueData* pkvd); + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; // Buttons that don't take damage can be IMPULSE used +public: + BOOL m_fStayPushed; // button stays pushed in until touched again? + BOOL m_fRotating; // a rotating button? default is a sliding button. - void ButtonActivate( ); - void SparkSoundCache( void ); - - void EXPORT ButtonShot( void ); - void EXPORT ButtonTouch( CBaseEntity *pOther ); - void EXPORT ButtonSpark ( void ); - void EXPORT TriggerAndWait( void ); - void EXPORT ButtonReturn( void ); - void EXPORT ButtonBackHome( void ); - void EXPORT ButtonUse ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ); - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - enum BUTTON_CODE { BUTTON_NOTHING, BUTTON_ACTIVATE, BUTTON_RETURN }; - BUTTON_CODE ButtonResponseToTouch( void ); - - static TYPEDESCRIPTION m_SaveData[]; - // Buttons that don't take damage can be IMPULSE used - virtual int ObjectCaps( void ) { return (CBaseToggle:: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | (pev->takedamage?0:FCAP_IMPULSE_USE); } - - BOOL m_fStayPushed; // button stays pushed in until touched again? - BOOL m_fRotating; // a rotating button? default is a sliding button. - - string_t m_strChangeTarget; // if this field is not null, this is an index into the engine string array. + string_t m_strChangeTarget; // if this field is not null, this is an index into the engine string array. // when this button is touched, it's target entity's TARGET field will be set // to the button's ChangeTarget. This allows you to make a func_train switch paths, etc. locksound_t m_ls; // door lock sounds - - BYTE m_bLockedSound; // ordinals from entity selection - BYTE m_bLockedSentence; - BYTE m_bUnlockedSound; - BYTE m_bUnlockedSentence; - int m_sounds; + + byte m_bLockedSound; // ordinals from entity selection + byte m_bLockedSentence; + byte m_bUnlockedSound; + byte m_bUnlockedSentence; + int m_sounds; }; -// -// Weapons -// +// MultiSouce -#define BAD_WEAPON 0x00007FFF +#define MAX_MULTI_TARGETS 16 // maximum number of targets a single multi_manager entity may be assigned. +#define MS_MAX_TARGETS 32 -// -// Converts a entvars_t * to a class pointer -// It will allocate the class and entity if necessary -// -template T * GetClassPtr( T *a ) +class CMultiSource: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual BOOL IsTriggered(CBaseEntity *pActivator) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + EHANDLE m_rgEntities[MS_MAX_TARGETS]; + int m_rgTriggered[MS_MAX_TARGETS]; + + int m_iTotal; + string_t m_globalstate; +}; + +// This spawns first when each level begins. +class CWorld: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +}; + +// Inlines +inline edict_t *EHANDLE::Get() { - entvars_t *pev = (entvars_t *)a; + if (!m_pent || m_pent->serialnumber != m_serialnumber) + return NULL; - // allocate entity if necessary - if (pev == NULL) - pev = VARS(CREATE_ENTITY()); - - // get the private data - a = (T *)GET_PRIVATE(ENT(pev)); - - if (a == NULL) - { - // allocate private data - a = new(pev) T; - a->pev = pev; - } - return a; + return m_pent; } - -/* -bit_PUSHBRUSH_DATA | bit_TOGGLE_DATA -bit_MONSTER_DATA -bit_DELAY_DATA -bit_TOGGLE_DATA | bit_DELAY_DATA | bit_MONSTER_DATA -bit_PLAYER_DATA | bit_MONSTER_DATA -bit_MONSTER_DATA | CYCLER_DATA -bit_LIGHT_DATA -path_corner_data -bit_MONSTER_DATA | wildcard_data -bit_MONSTER_DATA | bit_GROUP_DATA -boid_flock_data -boid_data -CYCLER_DATA -bit_ITEM_DATA -bit_ITEM_DATA | func_hud_data -bit_TOGGLE_DATA | bit_ITEM_DATA -EOFFSET -env_sound_data -env_sound_data -push_trigger_data -*/ - -#define TRACER_FREQ 4 // Tracers fire every 4 bullets - -typedef struct _SelAmmo +inline edict_t *EHANDLE::Set(edict_t *pent) { - BYTE Ammo1Type; - BYTE Ammo1; - BYTE Ammo2Type; - BYTE Ammo2; -} SelAmmo; + m_pent = pent; + if (pent) + m_serialnumber = pent->serialnumber; + return pent; +} -// this moved here from world.cpp, to allow classes to be derived from it -//======================= -// CWorld -// -// This spawns first when each level begins. -//======================= -class CWorld : public CBaseEntity +inline EHANDLE::operator int() { -public: - void Spawn( void ); - void Precache( void ); - void KeyValue( KeyValueData *pkvd ); -}; + return Get() != NULL; +} + +inline EHANDLE::operator CBaseEntity *() +{ + return (CBaseEntity *)GET_PRIVATE(Get()); +} + +inline EHANDLE::operator CBasePlayer *() +{ + return static_cast(GET_PRIVATE(Get())); +} + +inline CBaseEntity *EHANDLE::operator=(CBaseEntity *pEntity) +{ + if (pEntity != NULL) + { + m_pent = ENT(pEntity->pev); + if (m_pent) + m_serialnumber = m_pent->serialnumber; + } + else + { + m_pent = NULL; + m_serialnumber = 0; + } + + return pEntity; +} + +inline CBaseEntity *EHANDLE::operator->() +{ + return (CBaseEntity *)GET_PRIVATE(Get()); +} diff --git a/dlls/cdll_dll.h b/dlls/cdll_dll.h index 920fa29..cb0a225 100644 --- a/dlls/cdll_dll.h +++ b/dlls/cdll_dll.h @@ -1,46 +1,127 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -// -// cdll_dll.h +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -// this file is included by both the game-dll and the client-dll, +#define MAX_WEAPON_SLOTS 5 // hud item selection slots +#define MAX_ITEM_TYPES 6 // hud item selection slots -#ifndef CDLL_DLL_H -#define CDLL_DLL_H +#define MAX_ITEMS 4 // hard coded item types -#define MAX_WEAPONS 32 // ??? +#define DEFAULT_FOV 90 // the default field of view -#define MAX_WEAPON_SLOTS 5 // hud item selection slots -#define MAX_ITEM_TYPES 6 // hud item selection slots +#define HIDEHUD_WEAPONS (1<<0) +#define HIDEHUD_FLASHLIGHT (1<<1) +#define HIDEHUD_ALL (1<<2) +#define HIDEHUD_HEALTH (1<<3) +#define HIDEHUD_TIMER (1<<4) +#define HIDEHUD_MONEY (1<<5) +#define HIDEHUD_CROSSHAIR (1<<6) +#define HIDEHUD_OBSERVER_CROSSHAIR (1<<7) -#define MAX_ITEMS 5 // hard coded item types +#define STATUSICON_HIDE 0 +#define STATUSICON_SHOW 1 +#define STATUSICON_FLASH 2 -#define HIDEHUD_WEAPONS ( 1<<0 ) -#define HIDEHUD_FLASHLIGHT ( 1<<1 ) -#define HIDEHUD_ALL ( 1<<2 ) -#define HIDEHUD_HEALTH ( 1<<3 ) +#define HUD_PRINTNOTIFY 1 +#define HUD_PRINTCONSOLE 2 +#define HUD_PRINTTALK 3 +#define HUD_PRINTCENTER 4 +#define HUD_PRINTRADIO 5 -#define MAX_AMMO_TYPES 32 // ??? -#define MAX_AMMO_SLOTS 32 // not really slots +#define STATUS_NIGHTVISION_ON 1 +#define STATUS_NIGHTVISION_OFF 0 -#define HUD_PRINTNOTIFY 1 -#define HUD_PRINTCONSOLE 2 -#define HUD_PRINTTALK 3 -#define HUD_PRINTCENTER 4 +#define ITEM_STATUS_NIGHTVISION (1<<0) +#define ITEM_STATUS_DEFUSER (1<<1) +#define SCORE_STATUS_DEAD (1<<0) +#define SCORE_STATUS_BOMB (1<<1) +#define SCORE_STATUS_VIP (1<<2) + +#define SIGNAL_BUY (1<<0) +#define SIGNAL_BOMB (1<<1) +#define SIGNAL_RESCUE (1<<2) +#define SIGNAL_ESCAPE (1<<3) +#define SIGNAL_VIPSAFETY (1<<4) + +// player data iuser3 +#define PLAYER_CAN_SHOOT (1<<0) +#define PLAYER_FREEZE_TIME_OVER (1<<1) +#define PLAYER_IN_BOMB_ZONE (1<<2) +#define PLAYER_HOLDING_SHIELD (1<<3) + +#define MENU_KEY_1 (1<<0) +#define MENU_KEY_2 (1<<1) +#define MENU_KEY_3 (1<<2) +#define MENU_KEY_4 (1<<3) +#define MENU_KEY_5 (1<<4) +#define MENU_KEY_6 (1<<5) +#define MENU_KEY_7 (1<<6) +#define MENU_KEY_8 (1<<7) +#define MENU_KEY_9 (1<<8) +#define MENU_KEY_0 (1<<9) + +#define MAX_AMMO_SLOTS 32 // not really slots + +#define HUD_PRINTNOTIFY 1 +#define HUD_PRINTCONSOLE 2 +#define HUD_PRINTTALK 3 +#define HUD_PRINTCENTER 4 #define WEAPON_SUIT 31 +#define WEAPON_ALLWEAPONS (~(1 << WEAPON_SUIT)) -#endif +// custom enum +enum VGUIMenu +{ + VGUI_Menu_Team = 2, + VGUI_Menu_MapBriefing = 4, + + VGUI_Menu_Class_T = 26, + VGUI_Menu_Class_CT, + VGUI_Menu_Buy, + VGUI_Menu_Buy_Pistol, + VGUI_Menu_Buy_ShotGun, + VGUI_Menu_Buy_Rifle, + VGUI_Menu_Buy_SubMachineGun, + VGUI_Menu_Buy_MachineGun, + VGUI_Menu_Buy_Item, +}; + +// custom enum +enum VGUIMenuSlot +{ + VGUI_MenuSlot_Buy_Pistol = 1, + VGUI_MenuSlot_Buy_ShotGun, + VGUI_MenuSlot_Buy_SubMachineGun, + VGUI_MenuSlot_Buy_Rifle, + VGUI_MenuSlot_Buy_MachineGun, + VGUI_MenuSlot_Buy_PrimAmmo, + VGUI_MenuSlot_Buy_SecAmmo, + VGUI_MenuSlot_Buy_Item, +}; diff --git a/dlls/client.h b/dlls/client.h index 1e66cc8..f7f8a55 100644 --- a/dlls/client.h +++ b/dlls/client.h @@ -1,65 +1,97 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef CLIENT_H -#define CLIENT_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -extern void respawn( entvars_t* pev, BOOL fCopyCorpse ); -extern BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ); -extern void ClientDisconnect( edict_t *pEntity ); -extern void ClientKill( edict_t *pEntity ); -extern void ClientPutInServer( edict_t *pEntity ); -extern void ClientCommand( edict_t *pEntity ); -extern void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer ); -extern void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ); -extern void ServerDeactivate( void ); -extern void StartFrame( void ); -extern void PlayerPostThink( edict_t *pEntity ); -extern void PlayerPreThink( edict_t *pEntity ); -extern void ParmsNewLevel( void ); -extern void ParmsChangeLevel( void ); +// custom enum +enum ChooseTeamMenuSlot +{ + MENU_SLOT_TEAM_UNDEFINED = -1, -extern void ClientPrecache( void ); + MENU_SLOT_TEAM_TERRORIST = 1, + MENU_SLOT_TEAM_CT, + MENU_SLOT_TEAM_VIP, -extern const char *GetGameDescription( void ); -extern void PlayerCustomization( edict_t *pEntity, customization_t *pCust ); + MENU_SLOT_TEAM_RANDOM = 5, + MENU_SLOT_TEAM_SPECT +}; -extern void SpectatorConnect ( edict_t *pEntity ); -extern void SpectatorDisconnect ( edict_t *pEntity ); -extern void SpectatorThink ( edict_t *pEntity ); +// custom enum +enum BuyItemMenuSlot +{ + MENU_SLOT_ITEM_VEST = 1, + MENU_SLOT_ITEM_VESTHELM, + MENU_SLOT_ITEM_FLASHGREN, + MENU_SLOT_ITEM_HEGREN, + MENU_SLOT_ITEM_SMOKEGREN, + MENU_SLOT_ITEM_NVG, + MENU_SLOT_ITEM_DEFUSEKIT, + MENU_SLOT_ITEM_SHIELD, +}; -extern void Sys_Error( const char *error_string ); +#define CS_NUM_SKIN 4 +#define CZ_NUM_SKIN 5 -extern void SetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas ); -extern void UpdateClientData ( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd ); -extern int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet ); -extern void CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs ); -extern void RegisterEncoders( void ); +#define FIELD_ORIGIN0 0 +#define FIELD_ORIGIN1 1 +#define FIELD_ORIGIN2 2 -extern int GetWeaponData( struct edict_s *player, struct weapon_data_s *info ); +#define FIELD_ANGLES0 3 +#define FIELD_ANGLES1 4 +#define FIELD_ANGLES2 5 -extern void CmdStart( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed ); -extern void CmdEnd ( const edict_t *player ); +#define CUSTOMFIELD_ORIGIN0 0 +#define CUSTOMFIELD_ORIGIN1 1 +#define CUSTOMFIELD_ORIGIN2 2 -extern int ConnectionlessPacket( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ); +#define CUSTOMFIELD_ANGLES0 3 +#define CUSTOMFIELD_ANGLES1 4 +#define CUSTOMFIELD_ANGLES2 5 -extern int GetHullBounds( int hullnumber, float *mins, float *maxs ); +#define CUSTOMFIELD_SKIN 6 +#define CUSTOMFIELD_SEQUENCE 7 +#define CUSTOMFIELD_ANIMTIME 8 -extern void CreateInstancedBaselines ( void ); +typedef struct +{ + float m_fTimeEnteredPVS; -extern int InconsistentFile( const edict_t *player, const char *filename, char *disconnect_message ); +} ENTITYPVSSTATUS; -extern int AllowLagCompensation( void ); +struct PLAYERPVSSTATUS +{ + ENTITYPVSSTATUS m_Status[1380]; + int headnode; + int num_leafs; + short int leafnums[ MAX_ENT_LEAFS ]; +}; -#endif // CLIENT_H +struct entity_field_alias_t +{ + char name[32]; + int field; +}; diff --git a/dlls/csbot_dll.h b/dlls/csbot_dll.h new file mode 100644 index 0000000..f96b728 --- /dev/null +++ b/dlls/csbot_dll.h @@ -0,0 +1,50 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "../game_shared/GameEvent.h" +#include "../game_shared/bot/bot_util.h" +#include "../game_shared/bot/simple_state_machine.h" +#include "../game_shared/steam_util.h" +#include "../game_shared/perf_counter.h" +#include "../game_shared/bot/bot_manager.h" +#include "../game_shared/bot/bot_constants.h" +#include "../game_shared/bot/bot.h" +#include "../game_shared/shared_util.h" +#include "../game_shared/bot/bot_profile.h" + +#include "../game_shared/bot/improv.h" +#include "../game_shared/bot/nav.h" +#include "../game_shared/bot/nav_node.h" +#include "../game_shared/bot/nav_area.h" +#include "../game_shared/bot/nav_path.h" + +#include "../dlls/hostage/hostage.h" +#include "../dlls/hostage/hostage_localnav.h" + +#include "../dlls/bot/cs_bot.h" diff --git a/dlls/decals.h b/dlls/decals.h index f66da95..6f37432 100644 --- a/dlls/decals.h +++ b/dlls/decals.h @@ -1,26 +1,35 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef DECALS_H -#define DECALS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -// -// Dynamic Decals -// -enum decal_e -{ - DECAL_GUNSHOT1 = 0, +enum decal_e +{ + DECAL_GUNSHOT1 = 0, DECAL_GUNSHOT2, DECAL_GUNSHOT3, DECAL_GUNSHOT4, @@ -33,18 +42,18 @@ enum decal_e DECAL_LAMBDA6, DECAL_SCORCH1, DECAL_SCORCH2, - DECAL_BLOOD1, - DECAL_BLOOD2, - DECAL_BLOOD3, - DECAL_BLOOD4, - DECAL_BLOOD5, - DECAL_BLOOD6, - DECAL_YBLOOD1, - DECAL_YBLOOD2, - DECAL_YBLOOD3, - DECAL_YBLOOD4, - DECAL_YBLOOD5, - DECAL_YBLOOD6, + DECAL_BLOOD1, + DECAL_BLOOD2, + DECAL_BLOOD3, + DECAL_BLOOD4, + DECAL_BLOOD5, + DECAL_BLOOD6, + DECAL_YBLOOD1, + DECAL_YBLOOD2, + DECAL_YBLOOD3, + DECAL_YBLOOD4, + DECAL_YBLOOD5, + DECAL_YBLOOD6, DECAL_GLASSBREAK1, DECAL_GLASSBREAK2, DECAL_GLASSBREAK3, @@ -67,18 +76,8 @@ enum decal_e typedef struct { char *name; - short entityIndex; - byte depth; - byte flags; - vec3_t position; -} DECALLIST; + int index; -typedef struct -{ - char *name; - int index; } DLL_DECALLIST; -extern DLL_DECALLIST gDecals[]; - -#endif // DECALS_H +extern DLL_DECALLIST gDecals[42]; diff --git a/dlls/doors.h b/dlls/doors.h index 8008861..43ef05d 100644 --- a/dlls/doors.h +++ b/dlls/doors.h @@ -1,33 +1,93 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef DOORS_H -#define DOORS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -// doors -#define SF_DOOR_ROTATE_Y 0 -#define SF_DOOR_START_OPEN 1 +#define DOOR_SENTENCEWAIT 6 +#define DOOR_SOUNDWAIT 3 +#define BUTTON_SOUNDWAIT 0.5 + +#define SF_DOOR_ROTATE_Y 0 +#define SF_DOOR_START_OPEN 1 #define SF_DOOR_ROTATE_BACKWARDS 2 -#define SF_DOOR_PASSABLE 8 -#define SF_DOOR_ONEWAY 16 -#define SF_DOOR_NO_AUTO_RETURN 32 -#define SF_DOOR_ROTATE_Z 64 -#define SF_DOOR_ROTATE_X 128 -#define SF_DOOR_USE_ONLY 256 // door must be opened by player's use button. -#define SF_DOOR_NOMONSTERS 512 // Monster can't open -#define SF_DOOR_SILENT 0x80000000 +#define SF_DOOR_PASSABLE 8 +#define SF_DOOR_ONEWAY 16 +#define SF_DOOR_NO_AUTO_RETURN 32 +#define SF_DOOR_ROTATE_Z 64 +#define SF_DOOR_ROTATE_X 128 +#define SF_DOOR_USE_ONLY 256 // door must be opened by player's use button. +#define SF_DOOR_NOMONSTERS 512 // Monster can't open +#define SF_DOOR_TOUCH_ONLY_CLIENTS 1024 // Only clients can touch +#define SF_DOOR_SILENT 0x80000000 +class CBaseDoor: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void SetToggleState(int state) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + byte m_bHealthValue; // some doors are medi-kit doors, they give players health + byte m_bMoveSnd; // sound a door makes while moving + byte m_bStopSnd; // sound a door makes when it stops -#endif //DOORS_H + locksound_t m_ls; // door lock sounds + + byte m_bLockedSound; // ordinals from entity selection + byte m_bLockedSentence; + byte m_bUnlockedSound; + byte m_bUnlockedSentence; + + float m_lastBlockedTimestamp; +}; + +class CRotDoor: public CBaseDoor { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual void SetToggleState(int state) = 0; +}; + +class CMomentaryDoor: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + byte m_bMoveSnd; // sound a door makes while moving +}; diff --git a/dlls/effects.h b/dlls/effects.h index f93a9d8..5df1335 100644 --- a/dlls/effects.h +++ b/dlls/effects.h @@ -1,19 +1,31 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef EFFECTS_H -#define EFFECTS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once #define SF_BEAM_STARTON 0x0001 #define SF_BEAM_TOGGLE 0x0002 @@ -26,33 +38,45 @@ #define SF_BEAM_SHADEOUT 0x0100 #define SF_BEAM_TEMPORARY 0x8000 +#define SF_GIBSHOOTER_REPEATABLE 1 +#define SF_FUNNEL_REVERSE 1 + +#define SF_BUBBLES_STARTOFF 0x0001 + +#define SF_BLOOD_RANDOM 0x0001 +#define SF_BLOOD_STREAM 0x0002 +#define SF_BLOOD_PLAYER 0x0004 +#define SF_BLOOD_DECAL 0x0008 + +#define SF_SHAKE_EVERYONE 0x0001 +#define SF_SHAKE_DISRUPT 0x0002 +#define SF_SHAKE_INAIR 0x0004 + +#define SF_FADE_IN 0x0001 +#define SF_FADE_MODULATE 0x0002 +#define SF_FADE_ONLYONE 0x0004 + #define SF_SPRITE_STARTON 0x0001 #define SF_SPRITE_ONCE 0x0002 #define SF_SPRITE_TEMPORARY 0x8000 -class CSprite : public CPointEntity -{ +#define SF_MESSAGE_ONCE 0x0001 // Fade in, not out +#define SF_MESSAGE_ALL 0x0002 // Send to all clients + +class CSprite: public CPointEntity { public: - void Spawn( void ); - void Precache( void ); + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; - int ObjectCaps( void ) - { - int flags = 0; - if ( pev->spawnflags & SF_SPRITE_TEMPORARY ) - flags = FCAP_DONT_SAVE; - return (CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags; - } - void EXPORT AnimateThink( void ); - void EXPORT ExpandThink( void ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void Animate( float frames ); - void Expand( float scaleSpeed, float fadeSpeed ); - void SpriteInit( const char *pSpriteName, const Vector &origin ); - - inline void SetAttachment( edict_t *pEntity, int attachment ) +public: + void SetAttachment(edict_t *pEntity, int attachment) { - if ( pEntity ) + if (pEntity != NULL) { pev->skin = ENTINDEX(pEntity); pev->body = attachment; @@ -60,10 +84,9 @@ public: pev->movetype = MOVETYPE_FOLLOW; } } - void TurnOff( void ); - void TurnOn( void ); - inline float Frames( void ) { return m_maxFrame; } - inline void SetTransparency( int rendermode, int r, int g, int b, int a, int fx ) + + float Frames() const { return m_maxFrame; } + void SetTransparency(int rendermode, int r, int g, int b, int a, int fx) { pev->rendermode = rendermode; pev->rendercolor.x = r; @@ -72,138 +95,313 @@ public: pev->renderamt = a; pev->renderfx = fx; } - inline void SetTexture( int spriteIndex ) { pev->modelindex = spriteIndex; } - inline void SetScale( float scale ) { pev->scale = scale; } - inline void SetColor( int r, int g, int b ) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; } - inline void SetBrightness( int brightness ) { pev->renderamt = brightness; } - inline void AnimateAndDie( float framerate ) - { - SetThink(&CSprite::AnimateUntilDead); + void SetTexture(int spriteIndex) { pev->modelindex = spriteIndex; } + void SetScale(float scale) { pev->scale = scale; } + void SetColor(int r, int g, int b) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; } + void SetBrightness(int brightness) { pev->renderamt = brightness; } + void AnimateAndDie(float framerate) + { + SetThink(&CSprite::AnimateUntilDead); pev->framerate = framerate; - pev->dmgtime = gpGlobals->time + (m_maxFrame / framerate); - pev->nextthink = gpGlobals->time; + pev->dmgtime = gpGlobals->time + (m_maxFrame / framerate); + pev->nextthink = gpGlobals->time; } - - void EXPORT AnimateUntilDead( void ); - - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - static TYPEDESCRIPTION m_SaveData[]; - static CSprite *SpriteCreate( const char *pSpriteName, const Vector &origin, BOOL animate ); - private: - - float m_lastTime; - float m_maxFrame; + float m_lastTime; + float m_maxFrame; }; - -class CBeam : public CBaseEntity -{ +class CBeam: public CBaseEntity { public: - void Spawn( void ); - void Precache( void ); - int ObjectCaps( void ) - { - int flags = 0; - if ( pev->spawnflags & SF_BEAM_TEMPORARY ) - flags = FCAP_DONT_SAVE; - return (CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags; + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int ObjectCaps() = 0; + virtual Vector Center() = 0; +public: + void SetType(int type) { pev->rendermode = (pev->rendermode & 0xF0) | (type & 0x0F); } + void SetFlags(int flags) { pev->rendermode = (pev->rendermode & 0x0F) | (flags & 0xF0); } + void SetStartPos(const Vector &pos) { pev->origin = pos; } + void SetEndPos(const Vector &pos) { pev->angles = pos; } + + void SetStartEntity(int entityIndex); + void SetEndEntity(int entityIndex); + + void SetStartAttachment(int attachment) { pev->sequence = (pev->sequence & 0x0FFF) | ((attachment & 0xF) << 12); } + void SetEndAttachment(int attachment) { pev->skin = (pev->skin & 0x0FFF) | ((attachment & 0xF) << 12); } + void SetTexture(int spriteIndex) { pev->modelindex = spriteIndex; } + void SetWidth(int width) { pev->scale = width; } + void SetNoise(int amplitude) { pev->body = amplitude; } + void SetColor(int r, int g, int b) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; } + void SetBrightness(int brightness) { pev->renderamt = brightness; } + void SetFrame(float frame) { pev->frame = frame; } + void SetScrollRate(int speed) { pev->animtime = speed; } + int GetType() const { return pev->rendermode & 0x0F; } + int GetFlags() const { return pev->rendermode & 0xF0; } + int GetStartEntity() const { return pev->sequence & 0xFFF; } + int GetEndEntity() const { return pev->skin & 0xFFF; } + + const Vector &GetStartPos(); + const Vector &GetEndPos(); + + int GetTexture() const { return pev->modelindex; } + int GetWidth() const { return pev->scale; } + int GetNoise() const { return pev->body; } + int GetBrightness() const { return pev->renderamt; } + int GetFrame() const { return pev->frame; } + int GetScrollRate() const { return pev->animtime; } + + void LiveForTime(float time) + { + SetThink(&CBeam::SUB_Remove); + pev->nextthink = gpGlobals->time + time; } - - void EXPORT TriggerTouch( CBaseEntity *pOther ); - - // These functions are here to show the way beams are encoded as entities. - // Encoding beams as entities simplifies their management in the client/server architecture - inline void SetType( int type ) { pev->rendermode = (pev->rendermode & 0xF0) | (type&0x0F); } - inline void SetFlags( int flags ) { pev->rendermode = (pev->rendermode & 0x0F) | (flags&0xF0); } - inline void SetStartPos( const Vector& pos ) { pev->origin = pos; } - inline void SetEndPos( const Vector& pos ) { pev->angles = pos; } - void SetStartEntity( int entityIndex ); - void SetEndEntity( int entityIndex ); - - inline void SetStartAttachment( int attachment ) { pev->sequence = (pev->sequence & 0x0FFF) | ((attachment&0xF)<<12); } - inline void SetEndAttachment( int attachment ) { pev->skin = (pev->skin & 0x0FFF) | ((attachment&0xF)<<12); } - - inline void SetTexture( int spriteIndex ) { pev->modelindex = spriteIndex; } - inline void SetWidth( int width ) { pev->scale = width; } - inline void SetNoise( int amplitude ) { pev->body = amplitude; } - inline void SetColor( int r, int g, int b ) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; } - inline void SetBrightness( int brightness ) { pev->renderamt = brightness; } - inline void SetFrame( float frame ) { pev->frame = frame; } - inline void SetScrollRate( int speed ) { pev->animtime = speed; } - - inline int GetType( void ) { return pev->rendermode & 0x0F; } - inline int GetFlags( void ) { return pev->rendermode & 0xF0; } - inline int GetStartEntity( void ) { return pev->sequence & 0xFFF; } - inline int GetEndEntity( void ) { return pev->skin & 0xFFF; } - - const Vector &GetStartPos( void ); - const Vector &GetEndPos( void ); - - Vector Center( void ) { return (GetStartPos() + GetEndPos()) * 0.5; }; // center point of beam - - inline int GetTexture( void ) { return pev->modelindex; } - inline int GetWidth( void ) { return pev->scale; } - inline int GetNoise( void ) { return pev->body; } - // inline void GetColor( int r, int g, int b ) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; } - inline int GetBrightness( void ) { return pev->renderamt; } - inline int GetFrame( void ) { return pev->frame; } - inline int GetScrollRate( void ) { return pev->animtime; } - - // Call after you change start/end positions - void RelinkBeam( void ); -// void SetObjectCollisionBox( void ); - - void DoSparks( const Vector &start, const Vector &end ); - CBaseEntity *RandomTargetname( const char *szName ); - void BeamDamage( TraceResult *ptr ); - // Init after BeamCreate() - void BeamInit( const char *pSpriteName, int width ); - void PointsInit( const Vector &start, const Vector &end ); - void PointEntInit( const Vector &start, int endIndex ); - void EntsInit( int startIndex, int endIndex ); - void HoseInit( const Vector &start, const Vector &direction ); - - static CBeam *BeamCreate( const char *pSpriteName, int width ); - - inline void LiveForTime( float time ) { SetThink(&CBeam::SUB_Remove); pev->nextthink = gpGlobals->time + time; } - inline void BeamDamageInstant( TraceResult *ptr, float damage ) - { - pev->dmg = damage; + void BeamDamageInstant(TraceResult *ptr, float damage) + { + pev->dmg = damage; pev->dmgtime = gpGlobals->time - 1; - BeamDamage(ptr); + BeamDamage(ptr); } }; - -#define SF_MESSAGE_ONCE 0x0001 // Fade in, not out -#define SF_MESSAGE_ALL 0x0002 // Send to all clients - - -class CLaser : public CBeam -{ +class CLaser: public CBeam { public: - void Spawn( void ); - void Precache( void ); - void KeyValue( KeyValueData *pkvd ); - - void TurnOn( void ); - void TurnOff( void ); - int IsOn( void ); - - void FireAtPoint( TraceResult &point ); - - void EXPORT StrikeThink( void ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - static TYPEDESCRIPTION m_SaveData[]; - - CSprite *m_pSprite; - int m_iszSpriteName; - Vector m_firePosition; + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + CSprite *m_pSprite; + int m_iszSpriteName; + Vector m_firePosition; }; -#endif //EFFECTS_H +class CBubbling: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_density; + int m_frequency; + int m_bubbleModel; + int m_state; +}; + +class CLightning: public CBeam { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Activate() = 0; +public: + inline BOOL ServerSide() const + { + if (!m_life && !(pev->spawnflags & SF_BEAM_RING)) + return TRUE; + + return FALSE; + } +public: + int m_active; + int m_iszStartEntity; + int m_iszEndEntity; + float m_life; + int m_boltWidth; + int m_noiseAmplitude; + int m_brightness; + int m_speed; + float m_restrike; + int m_spriteTexture; + int m_iszSpriteName; + int m_frameStart; + float m_radius; +}; + +class CGlow: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Think() = 0; +public: + float m_lastTime; + float m_maxFrame; +}; + +class CBombGlow: public CSprite { +public: + virtual void Spawn() = 0; + virtual void Think() = 0; +public: + float m_lastTime; + float m_tmBeepPeriod; + bool m_bSetModel; +}; + +class CGibShooter: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual CGib *CreateGib() = 0; +public: + int m_iGibs; + int m_iGibCapacity; + int m_iGibMaterial; + int m_iGibModelIndex; + + float m_flGibVelocity; + float m_flVariance; + float m_flGibLife; +}; + +class CEnvShooter: public CGibShooter { +public: + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual CGib *CreateGib() = 0; +}; + +#define MAX_BEAM 24 + +class CTestEffect: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_iLoop; + int m_iBeam; + + CBeam *m_pBeam[MAX_BEAM]; + + float m_flBeamTime[MAX_BEAM]; + float m_flStartTime; +}; + +class CBlood: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + +public: + int Color() const { return pev->impulse; } + float BloodAmount() const { return pev->dmg; } + + void SetColor(int color) { pev->impulse = color; } + void SetBloodAmount(float amount) { pev->dmg = amount; } +}; + +class CShake: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float Amplitude() const { return pev->scale; } + float Frequency() const { return pev->dmg_save; } + float Duration() const { return pev->dmg_take; } + float Radius() const { return pev->dmg; } + + void SetAmplitude(float amplitude) { pev->scale = amplitude; } + void SetFrequency(float frequency) { pev->dmg_save = frequency; } + void SetDuration(float duration) { pev->dmg_take = duration; } + void SetRadius(float radius) { pev->dmg = radius; } +}; + +class CFade: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float Duration() const { return pev->dmg_take; } + float HoldTime() const { return pev->dmg_save; } + + void SetDuration(float duration) { pev->dmg_take = duration; } + void SetHoldTime(float hold) { pev->dmg_save = hold; } +}; + +class CMessage: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CEnvFunnel: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_iSprite; +}; + +class CEnvBeverage: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CItemSoda: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; +}; + +// Inlines +inline void CBeam::SetStartEntity(int entityIndex) +{ + pev->sequence = (entityIndex & 0x0FFF) | ((pev->sequence & 0xF000) << 12); + pev->owner = INDEXENT(entityIndex); +} + +inline void CBeam::SetEndEntity(int entityIndex) +{ + pev->skin = (entityIndex & 0x0FFF) | ((pev->skin & 0xF000) << 12); + pev->aiment = INDEXENT(entityIndex); +} + +inline const Vector &CBeam::GetStartPos() +{ + if (GetType() == BEAM_ENTS) + { + edict_t *pent = INDEXENT(GetStartEntity()); + return pent->v.origin; + } + + return pev->origin; +} + +inline const Vector &CBeam::GetEndPos() +{ + int type = GetType(); + if (type == BEAM_POINTS || type == BEAM_HOSE) + { + return pev->angles; + } + + edict_t *pent = INDEXENT(GetEndEntity()); + if (pent != NULL) + { + return pent->v.origin; + } + + return pev->angles; +} diff --git a/dlls/enginecallback.h b/dlls/enginecallback.h index ddca3d3..dbe3e71 100644 --- a/dlls/enginecallback.h +++ b/dlls/enginecallback.h @@ -1,22 +1,31 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef ENGINECALLBACK_H -#define ENGINECALLBACK_H -#ifdef _WIN32 +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ #pragma once -#endif #include "event_flags.h" @@ -24,137 +33,146 @@ extern enginefuncs_t g_engfuncs; // The actual engine callbacks -#define GETPLAYERUSERID (*g_engfuncs.pfnGetPlayerUserId) -#define PRECACHE_MODEL (*g_engfuncs.pfnPrecacheModel) -#define PRECACHE_SOUND (*g_engfuncs.pfnPrecacheSound) -#define PRECACHE_GENERIC (*g_engfuncs.pfnPrecacheGeneric) -#define SET_MODEL (*g_engfuncs.pfnSetModel) -#define MODEL_INDEX (*g_engfuncs.pfnModelIndex) -#define MODEL_FRAMES (*g_engfuncs.pfnModelFrames) -#define SET_SIZE (*g_engfuncs.pfnSetSize) -#define CHANGE_LEVEL (*g_engfuncs.pfnChangeLevel) -#define GET_SPAWN_PARMS (*g_engfuncs.pfnGetSpawnParms) -#define SAVE_SPAWN_PARMS (*g_engfuncs.pfnSaveSpawnParms) -#define VEC_TO_YAW (*g_engfuncs.pfnVecToYaw) -#define VEC_TO_ANGLES (*g_engfuncs.pfnVecToAngles) -#define MOVE_TO_ORIGIN (*g_engfuncs.pfnMoveToOrigin) -#define oldCHANGE_YAW (*g_engfuncs.pfnChangeYaw) -#define CHANGE_PITCH (*g_engfuncs.pfnChangePitch) -#define MAKE_VECTORS (*g_engfuncs.pfnMakeVectors) -#define CREATE_ENTITY (*g_engfuncs.pfnCreateEntity) -#define REMOVE_ENTITY (*g_engfuncs.pfnRemoveEntity) +#define GETPLAYERUSERID (*g_engfuncs.pfnGetPlayerUserId) +#define PRECACHE_MODEL (*g_engfuncs.pfnPrecacheModel) +#define PRECACHE_SOUND (*g_engfuncs.pfnPrecacheSound) +#define PRECACHE_GENERIC (*g_engfuncs.pfnPrecacheGeneric) +#define SET_MODEL (*g_engfuncs.pfnSetModel) +#define MODEL_INDEX (*g_engfuncs.pfnModelIndex) +#define MODEL_FRAMES (*g_engfuncs.pfnModelFrames) +#define SET_SIZE (*g_engfuncs.pfnSetSize) +#define CHANGE_LEVEL (*g_engfuncs.pfnChangeLevel) +#define GET_SPAWN_PARMS (*g_engfuncs.pfnGetSpawnParms) +#define SAVE_SPAWN_PARMS (*g_engfuncs.pfnSaveSpawnParms) +#define VEC_TO_YAW (*g_engfuncs.pfnVecToYaw) +#define VEC_TO_ANGLES (*g_engfuncs.pfnVecToAngles) +#define MOVE_TO_ORIGIN (*g_engfuncs.pfnMoveToOrigin) +#define oldCHANGE_YAW (*g_engfuncs.pfnChangeYaw) +#define CHANGE_PITCH (*g_engfuncs.pfnChangePitch) +#define MAKE_VECTORS (*g_engfuncs.pfnMakeVectors) +#define CREATE_ENTITY (*g_engfuncs.pfnCreateEntity) +#define REMOVE_ENTITY (*g_engfuncs.pfnRemoveEntity) #define CREATE_NAMED_ENTITY (*g_engfuncs.pfnCreateNamedEntity) -#define MAKE_STATIC (*g_engfuncs.pfnMakeStatic) -#define ENT_IS_ON_FLOOR (*g_engfuncs.pfnEntIsOnFloor) -#define DROP_TO_FLOOR (*g_engfuncs.pfnDropToFloor) -#define WALK_MOVE (*g_engfuncs.pfnWalkMove) -#define SET_ORIGIN (*g_engfuncs.pfnSetOrigin) -#define EMIT_SOUND_DYN2 (*g_engfuncs.pfnEmitSound) -#define BUILD_SOUND_MSG (*g_engfuncs.pfnBuildSoundMsg) -#define TRACE_LINE (*g_engfuncs.pfnTraceLine) -#define TRACE_TOSS (*g_engfuncs.pfnTraceToss) +#define MAKE_STATIC (*g_engfuncs.pfnMakeStatic) +#define ENT_IS_ON_FLOOR (*g_engfuncs.pfnEntIsOnFloor) +#define DROP_TO_FLOOR (*g_engfuncs.pfnDropToFloor) +#define WALK_MOVE (*g_engfuncs.pfnWalkMove) +#define SET_ORIGIN (*g_engfuncs.pfnSetOrigin) +#define EMIT_SOUND_DYN2 (*g_engfuncs.pfnEmitSound) +#define BUILD_SOUND_MSG (*g_engfuncs.pfnBuildSoundMsg) +#define TRACE_LINE (*g_engfuncs.pfnTraceLine) +#define TRACE_TOSS (*g_engfuncs.pfnTraceToss) #define TRACE_MONSTER_HULL (*g_engfuncs.pfnTraceMonsterHull) -#define TRACE_HULL (*g_engfuncs.pfnTraceHull) -#define GET_AIM_VECTOR (*g_engfuncs.pfnGetAimVector) -#define SERVER_COMMAND (*g_engfuncs.pfnServerCommand) -#define SERVER_EXECUTE (*g_engfuncs.pfnServerExecute) -#define CLIENT_COMMAND (*g_engfuncs.pfnClientCommand) -#define PARTICLE_EFFECT (*g_engfuncs.pfnParticleEffect) -#define LIGHT_STYLE (*g_engfuncs.pfnLightStyle) -#define DECAL_INDEX (*g_engfuncs.pfnDecalIndex) -#define POINT_CONTENTS (*g_engfuncs.pfnPointContents) -#define CRC32_INIT (*g_engfuncs.pfnCRC32_Init) -#define CRC32_PROCESS_BUFFER (*g_engfuncs.pfnCRC32_ProcessBuffer) -#define CRC32_PROCESS_BYTE (*g_engfuncs.pfnCRC32_ProcessByte) -#define CRC32_FINAL (*g_engfuncs.pfnCRC32_Final) -#define RANDOM_LONG (*g_engfuncs.pfnRandomLong) -#define RANDOM_FLOAT (*g_engfuncs.pfnRandomFloat) -#define GETPLAYERAUTHID (*g_engfuncs.pfnGetPlayerAuthId) +#define TRACE_HULL (*g_engfuncs.pfnTraceHull) +#define TRACE_MODEL (*g_engfuncs.pfnTraceModel) +#define GET_AIM_VECTOR (*g_engfuncs.pfnGetAimVector) +#define SERVER_COMMAND (*g_engfuncs.pfnServerCommand) +#define SERVER_EXECUTE (*g_engfuncs.pfnServerExecute) +#define CLIENT_COMMAND (*g_engfuncs.pfnClientCommand) +#define PARTICLE_EFFECT (*g_engfuncs.pfnParticleEffect) +#define LIGHT_STYLE (*g_engfuncs.pfnLightStyle) +#define DECAL_INDEX (*g_engfuncs.pfnDecalIndex) +#define POINT_CONTENTS (*g_engfuncs.pfnPointContents) +#define CRC32_INIT (*g_engfuncs.pfnCRC32_Init) +#define CRC32_PROCESS_BUFFER (*g_engfuncs.pfnCRC32_ProcessBuffer) +#define CRC32_PROCESS_BYTE (*g_engfuncs.pfnCRC32_ProcessByte) +#define CRC32_FINAL (*g_engfuncs.pfnCRC32_Final) +#define RANDOM_LONG (*g_engfuncs.pfnRandomLong) +#define RANDOM_FLOAT (*g_engfuncs.pfnRandomFloat) +#define ADD_SERVER_COMMAND (*g_engfuncs.pfnAddServerCommand) +#define SET_CLIENT_LISTENING (*g_engfuncs.pfnVoice_SetClientListening) +#define GETPLAYERAUTHID (*g_engfuncs.pfnGetPlayerAuthId) +#define GET_FILE_SIZE (*g_engfuncs.pfnGetFileSize) +#define GET_APPROX_WAVE_PLAY_LEN (*g_engfuncs.pfnGetApproxWavePlayLen) +#define IS_CAREER_MATCH (*g_engfuncs.pfnIsCareerMatch) +#define GET_LOCALIZED_STRING_LENGTH (*g_engfuncs.pfnGetLocalizedStringLength) +#define REGISTER_TUTOR_MESSAGE_SHOWN (*g_engfuncs.pfnRegisterTutorMessageShown) +#define GET_TIMES_TUTOR_MESSAGE_SHOWN (*g_engfuncs.pfnGetTimesTutorMessageShown) +#define ENG_CHECK_PARM (*g_engfuncs.pfnEngCheckParm) -inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin = NULL, edict_t *ed = NULL ) { - (*g_engfuncs.pfnMessageBegin)(msg_dest, msg_type, pOrigin, ed); -} -#define MESSAGE_END (*g_engfuncs.pfnMessageEnd) -#define WRITE_BYTE (*g_engfuncs.pfnWriteByte) -#define WRITE_CHAR (*g_engfuncs.pfnWriteChar) -#define WRITE_SHORT (*g_engfuncs.pfnWriteShort) -#define WRITE_LONG (*g_engfuncs.pfnWriteLong) -#define WRITE_ANGLE (*g_engfuncs.pfnWriteAngle) -#define WRITE_COORD (*g_engfuncs.pfnWriteCoord) -#define WRITE_STRING (*g_engfuncs.pfnWriteString) -#define WRITE_ENTITY (*g_engfuncs.pfnWriteEntity) -#define CVAR_REGISTER (*g_engfuncs.pfnCVarRegister) -#define CVAR_GET_FLOAT (*g_engfuncs.pfnCVarGetFloat) -#define CVAR_GET_STRING (*g_engfuncs.pfnCVarGetString) -#define CVAR_SET_FLOAT (*g_engfuncs.pfnCVarSetFloat) -#define CVAR_SET_STRING (*g_engfuncs.pfnCVarSetString) -#define CVAR_GET_POINTER (*g_engfuncs.pfnCVarGetPointer) -#define ALERT (*g_engfuncs.pfnAlertMessage) -#define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf) -#define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData) -inline void *GET_PRIVATE( edict_t *pent ) +inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float *pOrigin = NULL, edict_t *ed = NULL) { (*g_engfuncs.pfnMessageBegin)(msg_dest, msg_type, pOrigin, ed); } + +inline void *GET_PRIVATE(edict_t *pent) { - if ( pent ) + if (pent) return pent->pvPrivateData; return NULL; } -#define FREE_PRIVATE (*g_engfuncs.pfnFreeEntPrivateData) +#define MESSAGE_END (*g_engfuncs.pfnMessageEnd) +#define WRITE_BYTE (*g_engfuncs.pfnWriteByte) +#define WRITE_CHAR (*g_engfuncs.pfnWriteChar) +#define WRITE_SHORT (*g_engfuncs.pfnWriteShort) +#define WRITE_LONG (*g_engfuncs.pfnWriteLong) +#define WRITE_ANGLE (*g_engfuncs.pfnWriteAngle) +#define WRITE_COORD (*g_engfuncs.pfnWriteCoord) +#define WRITE_STRING (*g_engfuncs.pfnWriteString) +#define WRITE_ENTITY (*g_engfuncs.pfnWriteEntity) +#define CVAR_REGISTER (*g_engfuncs.pfnCVarRegister) +#define CVAR_GET_FLOAT (*g_engfuncs.pfnCVarGetFloat) +#define CVAR_GET_STRING (*g_engfuncs.pfnCVarGetString) +#define CVAR_SET_FLOAT (*g_engfuncs.pfnCVarSetFloat) +#define CVAR_SET_STRING (*g_engfuncs.pfnCVarSetString) +#define CVAR_GET_POINTER (*g_engfuncs.pfnCVarGetPointer) +#define ALERT (*g_engfuncs.pfnAlertMessage) +#define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf) +#define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData) +#define FREE_PRIVATE (*g_engfuncs.pfnFreeEntPrivateData) //#define STRING (*g_engfuncs.pfnSzFromIndex) -#define ALLOC_STRING (*g_engfuncs.pfnAllocString) -#define FIND_ENTITY_BY_STRING (*g_engfuncs.pfnFindEntityByString) -#define GETENTITYILLUM (*g_engfuncs.pfnGetEntityIllum) +#define ALLOC_STRING (*g_engfuncs.pfnAllocString) +#define FIND_ENTITY_BY_STRING (*g_engfuncs.pfnFindEntityByString) +#define GETENTITYILLUM (*g_engfuncs.pfnGetEntityIllum) #define FIND_ENTITY_IN_SPHERE (*g_engfuncs.pfnFindEntityInSphere) -#define FIND_CLIENT_IN_PVS (*g_engfuncs.pfnFindClientInPVS) -#define EMIT_AMBIENT_SOUND (*g_engfuncs.pfnEmitAmbientSound) -#define GET_MODEL_PTR (*g_engfuncs.pfnGetModelPtr) -#define REG_USER_MSG (*g_engfuncs.pfnRegUserMsg) -#define GET_BONE_POSITION (*g_engfuncs.pfnGetBonePosition) -#define FUNCTION_FROM_NAME (*g_engfuncs.pfnFunctionFromName) -#define NAME_FOR_FUNCTION (*g_engfuncs.pfnNameForFunction) -#define TRACE_TEXTURE (*g_engfuncs.pfnTraceTexture) -#define CLIENT_PRINTF (*g_engfuncs.pfnClientPrintf) -#define CMD_ARGS (*g_engfuncs.pfnCmd_Args) -#define CMD_ARGC (*g_engfuncs.pfnCmd_Argc) -#define CMD_ARGV (*g_engfuncs.pfnCmd_Argv) +#define FIND_CLIENT_IN_PVS (*g_engfuncs.pfnFindClientInPVS) +#define FIND_ENTITY_IN_PVS (*g_engfuncs.pfnEntitiesInPVS) +#define EMIT_AMBIENT_SOUND (*g_engfuncs.pfnEmitAmbientSound) +#define GET_MODEL_PTR (*g_engfuncs.pfnGetModelPtr) +#define REG_USER_MSG (*g_engfuncs.pfnRegUserMsg) +#define GET_BONE_POSITION (*g_engfuncs.pfnGetBonePosition) +#define FUNCTION_FROM_NAME (*g_engfuncs.pfnFunctionFromName) +#define NAME_FOR_FUNCTION (*g_engfuncs.pfnNameForFunction) +#define TRACE_TEXTURE (*g_engfuncs.pfnTraceTexture) +#define CLIENT_PRINTF (*g_engfuncs.pfnClientPrintf) +#define SERVER_PRINT (*g_engfuncs.pfnServerPrint) +#define CMD_ARGS (*g_engfuncs.pfnCmd_Args) +#define CMD_ARGC (*g_engfuncs.pfnCmd_Argc) +#define CMD_ARGV (*g_engfuncs.pfnCmd_Argv) #define GET_ATTACHMENT (*g_engfuncs.pfnGetAttachment) -#define SET_VIEW (*g_engfuncs.pfnSetView) +#define SET_VIEW (*g_engfuncs.pfnSetView) #define SET_CROSSHAIRANGLE (*g_engfuncs.pfnCrosshairAngle) #define LOAD_FILE_FOR_ME (*g_engfuncs.pfnLoadFileForMe) -#define FREE_FILE (*g_engfuncs.pfnFreeFile) +#define FREE_FILE (*g_engfuncs.pfnFreeFile) +#define END_SECTION (*g_engfuncs.pfnEndSection) #define COMPARE_FILE_TIME (*g_engfuncs.pfnCompareFileTime) #define GET_GAME_DIR (*g_engfuncs.pfnGetGameDir) -#define IS_MAP_VALID (*g_engfuncs.pfnIsMapValid) +#define SET_CLIENT_MAXSPEED (*g_engfuncs.pfnSetClientMaxspeed) +#define CREATE_FAKE_CLIENT (*g_engfuncs.pfnCreateFakeClient) +#define PLAYER_RUN_MOVE (*g_engfuncs.pfnRunPlayerMove) #define NUMBER_OF_ENTITIES (*g_engfuncs.pfnNumberOfEntities) +#define GET_INFO_BUFFER (*g_engfuncs.pfnGetInfoKeyBuffer) +#define GET_KEY_VALUE (*g_engfuncs.pfnInfoKeyValue) +#define SET_KEY_VALUE (*g_engfuncs.pfnSetKeyValue) +#define SET_CLIENT_KEY_VALUE (*g_engfuncs.pfnSetClientKeyValue) +#define IS_MAP_VALID (*g_engfuncs.pfnIsMapValid) +#define STATIC_DECAL (*g_engfuncs.pfnStaticDecal) #define IS_DEDICATED_SERVER (*g_engfuncs.pfnIsDedicatedServer) - #define PRECACHE_EVENT (*g_engfuncs.pfnPrecacheEvent) #define PLAYBACK_EVENT_FULL (*g_engfuncs.pfnPlaybackEvent) - #define ENGINE_SET_PVS (*g_engfuncs.pfnSetFatPVS) #define ENGINE_SET_PAS (*g_engfuncs.pfnSetFatPAS) - -#define ENGINE_CHECK_VISIBILITY (*g_engfuncs.pfnCheckVisibility) - -#define DELTA_SET ( *g_engfuncs.pfnDeltaSetField ) -#define DELTA_UNSET ( *g_engfuncs.pfnDeltaUnsetField ) -#define DELTA_ADDENCODER ( *g_engfuncs.pfnDeltaAddEncoder ) -#define ENGINE_CURRENT_PLAYER ( *g_engfuncs.pfnGetCurrentPlayer ) - -#define ENGINE_CANSKIP ( *g_engfuncs.pfnCanSkipPlayer ) - -#define DELTA_FINDFIELD ( *g_engfuncs.pfnDeltaFindField ) -#define DELTA_SETBYINDEX ( *g_engfuncs.pfnDeltaSetFieldByIndex ) -#define DELTA_UNSETBYINDEX ( *g_engfuncs.pfnDeltaUnsetFieldByIndex ) - -#define ENGINE_GETPHYSINFO ( *g_engfuncs.pfnGetPhysicsInfoString ) - -#define ENGINE_SETGROUPMASK ( *g_engfuncs.pfnSetGroupMask ) - -#define ENGINE_INSTANCE_BASELINE ( *g_engfuncs.pfnCreateInstancedBaseline ) - -#define ENGINE_FORCE_UNMODIFIED ( *g_engfuncs.pfnForceUnmodified ) - -#define PLAYER_CNX_STATS ( *g_engfuncs.pfnGetPlayerStats ) - -#endif //ENGINECALLBACK_H +#define ENGINE_CHECK_VISIBILITY (*g_engfuncs.pfnCheckVisibility) +#define DELTA_SET (*g_engfuncs.pfnDeltaSetField) +#define DELTA_UNSET (*g_engfuncs.pfnDeltaUnsetField) +#define DELTA_ADDENCODER (*g_engfuncs.pfnDeltaAddEncoder) +#define ENGINE_CURRENT_PLAYER (*g_engfuncs.pfnGetCurrentPlayer) +#define ENGINE_CANSKIP (*g_engfuncs.pfnCanSkipPlayer) +#define DELTA_FINDFIELD (*g_engfuncs.pfnDeltaFindField) +#define DELTA_SETBYINDEX (*g_engfuncs.pfnDeltaSetFieldByIndex) +#define DELTA_UNSETBYINDEX (*g_engfuncs.pfnDeltaUnsetFieldByIndex) +#define REMOVE_KEY_VALUE (*g_engfuncs.pfnInfo_RemoveKey) +#define SET_PHYSICS_KEY_VALUE (*g_engfuncs.pfnSetPhysicsKeyValue) +#define ENGINE_GETPHYSINFO (*g_engfuncs.pfnGetPhysicsInfoString) +#define ENGINE_SETGROUPMASK (*g_engfuncs.pfnSetGroupMask) +#define ENGINE_INSTANCE_BASELINE (*g_engfuncs.pfnCreateInstancedBaseline) +#define ENGINE_FORCE_UNMODIFIED (*g_engfuncs.pfnForceUnmodified) +#define PLAYER_CNX_STATS (*g_engfuncs.pfnGetPlayerStats) diff --git a/dlls/explode.h b/dlls/explode.h index 3feb011..1a2f7a0 100644 --- a/dlls/explode.h +++ b/dlls/explode.h @@ -1,32 +1,55 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef EXPLODE_H -#define EXPLODE_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once +#define SF_ENVEXPLOSION_NODAMAGE (1<<0) // when set, ENV_EXPLOSION will not actually inflict damage +#define SF_ENVEXPLOSION_REPEATABLE (1<<1) // can this entity be refired? +#define SF_ENVEXPLOSION_NOFIREBALL (1<<2) // don't draw the fireball +#define SF_ENVEXPLOSION_NOSMOKE (1<<3) // don't draw the smoke +#define SF_ENVEXPLOSION_NODECAL (1<<4) // don't make a scorch mark +#define SF_ENVEXPLOSION_NOSPARKS (1<<5) // don't make a scorch mark -#define SF_ENVEXPLOSION_NODAMAGE ( 1 << 0 ) // when set, ENV_EXPLOSION will not actually inflict damage -#define SF_ENVEXPLOSION_REPEATABLE ( 1 << 1 ) // can this entity be refired? -#define SF_ENVEXPLOSION_NOFIREBALL ( 1 << 2 ) // don't draw the fireball -#define SF_ENVEXPLOSION_NOSMOKE ( 1 << 3 ) // don't draw the smoke -#define SF_ENVEXPLOSION_NODECAL ( 1 << 4 ) // don't make a scorch mark -#define SF_ENVEXPLOSION_NOSPARKS ( 1 << 5 ) // don't make a scorch mark +class CShower: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int ObjectCaps() = 0; + virtual void Think() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +}; -extern DLL_GLOBAL short g_sModelIndexFireball; -extern DLL_GLOBAL short g_sModelIndexSmoke; - - -extern void ExplosionCreate( const Vector ¢er, const Vector &angles, edict_t *pOwner, int magnitude, BOOL doDamage ); - -#endif //EXPLODE_H +class CEnvExplosion: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_iMagnitude; + int m_spriteScale; +}; diff --git a/dlls/extdef.h b/dlls/extdef.h new file mode 100644 index 0000000..383a668 --- /dev/null +++ b/dlls/extdef.h @@ -0,0 +1,113 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "regamedll_const.h" + +#undef DLLEXPORT +#ifdef _WIN32 + // Attributes to specify an "exported" function, visible from outside the + // DLL. + #define DLLEXPORT __declspec(dllexport) + // WINAPI should be provided in the windows compiler headers. + // It's usually defined to something like "__stdcall". + + #define NOINLINE __declspec(noinline) +#else + #define DLLEXPORT __attribute__((visibility("default"))) + #define WINAPI /* */ + #define NOINLINE __attribute__((noinline)) +#endif // _WIN32 + +// Manual branch optimization for GCC 3.0.0 and newer +#if !defined(__GNUC__) || __GNUC__ < 3 + #define likely(x) (x) + #define unlikely(x) (x) +#else + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#endif + +// Simplified macro for declaring/defining exported DLL functions. They +// need to be 'extern "C"' so that the C++ compiler enforces parameter +// type-matching, rather than considering routines with mis-matched +// arguments/types to be overloaded functions... +// +// AFAIK, this is os-independent, but it's included here in osdep.h where +// DLLEXPORT is defined, for convenience. +#define C_DLLEXPORT extern "C" DLLEXPORT + +enum hash_types_e { CLASSNAME }; + +// Things that toggle (buttons/triggers/doors) need this +enum TOGGLE_STATE { TS_AT_TOP, TS_AT_BOTTOM, TS_GOING_UP, TS_GOING_DOWN }; + +typedef struct hash_item_s +{ + entvars_t *pev; + struct hash_item_s *next; + struct hash_item_s *lastHash; + int pevIndex; + +} hash_item_t; + +typedef struct locksounds +{ + string_t sLockedSound; + string_t sLockedSentence; + string_t sUnlockedSound; + string_t sUnlockedSentence; + int iLockedSentence; + int iUnlockedSentence; + float flwaitSound; + float flwaitSentence; + byte bEOFLocked; + byte bEOFUnlocked; + +} locksound_t; + +typedef struct hudtextparms_s +{ + float x; + float y; + int effect; + byte r1,g1,b1,a1; + byte r2,g2,b2,a2; + float fadeinTime; + float fadeoutTime; + float holdTime; + float fxTime; + int channel; + +} hudtextparms_t; + +enum USE_TYPE { USE_OFF, USE_ON, USE_SET, USE_TOGGLE }; +enum TRAIN_CODE { TRAIN_SAFE, TRAIN_BLOCKING, TRAIN_FOLLOWING }; +enum IGNORE_MONSTERS { ignore_monsters = 1, dont_ignore_monsters = 0, missile = 2 }; +enum IGNORE_GLASS { ignore_glass = 1, dont_ignore_glass = 0 }; +enum { point_hull = 0, human_hull = 1, large_hull = 2, head_hull = 3 }; diff --git a/dlls/extdll.h b/dlls/extdll.h index 2f8786c..e81fcd1 100644 --- a/dlls/extdll.h +++ b/dlls/extdll.h @@ -1,71 +1,58 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef EXTDLL_H -#define EXTDLL_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -// -// Global header file for extension DLLs -// +#pragma warning(disable:4244) // int or float down-conversion +#pragma warning(disable:4305) // int or float data truncation +#pragma warning(disable:4201) // nameless struct/union +#pragma warning(disable:4514) // unreferenced inline function removed +#pragma warning(disable:4100) // unreferenced formal parameter -// Allow "DEBUG" in addition to default "_DEBUG" -#ifdef _DEBUG -#define DEBUG 1 -#endif +#include "archtypes.h" +#include "maintypes.h" +#include "regamedll_common.h" -// Silence certain warnings -#pragma warning(disable : 4244) // int or float down-conversion -#pragma warning(disable : 4305) // int or float data truncation -#pragma warning(disable : 4201) // nameless struct/union -#pragma warning(disable : 4514) // unreferenced inline function removed -#pragma warning(disable : 4100) // unreferenced formal parameter - -#include "archtypes.h" // DAL - -// Prevent tons of unused windows definitions #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#define NOWINRES -#define NOSERVICE -#define NOMCX -#define NOIME -#include "winsani_in.h" -#include "windows.h" -#include "winsani_out.h" -#else // _WIN32 -#ifndef TRUE -#define FALSE 0 -#define TRUE (!FALSE) -#endif //TRUE -typedef uint32 ULONG; -typedef unsigned char BYTE; -typedef int BOOL; -#ifndef MAX_PATH -#define MAX_PATH PATH_MAX -#endif // MAX_PATH -#include -#include -#include // memset -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d) -#endif -#endif //_WIN32 + #define WIN32_LEAN_AND_MEAN + #define NOWINRES + #define NOSERVICE + #define NOMCX + #define NOIME + #include "winsani_in.h" + #include "windows.h" + #include "winsani_out.h" + #undef PlaySound +#else + #include + #include + #include +#endif // _WIN32 // Misc C-runtime library headers #include "stdio.h" @@ -73,25 +60,23 @@ typedef int BOOL; #include "math.h" // Header file containing definition of globalvars_t and entvars_t -typedef unsigned int func_t; // +typedef int EOFFSET; // More explicit than "int" +typedef unsigned int func_t; typedef unsigned int string_t; // from engine's pr_comp.h; -typedef float vec_t; // needed before including progdefs.h +typedef float vec_t; // needed before including progdefs.h // Vector class #include "vector.h" - +//#include "vector.h" // Defining it as a (bogus) struct helps enforce type-checking #define vec3_t Vector - // Shared engine/DLL constants + #include "const.h" -#include "progdefs.h" #include "edict.h" // Shared header describing protocol between engine and DLLs #include "eiface.h" - // Shared header between the client DLL and the game DLLs #include "cdll_dll.h" - -#endif //EXTDLL_H +#include "extdef.h" diff --git a/dlls/func_break.h b/dlls/func_break.h index 9bb281d..c1e9ddb 100644 --- a/dlls/func_break.h +++ b/dlls/func_break.h @@ -1,74 +1,120 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef FUNC_BREAK_H -#define FUNC_BREAK_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -typedef enum { expRandom, expDirected} Explosions; -typedef enum { matGlass = 0, matWood, matMetal, matFlesh, matCinderBlock, matCeilingTile, matComputer, matUnbreakableGlass, matRocks, matNone, matLastMaterial } Materials; +// this many shards spawned when breakable objects break; +#define NUM_SHARDS 6 -#define NUM_SHARDS 6 // this many shards spawned when breakable objects break; +// func breakable +#define SF_BREAK_TRIGGER_ONLY 1 // may only be broken by trigger +#define SF_BREAK_TOUCH 2 // can be 'crashed through' by running player (plate glass) +#define SF_BREAK_PRESSURE 4 // can be broken by a player standing on it +#define SF_BREAK_CROWBAR 256 // instant break if hit with crowbar -class CBreakable : public CBaseDelay +// func_pushable (it's also func_breakable, so don't collide with those flags) +#define SF_PUSH_BREAKABLE 128 + +typedef enum { + expRandom = 0, + expDirected, + +} Explosions; + +typedef enum +{ + matGlass = 0, + matWood, + matMetal, + matFlesh, + matCinderBlock, + matCeilingTile, + matComputer, + matUnbreakableGlass, + matRocks, + matNone, + matLastMaterial, + +} Materials; + +class CBreakable: public CBaseDelay { public: // basic functions - void Spawn( void ); - void Precache( void ); - void KeyValue( KeyValueData* pkvd); - void EXPORT BreakTouch( CBaseEntity *pOther ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void DamageSound( void ); + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + + // To spark when hit + virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; // breakables use an overridden takedamage - virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType ); - // To spark when hit - void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType ); + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; - BOOL IsBreakable( void ); - BOOL SparkWhenHit( void ); + virtual int DamageDecal(int bitsDamageType) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; - int DamageDecal( int bitsDamageType ); +public: + BOOL Explodable() const { return ExplosionMagnitude() > 0; } + int ExplosionMagnitude() const { return pev->impulse; } + void ExplosionSetMagnitude(int magnitude) { pev->impulse = magnitude; } - void EXPORT Die( void ); - virtual int ObjectCaps( void ) { return (CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION); } - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - inline BOOL Explodable( void ) { return ExplosionMagnitude() > 0; } - inline int ExplosionMagnitude( void ) { return pev->impulse; } - inline void ExplosionSetMagnitude( int magnitude ) { pev->impulse = magnitude; } - - static void MaterialSoundPrecache( Materials precacheMaterial ); - static void MaterialSoundRandom( edict_t *pEdict, Materials soundMaterial, float volume ); - static const char **MaterialSoundList( Materials precacheMaterial, int &soundCount ); - - static const char *pSoundsWood[]; - static const char *pSoundsFlesh[]; - static const char *pSoundsGlass[]; - static const char *pSoundsMetal[]; - static const char *pSoundsConcrete[]; - static const char *pSpawnObjects[]; - - static TYPEDESCRIPTION m_SaveData[]; - - Materials m_Material; - Explosions m_Explosion; - int m_idShard; - float m_angle; - int m_iszGibModel; - int m_iszSpawnObject; +public: + Materials m_Material; + Explosions m_Explosion; + int m_idShard; + float m_angle; + int m_iszGibModel; + int m_iszSpawnObject; + float m_flHealth; }; -#endif // FUNC_BREAK_H +class CPushable: public CBreakable { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0 + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + +public: + float MaxSpeed() const { return m_maxSpeed; } + +public: + int m_lastSound; + float m_maxSpeed; + float m_soundTime; +}; \ No newline at end of file diff --git a/dlls/func_tank.h b/dlls/func_tank.h new file mode 100644 index 0000000..6ae26fa --- /dev/null +++ b/dlls/func_tank.h @@ -0,0 +1,159 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SF_TANK_ACTIVE 0x0001 +#define SF_TANK_PLAYER 0x0002 +#define SF_TANK_HUMANS 0x0004 +#define SF_TANK_ALIENS 0x0008 +#define SF_TANK_LINEOFSIGHT 0x0010 +#define SF_TANK_CANCONTROL 0x0020 +#define SF_TANK_SOUNDON 0x8000 + +enum TANKBULLET +{ + TANK_BULLET_NONE = 0, // Custom damage + TANK_BULLET_9MM, // env_laser (duration is 0.5 rate of fire) + TANK_BULLET_MP5, // rockets + TANK_BULLET_12MM, // explosion? +}; + +class CFuncTank: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + + // Bmodels don't go across transitions + virtual int ObjectCaps() = 0; + virtual BOOL OnControls(entvars_t *pevTest) = 0; + virtual void Think() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) = 0; + virtual Vector UpdateTargetPosition(CBaseEntity *pTarget) = 0; +public: + BOOL IsActive() const { return (pev->spawnflags & SF_TANK_ACTIVE) == SF_TANK_ACTIVE; } + void TankActivate() + { + pev->spawnflags |= SF_TANK_ACTIVE; + pev->nextthink = pev->ltime + 0.1f; + m_fireLast = 0.0f; + } + void TankDeactivate() + { + pev->spawnflags &= ~SF_TANK_ACTIVE; + m_fireLast = 0.0f; + StopRotSound(); + } + + BOOL CanFire() const { return (gpGlobals->time - m_lastSightTime) < m_persist; } + Vector BarrelPosition() + { + Vector forward, right, up; + UTIL_MakeVectorsPrivate(pev->angles, forward, right, up); + return pev->origin + (forward * m_barrelPos.x) + (right * m_barrelPos.y) + (up * m_barrelPos.z); + } +protected: + CBasePlayer *m_pController; + float m_flNextAttack; + Vector m_vecControllerUsePos; + + float m_yawCenter; // "Center" yaw + float m_yawRate; // Max turn rate to track targets + float m_yawRange; // Range of turning motion (one-sided: 30 is +/- 30 degress from center) + // Zero is full rotation + + float m_yawTolerance; // Tolerance angle + + float m_pitchCenter; // "Center" pitch + float m_pitchRate; // Max turn rate on pitch + float m_pitchRange; // Range of pitch motion as above + float m_pitchTolerance; // Tolerance angle + + float m_fireLast; // Last time I fired + float m_fireRate; // How many rounds/second + float m_lastSightTime; // Last time I saw target + float m_persist; // Persistence of firing (how long do I shoot when I can't see) + float m_minRange; // Minimum range to aim/track + float m_maxRange; // Max range to aim/track + + Vector m_barrelPos; // Length of the freakin barrel + float m_spriteScale; // Scale of any sprites we shoot + int m_iszSpriteSmoke; + int m_iszSpriteFlash; + TANKBULLET m_bulletType; // Bullet type + int m_iBulletDamage; // 0 means use Bullet type's default damage + + Vector m_sightOrigin; // Last sight of target + int m_spread; // firing spread + int m_iszMaster; // Master entity (game_team_master or multisource) +}; + +class CFuncTankGun: public CFuncTank { +public: + virtual void Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) = 0; +}; + +class CFuncTankLaser: public CFuncTank { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Activate() = 0; + virtual void Think() = 0; + virtual void Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) = 0; +private: + CLaser *m_pLaser; + float m_laserTime; +}; + +class CFuncTankRocket: public CFuncTank { +public: + virtual void Precache() = 0; + virtual void Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) = 0; +}; + +class CFuncTankMortar: public CFuncTank { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) = 0; +}; + +class CFuncTankControls: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Think() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + CFuncTank *m_pTank; +}; diff --git a/dlls/game.h b/dlls/game.h deleted file mode 100644 index 58e7e75..0000000 --- a/dlls/game.h +++ /dev/null @@ -1,45 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ - -#ifndef GAME_H -#define GAME_H - -extern void GameDLLInit( void ); - - -extern cvar_t displaysoundlist; - -// multiplayer server rules -extern cvar_t teamplay; -extern cvar_t fraglimit; -extern cvar_t timelimit; -extern cvar_t friendlyfire; -extern cvar_t falldamage; -extern cvar_t weaponstay; -extern cvar_t forcerespawn; -extern cvar_t flashlight; -extern cvar_t aimcrosshair; -extern cvar_t decalfrequency; -extern cvar_t teamlist; -extern cvar_t teamoverride; -extern cvar_t defaultteam; -extern cvar_t allowmonsters; - -// Engine Cvars -extern cvar_t *g_psv_gravity; -extern cvar_t *g_psv_aim; -extern cvar_t *g_footsteps; - -#endif // GAME_H diff --git a/dlls/gamerules.h b/dlls/gamerules.h index 76b3515..1555284 100644 --- a/dlls/gamerules.h +++ b/dlls/gamerules.h @@ -1,39 +1,180 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -//========================================================= -// GameRules -//========================================================= +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -//#include "weapons.h" -//#include "items.h" -class CBasePlayerItem; -class CBasePlayer; -class CItem; -class CBasePlayerAmmo; +#include "voice_gamemgr.h" + +#define MAX_RULE_BUFFER 1024 +#define MAX_VOTE_MAPS 100 +#define MAX_VIP_QUEUES 5 + +#define MAX_BOMB_RADIUS 2048 + +#define ITEM_RESPAWN_TIME 30 +#define WEAPON_RESPAWN_TIME 20 +#define AMMO_RESPAWN_TIME 20 + +// longest the intermission can last, in seconds +#define MAX_INTERMISSION_TIME 120 + +// when we are within this close to running out of entities, items +// marked with the ITEM_FLAG_LIMITINWORLD will delay their respawn +#define ENTITY_INTOLERANCE 100 + +#define MAX_MOTD_CHUNK 60 +#define MAX_MOTD_LENGTH 1536 // (MAX_MOTD_CHUNK * 4) + +// custom enum +#define WINNER_NONE 0 +#define WINNER_DRAW 1 + +enum +{ + WINSTATUS_CTS = 1, + WINSTATUS_TERRORISTS, + WINSTATUS_DRAW, +}; + +// custom enum +// used for EndRoundMessage() logged messages +enum ScenarioEventEndRound +{ + ROUND_NONE, + ROUND_TARGET_BOMB, + ROUND_VIP_ESCAPED, + ROUND_VIP_ASSASSINATED, + ROUND_TERRORISTS_ESCAPED, + ROUND_CTS_PREVENT_ESCAPE, + ROUND_ESCAPING_TERRORISTS_NEUTRALIZED, + ROUND_BOMB_DEFUSED, + ROUND_CTS_WIN, + ROUND_TERRORISTS_WIN, + ROUND_END_DRAW, + ROUND_ALL_HOSTAGES_RESCUED, + ROUND_TARGET_SAVED, + ROUND_HOSTAGE_NOT_RESCUED, + ROUND_TERRORISTS_NOT_ESCAPED, + ROUND_VIP_NOT_ESCAPED, + ROUND_GAME_COMMENCE, + ROUND_GAME_RESTART, + ROUND_GAME_OVER +}; + +enum RewardRules +{ + RR_CTS_WIN, + RR_TERRORISTS_WIN, + RR_TARGET_BOMB, + RR_VIP_ESCAPED, + RR_VIP_ASSASSINATED, + RR_TERRORISTS_ESCAPED, + RR_CTS_PREVENT_ESCAPE, + RR_ESCAPING_TERRORISTS_NEUTRALIZED, + RR_BOMB_DEFUSED, + RR_BOMB_PLANTED, + RR_BOMB_EXPLODED, + RR_ALL_HOSTAGES_RESCUED, + RR_TARGET_BOMB_SAVED, + RR_HOSTAGE_NOT_RESCUED, + RR_VIP_NOT_ESCAPED, + RR_LOSER_BONUS_DEFAULT, + RR_LOSER_BONUS_MIN, + RR_LOSER_BONUS_MAX, + RR_LOSER_BONUS_ADD, + RR_RESCUED_HOSTAGE, + RR_TOOK_HOSTAGE_ACC, + RR_TOOK_HOSTAGE, + RR_END +}; + +// custom enum +enum RewardAccount +{ + REWARD_TARGET_BOMB = 3500, + REWARD_VIP_ESCAPED = 3500, + REWARD_VIP_ASSASSINATED = 3250, + REWARD_TERRORISTS_ESCAPED = 3150, + REWARD_CTS_PREVENT_ESCAPE = 3500, + REWARD_ESCAPING_TERRORISTS_NEUTRALIZED = 3250, + REWARD_BOMB_DEFUSED = 3250, + REWARD_BOMB_PLANTED = 800, + REWARD_BOMB_EXPLODED = 3250, + REWARD_CTS_WIN = 3000, + REWARD_TERRORISTS_WIN = 3000, + REWARD_ALL_HOSTAGES_RESCUED = 2500, + + // the end round was by the expiration time + REWARD_TARGET_BOMB_SAVED = 3250, + REWARD_HOSTAGE_NOT_RESCUED = 3250, + REWARD_VIP_NOT_ESCAPED = 3250, + + // loser bonus + REWARD_LOSER_BONUS_DEFAULT = 1400, + REWARD_LOSER_BONUS_MIN = 1500, + REWARD_LOSER_BONUS_MAX = 3000, + REWARD_LOSER_BONUS_ADD = 500, + + REWARD_RESCUED_HOSTAGE = 750, + REWARD_KILLED_ENEMY = 300, + REWARD_KILLED_VIP = 2500, + REWARD_VIP_HAVE_SELF_RESCUED = 2500, + + REWARD_TAKEN_HOSTAGE = 1000, + REWARD_TOOK_HOSTAGE_ACC = 100, + REWARD_TOOK_HOSTAGE = 150, +}; + +// custom enum +enum PaybackForBadThing +{ + PAYBACK_FOR_KILLED_TEAMMATES = -3300, +}; + +// custom enum +enum InfoMapBuyParam +{ + BUYING_EVERYONE = 0, + BUYING_ONLY_CTS, + BUYING_ONLY_TERRORISTS, + BUYING_NO_ONE, +}; // weapon respawning return codes enum -{ +{ GR_NONE = 0, - + GR_WEAPON_RESPAWN_YES, GR_WEAPON_RESPAWN_NO, - + GR_AMMO_RESPAWN_YES, GR_AMMO_RESPAWN_NO, - + GR_ITEM_RESPAWN_YES, GR_ITEM_RESPAWN_NO, @@ -46,6 +187,18 @@ enum GR_PLR_DROP_AMMO_NO, }; +// custom enum +enum +{ + SCENARIO_BLOCK_TIME_EXPRIRED = (1 << 0), // flag "a" + SCENARIO_BLOCK_NEED_PLAYERS = (1 << 1), // flag "b" + SCENARIO_BLOCK_VIP_ESCAPE = (1 << 2), // flag "c" + SCENARIO_BLOCK_PRISON_ESCAPE = (1 << 3), // flag "d" + SCENARIO_BLOCK_BOMB = (1 << 4), // flag "e" + SCENARIO_BLOCK_TEAM_EXTERMINATION = (1 << 5), // flag "f" + SCENARIO_BLOCK_HOSTAGE_RESCUE = (1 << 6), // flag "g" +}; + // Player relationship return codes enum { @@ -56,305 +209,480 @@ enum GR_NEUTRAL, }; -class CGameRules -{ -public: - virtual void RefreshSkillData( void );// fill skill data struct with proper values - virtual void Think( void ) = 0;// GR_Think - runs every server frame, should handle any timer tasks, periodic events, etc. - virtual BOOL IsAllowedToSpawn( CBaseEntity *pEntity ) = 0; // Can this item spawn (eg monsters don't spawn in deathmatch). - - virtual BOOL FAllowFlashlight( void ) = 0;// Are players allowed to switch on their flashlight? - virtual BOOL FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ) = 0;// should the player switch to this weapon? - virtual BOOL GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ) = 0;// I can't use this weapon anymore, get me the next best one. - -// Functions to verify the single/multiplayer status of a game - virtual BOOL IsMultiplayer( void ) = 0;// is this a multiplayer game? (either coop or deathmatch) - virtual BOOL IsDeathmatch( void ) = 0;//is this a deathmatch game? - virtual BOOL IsTeamplay( void ) { return FALSE; };// is this deathmatch game being played with team rules? - virtual BOOL IsCoOp( void ) = 0;// is this a coop game? - virtual const char *GetGameDescription( void ) { return "Half-Life"; } // this is the game name that gets seen in the server browser - -// Client connection/disconnection - virtual BOOL ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) = 0;// a client just connected to the server (player hasn't spawned yet) - virtual void InitHUD( CBasePlayer *pl ) = 0; // the client dll is ready for updating - virtual void ClientDisconnected( edict_t *pClient ) = 0;// a client just disconnected from the server - virtual void UpdateGameMode( CBasePlayer *pPlayer ) {} // the client needs to be informed of the current game mode - -// Client damage rules - virtual float FlPlayerFallDamage( CBasePlayer *pPlayer ) = 0;// this client just hit the ground after a fall. How much damage? - virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker ) {return TRUE;};// can this player take damage from this attacker? - virtual BOOL ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target ) { return TRUE; } - -// Client spawn/respawn control - virtual void PlayerSpawn( CBasePlayer *pPlayer ) = 0;// called by CBasePlayer::Spawn just before releasing player into the game - virtual void PlayerThink( CBasePlayer *pPlayer ) = 0; // called by CBasePlayer::PreThink every frame, before physics are run and after keys are accepted - virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ) = 0;// is this player allowed to respawn now? - virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer ) = 0;// When in the future will this player be able to spawn? - virtual edict_t *GetPlayerSpawnSpot( CBasePlayer *pPlayer );// Place this player on their spawnspot and face them the proper direction. - - virtual BOOL AllowAutoTargetCrosshair( void ) { return TRUE; }; - virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) { return FALSE; }; // handles the user commands; returns TRUE if command handled properly - virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ) {} // the player has changed userinfo; can change it now - -// Client kills/scoring - virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ) = 0;// how many points do I award whoever kills this player? - virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ) = 0;// Called each time a player dies - virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor )= 0;// Call this from within a GameRules class to report an obituary. -// Weapon retrieval - virtual BOOL CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon );// The player is touching an CBasePlayerItem, do I give it to him? - virtual void PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ) = 0;// Called each time a player picks up a weapon from the ground - -// Weapon spawn/respawn control - virtual int WeaponShouldRespawn( CBasePlayerItem *pWeapon ) = 0;// should this weapon respawn? - virtual float FlWeaponRespawnTime( CBasePlayerItem *pWeapon ) = 0;// when may this weapon respawn? - virtual float FlWeaponTryRespawn( CBasePlayerItem *pWeapon ) = 0; // can i respawn now, and if not, when should i try again? - virtual Vector VecWeaponRespawnSpot( CBasePlayerItem *pWeapon ) = 0;// where in the world should this weapon respawn? - -// Item retrieval - virtual BOOL CanHaveItem( CBasePlayer *pPlayer, CItem *pItem ) = 0;// is this player allowed to take this item? - virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem ) = 0;// call each time a player picks up an item (battery, healthkit, longjump) - -// Item spawn/respawn control - virtual int ItemShouldRespawn( CItem *pItem ) = 0;// Should this item respawn? - virtual float FlItemRespawnTime( CItem *pItem ) = 0;// when may this item respawn? - virtual Vector VecItemRespawnSpot( CItem *pItem ) = 0;// where in the world should this item respawn? - -// Ammo retrieval - virtual BOOL CanHaveAmmo( CBasePlayer *pPlayer, const char *pszAmmoName, int iMaxCarry );// can this player take more of this ammo? - virtual void PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount ) = 0;// called each time a player picks up some ammo in the world - -// Ammo spawn/respawn control - virtual int AmmoShouldRespawn( CBasePlayerAmmo *pAmmo ) = 0;// should this ammo item respawn? - virtual float FlAmmoRespawnTime( CBasePlayerAmmo *pAmmo ) = 0;// when should this ammo item respawn? - virtual Vector VecAmmoRespawnSpot( CBasePlayerAmmo *pAmmo ) = 0;// where in the world should this ammo item respawn? - // by default, everything spawns - -// Healthcharger respawn control - virtual float FlHealthChargerRechargeTime( void ) = 0;// how long until a depleted HealthCharger recharges itself? - virtual float FlHEVChargerRechargeTime( void ) { return 0; }// how long until a depleted HealthCharger recharges itself? - -// What happens to a dead player's weapons - virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ) = 0;// what do I do with a player's weapons when he's killed? - -// What happens to a dead player's ammo - virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ) = 0;// Do I drop ammo when the player dies? How much? - -// Teamplay stuff - virtual const char *GetTeamID( CBaseEntity *pEntity ) = 0;// what team is this entity on? - virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ) = 0;// What is the player's relationship with this entity? - virtual int GetTeamIndex( const char *pTeamName ) { return -1; } - virtual const char *GetIndexedTeamName( int teamIndex ) { return ""; } - virtual BOOL IsValidTeam( const char *pTeamName ) { return TRUE; } - virtual void ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib ) {} - virtual const char *SetDefaultPlayerTeam( CBasePlayer *pPlayer ) { return ""; } - -// Sounds - virtual BOOL PlayTextureSounds( void ) { return TRUE; } - virtual BOOL PlayFootstepSounds( CBasePlayer *pl, float fvol ) { return TRUE; } - -// Monsters - virtual BOOL FAllowMonsters( void ) = 0;//are monsters allowed - - // Immediately end a multiplayer game - virtual void EndMultiplayerGame( void ) {} -}; - -extern CGameRules *InstallGameRules( void ); - - -//========================================================= -// CHalfLifeRules - rules for the single player Half-Life -// game. -//========================================================= -class CHalfLifeRules : public CGameRules -{ -public: - CHalfLifeRules ( void ); - -// GR_Think - virtual void Think( void ); - virtual BOOL IsAllowedToSpawn( CBaseEntity *pEntity ); - virtual BOOL FAllowFlashlight( void ) { return TRUE; }; - - virtual BOOL FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); - virtual BOOL GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ); - -// Functions to verify the single/multiplayer status of a game - virtual BOOL IsMultiplayer( void ); - virtual BOOL IsDeathmatch( void ); - virtual BOOL IsCoOp( void ); - -// Client connection/disconnection - virtual BOOL ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ); - virtual void InitHUD( CBasePlayer *pl ); // the client dll is ready for updating - virtual void ClientDisconnected( edict_t *pClient ); - -// Client damage rules - virtual float FlPlayerFallDamage( CBasePlayer *pPlayer ); - -// Client spawn/respawn control - virtual void PlayerSpawn( CBasePlayer *pPlayer ); - virtual void PlayerThink( CBasePlayer *pPlayer ); - virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ); - virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer ); - - virtual BOOL AllowAutoTargetCrosshair( void ); - -// Client kills/scoring - virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ); - virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); - virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); - -// Weapon retrieval - virtual void PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); - -// Weapon spawn/respawn control - virtual int WeaponShouldRespawn( CBasePlayerItem *pWeapon ); - virtual float FlWeaponRespawnTime( CBasePlayerItem *pWeapon ); - virtual float FlWeaponTryRespawn( CBasePlayerItem *pWeapon ); - virtual Vector VecWeaponRespawnSpot( CBasePlayerItem *pWeapon ); - -// Item retrieval - virtual BOOL CanHaveItem( CBasePlayer *pPlayer, CItem *pItem ); - virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem ); - -// Item spawn/respawn control - virtual int ItemShouldRespawn( CItem *pItem ); - virtual float FlItemRespawnTime( CItem *pItem ); - virtual Vector VecItemRespawnSpot( CItem *pItem ); - -// Ammo retrieval - virtual void PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount ); - -// Ammo spawn/respawn control - virtual int AmmoShouldRespawn( CBasePlayerAmmo *pAmmo ); - virtual float FlAmmoRespawnTime( CBasePlayerAmmo *pAmmo ); - virtual Vector VecAmmoRespawnSpot( CBasePlayerAmmo *pAmmo ); - -// Healthcharger respawn control - virtual float FlHealthChargerRechargeTime( void ); - -// What happens to a dead player's weapons - virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ); - -// What happens to a dead player's ammo - virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ); - -// Monsters - virtual BOOL FAllowMonsters( void ); - -// Teamplay stuff - virtual const char *GetTeamID( CBaseEntity *pEntity ) {return "";}; - virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); -}; - -//========================================================= -// CHalfLifeMultiplay - rules for the basic half life multiplayer -// competition -//========================================================= -class CHalfLifeMultiplay : public CGameRules -{ -public: - CHalfLifeMultiplay(); - -// GR_Think - virtual void Think( void ); - virtual void RefreshSkillData( void ); - virtual BOOL IsAllowedToSpawn( CBaseEntity *pEntity ); - virtual BOOL FAllowFlashlight( void ); - - virtual BOOL FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); - virtual BOOL GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ); - -// Functions to verify the single/multiplayer status of a game - virtual BOOL IsMultiplayer( void ); - virtual BOOL IsDeathmatch( void ); - virtual BOOL IsCoOp( void ); - -// Client connection/disconnection - // If ClientConnected returns FALSE, the connection is rejected and the user is provided the reason specified in - // svRejectReason - // Only the client's name and remote address are provided to the dll for verification. - virtual BOOL ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ); - virtual void InitHUD( CBasePlayer *pl ); // the client dll is ready for updating - virtual void ClientDisconnected( edict_t *pClient ); - virtual void UpdateGameMode( CBasePlayer *pPlayer ); // the client needs to be informed of the current game mode - -// Client damage rules - virtual float FlPlayerFallDamage( CBasePlayer *pPlayer ); - virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker ); - -// Client spawn/respawn control - virtual void PlayerSpawn( CBasePlayer *pPlayer ); - virtual void PlayerThink( CBasePlayer *pPlayer ); - virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ); - virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer ); - virtual edict_t *GetPlayerSpawnSpot( CBasePlayer *pPlayer ); - - virtual BOOL AllowAutoTargetCrosshair( void ); - virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ); - -// Client kills/scoring - virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ); - virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); - virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); - -// Weapon retrieval - virtual void PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon ); - virtual BOOL CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon );// The player is touching an CBasePlayerItem, do I give it to him? - -// Weapon spawn/respawn control - virtual int WeaponShouldRespawn( CBasePlayerItem *pWeapon ); - virtual float FlWeaponRespawnTime( CBasePlayerItem *pWeapon ); - virtual float FlWeaponTryRespawn( CBasePlayerItem *pWeapon ); - virtual Vector VecWeaponRespawnSpot( CBasePlayerItem *pWeapon ); - -// Item retrieval - virtual BOOL CanHaveItem( CBasePlayer *pPlayer, CItem *pItem ); - virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem ); - -// Item spawn/respawn control - virtual int ItemShouldRespawn( CItem *pItem ); - virtual float FlItemRespawnTime( CItem *pItem ); - virtual Vector VecItemRespawnSpot( CItem *pItem ); - -// Ammo retrieval - virtual void PlayerGotAmmo( CBasePlayer *pPlayer, char *szName, int iCount ); - -// Ammo spawn/respawn control - virtual int AmmoShouldRespawn( CBasePlayerAmmo *pAmmo ); - virtual float FlAmmoRespawnTime( CBasePlayerAmmo *pAmmo ); - virtual Vector VecAmmoRespawnSpot( CBasePlayerAmmo *pAmmo ); - -// Healthcharger respawn control - virtual float FlHealthChargerRechargeTime( void ); - virtual float FlHEVChargerRechargeTime( void ); - -// What happens to a dead player's weapons - virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ); - -// What happens to a dead player's ammo - virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ); - -// Teamplay stuff - virtual const char *GetTeamID( CBaseEntity *pEntity ) {return "";} - virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); - - virtual BOOL PlayTextureSounds( void ) { return FALSE; } - virtual BOOL PlayFootstepSounds( CBasePlayer *pl, float fvol ); - -// Monsters - virtual BOOL FAllowMonsters( void ); - - // Immediately end a multiplayer game - virtual void EndMultiplayerGame( void ) { GoToIntermission(); } +class CItem; +class CGameRules { protected: - virtual void ChangeLevel( void ); - virtual void GoToIntermission( void ); - float m_flIntermissionEndTime; - BOOL m_iEndIntermissionButtonHit; - void SendMOTDToClient( edict_t *client ); + virtual ~CGameRules() {}; +public: + virtual void RefreshSkillData() = 0; // fill skill data struct with proper values + virtual void Think() = 0; // runs every server frame, should handle any timer tasks, periodic events, etc. + virtual BOOL IsAllowedToSpawn(CBaseEntity *pEntity) = 0; // Can this item spawn (eg monsters don't spawn in deathmatch). + + virtual BOOL FAllowFlashlight() = 0; // Are players allowed to switch on their flashlight? + virtual BOOL FShouldSwitchWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; // should the player switch to this weapon? + virtual BOOL GetNextBestWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon) = 0; // I can't use this weapon anymore, get me the next best one. + + // Functions to verify the single/multiplayer status of a game + virtual BOOL IsMultiplayer() = 0; // is this a multiplayer game? (either coop or deathmatch) + virtual BOOL IsDeathmatch() = 0; // is this a deathmatch game? + virtual BOOL IsTeamplay() = 0; // is this deathmatch game being played with team rules? + virtual BOOL IsCoOp() = 0; // is this a coop game? + virtual const char *GetGameDescription() = 0; // this is the game name that gets seen in the server browser + + // Client connection/disconnection + virtual BOOL ClientConnected(edict_t *pEntity, const char *pszName, const char *pszAddress, char *szRejectReason) = 0; // a client just connected to the server (player hasn't spawned yet) + virtual void InitHUD(CBasePlayer *pl) = 0; // the client dll is ready for updating + virtual void ClientDisconnected(edict_t *pClient) = 0; // a client just disconnected from the server + virtual void UpdateGameMode(CBasePlayer *pPlayer) = 0; // the client needs to be informed of the current game mode + + // Client damage rules + virtual float FlPlayerFallDamage(CBasePlayer *pPlayer) = 0; + virtual BOOL FPlayerCanTakeDamage(CBasePlayer *pPlayer, CBaseEntity *pAttacker) = 0; // can this player take damage from this attacker? + virtual BOOL ShouldAutoAim(CBasePlayer *pPlayer, edict_t *target) = 0; + + // Client spawn/respawn control + virtual void PlayerSpawn(CBasePlayer *pPlayer) = 0; // called by CBasePlayer::Spawn just before releasing player into the game + virtual void PlayerThink(CBasePlayer *pPlayer) = 0; // called by CBasePlayer::PreThink every frame, before physics are run and after keys are accepted + virtual BOOL FPlayerCanRespawn(CBasePlayer *pPlayer) = 0; // is this player allowed to respawn now? + virtual float FlPlayerSpawnTime(CBasePlayer *pPlayer) = 0; // When in the future will this player be able to spawn? + virtual edict_t *GetPlayerSpawnSpot(CBasePlayer *pPlayer) = 0; // Place this player on their spawnspot and face them the proper direction. + + virtual BOOL AllowAutoTargetCrosshair() = 0; + virtual BOOL ClientCommand_DeadOrAlive(CBasePlayer *pPlayer, const char *pcmd) = 0; + virtual BOOL ClientCommand(CBasePlayer *pPlayer, const char *pcmd) = 0; // handles the user commands; returns TRUE if command handled properly + virtual void ClientUserInfoChanged(CBasePlayer *pPlayer, char *infobuffer) = 0; // the player has changed userinfo; can change it now + + // Client kills/scoring + virtual int IPointsForKill(CBasePlayer *pAttacker, CBasePlayer *pKilled) = 0; // how many points do I award whoever kills this player? + virtual void PlayerKilled(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; // Called each time a player dies + virtual void DeathNotice(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor) = 0; // Call this from within a GameRules class to report an obituary. + + // Weapon retrieval + virtual BOOL CanHavePlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem) = 0; // The player is touching an CBasePlayerItem, do I give it to him? + virtual void PlayerGotWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; // Called each time a player picks up a weapon from the ground + + // Weapon spawn/respawn control + virtual int WeaponShouldRespawn(CBasePlayerItem *pWeapon) = 0; // should this weapon respawn? + virtual float FlWeaponRespawnTime(CBasePlayerItem *pWeapon) = 0; // when may this weapon respawn? + virtual float FlWeaponTryRespawn(CBasePlayerItem *pWeapon) = 0; // can i respawn now, and if not, when should i try again? + virtual Vector VecWeaponRespawnSpot(CBasePlayerItem *pWeapon) = 0; // where in the world should this weapon respawn? + + // Item retrieval + virtual BOOL CanHaveItem(CBasePlayer *pPlayer, CItem *pItem) = 0; // is this player allowed to take this item? + virtual void PlayerGotItem(CBasePlayer *pPlayer, CItem *pItem) = 0; // call each time a player picks up an item (battery, healthkit, longjump) + + // Item spawn/respawn control + virtual int ItemShouldRespawn(CItem *pItem) = 0; // Should this item respawn? + virtual float FlItemRespawnTime(CItem *pItem) = 0; // when may this item respawn? + virtual Vector VecItemRespawnSpot(CItem *pItem) = 0; // where in the world should this item respawn? + + // Ammo retrieval + virtual BOOL CanHaveAmmo(CBasePlayer *pPlayer, const char *pszAmmoName, int iMaxCarry) = 0; // can this player take more of this ammo? + virtual void PlayerGotAmmo(CBasePlayer *pPlayer, char *szName, int iCount) = 0; // called each time a player picks up some ammo in the world + + // Ammo spawn/respawn control + virtual int AmmoShouldRespawn(CBasePlayerAmmo *pAmmo) = 0; // should this ammo item respawn? + virtual float FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo) = 0; // when should this ammo item respawn? + virtual Vector VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo) = 0; // where in the world should this ammo item respawn? + + // Healthcharger respawn control + virtual float FlHealthChargerRechargeTime() = 0; // how long until a depleted HealthCharger recharges itself? + virtual float FlHEVChargerRechargeTime() = 0; // how long until a depleted HealthCharger recharges itself? + + // What happens to a dead player's weapons + virtual int DeadPlayerWeapons(CBasePlayer *pPlayer) = 0; // what do I do with a player's weapons when he's killed? + + // What happens to a dead player's ammo + virtual int DeadPlayerAmmo(CBasePlayer *pPlayer) = 0; // Do I drop ammo when the player dies? How much? + + // Teamplay stuff + virtual const char *GetTeamID(CBaseEntity *pEntity) = 0; // what team is this entity on? + virtual int PlayerRelationship(CBasePlayer *pPlayer, CBaseEntity *pTarget) = 0; // What is the player's relationship with this entity? + virtual int GetTeamIndex(const char *pTeamName) = 0; + virtual const char *GetIndexedTeamName(int teamIndex) = 0; + virtual BOOL IsValidTeam(const char *pTeamName) = 0; + virtual void ChangePlayerTeam(CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib) = 0; + virtual const char *SetDefaultPlayerTeam(CBasePlayer *pPlayer) = 0; + + // Sounds + virtual BOOL PlayTextureSounds() = 0; + + // Monsters + virtual BOOL FAllowMonsters() = 0; // are monsters allowed + + // Immediately end a multiplayer game + virtual void EndMultiplayerGame() = 0; + + // Stuff that is shared between client and server. + virtual BOOL IsFreezePeriod() = 0; + virtual void ServerDeactivate() = 0; + virtual void CheckMapConditions() = 0; + + // inline function's + inline bool IsGameOver() const { return m_bGameOver; } + inline void SetGameOver() { m_bGameOver = true; } + +public: + BOOL m_bFreezePeriod; // TRUE at beginning of round, set to FALSE when the period expires + BOOL m_bBombDropped; + + // custom + char *m_GameDesc; + bool m_bGameOver; // intermission or finale (deprecated name g_fGameOver) }; -extern DLL_GLOBAL CGameRules* g_pGameRules; +// CHalfLifeRules - rules for the single player Half-Life game. +class CHalfLifeRules: public CGameRules { +protected: + virtual ~CHalfLifeRules() {}; +public: + virtual void Think() = 0; + virtual BOOL IsAllowedToSpawn(CBaseEntity *pEntity) = 0; + virtual BOOL FAllowFlashlight() = 0; + + virtual BOOL FShouldSwitchWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; + virtual BOOL GetNextBestWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon) = 0; + + // Functions to verify the single/multiplayer status of a game + virtual BOOL IsMultiplayer() = 0; + virtual BOOL IsDeathmatch() = 0; + virtual BOOL IsCoOp() = 0; + + // Client connection/disconnection + virtual BOOL ClientConnected(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) = 0; + virtual void InitHUD(CBasePlayer *pl) = 0; // the client dll is ready for updating + virtual void ClientDisconnected(edict_t *pClient) = 0; + + // Client damage rules + virtual float FlPlayerFallDamage(CBasePlayer *pPlayer) = 0; + + // Client spawn/respawn control + virtual void PlayerSpawn(CBasePlayer *pPlayer) = 0; + virtual void PlayerThink(CBasePlayer *pPlayer) = 0; + virtual BOOL FPlayerCanRespawn(CBasePlayer *pPlayer) = 0; + virtual float FlPlayerSpawnTime(CBasePlayer *pPlayer) = 0; + virtual edict_t *GetPlayerSpawnSpot(CBasePlayer *pPlayer) = 0; + + virtual BOOL AllowAutoTargetCrosshair() = 0; + + // Client kills/scoring + virtual int IPointsForKill(CBasePlayer *pAttacker, CBasePlayer *pKilled) = 0; + virtual void PlayerKilled(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; + virtual void DeathNotice(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; + + // Weapon retrieval + virtual void PlayerGotWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; + + // Weapon spawn/respawn control + virtual int WeaponShouldRespawn(CBasePlayerItem *pWeapon) = 0; + virtual float FlWeaponRespawnTime(CBasePlayerItem *pWeapon) = 0; + virtual float FlWeaponTryRespawn(CBasePlayerItem *pWeapon) = 0; + virtual Vector VecWeaponRespawnSpot(CBasePlayerItem *pWeapon) = 0; + + // Item retrieval + virtual BOOL CanHaveItem(CBasePlayer *pPlayer, CItem *pItem) = 0; + virtual void PlayerGotItem(CBasePlayer *pPlayer, CItem *pItem) = 0; + + // Item spawn/respawn control + virtual int ItemShouldRespawn(CItem *pItem) = 0; + virtual float FlItemRespawnTime(CItem *pItem) = 0; + virtual Vector VecItemRespawnSpot(CItem *pItem) = 0; + + // Ammo retrieval + virtual void PlayerGotAmmo(CBasePlayer *pPlayer, char *szName, int iCount) = 0; + + // Ammo spawn/respawn control + virtual int AmmoShouldRespawn(CBasePlayerAmmo *pAmmo) = 0; + virtual float FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo) = 0; + virtual Vector VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo) = 0; + + // Healthcharger respawn control + virtual float FlHealthChargerRechargeTime() = 0; + + // What happens to a dead player's weapons + virtual int DeadPlayerWeapons(CBasePlayer *pPlayer) = 0; + + // What happens to a dead player's ammo + virtual int DeadPlayerAmmo(CBasePlayer *pPlayer) = 0; + + // Teamplay stuff + virtual const char *GetTeamID(CBaseEntity *pEntity) = 0; + virtual int PlayerRelationship(CBasePlayer *pPlayer, CBaseEntity *pTarget) = 0; + + // Monsters + virtual BOOL FAllowMonsters() = 0; +}; + +// CHalfLifeMultiplay - rules for the basic half life multiplayer competition +class CHalfLifeMultiplay: public CGameRules { +protected: + virtual ~CHalfLifeMultiplay() {}; +public: + virtual void RefreshSkillData() = 0; + virtual void Think() = 0; + virtual BOOL IsAllowedToSpawn(CBaseEntity *pEntity) = 0; + virtual BOOL FAllowFlashlight() = 0; + + virtual BOOL FShouldSwitchWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; + virtual BOOL GetNextBestWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon) = 0; + + virtual BOOL IsMultiplayer() = 0; + virtual BOOL IsDeathmatch() = 0; + virtual BOOL IsCoOp() = 0; + + // Client connection/disconnection + // If ClientConnected returns FALSE, the connection is rejected and the user is provided the reason specified in szRejectReason + // Only the client's name and remote address are provided to the dll for verification. + virtual BOOL ClientConnected(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) = 0; + virtual void InitHUD(CBasePlayer *pl) = 0; + virtual void ClientDisconnected(edict_t *pClient) = 0; + virtual void UpdateGameMode(CBasePlayer *pPlayer) = 0; + + // Client damage rules + virtual float FlPlayerFallDamage(CBasePlayer *pPlayer) = 0; + virtual BOOL FPlayerCanTakeDamage(CBasePlayer *pPlayer, CBaseEntity *pAttacker) = 0; + + // Client spawn/respawn control + virtual void PlayerSpawn(CBasePlayer *pPlayer) = 0; + virtual void PlayerThink(CBasePlayer *pPlayer) = 0; + virtual BOOL FPlayerCanRespawn(CBasePlayer *pPlayer) = 0; + virtual float FlPlayerSpawnTime(CBasePlayer *pPlayer) = 0; + virtual edict_t *GetPlayerSpawnSpot(CBasePlayer *pPlayer) = 0; + + virtual BOOL AllowAutoTargetCrosshair() = 0; + + virtual BOOL ClientCommand_DeadOrAlive(CBasePlayer *pPlayer, const char *pcmd) = 0; + virtual BOOL ClientCommand(CBasePlayer *pPlayer, const char *pcmd) = 0; + virtual void ClientUserInfoChanged(CBasePlayer *pPlayer, char *infobuffer) = 0; + + // Client kills/scoring + virtual int IPointsForKill(CBasePlayer *pAttacker, CBasePlayer *pKilled) = 0; + virtual void PlayerKilled(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; + virtual void DeathNotice(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; + + // Weapon retrieval + virtual BOOL CanHavePlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; + virtual void PlayerGotWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pWeapon) = 0; + + // Weapon spawn/respawn control + virtual int WeaponShouldRespawn(CBasePlayerItem *pWeapon) = 0; + virtual float FlWeaponRespawnTime(CBasePlayerItem *pWeapon) = 0; + virtual float FlWeaponTryRespawn(CBasePlayerItem *pWeapon) = 0; + virtual Vector VecWeaponRespawnSpot(CBasePlayerItem *pWeapon) = 0; + + // Item retrieval + virtual BOOL CanHaveItem(CBasePlayer *pPlayer, CItem *pItem) = 0; + virtual void PlayerGotItem(CBasePlayer *pPlayer, CItem *pItem) = 0; + + // Item spawn/respawn control + virtual int ItemShouldRespawn(CItem *pItem) = 0; + virtual float FlItemRespawnTime(CItem *pItem) = 0; + virtual Vector VecItemRespawnSpot(CItem *pItem) = 0; + + // Ammo retrieval + virtual void PlayerGotAmmo(CBasePlayer *pPlayer, char *szName, int iCount) = 0; + + // Ammo spawn/respawn control + virtual int AmmoShouldRespawn(CBasePlayerAmmo *pAmmo) = 0; + virtual float FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo) = 0; + virtual Vector VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo) = 0; + + // Healthcharger respawn control + virtual float FlHealthChargerRechargeTime() = 0; + virtual float FlHEVChargerRechargeTime() = 0; + + // What happens to a dead player's weapons + virtual int DeadPlayerWeapons(CBasePlayer *pPlayer) = 0; + + // What happens to a dead player's ammo + virtual int DeadPlayerAmmo(CBasePlayer *pPlayer) = 0; + + // Teamplay stuff + virtual const char *GetTeamID(CBaseEntity *pEntity) = 0; + virtual int PlayerRelationship(CBasePlayer *pPlayer, CBaseEntity *pTarget) = 0; + + virtual BOOL PlayTextureSounds() = 0; + + // Monsters + virtual BOOL FAllowMonsters() = 0; + + // Immediately end a multiplayer game + virtual void EndMultiplayerGame() = 0; + virtual void ServerDeactivate() = 0; + virtual void CheckMapConditions() = 0; + + // Recreate all the map entities from the map data (preserving their indices), + // then remove everything else except the players. + // Also get rid of all world decals. + virtual void CleanUpMap() = 0; + + virtual void RestartRound() = 0; + + // check if the scenario has been won/lost + virtual void CheckWinConditions() = 0; + virtual void RemoveGuns() = 0; + virtual void GiveC4() = 0; + virtual void ChangeLevel() = 0; + virtual void GoToIntermission() = 0; + + // Setup counts for m_iNumTerrorist, m_iNumCT, m_iNumSpawnableTerrorist, m_iNumSpawnableCT, etc. + virtual void InitializePlayerCounts(int &NumAliveTerrorist, int &NumAliveCT, int &NumDeadTerrorist, int &NumDeadCT) = 0; + + virtual void BalanceTeams() = 0; + virtual void SwapAllPlayers() = 0; + virtual void UpdateTeamScores() = 0; + virtual void EndRoundMessage(const char *sentence, int event) = 0; + virtual void SetAccountRules(RewardRules rules, int amount) = 0; + virtual RewardAccount GetAccountRules(RewardRules rules) const = 0; + + // BOMB MAP FUNCTIONS + virtual BOOL IsThereABomber() = 0; + virtual BOOL IsThereABomb() = 0; + virtual TeamName SelectDefaultTeam() = 0; + + virtual bool HasRoundTimeExpired() = 0; + virtual bool IsBombPlanted() = 0; + +public: + bool ShouldSkipShowMenu() const { return m_bSkipShowMenu; } + void MarkShowMenuSkipped() { m_bSkipShowMenu = false; } + + bool ShouldSkipSpawn() const { return m_bSkipSpawn; } + void MarkSpawnSkipped() { m_bSkipSpawn = false; } + + float GetRoundRemainingTime() const { return m_iRoundTimeSecs - gpGlobals->time + m_fRoundStartTime; } + float GetRoundRemainingTimeReal() const { return m_iRoundTimeSecs - gpGlobals->time + m_fRoundStartTimeReal; } + float GetTimeLeft() const { return m_flTimeLimit - gpGlobals->time; } + bool IsMatchStarted() { return (m_flRestartRoundTime != 0.0f || m_fCareerRoundMenuTime != 0.0f || m_fCareerMatchMenuTime != 0.0f); } + + void TerminateRound(float tmDelay, int iWinStatus); + +public: + CVoiceGameMgr m_VoiceGameMgr; + float m_flRestartRoundTime; // The global time when the round is supposed to end, if this is not 0 (deprecated name m_fTeamCount) + float m_flCheckWinConditions; + float m_fRoundStartTime; // Time round has started (deprecated name m_fRoundCount) + int m_iRoundTime; // (From mp_roundtime) - How many seconds long this round is. + int m_iRoundTimeSecs; + int m_iIntroRoundTime; // (From mp_freezetime) - How many seconds long the intro round (when players are frozen) is. + float m_fRoundStartTimeReal; // The global time when the intro round ends and the real one starts + // wrote the original "m_flRoundTime" comment for this variable). + int m_iAccountTerrorist; + int m_iAccountCT; + int m_iNumTerrorist; // The number of terrorists on the team (this is generated at the end of a round) + int m_iNumCT; // The number of CTs on the team (this is generated at the end of a round) + int m_iNumSpawnableTerrorist; + int m_iNumSpawnableCT; + int m_iSpawnPointCount_Terrorist; // Number of Terrorist spawn points + int m_iSpawnPointCount_CT; // Number of CT spawn points + int m_iHostagesRescued; + int m_iHostagesTouched; + int m_iRoundWinStatus; // 1 == CT's won last round, 2 == Terrorists did, 3 == Draw, no winner + + short m_iNumCTWins; + short m_iNumTerroristWins; + + bool m_bTargetBombed; // whether or not the bomb has been bombed + bool m_bBombDefused; // whether or not the bomb has been defused + + bool m_bMapHasBombTarget; + bool m_bMapHasBombZone; + bool m_bMapHasBuyZone; + bool m_bMapHasRescueZone; + bool m_bMapHasEscapeZone; + + BOOL m_bMapHasVIPSafetyZone; // TRUE = has VIP safety zone, FALSE = does not have VIP safetyzone + BOOL m_bMapHasCameras; + int m_iC4Timer; + int m_iC4Guy; // The current Terrorist who has the C4. + int m_iLoserBonus; // the amount of money the losing team gets. This scales up as they lose more rounds in a row + int m_iNumConsecutiveCTLoses; // the number of rounds the CTs have lost in a row. + int m_iNumConsecutiveTerroristLoses; // the number of rounds the Terrorists have lost in a row. + + float m_fMaxIdlePeriod; // For the idle kick functionality. This is tha max amount of time that the player has to be idle before being kicked + + int m_iLimitTeams; + bool m_bLevelInitialized; + bool m_bRoundTerminating; + bool m_bCompleteReset; // Set to TRUE to have the scores reset next time round restarts + float m_flRequiredEscapeRatio; + int m_iNumEscapers; + int m_iHaveEscaped; + bool m_bCTCantBuy; + bool m_bTCantBuy; // Who can and can't buy. + float m_flBombRadius; + int m_iConsecutiveVIP; + int m_iTotalGunCount; + int m_iTotalGrenadeCount; + int m_iTotalArmourCount; + int m_iUnBalancedRounds; // keeps track of the # of consecutive rounds that have gone by where one team outnumbers the other team by more than 2 + int m_iNumEscapeRounds; // keeps track of the # of consecutive rounds of escape played.. Teams will be swapped after 8 rounds + int m_iMapVotes[MAX_VOTE_MAPS]; + int m_iLastPick; + int m_iMaxMapTime; + int m_iMaxRounds; + int m_iTotalRoundsPlayed; + int m_iMaxRoundsWon; + int m_iStoredSpectValue; + float m_flForceCameraValue; + float m_flForceChaseCamValue; + float m_flFadeToBlackValue; + CBasePlayer *m_pVIP; + CBasePlayer *m_pVIPQueue[MAX_VIP_QUEUES]; + float m_flIntermissionEndTime; + float m_flIntermissionStartTime; + BOOL m_iEndIntermissionButtonHit; + float m_tmNextPeriodicThink; + bool m_bGameStarted; // TRUE = the game commencing when there is at least one CT and T, FALSE = scoring will not start until both teams have players (deprecated name m_bFirstConnected) + bool m_bInCareerGame; + float m_fCareerRoundMenuTime; + int m_iCareerMatchWins; + int m_iRoundWinDifference; + float m_fCareerMatchMenuTime; + bool m_bSkipSpawn; + + // custom + bool m_bSkipShowMenu; + bool m_bNeededPlayers; + float m_flEscapeRatio; + float m_flTimeLimit; + float m_flGameStartTime; +}; + +typedef struct mapcycle_item_s +{ + struct mapcycle_item_s *next; + char mapname[32]; + int minplayers; + int maxplayers; + char rulebuffer[MAX_RULE_BUFFER]; + +} mapcycle_item_t; + +typedef struct mapcycle_s +{ + struct mapcycle_item_s *items; + struct mapcycle_item_s *next_item; + +} mapcycle_t; + +class CCStrikeGameMgrHelper: public IVoiceGameMgrHelper { +public: + virtual bool CanPlayerHearPlayer(CBasePlayer *pListener, CBasePlayer *pSender) = 0; +}; + +extern CGameRules *g_pGameRules; + +// Gets us at the CS game rules +inline CHalfLifeMultiplay *CSGameRules() +{ + return static_cast(g_pGameRules); +} + +inline void CHalfLifeMultiplay::TerminateRound(float tmDelay, int iWinStatus) +{ + m_iRoundWinStatus = iWinStatus; + m_flRestartRoundTime = gpGlobals->time + tmDelay; + m_bRoundTerminating = true; +} diff --git a/dlls/h_battery.h b/dlls/h_battery.h new file mode 100644 index 0000000..e523dd6 --- /dev/null +++ b/dlls/h_battery.h @@ -0,0 +1,45 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CRecharge: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float m_flNextCharge; + int m_iReactivate; + int m_iJuice; + int m_iOn; + float m_flSoundTime; +}; diff --git a/dlls/h_cycler.h b/dlls/h_cycler.h new file mode 100644 index 0000000..5f9ab00 --- /dev/null +++ b/dlls/h_cycler.h @@ -0,0 +1,104 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CCycler: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + + // Don't treat as a live target + virtual BOOL IsAlive() = 0; + virtual void Think() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int m_animate; +}; + +// we should get rid of all the other cyclers and replace them with this. +class CGenericCycler: public CCycler { +public: + virtual void Spawn() = 0; +}; + +// Probe droid imported for tech demo compatibility +class CCyclerProbe: public CCycler { +public: + virtual void Spawn() = 0; +}; + +class CCyclerSprite: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual void Think() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + inline int ShouldAnimate() { return (m_animate && m_maxFrame > 1.0f); } +public: + int m_animate; + float m_lastTime; + float m_maxFrame; + int m_renderfx; + int m_rendermode; + float m_renderamt; + vec3_t m_rendercolor; +}; + +class CWeaponCycler: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal = 0) = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; +public: + int m_iszModel; + int m_iModel; +}; + +// Flaming Wreakage +class CWreckage: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Think() = 0; +public: + int m_flStartTime; +}; diff --git a/dlls/healthkit.h b/dlls/healthkit.h new file mode 100644 index 0000000..eb4e63d --- /dev/null +++ b/dlls/healthkit.h @@ -0,0 +1,52 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CHealthKit: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CWallHealth: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float m_flNextCharge; + int m_iReactivate; + int m_iJuice; + int m_iOn; + float m_flSoundTime; +}; diff --git a/dlls/hintmessage.h b/dlls/hintmessage.h new file mode 100644 index 0000000..ce63fde --- /dev/null +++ b/dlls/hintmessage.h @@ -0,0 +1,81 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "utlvector.h" + +#define DHF_ROUND_STARTED (1<<1) +#define DHF_HOSTAGE_SEEN_FAR (1<<2) +#define DHF_HOSTAGE_SEEN_NEAR (1<<3) +#define DHF_HOSTAGE_USED (1<<4) +#define DHF_HOSTAGE_INJURED (1<<5) +#define DHF_HOSTAGE_KILLED (1<<6) +#define DHF_FRIEND_SEEN (1<<7) +#define DHF_ENEMY_SEEN (1<<8) +#define DHF_FRIEND_INJURED (1<<9) +#define DHF_FRIEND_KILLED (1<<10) +#define DHF_ENEMY_KILLED (1<<11) +#define DHF_BOMB_RETRIEVED (1<<12) +#define DHF_AMMO_EXHAUSTED (1<<15) +#define DHF_IN_TARGET_ZONE (1<<16) +#define DHF_IN_RESCUE_ZONE (1<<17) +#define DHF_IN_ESCAPE_ZONE (1<<18) +#define DHF_IN_VIPSAFETY_ZONE (1<<19) +#define DHF_NIGHTVISION (1<<20) +#define DHF_HOSTAGE_CTMOVE (1<<21) +#define DHF_SPEC_DUCK (1<<22) + +#define DHM_ROUND_CLEAR (DHF_ROUND_STARTED | DHF_HOSTAGE_KILLED | DHF_FRIEND_KILLED | DHF_BOMB_RETRIEVED) +#define DHM_CONNECT_CLEAR (DHF_HOSTAGE_SEEN_FAR | DHF_HOSTAGE_SEEN_NEAR | DHF_HOSTAGE_USED | DHF_HOSTAGE_INJURED | DHF_FRIEND_SEEN | DHF_ENEMY_SEEN | DHF_FRIEND_INJURED | DHF_ENEMY_KILLED | DHF_AMMO_EXHAUSTED | DHF_IN_TARGET_ZONE | DHF_IN_RESCUE_ZONE | DHF_IN_ESCAPE_ZONE | DHF_IN_VIPSAFETY_ZONE | DHF_HOSTAGE_CTMOVE | DHF_SPEC_DUCK) + +class CHintMessage { +public: + CHintMessage(const char *hintString, bool isHint, CUtlVector *args, float duration); + ~CHintMessage(); +public: + float GetDuration() const { return m_duration; } + void Send(CBaseEntity *client); + +private: + const char *m_hintString; + bool m_isHint; + CUtlVector m_args; + float m_duration; +}; + +class CHintMessageQueue { +public: + void Reset(); + void Update(CBaseEntity *client); + bool AddMessage(const char *message, float duration, bool isHint, CUtlVector *args); + bool IsEmpty() const { return m_messages.Count() == 0; } + +private: + float m_tmMessageEnd; + CUtlVector m_messages; +}; diff --git a/dlls/hornet.h b/dlls/hornet.h deleted file mode 100644 index 98d1710..0000000 --- a/dlls/hornet.h +++ /dev/null @@ -1,58 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -//========================================================= -// Hornets -//========================================================= - -//========================================================= -// Hornet Defines -//========================================================= -#define HORNET_TYPE_RED 0 -#define HORNET_TYPE_ORANGE 1 -#define HORNET_RED_SPEED (float)600 -#define HORNET_ORANGE_SPEED (float)800 -#define HORNET_BUZZ_VOLUME (float)0.8 - -extern int iHornetPuff; - -//========================================================= -// Hornet - this is the projectile that the Alien Grunt fires. -//========================================================= -class CHornet : public CBaseMonster -{ -public: - void Spawn( void ); - void Precache( void ); - int Classify ( void ); - int IRelationship ( CBaseEntity *pTarget ); - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - static TYPEDESCRIPTION m_SaveData[]; - - void IgniteTrail( void ); - void EXPORT StartTrack ( void ); - void EXPORT StartDart ( void ); - void EXPORT TrackTarget ( void ); - void EXPORT TrackTouch ( CBaseEntity *pOther ); - void EXPORT DartTouch( CBaseEntity *pOther ); - void EXPORT DieTouch ( CBaseEntity *pOther ); - - int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ); - - float m_flStopAttack; - int m_iHornetType; - float m_flFlySpeed; -}; - diff --git a/dlls/hostage/hostage.h b/dlls/hostage/hostage.h new file mode 100644 index 0000000..a0be24c --- /dev/null +++ b/dlls/hostage/hostage.h @@ -0,0 +1,233 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define MAX_NODES 100 +#define MAX_HOSTAGES 12 +#define MAX_HOSTAGES_NAV 20 + +#define HOSTAGE_STEPSIZE 26.0f +#define HOSTAGE_STEPSIZE_DEFAULT 18.0f + +#define VEC_HOSTAGE_VIEW Vector(0, 0, 12) +#define VEC_HOSTAGE_HULL_MIN Vector(-10, -10, 0) +#define VEC_HOSTAGE_HULL_MAX Vector(10, 10, 62) + +#define VEC_HOSTAGE_CROUCH Vector(10, 10, 30) +#define RESCUE_HOSTAGES_RADIUS 256.0f // rescue zones from legacy info_* + +class CHostage; +class CLocalNav; +class CHostageImprov; +class CHostageManager; + +enum HostageChatterType +{ + HOSTAGE_CHATTER_START_FOLLOW = 0, + HOSTAGE_CHATTER_STOP_FOLLOW, + HOSTAGE_CHATTER_INTIMIDATED, + HOSTAGE_CHATTER_PAIN, + HOSTAGE_CHATTER_SCARED_OF_GUNFIRE, + HOSTAGE_CHATTER_SCARED_OF_MURDER, + HOSTAGE_CHATTER_LOOK_OUT, + HOSTAGE_CHATTER_PLEASE_RESCUE_ME, + HOSTAGE_CHATTER_SEE_RESCUE_ZONE, + HOSTAGE_CHATTER_IMPATIENT_FOR_RESCUE, + HOSTAGE_CHATTER_CTS_WIN , + HOSTAGE_CHATTER_TERRORISTS_WIN, + HOSTAGE_CHATTER_RESCUED, + HOSTAGE_CHATTER_WARN_NEARBY, + HOSTAGE_CHATTER_WARN_SPOTTED, + HOSTAGE_CHATTER_CALL_TO_RESCUER, + HOSTAGE_CHATTER_RETREAT, + HOSTAGE_CHATTER_COUGH, + HOSTAGE_CHATTER_BLINDED, + HOSTAGE_CHATTER_SAW_HE_GRENADE, + HOSTAGE_CHATTER_DEATH_CRY, + NUM_HOSTAGE_CHATTER_TYPES, +}; + +// Improved the hostages from CZero +#include "hostage/hostage_improv.h" + +extern CHostageManager *g_pHostages; +extern int g_iHostageNumber; + +// A Counter-Strike Hostage Simple +class CHostage: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int ObjectCaps() = 0; // make hostage "useable" + virtual int Classify() = 0; + virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual int BloodColor() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int GetActivity() { return m_Activity; } + + // queries + bool IsFollowingSomeone() { return IsFollowing(); } + CBaseEntity *GetLeader() // return our leader, or NULL + { + if (m_improv != NULL) + { + return m_improv->GetFollowLeader(); + } + + return m_hTargetEnt; + } + bool IsFollowing(const CBaseEntity *entity = NULL) + { + if (m_improv != NULL) + { + return m_improv->IsFollowing(); + } + + if (entity == NULL && m_hTargetEnt == NULL || (entity != NULL && m_hTargetEnt != entity)) + return false; + + if (m_State != FOLLOW) + return false; + + return true; + } + bool IsValid() const { return (pev->takedamage == DAMAGE_YES); } + bool IsDead() const { return (pev->deadflag == DEAD_DEAD); } + bool IsAtHome() const { return (pev->origin - m_vStart).IsLengthGreaterThan(20) != true; } + const Vector *GetHomePosition() const { return &m_vStart; } +public: + int m_Activity; + BOOL m_bTouched; + BOOL m_bRescueMe; + float m_flFlinchTime; + float m_flNextChange; + float m_flMarkPosition; + int m_iModel; + int m_iSkin; + float m_flNextRadarTime; + enum state { FOLLOW, STAND, DUCK, SCARED, IDLE, FOLLOWPATH } + m_State; + Vector m_vStart; + Vector m_vStartAngles; + Vector m_vPathToFollow[20]; + int m_iWaypoint; + CBasePlayer *m_target; + CLocalNav *m_LocalNav; + int nTargetNode; + Vector vecNodes[MAX_NODES]; + EHANDLE m_hStoppedTargetEnt; + float m_flNextFullThink; + float m_flPathCheckInterval; + float m_flLastPathCheck; + int m_nPathNodes; + BOOL m_fHasPath; + float m_flPathAcquired; + Vector m_vOldPos; + int m_iHostageIndex; + BOOL m_bStuck; + float m_flStuckTime; + CHostageImprov *m_improv; + + enum ModelType { REGULAR_GUY, OLD_GUY, BLACK_GUY, GOOFY_GUY } + m_whichModel; +}; + +class SimpleChatter { +public: + struct SoundFile + { + char *filename; + float duration; + }; + + struct ChatterSet + { + SoundFile file[32]; + int count; + int index; + bool needsShuffle; + }; +private: + ChatterSet m_chatter[21]; +}; + +class CHostageManager { +public: + SimpleChatter *GetChatter() + { + return &m_chatter; + } + // Iterate over all active hostages in the game, invoking functor on each. + // If functor returns false, stop iteration and return false. + template + inline bool ForEachHostage(Functor &func) const + { + for (int i = 0; i < m_hostageCount; i++) + { + CHostage *hostage = m_hostage[i]; + + if (hostage == NULL || hostage->pev->deadflag == DEAD_DEAD) + continue; + + if (func(hostage) == false) + return false; + } + + return true; + } + inline CHostage *GetClosestHostage(const Vector &pos, float *resultRange = NULL) + { + float range; + float closeRange = 1e8f; + CHostage *close = NULL; + + for (int i = 0; i < m_hostageCount; i++) + { + range = (m_hostage[i]->pev->origin - pos).Length(); + + if (range < closeRange) + { + closeRange = range; + close = m_hostage[i]; + } + } + + if (resultRange) + *resultRange = closeRange; + + return close; + } + +private: + CHostage *m_hostage[MAX_HOSTAGES]; + int m_hostageCount; + SimpleChatter m_chatter; +}; diff --git a/dlls/hostage/hostage_improv.h b/dlls/hostage/hostage_improv.h new file mode 100644 index 0000000..9ec69a7 --- /dev/null +++ b/dlls/hostage/hostage_improv.h @@ -0,0 +1,331 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "hostage/hostage.h" +#include "hostage/hostage_states.h" + +class CHostage; +enum HostageChatterType; + +// A Counter-Strike Hostage improved +class CHostageImprov: public CImprov { +public: + // invoked when an improv reaches its MoveTo goal + virtual void OnMoveToSuccess(const Vector &goal) = 0; + + // invoked when an improv fails to reach a MoveTo goal + virtual void OnMoveToFailure(const Vector &goal, MoveToFailureType reason) = 0; + virtual void OnInjury(float amount) = 0; + virtual bool IsAlive() const = 0; + virtual void MoveTo(const Vector &goal) = 0; + virtual void LookAt(const Vector &target) = 0; + virtual void ClearLookAt() = 0; + virtual void FaceTo(const Vector &goal) = 0; + virtual void ClearFaceTo() = 0; + virtual bool IsAtMoveGoal(float error = 20.0f) const = 0; + virtual bool HasLookAt() const = 0; + virtual bool HasFaceTo() const = 0; + virtual bool IsAtFaceGoal() const = 0; + virtual bool IsFriendInTheWay(const Vector &goalPos) const = 0; + virtual bool IsFriendInTheWay(CBaseEntity *myFriend, const Vector &goalPos) const = 0; + virtual void MoveForward() = 0; + virtual void MoveBackward() = 0; + virtual void StrafeLeft() = 0; + virtual void StrafeRight() = 0; + + #define HOSTAGE_MUST_JUMP true + virtual bool Jump() = 0; + + virtual void Crouch() = 0; + virtual void StandUp() = 0; + virtual void TrackPath(const Vector &pathGoal, float deltaT) = 0; // move along path by following "pathGoal" + virtual void StartLadder(const CNavLadder *ladder, NavTraverseType how, const Vector *approachPos, const Vector *departPos) = 0; + virtual bool TraverseLadder(const CNavLadder *ladder, NavTraverseType how, const Vector *approachPos, const Vector *departPos, float deltaT) = 0; + virtual bool GetSimpleGroundHeightWithFloor(const Vector *pos, float *height, Vector *normal = NULL) = 0; + virtual void Run() = 0; + virtual void Walk() = 0; + virtual void Stop() = 0; + virtual float GetMoveAngle() const = 0; + virtual float GetFaceAngle() const = 0; + virtual const Vector &GetFeet() const = 0; + virtual const Vector &GetCentroid() const = 0; + virtual const Vector &GetEyes() const = 0; + virtual bool IsRunning() const = 0; + virtual bool IsWalking() const = 0; + virtual bool IsStopped() const = 0; + virtual bool IsCrouching() const = 0; + virtual bool IsJumping() const = 0; + virtual bool IsUsingLadder() const = 0; + virtual bool IsOnGround() const = 0; + virtual bool IsMoving() const = 0; + virtual bool CanRun() const = 0; + virtual bool CanCrouch() const = 0; + virtual bool CanJump() const = 0; + virtual bool IsVisible(const Vector &pos, bool testFOV = false) const = 0; // return true if hostage can see position + virtual bool IsPlayerLookingAtMe(CBasePlayer *other, float cosTolerance = 0.95f) const = 0; + virtual CBasePlayer *IsAnyPlayerLookingAtMe(int team = 0, float cosTolerance = 0.95f) const = 0; + virtual CBasePlayer *GetClosestPlayerByTravelDistance(int team = 0, float *range = NULL) const = 0; + virtual CNavArea *GetLastKnownArea() const = 0; + virtual void OnUpdate(float deltaT) = 0; + virtual void OnUpkeep(float deltaT) = 0; + virtual void OnReset() = 0; + virtual void OnGameEvent(GameEventType event, CBaseEntity *entity = NULL, CBaseEntity *other = NULL) = 0; + virtual void OnTouch(CBaseEntity *other) = 0; // in contact with "other" +public: + enum MoveType { Stopped, Walking, Running }; + enum ScareType { NERVOUS, SCARED, TERRIFIED }; + + const Vector &GetKnownGoodPosition() const { return m_knownGoodPos; } + void ApplyForce(Vector force) { m_vel.x += force.x; m_vel.y += force.y; } // apply a force to the hostage + const Vector GetActualVelocity() const { return m_actualVel; } + void SetMoveLimit(MoveType limit) { m_moveLimit = limit; } + MoveType GetMoveLimit() const { return m_moveLimit; } + CNavPath *GetPath() { return &m_path; } + + // hostage states + // stand idle + void Idle() { m_behavior.SetState(&m_idleState); } + bool IsIdle() const { return m_behavior.IsState(&m_idleState); } + + // begin following "leader" + void Follow(CBasePlayer *leader) { m_followState.SetLeader(leader); m_behavior.SetState(&m_followState); } + bool IsFollowing(const CBaseEntity *leader = NULL) const { return m_behavior.IsState(&m_followState); } + + // Escape + void Escape() { m_behavior.SetState(&m_escapeState); } + bool IsEscaping() const { return m_behavior.IsState(&m_escapeState); } + + // Retreat + void Retreat() { m_behavior.SetState(&m_retreatState); } + bool IsRetreating() const { return m_behavior.IsState(&m_retreatState); } + + CBaseEntity *GetFollowLeader() const { return m_followState.GetLeader(); } + ScareType GetScareIntensity() const { return m_scareIntensity; } + bool IsIgnoringTerrorists() const { return m_ignoreTerroristTimer.IsElapsed(); } + float GetAggression() const { return m_aggression; } + bool IsTalking() const { return m_talkingTimer.IsElapsed(); } + CHostage *GetEntity() const { return m_hostage; } + void SetMoveAngle(float angle) { m_moveAngle = angle; } +public: + CountdownTimer m_coughTimer; + CountdownTimer m_grenadeTimer; +private: + CHostage *m_hostage; + CNavArea *m_lastKnownArea; // last area we were in + mutable Vector m_centroid; + mutable Vector m_eye; + HostageStateMachine m_behavior; + HostageIdleState m_idleState; + HostageEscapeState m_escapeState; + HostageRetreatState m_retreatState; + HostageFollowState m_followState; + HostageAnimateState m_animateState; + bool m_didFidget; + float m_aggression; + IntervalTimer m_lastSawCT; + IntervalTimer m_lastSawT; + CountdownTimer m_checkNearbyTerroristTimer; + bool m_isTerroristNearby; + CountdownTimer m_nearbyTerroristTimer; + CountdownTimer m_scaredTimer; + ScareType m_scareIntensity; + CountdownTimer m_ignoreTerroristTimer; + CountdownTimer m_blinkTimer; + char m_blinkCounter; + IntervalTimer m_lastInjuryTimer; + IntervalTimer m_lastNoiseTimer; + mutable CountdownTimer m_avoidFriendTimer; + mutable bool m_isFriendInTheWay; + CountdownTimer m_chatterTimer; + bool m_isDelayedChatterPending; + CountdownTimer m_delayedChatterTimer; + HostageChatterType m_delayedChatterType; + bool m_delayedChatterMustSpeak; + CountdownTimer m_talkingTimer; + unsigned int m_moveFlags; + Vector2D m_vel; + Vector m_actualVel; + Vector m_moveGoal; + Vector m_knownGoodPos; + bool m_hasKnownGoodPos; + Vector m_priorKnownGoodPos; + bool m_hasPriorKnownGoodPos; + CountdownTimer m_priorKnownGoodPosTimer; + IntervalTimer m_collisionTimer; + Vector m_viewGoal; + bool m_isLookingAt; + Vector m_faceGoal; + bool m_isFacingTo; + CNavPath m_path; // current path to follow + CNavPathFollower m_follower; + Vector m_lastPosition; + MoveType m_moveType; + MoveType m_moveLimit; + bool m_isCrouching; // true if hostage is crouching + CountdownTimer m_minCrouchTimer; + float m_moveAngle; + NavRelativeDirType m_wiggleDirection; + + CountdownTimer m_wiggleTimer; // for wiggling + CountdownTimer m_wiggleJumpTimer; + CountdownTimer m_inhibitObstacleAvoidance; + CountdownTimer m_jumpTimer; // if zero, we can jump + + bool m_hasJumped; + bool m_hasJumpedIntoAir; + Vector m_jumpTarget; + CountdownTimer m_clearPathTimer; + bool m_traversingLadder; + EHANDLE m_visiblePlayer[MAX_CLIENTS]; + int m_visiblePlayerCount; + CountdownTimer m_visionTimer; +}; + +class CheckWayFunctor { +public: + CheckWayFunctor(const CHostageImprov *me, const Vector &goalPos) + { + m_me = me; + m_goalPos = goalPos; + m_blocker = NULL; + } + bool operator()(CHostage *them) + { + if (((CBaseMonster *)them)->IsAlive() && m_me->IsFriendInTheWay((CBaseEntity *)them, m_goalPos)) + { + m_blocker = them; + return false; + } + + return true; + } + + const CHostageImprov *m_me; + Vector m_goalPos; + CHostage *m_blocker; +}; + +// Functor used with NavAreaBuildPath() for building Hostage paths. +// Once we hook up crouching and ladders, this can be removed and ShortestPathCost() can be used instead. +class HostagePathCost { +public: + float operator()(CNavArea *area, CNavArea *fromArea, const CNavLadder *ladder) + { + if (fromArea == NULL) + { + // first area in path, no cost + return 0.0f; + } + else + { + // compute distance travelled along path so far + float dist; + + if (ladder != NULL) + { + const float ladderCost = 10.0f; + return ladder->m_length * ladderCost + fromArea->GetCostSoFar(); + } + else + { + dist = (*area->GetCenter() - *fromArea->GetCenter()).Length(); + } + + float cost = dist + fromArea->GetCostSoFar(); + + // if this is a "crouch" area, add penalty + if (area->GetAttributes() & NAV_CROUCH) + { + const float crouchPenalty = 10.0f; + cost += crouchPenalty * dist; + } + + // if this is a "jump" area, add penalty + if (area->GetAttributes() & NAV_JUMP) + { + const float jumpPenalty = 10.0f; + cost += jumpPenalty * dist; + } + + return cost; + } + } +}; + +class KeepPersonalSpace { +public: + KeepPersonalSpace(CHostageImprov *improv) + { + m_improv = improv; + m_velDir = improv->GetActualVelocity(); + m_speed = m_velDir.NormalizeInPlace(); + } + bool operator()(CBaseEntity *entity) + { + const float space = 1.0f; + Vector to; + float range; + + if (entity == reinterpret_cast(m_improv->GetEntity())) + return true; + + if (entity->IsPlayer() && !entity->IsAlive()) + return true; + + to = entity->pev->origin - m_improv->GetCentroid(); + range = to.NormalizeInPlace(); + + CBasePlayer *player = static_cast(entity); + + const float spring = 50.0f; + const float damper = 1.0f; + + if (range >= spring) + return true; + + const float cosTolerance = 0.8f; + if (entity->IsPlayer() && player->m_iTeam == CT && !m_improv->IsFollowing() && m_improv->IsPlayerLookingAtMe(player, cosTolerance)) + return true; + + const float minSpace = (spring - range); + float ds = -minSpace; + + m_improv->ApplyForce(to * ds); + + const float force = 0.1f; + m_improv->ApplyForce(m_speed * -force * m_velDir); + + return true; + } + +private: + CHostageImprov *m_improv; + Vector m_velDir; + float m_speed; +}; diff --git a/dlls/hostage/hostage_localnav.h b/dlls/hostage/hostage_localnav.h new file mode 100644 index 0000000..5a40e6f --- /dev/null +++ b/dlls/hostage/hostage_localnav.h @@ -0,0 +1,58 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define NODE_INVALID_EMPTY -1 + +#define PATH_TRAVERSABLE_EMPTY 0 +#define PATH_TRAVERSABLE_SLOPE 1 +#define PATH_TRAVERSABLE_STEP 2 +#define PATH_TRAVERSABLE_STEPJUMPABLE 3 + +typedef int node_index_t; + +typedef struct localnode_s +{ + Vector vecLoc; + int offsetX; + int offsetY; + byte bDepth; + BOOL fSearched; + node_index_t nindexParent; + +} localnode_t; + +class CLocalNav { +private: + CHostage *m_pOwner; + edict_t *m_pTargetEnt; + BOOL m_fTargetEntHit; + localnode_t *m_nodeArr; + node_index_t m_nindexAvailableNode; + Vector m_vecStartingLoc; +}; diff --git a/dlls/hostage/hostage_states.h b/dlls/hostage/hostage_states.h new file mode 100644 index 0000000..9ac99cf --- /dev/null +++ b/dlls/hostage/hostage_states.h @@ -0,0 +1,203 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CHostageImprov; + +class HostageState: public SimpleState, public IImprovEvent { +public: + virtual ~HostageState() {} + virtual void UpdateStationaryAnimation(CHostageImprov *improv) {} +}; + +class HostageStateMachine: public SimpleStateMachine, public IImprovEvent { +public: + virtual void OnMoveToSuccess(const Vector &goal) {} + virtual void OnMoveToFailure(const Vector &goal, MoveToFailureType reason) {} + virtual void OnInjury(float amount) {} +}; + +class HostageIdleState: public HostageState { +public: + virtual ~HostageIdleState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Idle"; } + virtual void UpdateStationaryAnimation(CHostageImprov *improv) {} + virtual void OnMoveToSuccess(const Vector &goal) {} + virtual void OnMoveToFailure(const Vector &goal, MoveToFailureType reason) {} + virtual void OnInjury(float amount = -1.0f) {} +private: + CountdownTimer m_waveTimer; + CountdownTimer m_fleeTimer; + CountdownTimer m_disagreeTimer; + CountdownTimer m_escapeTimer; + CountdownTimer m_askTimer; + IntervalTimer m_intimidatedTimer; + CountdownTimer m_pleadTimer; + + enum + { + NotMoving = 0, + Moving, + MoveDone, + MoveFailed, + } m_moveState; + + bool m_mustFlee; +}; + +class HostageEscapeToCoverState: public HostageState { +public: + virtual ~HostageEscapeToCoverState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Escape:ToCover"; } + virtual void OnMoveToFailure(const Vector &goal, MoveToFailureType reason) {} +public: + void SetRescueGoal(const Vector &rescueGoal) { m_rescueGoal = rescueGoal; } + +private: + Vector m_rescueGoal; + Vector m_spot; + bool m_canEscape; +}; + +class HostageEscapeLookAroundState: public HostageState { +public: + virtual ~HostageEscapeLookAroundState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Escape:LookAround"; } + +private: + CountdownTimer m_timer; +}; + +class HostageEscapeState: public HostageState { +public: + virtual ~HostageEscapeState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Escape"; } + virtual void OnMoveToFailure(const Vector &goal, MoveToFailureType reason) {} +public: + void ToCover() { m_behavior.SetState(&m_toCoverState); } + void LookAround() { m_behavior.SetState(&m_lookAroundState); } +private: + HostageEscapeToCoverState m_toCoverState; + HostageEscapeLookAroundState m_lookAroundState; + HostageStateMachine m_behavior; + bool m_canEscape; + CountdownTimer m_runTimer; +}; + +class HostageRetreatState: public HostageState { +public: + virtual ~HostageRetreatState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Retreat"; } +}; + +class HostageFollowState: public HostageState { +public: + virtual ~HostageFollowState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Follow"; } + virtual void UpdateStationaryAnimation(CHostageImprov *improv) {} +public: + void SetLeader(CBaseEntity *leader) { m_leader = leader; } + CBaseEntity *GetLeader() const { return m_leader; } +private: + mutable EHANDLE m_leader; + Vector m_lastLeaderPos; + bool m_isWaiting; + float m_stopRange; + CountdownTimer m_makeWayTimer; + CountdownTimer m_impatientTimer; + CountdownTimer m_repathTimer; + bool m_isWaitingForFriend; + CountdownTimer m_waitForFriendTimer; +}; + +class HostageAnimateState: public HostageState { +public: + virtual ~HostageAnimateState() {} + virtual void OnEnter(CHostageImprov *improv) {} + virtual void OnUpdate(CHostageImprov *improv) {} + virtual void OnExit(CHostageImprov *improv) {} + virtual const char *GetName() const { return "Animate"; } +public: + struct SeqInfo + { + int seqID; + float holdTime; + float rate; + }; + + enum PerformanceType + { + None = 0, + Walk, + Run, + Jump, + Fall, + Crouch, + CrouchWalk, + Calm, + Anxious, + Afraid, + Sitting, + GettingUp, + Waving, + LookingAround, + Disagreeing, + Flinching, + }; + + bool IsBusy() const { return (m_sequenceCount > 0); } + int GetCurrentSequenceID() { return m_currentSequence; } + PerformanceType GetPerformance() const { return m_performance; } + void SetPerformance(PerformanceType performance) { m_performance = performance; } +private: + enum { MAX_SEQUENCES = 8 }; + struct SeqInfo m_sequence[MAX_SEQUENCES]; + int m_sequenceCount; + int m_currentSequence; + enum PerformanceType m_performance; + bool m_isHolding; + CountdownTimer m_holdTimer; +}; diff --git a/dlls/items.h b/dlls/items.h index e985296..e485295 100644 --- a/dlls/items.h +++ b/dlls/items.h @@ -1,29 +1,155 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef ITEMS_H -#define ITEMS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once - -class CItem : public CBaseEntity +enum ItemRestType { -public: - void Spawn( void ); - CBaseEntity* Respawn( void ); - void EXPORT ItemTouch( CBaseEntity *pOther ); - void EXPORT Materialize( void ); - virtual BOOL MyTouch( CBasePlayer *pPlayer ) { return FALSE; }; + ITEM_TYPE_BUYING, // when a player buying items + ITEM_TYPE_TOUCHED, // when the player touches with a weaponbox or armoury_entity + ITEM_TYPE_EQUIPPED // when a entity game_player_equip gives item to player or default item's on player spawn }; -#endif // ITEMS_H +// constant items +#define ITEM_ID_ANTIDOTE 2 +#define ITEM_ID_SECURITY 3 + +enum ItemID +{ + ITEM_NONE = -1, + ITEM_SHIELDGUN, + ITEM_P228, + ITEM_GLOCK, + ITEM_SCOUT, + ITEM_HEGRENADE, + ITEM_XM1014, + ITEM_C4, + ITEM_MAC10, + ITEM_AUG, + ITEM_SMOKEGRENADE, + ITEM_ELITE, + ITEM_FIVESEVEN, + ITEM_UMP45, + ITEM_SG550, + ITEM_GALIL, + ITEM_FAMAS, + ITEM_USP, + ITEM_GLOCK18, + ITEM_AWP, + ITEM_MP5N, + ITEM_M249, + ITEM_M3, + ITEM_M4A1, + ITEM_TMP, + ITEM_G3SG1, + ITEM_FLASHBANG, + ITEM_DEAGLE, + ITEM_SG552, + ITEM_AK47, + ITEM_KNIFE, + ITEM_P90, + ITEM_NVG, + ITEM_DEFUSEKIT, + ITEM_KEVLAR, + ITEM_ASSAULT, + ITEM_LONGJUMP, + ITEM_SODACAN, + ITEM_HEALTHKIT, + ITEM_ANTIDOTE, + ITEM_BATTERY +}; + +class CItem: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual CBaseEntity *Respawn() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CWorldItem: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +public: + int m_iType; +}; + +class CItemSuit: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemBattery: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemAntidote: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemSecurity: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemLongJump: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemKevlar: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemAssaultSuit: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; + +class CItemThighPack: public CItem { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual BOOL MyTouch(CBasePlayer *pPlayer) = 0; +}; diff --git a/dlls/lights.h b/dlls/lights.h new file mode 100644 index 0000000..df0fb68 --- /dev/null +++ b/dlls/lights.h @@ -0,0 +1,50 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SF_LIGHT_START_OFF 1 + +class CLight: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +private: + int m_iStyle; + int m_iszPattern; + BOOL m_iStartedOff; +}; + +class CEnvLight: public CLight { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +}; diff --git a/dlls/mapinfo.h b/dlls/mapinfo.h new file mode 100644 index 0000000..f6805fe --- /dev/null +++ b/dlls/mapinfo.h @@ -0,0 +1,41 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +class CMapInfo: public CPointEntity +{ +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void UpdateOnRemove() = 0; + +public: + InfoMapBuyParam m_iBuyingStatus; + float m_flBombRadius; +}; diff --git a/dlls/maprules.h b/dlls/maprules.h index 57f9939..dde173e 100644 --- a/dlls/maprules.h +++ b/dlls/maprules.h @@ -1,22 +1,236 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -#ifndef MAPRULES_H -#define MAPRULES_H +#define MAX_EQUIP 32 +#define SF_SCORE_NEGATIVE 0x0001 +#define SF_SCORE_TEAM 0x0002 +#define SF_ENVTEXT_ALLPLAYERS 0x0001 +#define SF_TEAMMASTER_FIREONCE 0x0001 +#define SF_TEAMMASTER_ANYTEAM 0x0002 -#endif // MAPRULES_H +#define SF_TEAMSET_FIREONCE 0x0001 +#define SF_TEAMSET_CLEARTEAM 0x0002 +#define SF_PKILL_FIREONCE 0x0001 + +#define SF_GAMECOUNT_FIREONCE 0x0001 +#define SF_GAMECOUNT_RESET 0x0002 + +#define SF_GAMECOUNTSET_FIREONCE 0x0001 + +#define SF_PLAYEREQUIP_USEONLY 0x0001 + +#define SF_PTEAM_FIREONCE 0x0001 +#define SF_PTEAM_KILL 0x0002 +#define SF_PTEAM_GIB 0x0004 + +class CRuleEntity: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; +public: + void SetMaster(int iszMaster) { m_iszMaster = iszMaster; } + +private: + string_t m_iszMaster; +}; + +// CRulePointEntity -- base class for all rule "point" entities (not brushes) +class CRulePointEntity: public CRuleEntity { +public: + virtual void Spawn() = 0; +}; + +// CRuleBrushEntity -- base class for all rule "brush" entities (not brushes) +// Default behavior is to set up like a trigger, invisible, but keep the model for volume testing +class CRuleBrushEntity: public CRuleEntity { +public: + virtual void Spawn() = 0; +}; + +// CGameScore / game_score -- award points to player / team +// Points +/- total +// Flag: Allow negative scores SF_SCORE_NEGATIVE +// Flag: Award points to team in teamplay SF_SCORE_TEAM +class CGameScore: public CRulePointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + int Points() const { return int(pev->frags); } + BOOL AllowNegativeScore() { return pev->spawnflags & SF_SCORE_NEGATIVE; } + BOOL AwardToTeam() const { return pev->spawnflags & SF_SCORE_TEAM; } + void SetPoints(int points) { pev->frags = points; } +}; + +// CGameEnd / game_end -- Ends the game in MP +class CGameEnd: public CRulePointEntity { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +// CGameText / game_text -- NON-Localized HUD Message (use env_message to display a titles.txt message) +// Flag: All players SF_ENVTEXT_ALLPLAYERS +class CGameText: public CRulePointEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + +public: + BOOL MessageToAll() const { return (pev->spawnflags & SF_ENVTEXT_ALLPLAYERS) == SF_ENVTEXT_ALLPLAYERS; } + void MessageSet(const char *pMessage) { pev->message = ALLOC_STRING(pMessage); } + const char *MessageGet() const { return STRING(pev->message); } + +private: + hudtextparms_t m_textParms; +}; + +// CGameTeamMaster / game_team_master -- "Masters" like multisource, but based on the team of the activator +// Only allows mastered entity to fire if the team matches my team +// +// team index (pulled from server team list "mp_teamlist" +// Flag: Remove on Fire +// Flag: Any team until set? -- Any team can use this until the team is set (otherwise no teams can use it) +class CGameTeamMaster: public CRulePointEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int ObjectCaps() = 0; + virtual BOOL IsTriggered(CBaseEntity *pActivator) = 0; + virtual const char *TeamID() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_TEAMMASTER_FIREONCE) == SF_TEAMMASTER_FIREONCE; } + BOOL AnyTeam() const { return (pev->spawnflags & SF_TEAMMASTER_ANYTEAM) == SF_TEAMMASTER_ANYTEAM; } + +public: + int m_teamIndex; + USE_TYPE triggerType; +}; + +// CGameTeamSet / game_team_set -- Changes the team of the entity it targets to the activator's team +// Flag: Fire once +// Flag: Clear team -- Sets the team to "NONE" instead of activator +class CGameTeamSet: public CRulePointEntity { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_TEAMSET_FIREONCE) == SF_TEAMSET_FIREONCE; } + BOOL ShouldClearTeam() const { return (pev->spawnflags & SF_TEAMSET_CLEARTEAM) == SF_TEAMSET_CLEARTEAM; } +}; + +// CGamePlayerZone / game_player_zone -- players in the zone fire my target when I'm fired +// Needs master? +class CGamePlayerZone: public CRuleBrushEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +private: + string_t m_iszInTarget; + string_t m_iszOutTarget; + string_t m_iszInCount; + string_t m_iszOutCount; +}; + +// CGamePlayerHurt / game_player_hurt -- Damages the player who fires it +// Flag: Fire once +class CGamePlayerHurt: public CRulePointEntity { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_PKILL_FIREONCE) == SF_PKILL_FIREONCE; } +}; + +// CGameCounter / game_counter -- Counts events and fires target +// Flag: Fire once +// Flag: Reset on Fire +class CGameCounter: public CRulePointEntity { +public: + virtual void Spawn() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_GAMECOUNT_FIREONCE) == SF_GAMECOUNT_FIREONCE; } + BOOL ResetOnFire() const { return (pev->spawnflags & SF_GAMECOUNT_RESET) == SF_GAMECOUNT_RESET; } + + void CountUp() { pev->frags++; } + void CountDown() { pev->frags--; } + void ResetCount() { pev->frags = pev->dmg; } + + int CountValue() const { return int(pev->frags); } + int LimitValue() const { return int(pev->health); } + BOOL HitLimit() const { return CountValue() == LimitValue(); } + +private: + void SetCountValue(int value) { pev->frags = value; } + void SetInitialValue(int value) { pev->dmg = value; } +}; + +// CGameCounterSet / game_counter_set -- Sets the counter's value +// Flag: Fire once +class CGameCounterSet: public CRulePointEntity { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_GAMECOUNTSET_FIREONCE) == SF_GAMECOUNTSET_FIREONCE; } +}; + +// CGamePlayerEquip / game_playerequip -- Sets the default player equipment +// Flag: USE Only +class CGamePlayerEquip: public CRulePointEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + BOOL UseOnly() const { return (pev->spawnflags & SF_PLAYEREQUIP_USEONLY) == SF_PLAYEREQUIP_USEONLY; } +public: + string_t m_weaponNames[ MAX_EQUIP ]; + int m_weaponCount[ MAX_EQUIP ]; +}; + +// CGamePlayerTeam / game_player_team -- Changes the team of the player who fired it +// Flag: Fire once +// Flag: Kill Player +// Flag: Gib Player +class CGamePlayerTeam: public CRulePointEntity { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +private: + BOOL RemoveOnFire() const { return (pev->spawnflags & SF_PTEAM_FIREONCE) == SF_PTEAM_FIREONCE; } + BOOL ShouldKillPlayer() const { return (pev->spawnflags & SF_PTEAM_KILL) == SF_PTEAM_KILL; } + BOOL ShouldGibPlayer() const { return (pev->spawnflags & SF_PTEAM_GIB) == SF_PTEAM_GIB; } +}; diff --git a/dlls/monsterevent.h b/dlls/monsterevent.h index 46c5624..d3f3205 100644 --- a/dlls/monsterevent.h +++ b/dlls/monsterevent.h @@ -1,34 +1,44 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef MONSTEREVENT_H -#define MONSTEREVENT_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -typedef struct +typedef struct MonsterEvent_s { - int event; - char *options; + int event; + char *options; + } MonsterEvent_t; -#define EVENT_SPECIFIC 0 -#define EVENT_SCRIPTED 1000 -#define EVENT_SHARED 2000 -#define EVENT_CLIENT 5000 - -#define MONSTER_EVENT_BODYDROP_LIGHT 2001 -#define MONSTER_EVENT_BODYDROP_HEAVY 2002 +#define EVENT_SPECIFIC 0 +#define EVENT_SCRIPTED 1000 +#define EVENT_SHARED 2000 +#define EVENT_CLIENT 5000 +#define MONSTER_EVENT_BODYDROP_LIGHT 2001 +#define MONSTER_EVENT_BODYDROP_HEAVY 2002 #define MONSTER_EVENT_SWISHSOUND 2010 - -#endif // MONSTEREVENT_H diff --git a/dlls/monsters.h b/dlls/monsters.h index 591ea52..842e058 100644 --- a/dlls/monsters.h +++ b/dlls/monsters.h @@ -1,116 +1,78 @@ -/*** -* -* 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. -* -****/ -#ifndef MONSTERS_H -#include "skill.h" -#define MONSTERS_H - /* - -===== monsters.h ======================================================== - - Header file for monster-related utility code - +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* */ +#pragma once -// CHECKLOCALMOVE result types -#define LOCALMOVE_INVALID 0 // move is not possible -#define LOCALMOVE_INVALID_DONT_TRIANGULATE 1 // move is not possible, don't try to triangulate -#define LOCALMOVE_VALID 2 // move is possible +#define LOCALMOVE_INVALID 0 // move is not possible +#define LOCALMOVE_INVALID_DONT_TRIANGULATE 1 // move is not possible, don't try to triangulate +#define LOCALMOVE_VALID 2 // move is possible -// Hit Group standards -#define HITGROUP_GENERIC 0 -#define HITGROUP_HEAD 1 -#define HITGROUP_CHEST 2 -#define HITGROUP_STOMACH 3 -#define HITGROUP_LEFTARM 4 -#define HITGROUP_RIGHTARM 5 -#define HITGROUP_LEFTLEG 6 -#define HITGROUP_RIGHTLEG 7 +#define SF_MONSTER_WAIT_TILL_SEEN 1 // spawnflag that makes monsters wait until player can see them before attacking. +#define SF_MONSTER_GAG 2 // no idle noises from this monster +#define SF_MONSTER_HITMONSTERCLIP 4 +#define SF_MONSTER_PRISONER 16 // monster won't attack anyone, no one will attacke him. +#define SF_MONSTER_WAIT_FOR_SCRIPT 128 //spawnflag that makes monsters wait to check for attacking until the script is done or they've been attacked +#define SF_MONSTER_PREDISASTER 256 //this is a predisaster scientist or barney. Influences how they speak. +#define SF_MONSTER_FADECORPSE 512 // Fade out corpse after death +#define SF_MONSTER_FALL_TO_GROUND 0x80000000 -// Monster Spawnflags -#define SF_MONSTER_WAIT_TILL_SEEN 1// spawnflag that makes monsters wait until player can see them before attacking. -#define SF_MONSTER_GAG 2 // no idle noises from this monster -#define SF_MONSTER_HITMONSTERCLIP 4 -// 8 -#define SF_MONSTER_PRISONER 16 // monster won't attack anyone, no one will attacke him. -// 32 -// 64 -#define SF_MONSTER_WAIT_FOR_SCRIPT 128 //spawnflag that makes monsters wait to check for attacking until the script is done or they've been attacked -#define SF_MONSTER_PREDISASTER 256 //this is a predisaster scientist or barney. Influences how they speak. -#define SF_MONSTER_FADECORPSE 512 // Fade out corpse after death -#define SF_MONSTER_FALL_TO_GROUND 0x80000000 +#define SF_MONSTER_TURRET_AUTOACTIVATE 32 +#define SF_MONSTER_TURRET_STARTINACTIVE 64 +#define SF_MONSTER_WAIT_UNTIL_PROVOKED 64 // don't attack the player unless provoked -// specialty spawnflags -#define SF_MONSTER_TURRET_AUTOACTIVATE 32 -#define SF_MONSTER_TURRET_STARTINACTIVE 64 -#define SF_MONSTER_WAIT_UNTIL_PROVOKED 64 // don't attack the player unless provoked +#define MOVE_START_TURN_DIST 64 // when this far away from moveGoal, start turning to face next goal +#define MOVE_STUCK_DIST 32 // if a monster can't step this far, it is stuck. +#define MOVE_NORMAL 0 // normal move in the direction monster is facing +#define MOVE_STRAFE 1 // moves in direction specified, no matter which way monster is facing +#define R_AL -2 // (ALLY) pals. Good alternative to R_NO when applicable. +#define R_FR -1 // (FEAR)will run +#define R_NO 0 // (NO RELATIONSHIP) disregard +#define R_DL 1 // (DISLIKE) will attack +#define R_HT 2 // (HATE)will attack this character instead of any visible DISLIKEd characters +#define R_NM 3 // (NEMESIS) A monster Will ALWAYS attack its nemsis, no matter what -// MoveToOrigin stuff -#define MOVE_START_TURN_DIST 64 // when this far away from moveGoal, start turning to face next goal -#define MOVE_STUCK_DIST 32 // if a monster can't step this far, it is stuck. - - -// MoveToOrigin stuff -#define MOVE_NORMAL 0// normal move in the direction monster is facing -#define MOVE_STRAFE 1// moves in direction specified, no matter which way monster is facing - -// spawn flags 256 and above are already taken by the engine -extern void UTIL_MoveToOrigin( edict_t* pent, const Vector &vecGoal, float flDist, int iMoveType ); - -Vector VecCheckToss ( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float flGravityAdj = 1.0 ); -Vector VecCheckThrow ( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float flSpeed, float flGravityAdj = 1.0 ); -extern DLL_GLOBAL Vector g_vecAttackDir; -extern DLL_GLOBAL CONSTANT float g_flMeleeRange; -extern DLL_GLOBAL CONSTANT float g_flMediumRange; -extern DLL_GLOBAL CONSTANT float g_flLongRange; -extern void EjectBrass (const Vector &vecOrigin, const Vector &vecVelocity, float rotation, int model, int soundtype ); -extern void ExplodeModel( const Vector &vecOrigin, float speed, int model, int count ); - -BOOL FBoxVisible ( entvars_t *pevLooker, entvars_t *pevTarget ); -BOOL FBoxVisible ( entvars_t *pevLooker, entvars_t *pevTarget, Vector &vecTargetOrigin, float flSize = 0.0 ); - -// monster to monster relationship types -#define R_AL -2 // (ALLY) pals. Good alternative to R_NO when applicable. -#define R_FR -1// (FEAR)will run -#define R_NO 0// (NO RELATIONSHIP) disregard -#define R_DL 1// (DISLIKE) will attack -#define R_HT 2// (HATE)will attack this character instead of any visible DISLIKEd characters -#define R_NM 3// (NEMESIS) A monster Will ALWAYS attack its nemsis, no matter what - - -// these bits represent the monster's memory #define MEMORY_CLEAR 0 -#define bits_MEMORY_PROVOKED ( 1 << 0 )// right now only used for houndeyes. -#define bits_MEMORY_INCOVER ( 1 << 1 )// monster knows it is in a covered position. -#define bits_MEMORY_SUSPICIOUS ( 1 << 2 )// Ally is suspicious of the player, and will move to provoked more easily -#define bits_MEMORY_PATH_FINISHED ( 1 << 3 )// Finished monster path (just used by big momma for now) -#define bits_MEMORY_ON_PATH ( 1 << 4 )// Moving on a path -#define bits_MEMORY_MOVE_FAILED ( 1 << 5 )// Movement has already failed -#define bits_MEMORY_FLINCHED ( 1 << 6 )// Has already flinched -#define bits_MEMORY_KILLED ( 1 << 7 )// HACKHACK -- remember that I've already called my Killed() -#define bits_MEMORY_CUSTOM4 ( 1 << 28 ) // Monster-specific memory -#define bits_MEMORY_CUSTOM3 ( 1 << 29 ) // Monster-specific memory -#define bits_MEMORY_CUSTOM2 ( 1 << 30 ) // Monster-specific memory -#define bits_MEMORY_CUSTOM1 ( 1 << 31 ) // Monster-specific memory +#define bits_MEMORY_PROVOKED (1 << 0) // right now only used for houndeyes. +#define bits_MEMORY_INCOVER (1 << 1) // monster knows it is in a covered position. +#define bits_MEMORY_SUSPICIOUS (1 << 2) // Ally is suspicious of the player, and will move to provoked more easily +#define bits_MEMORY_PATH_FINISHED (1 << 3) // Finished monster path (just used by big momma for now) +#define bits_MEMORY_ON_PATH (1 << 4) // Moving on a path +#define bits_MEMORY_MOVE_FAILED (1 << 5) // Movement has already failed +#define bits_MEMORY_FLINCHED (1 << 6) // Has already flinched +#define bits_MEMORY_KILLED (1 << 7) // HACKHACK -- remember that I've already called my Killed() +#define bits_MEMORY_CUSTOM4 (1 << 28) // Monster-specific memory +#define bits_MEMORY_CUSTOM3 (1 << 29) // Monster-specific memory +#define bits_MEMORY_CUSTOM2 (1 << 30) // Monster-specific memory +#define bits_MEMORY_CUSTOM1 (1 << 31) // Monster-specific memory -// trigger conditions for scripted AI -// these MUST match the CHOICES interface in halflife.fgd for the base monster -enum +enum { AITRIGGER_NONE = 0, AITRIGGER_SEEPLAYER_ANGRY_AT_PLAYER, @@ -125,59 +87,27 @@ enum AITRIGGER_SEEPLAYER_UNCONDITIONAL, AITRIGGER_SEEPLAYER_NOT_IN_COMBAT, }; -/* - 0 : "No Trigger" - 1 : "See Player" - 2 : "Take Damage" - 3 : "50% Health Remaining" - 4 : "Death" - 5 : "Squad Member Dead" - 6 : "Squad Leader Dead" - 7 : "Hear World" - 8 : "Hear Player" - 9 : "Hear Combat" -*/ -// -// A gib is a chunk of a body, or a piece of wood/metal/rocks/etc. -// -class CGib : public CBaseEntity +enum HitBoxGroup { -public: - void Spawn( const char *szGibModel ); - void EXPORT BounceGibTouch ( CBaseEntity *pOther ); - void EXPORT StickyGibTouch ( CBaseEntity *pOther ); - void EXPORT WaitTillLand( void ); - void LimitVelocity( void ); - - virtual int ObjectCaps( void ) { return (CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; } - static void SpawnHeadGib( entvars_t *pevVictim ); - static void SpawnRandomGibs( entvars_t *pevVictim, int cGibs, int human ); - static void SpawnStickyGibs( entvars_t *pevVictim, Vector vecOrigin, int cGibs ); - - int m_bloodColor; - int m_cBloodDecals; - int m_material; - float m_lifeTime; + HITGROUP_GENERIC = 0, + HITGROUP_HEAD, + HITGROUP_CHEST, + HITGROUP_STOMACH, + HITGROUP_LEFTARM, + HITGROUP_RIGHTARM, + HITGROUP_LEFTLEG, + HITGROUP_RIGHTLEG, + HITGROUP_SHIELD, + NUM_HITGROUPS, }; - -#define CUSTOM_SCHEDULES\ - virtual Schedule_t *ScheduleFromName( const char *pName );\ - static Schedule_t *m_scheduleList[]; - -#define DEFINE_CUSTOM_SCHEDULES(derivedClass)\ - Schedule_t *derivedClass::m_scheduleList[] = - -#define IMPLEMENT_CUSTOM_SCHEDULES(derivedClass, baseClass)\ - Schedule_t *derivedClass::ScheduleFromName( const char *pName )\ - {\ - Schedule_t *pSchedule = ScheduleInList( pName, m_scheduleList, ARRAYSIZE(m_scheduleList) );\ - if ( !pSchedule )\ - return baseClass::ScheduleFromName(pName);\ - return pSchedule;\ - } - - - -#endif //MONSTERS_H +class CGib: public CBaseEntity { +public: + virtual int ObjectCaps() = 0; +public: + int m_bloodColor; + int m_cBloodDecals; + int m_material; + float m_lifeTime; +}; diff --git a/dlls/mortar.h b/dlls/mortar.h new file mode 100644 index 0000000..e74636c --- /dev/null +++ b/dlls/mortar.h @@ -0,0 +1,55 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CFuncMortarField: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + + // Bmodels don't go across transitions + virtual int ObjectCaps() = 0; +public: + int m_iszXController; + int m_iszYController; + float m_flSpread; + float m_flDelay; + int m_iCount; + int m_fControl; +}; + +class CMortar: public CGrenade { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; +public: + int m_spriteTexture; +}; diff --git a/dlls/nodes.h b/dlls/nodes.h deleted file mode 100644 index 4465d1c..0000000 --- a/dlls/nodes.h +++ /dev/null @@ -1,379 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -//========================================================= -// nodes.h -//========================================================= - -#ifndef NODES_H -#define NODES_H - -//========================================================= -// DEFINE -//========================================================= -#define MAX_STACK_NODES 100 -#define NO_NODE -1 -#define MAX_NODE_HULLS 4 - -#define bits_NODE_LAND ( 1 << 0 ) // Land node, so nudge if necessary. -#define bits_NODE_AIR ( 1 << 1 ) // Air node, don't nudge. -#define bits_NODE_WATER ( 1 << 2 ) // Water node, don't nudge. -#define bits_NODE_GROUP_REALM (bits_NODE_LAND | bits_NODE_AIR | bits_NODE_WATER) - -//========================================================= -// Instance of a node. -//========================================================= -class CNode -{ -public: - Vector m_vecOrigin;// location of this node in space - Vector m_vecOriginPeek; // location of this node (LAND nodes are NODE_HEIGHT higher). - BYTE m_Region[3]; // Which of 256 regions do each of the coordinate belong? - int m_afNodeInfo;// bits that tell us more about this location - - int m_cNumLinks; // how many links this node has - int m_iFirstLink;// index of this node's first link in the link pool. - - // Where to start looking in the compressed routing table (offset into m_pRouteInfo). - // (4 hull sizes -- smallest to largest + fly/swim), and secondly, door capability. - // - int m_pNextBestNode[MAX_NODE_HULLS][2]; - - // Used in finding the shortest path. m_fClosestSoFar is -1 if not visited. - // Then it is the distance to the source. If another path uses this node - // and has a closer distance, then m_iPreviousNode is also updated. - // - float m_flClosestSoFar; // Used in finding the shortest path. - int m_iPreviousNode; - - short m_sHintType;// there is something interesting in the world at this node's position - short m_sHintActivity;// there is something interesting in the world at this node's position - float m_flHintYaw;// monster on this node should face this yaw to face the hint. -}; - -//========================================================= -// CLink - A link between 2 nodes -//========================================================= -#define bits_LINK_SMALL_HULL ( 1 << 0 )// headcrab box can fit through this connection -#define bits_LINK_HUMAN_HULL ( 1 << 1 )// player box can fit through this connection -#define bits_LINK_LARGE_HULL ( 1 << 2 )// big box can fit through this connection -#define bits_LINK_FLY_HULL ( 1 << 3 )// a flying big box can fit through this connection -#define bits_LINK_DISABLED ( 1 << 4 )// link is not valid when the set - -#define NODE_SMALL_HULL 0 -#define NODE_HUMAN_HULL 1 -#define NODE_LARGE_HULL 2 -#define NODE_FLY_HULL 3 - -class CLink -{ -public: - int m_iSrcNode;// the node that 'owns' this link ( keeps us from having to make reverse lookups ) - int m_iDestNode;// the node on the other end of the link. - - entvars_t *m_pLinkEnt;// the entity that blocks this connection (doors, etc) - - // m_szLinkEntModelname is not necessarily NULL terminated (so we can store it in a more alignment-friendly 4 bytes) - char m_szLinkEntModelname[ 4 ];// the unique name of the brush model that blocks the connection (this is kept for save/restore) - - int m_afLinkInfo;// information about this link - float m_flWeight;// length of the link line segment -}; - - -typedef struct -{ - int m_SortedBy[3]; - int m_CheckedEvent; -} DIST_INFO; - -typedef struct -{ - Vector v; - short n; // Nearest node or -1 if no node found. -} CACHE_ENTRY; - -//========================================================= -// CGraph -//========================================================= -#define GRAPH_VERSION (int)16// !!!increment this whever graph/node/link classes change, to obsolesce older disk files. -class CGraph -{ -public: - -// the graph has two flags, and should not be accessed unless both flags are TRUE! - BOOL m_fGraphPresent;// is the graph in memory? - BOOL m_fGraphPointersSet;// are the entity pointers for the graph all set? - BOOL m_fRoutingComplete; // are the optimal routes computed, yet? - - CNode *m_pNodes;// pointer to the memory block that contains all node info - CLink *m_pLinkPool;// big list of all node connections - char *m_pRouteInfo; // compressed routing information the nodes use. - - int m_cNodes;// total number of nodes - int m_cLinks;// total number of links - int m_nRouteInfo; // size of m_pRouteInfo in bytes. - - // Tables for making nearest node lookup faster. SortedBy provided nodes in a - // order of a particular coordinate. Instead of doing a binary search, RangeStart - // and RangeEnd let you get to the part of SortedBy that you are interested in. - // - // Once you have a point of interest, the only way you'll find a closer point is - // if at least one of the coordinates is closer than the ones you have now. So we - // search each range. After the search is exhausted, we know we have the closest - // node. - // -#define CACHE_SIZE 128 -#define NUM_RANGES 256 - DIST_INFO *m_di; // This is m_cNodes long, but the entries don't correspond to CNode entries. - int m_RangeStart[3][NUM_RANGES]; - int m_RangeEnd[3][NUM_RANGES]; - float m_flShortest; - int m_iNearest; - int m_minX, m_minY, m_minZ, m_maxX, m_maxY, m_maxZ; - int m_minBoxX, m_minBoxY, m_minBoxZ, m_maxBoxX, m_maxBoxY, m_maxBoxZ; - int m_CheckedCounter; - float m_RegionMin[3], m_RegionMax[3]; // The range of nodes. - CACHE_ENTRY m_Cache[CACHE_SIZE]; - - - int m_HashPrimes[16]; - short *m_pHashLinks; - int m_nHashLinks; - - - // kinda sleazy. In order to allow variety in active idles for monster groups in a room with more than one node, - // we keep track of the last node we searched from and store it here. Subsequent searches by other monsters will pick - // up where the last search stopped. - int m_iLastActiveIdleSearch; - - // another such system used to track the search for cover nodes, helps greatly with two monsters trying to get to the same node. - int m_iLastCoverSearch; - - // functions to create the graph - int LinkVisibleNodes ( CLink *pLinkPool, FILE *file, int *piBadNode ); - int RejectInlineLinks ( CLink *pLinkPool, FILE *file ); - int FindShortestPath ( int *piPath, int iStart, int iDest, int iHull, int afCapMask); - int FindNearestNode ( const Vector &vecOrigin, CBaseEntity *pEntity ); - int FindNearestNode ( const Vector &vecOrigin, int afNodeTypes ); - //int FindNearestLink ( const Vector &vecTestPoint, int *piNearestLink, BOOL *pfAlongLine ); - float PathLength( int iStart, int iDest, int iHull, int afCapMask ); - int NextNodeInRoute( int iCurrentNode, int iDest, int iHull, int iCap ); - - enum NODEQUERY { NODEGRAPH_DYNAMIC, NODEGRAPH_STATIC }; - // A static query means we're asking about the possiblity of handling this entity at ANY time - // A dynamic query means we're asking about it RIGHT NOW. So we should query the current state - int HandleLinkEnt ( int iNode, entvars_t *pevLinkEnt, int afCapMask, NODEQUERY queryType ); - entvars_t* LinkEntForLink ( CLink *pLink, CNode *pNode ); - void ShowNodeConnections ( int iNode ); - void InitGraph( void ); - int AllocNodes ( void ); - - int CheckNODFile(char *szMapName); - int FLoadGraph(char *szMapName); - int FSaveGraph(char *szMapName); - int FSetGraphPointers(void); - void CheckNode(Vector vecOrigin, int iNode); - - void BuildRegionTables(void); - void ComputeStaticRoutingTables(void); - void TestRoutingTables(void); - - void HashInsert(int iSrcNode, int iDestNode, int iKey); - void HashSearch(int iSrcNode, int iDestNode, int &iKey); - void HashChoosePrimes(int TableSize); - void BuildLinkLookups(void); - - void SortNodes(void); - - int HullIndex( const CBaseEntity *pEntity ); // what hull the monster uses - int NodeType( const CBaseEntity *pEntity ); // what node type the monster uses - inline int CapIndex( int afCapMask ) - { - if (afCapMask & (bits_CAP_OPEN_DOORS | bits_CAP_AUTO_DOORS | bits_CAP_USE)) - return 1; - return 0; - } - - - inline CNode &Node( int i ) - { -#ifdef _DEBUG - if ( !m_pNodes || i < 0 || i > m_cNodes ) - ALERT( at_error, "Bad Node!\n" ); -#endif - return m_pNodes[i]; - } - - inline CLink &Link( int i ) - { -#ifdef _DEBUG - if ( !m_pLinkPool || i < 0 || i > m_cLinks ) - ALERT( at_error, "Bad link!\n" ); -#endif - return m_pLinkPool[i]; - } - - inline CLink &NodeLink( int iNode, int iLink ) - { - return Link( Node( iNode ).m_iFirstLink + iLink ); - } - - inline CLink &NodeLink( const CNode &node, int iLink ) - { - return Link( node.m_iFirstLink + iLink ); - } - - inline int INodeLink ( int iNode, int iLink ) - { - return NodeLink( iNode, iLink ).m_iDestNode; - } - -#if 0 - inline CNode &SourceNode( int iNode, int iLink ) - { - return Node( NodeLink( iNode, iLink ).m_iSrcNode ); - } - - inline CNode &DestNode( int iNode, int iLink ) - { - return Node( NodeLink( iNode, iLink ).m_iDestNode ); - } - - inline CNode *PNodeLink ( int iNode, int iLink ) - { - return &DestNode( iNode, iLink ); - } -#endif -}; - -//========================================================= -// Nodes start out as ents in the level. The node graph -// is built, then these ents are discarded. -//========================================================= -class CNodeEnt : public CBaseEntity -{ - void Spawn( void ); - void KeyValue( KeyValueData *pkvd ); - virtual int ObjectCaps( void ) { return CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION; } - - short m_sHintType; - short m_sHintActivity; -}; - - -//========================================================= -// CStack - last in, first out. -//========================================================= -class CStack -{ -public: - CStack( void ); - void Push( int value ); - int Pop( void ); - int Top( void ); - int Empty( void ) { return m_level==0; } - int Size( void ) { return m_level; } - void CopyToArray ( int *piArray ); - -private: - int m_stack[ MAX_STACK_NODES ]; - int m_level; -}; - - -//========================================================= -// CQueue - first in, first out. -//========================================================= -class CQueue -{ -public: - - CQueue( void );// constructor - inline int Full ( void ) { return ( m_cSize == MAX_STACK_NODES ); } - inline int Empty ( void ) { return ( m_cSize == 0 ); } - //inline int Tail ( void ) { return ( m_queue[ m_tail ] ); } - inline int Size ( void ) { return ( m_cSize ); } - void Insert( int, float ); - int Remove( float & ); - -private: - int m_cSize; - struct tag_QUEUE_NODE - { - int Id; - float Priority; - } m_queue[ MAX_STACK_NODES ]; - int m_head; - int m_tail; -}; - -//========================================================= -// CQueuePriority - Priority queue (smallest item out first). -// -//========================================================= -class CQueuePriority -{ -public: - - CQueuePriority( void );// constructor - inline int Full ( void ) { return ( m_cSize == MAX_STACK_NODES ); } - inline int Empty ( void ) { return ( m_cSize == 0 ); } - //inline int Tail ( float & ) { return ( m_queue[ m_tail ].Id ); } - inline int Size ( void ) { return ( m_cSize ); } - void Insert( int, float ); - int Remove( float &); - -private: - int m_cSize; - struct tag_HEAP_NODE - { - int Id; - float Priority; - } m_heap[ MAX_STACK_NODES ]; - void Heap_SiftDown(int); - void Heap_SiftUp(void); - -}; - -//========================================================= -// hints - these MUST coincide with the HINTS listed under -// info_node in the FGD file! -//========================================================= -enum -{ - HINT_NONE = 0, - HINT_WORLD_DOOR, - HINT_WORLD_WINDOW, - HINT_WORLD_BUTTON, - HINT_WORLD_MACHINERY, - HINT_WORLD_LEDGE, - HINT_WORLD_LIGHT_SOURCE, - HINT_WORLD_HEAT_SOURCE, - HINT_WORLD_BLINKING_LIGHT, - HINT_WORLD_BRIGHT_COLORS, - HINT_WORLD_HUMAN_BLOOD, - HINT_WORLD_ALIEN_BLOOD, - - HINT_TACTICAL_EXIT = 100, - HINT_TACTICAL_VANTAGE, - HINT_TACTICAL_AMBUSH, - - HINT_STUKA_PERCH = 300, - HINT_STUKA_LANDING, -}; - -extern CGraph WorldGraph; - -#endif // NODES_H \ No newline at end of file diff --git a/dlls/observer.h b/dlls/observer.h new file mode 100644 index 0000000..67585a5 --- /dev/null +++ b/dlls/observer.h @@ -0,0 +1,32 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define CAMERA_MODE_SPEC_ANYONE 0 +#define CAMERA_MODE_SPEC_ONLY_TEAM 1 +#define CAMERA_MODE_SPEC_ONLY_FRIST_PERSON 2 diff --git a/dlls/pathcorner.h b/dlls/pathcorner.h new file mode 100644 index 0000000..5be28a3 --- /dev/null +++ b/dlls/pathcorner.h @@ -0,0 +1,39 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CPathCorner: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual float GetDelay() = 0; +private: + float m_flWait; +}; diff --git a/dlls/plane.h b/dlls/plane.h deleted file mode 100644 index af70f1c..0000000 --- a/dlls/plane.h +++ /dev/null @@ -1,43 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -#ifndef PLANE_H -#define PLANE_H - -//========================================================= -// Plane -//========================================================= -class CPlane -{ -public: - CPlane ( void ); - - //========================================================= - // InitializePlane - Takes a normal for the plane and a - // point on the plane and - //========================================================= - void InitializePlane ( const Vector &vecNormal, const Vector &vecPoint ); - - //========================================================= - // PointInFront - determines whether the given vector is - // in front of the plane. - //========================================================= - BOOL PointInFront ( const Vector &vecPoint ); - - Vector m_vecNormal; - float m_flDist; - BOOL m_fInitialized; -}; - -#endif // PLANE_H diff --git a/dlls/plats.h b/dlls/plats.h new file mode 100644 index 0000000..ec67be3 --- /dev/null +++ b/dlls/plats.h @@ -0,0 +1,178 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SF_PLAT_TOGGLE 0x0001 + +#define TRAIN_STARTPITCH 60 +#define TRAIN_MAXPITCH 200 +#define TRAIN_MAXSPEED 1000 + +#define SF_TRACK_ACTIVATETRAIN 0x00000001 +#define SF_TRACK_RELINK 0x00000002 +#define SF_TRACK_ROTMOVE 0x00000004 +#define SF_TRACK_STARTBOTTOM 0x00000008 +#define SF_TRACK_DONT_MOVE 0x00000010 + +#define FGUNTARGET_START_ON 0x0001 + +class CBasePlatTrain: public CBaseToggle { +public: + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + + // This is done to fix spawn flag collisions between this class and a derived class + virtual BOOL IsTogglePlat() = 0; +public: + byte m_bMoveSnd; + byte m_bStopSnd; + float m_volume; +}; + +class CFuncPlat: public CBasePlatTrain { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; + virtual void GoUp() = 0; + virtual void GoDown() = 0; + virtual void HitTop() = 0; + virtual void HitBottom() = 0; +}; + +class CPlatTrigger: public CBaseEntity { +public: + virtual int ObjectCaps() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +public: + CFuncPlat *m_pPlatform; +}; + +class CFuncPlatRot: public CFuncPlat { +public: + virtual void Spawn() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void GoUp() = 0; + virtual void GoDown() = 0; + virtual void HitTop() = 0; + virtual void HitBottom() = 0; +public: + Vector m_end; + Vector m_start; +}; + +class CFuncTrain: public CBasePlatTrain { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Activate() = 0; + virtual void OverrideReset() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + Vector m_vStartPosition; + entvars_t *m_pevFirstTarget; + entvars_t *m_pevCurrentTarget; + int m_sounds; + BOOL m_activated; +}; + +class CFuncTrainControls: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int ObjectCaps() = 0; +}; + +class CFuncTrackChange: public CFuncPlatRot { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void OverrideReset() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual BOOL IsTogglePlat() = 0; + virtual void GoUp() = 0; + virtual void GoDown() = 0; + virtual void HitTop() = 0; + virtual void HitBottom() = 0; + virtual void UpdateAutoTargets(int toggleState) = 0; + +public: + void DisableUse() { m_use = 0; } + void EnableUse() { m_use = 1; } + + int UseEnabled() const { return m_use; } + +public: + static TYPEDESCRIPTION IMPL(m_SaveData)[9]; + + CPathTrack *m_trackTop; + CPathTrack *m_trackBottom; + CFuncTrackTrain *m_train; + + int m_trackTopName; + int m_trackBottomName; + int m_trainName; + + TRAIN_CODE m_code; + int m_targetState; + int m_use; +}; + +class CFuncTrackAuto: public CFuncTrackChange { +public: + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void UpdateAutoTargets(int toggleState) = 0; +}; + +class CGunTarget: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Activate() = 0; + virtual int Classify() = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual int BloodColor() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual Vector BodyTarget(const Vector &posSrc) = 0; +private: + BOOL m_on; +}; diff --git a/dlls/player.h b/dlls/player.h index f760548..365d663 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -1,68 +1,158 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef PLAYER_H -#define PLAYER_H - +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once #include "pm_materials.h" +#include "hintmessage.h" +#include "unisignals.h" +#define MIN_BUY_TIME 15 // the minimum threshold values for cvar mp_buytime 15 sec's -#define PLAYER_FATAL_FALL_SPEED 1024// approx 60 feet -#define PLAYER_MAX_SAFE_FALL_SPEED 580// approx 20 feet -#define DAMAGE_FOR_FALL_SPEED (float) 100 / ( PLAYER_FATAL_FALL_SPEED - PLAYER_MAX_SAFE_FALL_SPEED )// damage per unit per second. -#define PLAYER_MIN_BOUNCE_SPEED 200 -#define PLAYER_FALL_PUNCH_THRESHHOLD (float)350 // won't punch player's screen/make scrape noise unless player falling at least this fast. +#define MAX_BUFFER_MENU 175 +#define MAX_BUFFER_MENU_BRIEFING 50 -// -// Player PHYSICS FLAGS bits -// -#define PFLAG_ONLADDER ( 1<<0 ) -#define PFLAG_ONSWING ( 1<<0 ) -#define PFLAG_ONTRAIN ( 1<<1 ) -#define PFLAG_ONBARNACLE ( 1<<2 ) -#define PFLAG_DUCKING ( 1<<3 ) // In the process of ducking, but totally squatted yet -#define PFLAG_USING ( 1<<4 ) // Using a continuous entity -#define PFLAG_OBSERVER ( 1<<5 ) // player is locked in stationary cam mode. Spectators can move, observers can't. +#define MAX_PLAYER_NAME_LENGTH 32 +#define MAX_AUTOBUY_LENGTH 256 +#define MAX_REBUY_LENGTH 256 -// -// generic player -// -//----------------------------------------------------- -//This is Half-Life player entity -//----------------------------------------------------- -#define CSUITPLAYLIST 4 // max of 4 suit sentences queued up at any time +#define MAX_RECENT_PATH 20 +#define MAX_HOSTAGE_ICON 4 // the maximum number of icons of the hostages in the HUD + +#define SUITUPDATETIME 3.5 +#define SUITFIRSTUPDATETIME 0.1 + +#define PLAYER_FATAL_FALL_SPEED 1100.0f +#define PLAYER_MAX_SAFE_FALL_SPEED 500.0f +#define PLAYER_USE_RADIUS 64.0f + +#define ARMOR_RATIO 0.5 // Armor Takes 50% of the damage +#define ARMOR_BONUS 0.5 // Each Point of Armor is work 1/x points of health + +#define FLASH_DRAIN_TIME 1.2 // 100 units/3 minutes +#define FLASH_CHARGE_TIME 0.2 // 100 units/20 seconds (seconds per unit) + +// damage per unit per second. +#define DAMAGE_FOR_FALL_SPEED 100.0f / (PLAYER_FATAL_FALL_SPEED - PLAYER_MAX_SAFE_FALL_SPEED) +#define PLAYER_MIN_BOUNCE_SPEED 350.0f + +// won't punch player's screen/make scrape noise unless player falling at least this fast. +#define PLAYER_FALL_PUNCH_THRESHHOLD 250.0f + +// Money blinks few of times on the freeze period +// NOTE: It works for CZ +#define MONEY_BLINK_AMOUNT 30 + +// Player physics flags bits +// CBasePlayer::m_afPhysicsFlags +#define PFLAG_ONLADDER (1<<0) +#define PFLAG_ONSWING (1<<0) +#define PFLAG_ONTRAIN (1<<1) +#define PFLAG_ONBARNACLE (1<<2) +#define PFLAG_DUCKING (1<<3) // In the process of ducking, but totally squatted yet +#define PFLAG_USING (1<<4) // Using a continuous entity +#define PFLAG_OBSERVER (1<<5) // player is locked in stationary cam mode. Spectators can move, observers can't. + +#define TRAIN_OFF 0x00 +#define TRAIN_NEUTRAL 0x01 +#define TRAIN_SLOW 0x02 +#define TRAIN_MEDIUM 0x03 +#define TRAIN_FAST 0x04 +#define TRAIN_BACK 0x05 + +#define TRAIN_ACTIVE 0x80 +#define TRAIN_NEW 0xc0 + +#define SIGNAL_BUY (1<<0) +#define SIGNAL_BOMB (1<<1) +#define SIGNAL_RESCUE (1<<2) +#define SIGNAL_ESCAPE (1<<3) +#define SIGNAL_VIPSAFETY (1<<4) + +#define IGNOREMSG_NONE 0 +#define IGNOREMSG_ENEMY 1 +#define IGNOREMSG_TEAM 2 + +// max of 4 suit sentences queued up at any time +#define CSUITPLAYLIST 4 #define SUIT_GROUP TRUE -#define SUIT_SENTENCE FALSE +#define SUIT_SENTENCE FALSE -#define SUIT_REPEAT_OK 0 -#define SUIT_NEXT_IN_30SEC 30 -#define SUIT_NEXT_IN_1MIN 60 -#define SUIT_NEXT_IN_5MIN 300 -#define SUIT_NEXT_IN_10MIN 600 -#define SUIT_NEXT_IN_30MIN 1800 -#define SUIT_NEXT_IN_1HOUR 3600 +#define SUIT_REPEAT_OK 0 +#define SUIT_NEXT_IN_30SEC 30 +#define SUIT_NEXT_IN_1MIN 60 +#define SUIT_NEXT_IN_5MIN 300 +#define SUIT_NEXT_IN_10MIN 600 +#define SUIT_NEXT_IN_30MIN 1800 +#define SUIT_NEXT_IN_1HOUR 3600 -#define CSUITNOREPEAT 32 +#define TEAM_NAME_LENGTH 16 -#define SOUND_FLASHLIGHT_ON "items/flashlight1.wav" -#define SOUND_FLASHLIGHT_OFF "items/flashlight1.wav" +#define MAX_ID_RANGE 2048.0f +#define MAX_SPECTATOR_ID_RANGE 8192.0f +#define SBAR_STRING_SIZE 128 -#define TEAM_NAME_LENGTH 16 +#define SBAR_TARGETTYPE_TEAMMATE 1 +#define SBAR_TARGETTYPE_ENEMY 2 +#define SBAR_TARGETTYPE_HOSTAGE 3 -typedef enum +#define CHAT_INTERVAL 1.0f +#define CSUITNOREPEAT 32 + +#define AUTOAIM_2DEGREES 0.0348994967025 +#define AUTOAIM_5DEGREES 0.08715574274766 +#define AUTOAIM_8DEGREES 0.1391731009601 +#define AUTOAIM_10DEGREES 0.1736481776669 + +#define SOUND_FLASHLIGHT_ON "items/flashlight1.wav" +#define SOUND_FLASHLIGHT_OFF "items/flashlight1.wav" + +// custom enum +enum RewardType +{ + RT_NONE, + RT_ROUND_BONUS, + RT_PLAYER_RESET, + RT_PLAYER_JOIN, + RT_PLAYER_SPEC_JOIN, + RT_PLAYER_BOUGHT_SOMETHING, + RT_HOSTAGE_TOOK, + RT_HOSTAGE_RESCUED, + RT_HOSTAGE_DAMAGED, + RT_HOSTAGE_KILLED, + RT_TEAMMATES_KILLED, + RT_ENEMY_KILLED, + RT_INTO_GAME, + RT_VIP_KILLED, + RT_VIP_RESCUED_MYSELF +}; + +enum PLAYER_ANIM { PLAYER_IDLE, PLAYER_WALK, @@ -70,267 +160,466 @@ typedef enum PLAYER_SUPERJUMP, PLAYER_DIE, PLAYER_ATTACK1, -} PLAYER_ANIM; + PLAYER_ATTACK2, + PLAYER_FLINCH, + PLAYER_LARGE_FLINCH, + PLAYER_RELOAD, + PLAYER_HOLDBOMB +}; -#define MAX_ID_RANGE 2048 -#define SBAR_STRING_SIZE 128 +enum _Menu +{ + Menu_OFF, + Menu_ChooseTeam, + Menu_IGChooseTeam, + Menu_ChooseAppearance, + Menu_Buy, + Menu_BuyPistol, + Menu_BuyRifle, + Menu_BuyMachineGun, + Menu_BuyShotgun, + Menu_BuySubMachineGun, + Menu_BuyItem, + Menu_Radio1, + Menu_Radio2, + Menu_Radio3, + Menu_ClientBuy +}; + +enum TeamName +{ + UNASSIGNED, + TERRORIST, + CT, + SPECTATOR, +}; + +enum ModelName +{ + MODEL_UNASSIGNED, + MODEL_URBAN, + MODEL_TERROR, + MODEL_LEET, + MODEL_ARCTIC, + MODEL_GSG9, + MODEL_GIGN, + MODEL_SAS, + MODEL_GUERILLA, + MODEL_VIP, + MODEL_MILITIA, + MODEL_SPETSNAZ, + MODEL_AUTO +}; + +enum JoinState +{ + JOINED, + SHOWLTEXT, + READINGLTEXT, + SHOWTEAMSELECT, + PICKINGTEAM, + GETINTOGAME +}; + +enum TrackCommands +{ + CMD_SAY = 0, + CMD_SAYTEAM, + CMD_FULLUPDATE, + CMD_VOTE, + CMD_VOTEMAP, + CMD_LISTMAPS, + CMD_LISTPLAYERS, + CMD_NIGHTVISION, + COMMANDS_TO_TRACK, +}; + +struct RebuyStruct +{ + int m_primaryWeapon; + int m_primaryAmmo; + int m_secondaryWeapon; + int m_secondaryAmmo; + int m_heGrenade; + int m_flashbang; + int m_smokeGrenade; + int m_defuser; + int m_nightVision; + ArmorType m_armor; +}; + +enum ThrowDirection +{ + THROW_NONE, + THROW_FORWARD, + THROW_BACKWARD, + THROW_HITVEL, + THROW_BOMB, + THROW_GRENADE, + THROW_HITVEL_MINUS_AIRVEL +}; enum sbar_data { - SBAR_ID_TARGETNAME = 1, + SBAR_ID_TARGETTYPE = 1, + SBAR_ID_TARGETNAME, SBAR_ID_TARGETHEALTH, - SBAR_ID_TARGETARMOR, - SBAR_END, + SBAR_END }; -#define CHAT_INTERVAL 1.0f +enum MusicState { SILENT, CALM, INTENSE }; -class CBasePlayer : public CBaseMonster -{ +class CCSPlayer; + +class CStripWeapons: public CPointEntity { public: - - // Spectator camera - void Observer_FindNextPlayer( bool bReverse ); - void Observer_HandleButtons(); - void Observer_SetMode( int iMode ); - void Observer_CheckTarget(); - void Observer_CheckProperties(); - EHANDLE m_hObserverTarget; - float m_flNextObserverInput; - int m_iObserverWeapon; // weapon of current tracked target - int m_iObserverLastMode;// last used observer mode - int IsObserver() { return pev->iuser1; }; - int random_seed; // See that is shared between client & server for shared weapons code + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; - int m_iPlayerSound;// the index of the sound list slot reserved for this player - int m_iTargetVolume;// ideal sound volume. - int m_iWeaponVolume;// how loud the player's weapon is right now. - int m_iExtraSoundTypes;// additional classification for this weapon's sound - int m_iWeaponFlash;// brightness of the weapon flash - float m_flStopExtraSoundTime; - - float m_flFlashLightTime; // Time until next battery draw/Recharge - int m_iFlashBattery; // Flashlight Battery Draw +// Multiplayer intermission spots. +class CInfoIntermission: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void Think() = 0; +}; - int m_afButtonLast; - int m_afButtonPressed; - int m_afButtonReleased; - - edict_t *m_pentSndLast; // last sound entity to modify player room type - float m_flSndRoomtype; // last roomtype set by sound entity - float m_flSndRange; // dist from player to sound entity +// Dead HEV suit prop +class CDeadHEV: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Classify() = 0; +public: + int m_iPose; // which sequence to display -- temporary, don't need to save + static char *m_szPoses[4]; +}; - float m_flFallVelocity; - - int m_rgItems[MAX_ITEMS]; - int m_fKnownItem; // True when a new item needs to be added - int m_fNewAmmo; // True when a new item has been added +class CSprayCan: public CBaseEntity { +public: + virtual void Think() = 0; + virtual int ObjectCaps() = 0; +}; - unsigned int m_afPhysicsFlags; // physics flags - set when 'normal' physics should be revisited or overriden - float m_fNextSuicideTime; // the time after which the player can next use the suicide command +class CBloodSplat: public CBaseEntity { +public: +}; +class CBasePlayer: public CBaseMonster { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual int Classify() = 0; + virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType) = 0; + virtual BOOL TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType) = 0; + virtual BOOL TakeHealth(float flHealth, int bitsDamageType) = 0; + virtual void Killed(entvars_t *pevAttacker, int iGib) = 0; + virtual void AddPoints(int score, BOOL bAllowNegativeScore) = 0; + virtual void AddPointsToTeam(int score, BOOL bAllowNegativeScore) = 0; + virtual BOOL AddPlayerItem(CBasePlayerItem *pItem) = 0; + virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem) = 0; + virtual int GiveAmmo(int iAmount, char *szName, int iMax = -1) = 0; + virtual void StartSneaking() = 0; + virtual void UpdateOnRemove() = 0; + virtual BOOL IsSneaking() = 0; + virtual BOOL IsAlive() = 0; + virtual BOOL IsPlayer() = 0; + virtual BOOL IsNetClient() = 0; + virtual const char *TeamID() = 0; + virtual BOOL FBecomeProne() = 0; + virtual Vector BodyTarget(const Vector &posSrc) = 0; + virtual int Illumination() = 0; + virtual BOOL ShouldFadeOnDeath() = 0; + virtual void ResetMaxSpeed() = 0; + virtual void Jump() = 0; + virtual void Duck() = 0; + virtual void PreThink() = 0; + virtual void PostThink() = 0; + virtual Vector GetGunPosition() = 0; + virtual BOOL IsBot() = 0; + virtual void UpdateClientData() = 0; + virtual void ImpulseCommands() = 0; + virtual void RoundRespawn() = 0; + virtual Vector GetAutoaimVector(float flDelta) = 0; + virtual void Blind(float flUntilTime, float flHoldTime, float flFadeTime, int iAlpha) = 0; + virtual void OnTouchingWeapon(CWeaponBox *pWeapon) = 0; +public: + static CBasePlayer *Instance(edict_t *pent) { return (CBasePlayer *)GET_PRIVATE(pent ? pent : ENT(0)); } + static CBasePlayer *Instance(entvars_t *pev) { return Instance(ENT(pev)); } + static CBasePlayer *Instance(int offset) { return Instance(ENT(offset)); } -// these are time-sensitive things that we keep track of - float m_flTimeStepSound; // when the last stepping sound was made - float m_flTimeWeaponIdle; // when to play another weapon idle animation. - float m_flSwimTime; // how long player has been underwater - float m_flDuckTime; // how long we've been ducking - float m_flWallJumpTime; // how long until next walljump + int IsObserver() { return pev->iuser1; } + void SetWeaponAnimType(const char *szExtention) { strcpy(m_szAnimExtention, szExtention); } + bool IsProtectedByShield() { return m_bOwnsShield && m_bShieldDrawn; } + bool IsReloading() const; + bool IsBlind() const { return (m_blindUntilTime > gpGlobals->time); } + bool IsAutoFollowAllowed() const { return (gpGlobals->time > m_allowAutoFollowTime); } + void InhibitAutoFollow(float duration) { m_allowAutoFollowTime = gpGlobals->time + duration; } + void AllowAutoFollow() { m_allowAutoFollowTime = 0; } + void SetObserverAutoDirector(bool val) { m_bObserverAutoDirector = val; } + bool CanSwitchObserverModes() const { return m_canSwitchObserverModes; } + CCSPlayer *CSPlayer() const; - float m_flSuitUpdate; // when to play next suit update - int m_rgSuitPlayList[CSUITPLAYLIST];// next sentencenum to play for suit update - int m_iSuitPlayNext; // next sentence slot for queue storage; - int m_rgiSuitNoRepeat[CSUITNOREPEAT]; // suit sentence no repeat list - float m_rgflSuitNoRepeatTime[CSUITNOREPEAT]; // how long to wait before allowing repeat - int m_lastDamageAmount; // Last damage taken - float m_tbdPrev; // Time-based damage timer + // templates + template + CBasePlayerItem *ForEachItem(int slot, const Functor &func) + { + auto item = m_rgpPlayerItems[ slot ]; + while (item) + { + if (func(item)) + return item; - float m_flgeigerRange; // range to nearest radiation source - float m_flgeigerDelay; // delay per update of range msg to client - int m_igeigerRangePrev; - int m_iStepLeft; // alternate left/right foot stepping sound - char m_szTextureName[CBTEXTURENAMEMAX]; // current texture name we're standing on - char m_chTextureType; // current texture type + item = item->m_pNext; + } + return nullptr; + } + template + CBasePlayerItem *ForEachItem(const Functor &func) + { + for (auto item : m_rgpPlayerItems) + { + while (item) + { + if (func(item)) + return item; - int m_idrowndmg; // track drowning damage taken - int m_idrownrestored; // track drowning damage restored + item = item->m_pNext; + } + } + return nullptr; + } +public: + enum { MaxLocationLen = 32 }; - int m_bitsHUDDamage; // Damage bits for the current fame. These get sent to - // the hude via the DAMAGE message - BOOL m_fInitHUD; // True when deferred HUD restart msg needs to be sent - BOOL m_fGameHUDInitialized; - int m_iTrain; // Train control position - BOOL m_fWeapon; // Set this to FALSE to force a reset of the current weapon HUD info - - EHANDLE m_pTank; // the tank which the player is currently controlling, NULL if no tank - float m_fDeadTime; // the time at which the player died (used in PlayerDeathThink()) - - BOOL m_fNoPlayerSound; // a debugging feature. Player makes no sound if this is true. - BOOL m_fLongJump; // does this player have the longjump module? - - float m_tSneaking; - int m_iUpdateTime; // stores the number of frame ticks before sending HUD update messages - int m_iClientHealth; // the health currently known by the client. If this changes, send a new - int m_iClientBattery; // the Battery currently known by the client. If this changes, send a new - int m_iHideHUD; // the players hud weapon info is to be hidden - int m_iClientHideHUD; - int m_iFOV; // field of view - int m_iClientFOV; // client's known FOV - // usable player items - CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES]; + int random_seed; + unsigned short m_usPlayerBleed; + EHANDLE m_hObserverTarget; + float m_flNextObserverInput; + int m_iObserverWeapon; + int m_iObserverC4State; + bool m_bObserverHasDefuser; + int m_iObserverLastMode; + float m_flFlinchTime; + float m_flAnimTime; + bool m_bHighDamage; + float m_flVelocityModifier; + int m_iLastZoom; + bool m_bResumeZoom; + float m_flEjectBrass; + ArmorType m_iKevlar; + bool m_bNotKilled; + TeamName m_iTeam; + int m_iAccount; + bool m_bHasPrimary; + float m_flDeathThrowTime; + int m_iThrowDirection; + float m_flLastTalk; + bool m_bJustConnected; + bool m_bContextHelp; + JoinState m_iJoiningState; + CBaseEntity *m_pIntroCamera; + float m_fIntroCamTime; + float m_fLastMovement; + bool m_bMissionBriefing; + bool m_bTeamChanged; + ModelName m_iModelName; + int m_iTeamKills; + int m_iIgnoreGlobalChat; + bool m_bHasNightVision; + bool m_bNightVisionOn; + Vector m_vRecentPath[MAX_RECENT_PATH]; + float m_flIdleCheckTime; + float m_flRadioTime; + int m_iRadioMessages; + bool m_bIgnoreRadio; + bool m_bHasC4; + bool m_bHasDefuser; + bool m_bKilledByBomb; + Vector m_vBlastVector; + bool m_bKilledByGrenade; + CHintMessageQueue m_hintMessageQueue; + int m_flDisplayHistory; + _Menu m_iMenu; + int m_iChaseTarget; + CBaseEntity *m_pChaseTarget; + float m_fCamSwitch; + bool m_bEscaped; + bool m_bIsVIP; + float m_tmNextRadarUpdate; + Vector m_vLastOrigin; + int m_iCurrentKickVote; + float m_flNextVoteTime; + bool m_bJustKilledTeammate; + int m_iHostagesKilled; + int m_iMapVote; + bool m_bCanShoot; + float m_flLastFired; + float m_flLastAttackedTeammate; + bool m_bHeadshotKilled; + bool m_bPunishedForTK; + bool m_bReceivesNoMoneyNextRound; + int m_iTimeCheckAllowed; + bool m_bHasChangedName; + char m_szNewName[MAX_PLAYER_NAME_LENGTH]; + bool m_bIsDefusing; + float m_tmHandleSignals; + CUnifiedSignals m_signals; + edict_t *m_pentCurBombTarget; + int m_iPlayerSound; + int m_iTargetVolume; + int m_iWeaponVolume; + int m_iExtraSoundTypes; + int m_iWeaponFlash; + float m_flStopExtraSoundTime; + float m_flFlashLightTime; + int m_iFlashBattery; + int m_afButtonLast; + int m_afButtonPressed; + int m_afButtonReleased; + edict_t *m_pentSndLast; + float m_flSndRoomtype; + float m_flSndRange; + float m_flFallVelocity; + int m_rgItems[MAX_ITEMS]; + int m_fNewAmmo; + unsigned int m_afPhysicsFlags; + float m_fNextSuicideTime; + float m_flTimeStepSound; + float m_flTimeWeaponIdle; + float m_flSwimTime; + float m_flDuckTime; + float m_flWallJumpTime; + float m_flSuitUpdate; + int m_rgSuitPlayList[CSUITPLAYLIST]; + int m_iSuitPlayNext; + int m_rgiSuitNoRepeat[CSUITNOREPEAT]; + float m_rgflSuitNoRepeatTime[CSUITNOREPEAT]; + int m_lastDamageAmount; + float m_tbdPrev; + float m_flgeigerRange; + float m_flgeigerDelay; + int m_igeigerRangePrev; + int m_iStepLeft; + char m_szTextureName[CBTEXTURENAMEMAX]; + char m_chTextureType; + int m_idrowndmg; + int m_idrownrestored; + int m_bitsHUDDamage; + BOOL m_fInitHUD; + BOOL m_fGameHUDInitialized; + int m_iTrain; + BOOL m_fWeapon; + EHANDLE m_pTank; + float m_fDeadTime; + BOOL m_fNoPlayerSound; + BOOL m_fLongJump; + float m_tSneaking; + int m_iUpdateTime; + int m_iClientHealth; + int m_iClientBattery; + int m_iHideHUD; + int m_iClientHideHUD; + int m_iFOV; + int m_iClientFOV; + int m_iNumSpawns; + CBaseEntity *m_pObserver; + CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES]; CBasePlayerItem *m_pActiveItem; - CBasePlayerItem *m_pClientActiveItem; // client version of the active item + CBasePlayerItem *m_pClientActiveItem; CBasePlayerItem *m_pLastItem; - // shared ammo slots - int m_rgAmmo[MAX_AMMO_SLOTS]; - int m_rgAmmoLast[MAX_AMMO_SLOTS]; - - Vector m_vecAutoAim; - BOOL m_fOnTarget; - int m_iDeaths; - float m_iRespawnFrames; // used in PlayerDeathThink() to make sure players can always respawn - - int m_lastx, m_lasty; // These are the previous update's crosshair angles, DON"T SAVE/RESTORE - - int m_nCustomSprayFrames;// Custom clan logo frames for this player - float m_flNextDecalTime;// next time this player can spray a decal - - char m_szTeamName[TEAM_NAME_LENGTH]; - - virtual void Spawn( void ); - void Pain( void ); - -// virtual void Think( void ); - virtual void Jump( void ); - virtual void Duck( void ); - virtual void PreThink( void ); - virtual void PostThink( void ); - virtual Vector GetGunPosition( void ); - virtual int TakeHealth( float flHealth, int bitsDamageType ); - virtual void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType); - virtual int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType); - virtual void Killed( entvars_t *pevAttacker, int iGib ); - virtual Vector BodyTarget( const Vector &posSrc ) { return Center( ) + pev->view_ofs * RANDOM_FLOAT( 0.5, 1.1 ); }; // position to shoot at - virtual void StartSneaking( void ) { m_tSneaking = gpGlobals->time - 1; } - virtual void StopSneaking( void ) { m_tSneaking = gpGlobals->time + 30; } - virtual BOOL IsSneaking( void ) { return m_tSneaking <= gpGlobals->time; } - virtual BOOL IsAlive( void ) { return (pev->deadflag == DEAD_NO) && pev->health > 0; } - virtual BOOL ShouldFadeOnDeath( void ) { return FALSE; } - virtual BOOL IsPlayer( void ) { return TRUE; } // Spectators should return FALSE for this, they aren't "players" as far as game logic is concerned - - virtual BOOL IsNetClient( void ) { return TRUE; } // Bots should return FALSE for this, they can't receive NET messages - // Spectators should return TRUE for this - virtual const char *TeamID( void ); - - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - void RenewItems(void); - void PackDeadPlayerItems( void ); - void RemoveAllItems( BOOL removeSuit ); - BOOL SwitchWeapon( CBasePlayerItem *pWeapon ); - - // JOHN: sends custom messages if player HUD data has changed (eg health, ammo) - virtual void UpdateClientData( void ); - - static TYPEDESCRIPTION m_playerSaveData[]; - - // Player is moved across the transition by other means - virtual int ObjectCaps( void ) { return CBaseMonster :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION; } - virtual void Precache( void ); - BOOL IsOnLadder( void ); - BOOL FlashlightIsOn( void ); - void FlashlightTurnOn( void ); - void FlashlightTurnOff( void ); - - void UpdatePlayerSound ( void ); - void DeathSound ( void ); - - int Classify ( void ); - void SetAnimation( PLAYER_ANIM playerAnim ); - void SetWeaponAnimType( const char *szExtention ); - char m_szAnimExtention[32]; - - // custom player functions - virtual void ImpulseCommands( void ); - void CheatImpulseCommands( int iImpulse ); - - void StartDeathCam( void ); - void StartObserver( Vector vecPosition, Vector vecViewAngle ); - - void AddPoints( int score, BOOL bAllowNegativeScore ); - void AddPointsToTeam( int score, BOOL bAllowNegativeScore ); - BOOL AddPlayerItem( CBasePlayerItem *pItem ); - BOOL RemovePlayerItem( CBasePlayerItem *pItem ); - void DropPlayerItem ( char *pszItemName ); - BOOL HasPlayerItem( CBasePlayerItem *pCheckItem ); - BOOL HasNamedPlayerItem( const char *pszItemName ); - BOOL HasWeapons( void );// do I have ANY weapons? - void SelectPrevItem( int iItem ); - void SelectNextItem( int iItem ); - void SelectLastItem(void); - void SelectItem(const char *pstr); - void ItemPreFrame( void ); - void ItemPostFrame( void ); - void GiveNamedItem( const char *szName ); - void EnableControl(BOOL fControl); - - int GiveAmmo( int iAmount, char *szName, int iMax ); - void SendAmmoUpdate(void); - - void WaterMove( void ); - void EXPORT PlayerDeathThink( void ); - void PlayerUse( void ); - - void CheckSuitUpdate(); - void SetSuitUpdate(char *name, int fgroup, int iNoRepeat); - void UpdateGeigerCounter( void ); - void CheckTimeBasedDamage( void ); - - BOOL FBecomeProne ( void ); - void BarnacleVictimBitten ( entvars_t *pevBarnacle ); - void BarnacleVictimReleased ( void ); - static int GetAmmoIndex(const char *psz); - int AmmoInventory( int iAmmoIndex ); - int Illumination( void ); - - void ResetAutoaim( void ); - Vector GetAutoaimVector( float flDelta ); - Vector AutoaimDeflection( Vector &vecSrc, float flDist, float flDelta ); - - void ForceClientDllUpdate( void ); // Forces all client .dll specific data to be resent to client. - - void DeathMessage( entvars_t *pevKiller ); - - void SetCustomDecalFrames( int nFrames ); - int GetCustomDecalFrames( void ); - - void CBasePlayer::TabulateAmmo( void ); - - float m_flStartCharge; - float m_flAmmoStartCharge; - float m_flPlayAftershock; - float m_flNextAmmoBurn;// while charging, when to absorb another unit of player's ammo? - - //Player ID - void InitStatusBar( void ); - void UpdateStatusBar( void ); - int m_izSBarState[ SBAR_END ]; + int m_rgAmmo[MAX_AMMO_SLOTS]; + int m_rgAmmoLast[MAX_AMMO_SLOTS]; + Vector m_vecAutoAim; + BOOL m_fOnTarget; + int m_iDeaths; + int m_izSBarState[SBAR_END]; float m_flNextSBarUpdateTime; float m_flStatusBarDisappearDelay; - char m_SbarString0[ SBAR_STRING_SIZE ]; - char m_SbarString1[ SBAR_STRING_SIZE ]; - - float m_flNextChatTime; - + char m_SbarString0[SBAR_STRING_SIZE]; + int m_lastx; + int m_lasty; + int m_nCustomSprayFrames; + float m_flNextDecalTime; + char m_szTeamName[TEAM_NAME_LENGTH]; + int m_modelIndexPlayer; + char m_szAnimExtention[32]; + int m_iGaitsequence; + float m_flGaitframe; + float m_flGaityaw; + Vector m_prevgaitorigin; + float m_flPitch; + float m_flYaw; + float m_flGaitMovement; + int m_iAutoWepSwitch; + bool m_bVGUIMenus; + bool m_bShowHints; + bool m_bShieldDrawn; + bool m_bOwnsShield; + bool m_bWasFollowing; + float m_flNextFollowTime; + float m_flYawModifier; + float m_blindUntilTime; + float m_blindStartTime; + float m_blindHoldTime; + float m_blindFadeTime; + int m_blindAlpha; + float m_allowAutoFollowTime; + char m_autoBuyString[MAX_AUTOBUY_LENGTH]; + char *m_rebuyString; + RebuyStruct m_rebuyStruct; + bool m_bIsInRebuy; + float m_flLastUpdateTime; + char m_lastLocation[MaxLocationLen]; + float m_progressStart; + float m_progressEnd; + bool m_bObserverAutoDirector; + bool m_canSwitchObserverModes; + float m_heartBeatTime; + float m_intenseTimestamp; + float m_silentTimestamp; + MusicState m_musicState; + float m_flLastCommandTime[COMMANDS_TO_TRACK]; }; -#define AUTOAIM_2DEGREES 0.0348994967025 -#define AUTOAIM_5DEGREES 0.08715574274766 -#define AUTOAIM_8DEGREES 0.1391731009601 -#define AUTOAIM_10DEGREES 0.1736481776669 +class CWShield: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +public: + void SetCantBePickedUpByUser(CBaseEntity *pEntity, float time) { m_hEntToIgnoreTouchesFrom = pEntity; m_flTimeToIgnoreTouches = gpGlobals->time + time; } +public: + EHANDLE m_hEntToIgnoreTouchesFrom; + float m_flTimeToIgnoreTouches; +}; +inline bool CBasePlayer::IsReloading() const +{ + CBasePlayerWeapon *weapon = static_cast(m_pActiveItem); + if (weapon && weapon->m_fInReload) + return true; -extern int gmsgHudText; -extern BOOL gInitHUD; + return false; +} -#endif // PLAYER_H +inline CCSPlayer *CBasePlayer::CSPlayer() const { + return reinterpret_cast(this->m_pEntity); +} + +// returns a CBaseEntity pointer to a player by index. Only returns if the player is spawned and connected otherwise returns NULL +// Index is 1 based +inline CBasePlayer *UTIL_PlayerByIndex(int playerIndex) +{ + return (CBasePlayer *)GET_PRIVATE(INDEXENT(playerIndex)); +} + +inline CBasePlayer *UTIL_PlayerByIndexSafe(int playerIndex) +{ + CBasePlayer *player = nullptr; + if (likely(playerIndex > 0 && playerIndex <= gpGlobals->maxClients)) + player = UTIL_PlayerByIndex(playerIndex); + + return player; +} diff --git a/dlls/regamedll_api.h b/dlls/regamedll_api.h new file mode 100644 index 0000000..165f5b2 --- /dev/null +++ b/dlls/regamedll_api.h @@ -0,0 +1,480 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once +#include "archtypes.h" +#include "regamedll_interfaces.h" +#include "hookchains.h" +#include "interface.h" +#include "player.h" +#include "gamerules.h" +#include "client.h" +#include "items.h" + +#define REGAMEDLL_API_VERSION_MAJOR 5 +#define REGAMEDLL_API_VERSION_MINOR 0 + +// CBasePlayer::Spawn hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Spawn; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Spawn; + +// CBasePlayer::Precache hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Precache; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Precache; + +// CBasePlayer::ObjectCaps hook +typedef IHookChainClass IReGameHook_CBasePlayer_ObjectCaps; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_ObjectCaps; + +// CBasePlayer::Classify hook +typedef IHookChainClass IReGameHook_CBasePlayer_Classify; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Classify; + +// CBasePlayer::TraceAttack hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_TraceAttack; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_TraceAttack; + +// CBasePlayer::TakeDamage hook +typedef IHookChainClass IReGameHook_CBasePlayer_TakeDamage; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_TakeDamage; + +// CBasePlayer::TakeHealth hook +typedef IHookChainClass IReGameHook_CBasePlayer_TakeHealth; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_TakeHealth; + +// CBasePlayer::Killed hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Killed; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Killed; + +// CBasePlayer::AddPoints hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_AddPoints; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_AddPoints; + +// CBasePlayer::AddPointsToTeam hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_AddPointsToTeam; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_AddPointsToTeam; + +// CBasePlayer::AddPlayerItem hook +typedef IHookChainClass IReGameHook_CBasePlayer_AddPlayerItem; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_AddPlayerItem; + +// CBasePlayer::RemovePlayerItem hook +typedef IHookChainClass IReGameHook_CBasePlayer_RemovePlayerItem; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemovePlayerItem; + +// CBasePlayer::GiveAmmo hook +typedef IHookChainClass IReGameHook_CBasePlayer_GiveAmmo; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_GiveAmmo; + +// CBasePlayer::ResetMaxSpeed hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_ResetMaxSpeed; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_ResetMaxSpeed; + +// CBasePlayer::Jump hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Jump; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Jump; + +// CBasePlayer::Duck hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Duck; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Duck; + +// CBasePlayer::PreThink hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_PreThink; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_PreThink; + +// CBasePlayer::PostThink hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_PostThink; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_PostThink; + +// CBasePlayer::UpdateClientData hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_UpdateClientData; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_UpdateClientData; + +// CBasePlayer::ImpulseCommands hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_ImpulseCommands; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_ImpulseCommands; + +// CBasePlayer::RoundRespawn hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_RoundRespawn; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RoundRespawn; + +// CBasePlayer::Blind hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Blind; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Blind; + +// CBasePlayer::Observer_IsValidTarget hook +typedef IHookChainClass IReGameHook_CBasePlayer_Observer_IsValidTarget; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Observer_IsValidTarget; + +// CBasePlayer::SetAnimation hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_SetAnimation; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_SetAnimation; + +// CBasePlayer::GiveDefaultItems hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_GiveDefaultItems; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_GiveDefaultItems; + +// CBasePlayer::GiveNamedItem hook +typedef IHookChainClass IReGameHook_CBasePlayer_GiveNamedItem; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_GiveNamedItem; + +// CBasePlayer::AddAccount hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_AddAccount; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_AddAccount; + +// CBasePlayer::GiveShield hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_GiveShield; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_GiveShield; + +// CBasePlayer:SetClientUserInfoModel hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_SetClientUserInfoModel; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_SetClientUserInfoModel; + +// CBasePlayer:SetClientUserInfoName hook +typedef IHookChainClass IReGameHook_CBasePlayer_SetClientUserInfoName; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_SetClientUserInfoName; + +// CBasePlayer::HasRestrictItem hook +typedef IHookChainClass IReGameHook_CBasePlayer_HasRestrictItem; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_HasRestrictItem; + +// CBasePlayer::DropPlayerItem hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_DropPlayerItem; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropPlayerItem; + +// CBasePlayer::DropShield hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_DropShield; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_DropShield; + +// CBasePlayer::OnSpawnEquip hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_OnSpawnEquip; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_OnSpawnEquip; + +// CBasePlayer::Radio hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Radio; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Radio; + +// CBasePlayer::Disappear hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_Disappear; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Disappear; + +// CBasePlayer::MakeVIP hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_MakeVIP; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_MakeVIP; + +// CBasePlayer::MakeBomber hook +typedef IHookChainClass IReGameHook_CBasePlayer_MakeBomber; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_MakeBomber; + +// CBasePlayer::StartObserver hook +typedef IVoidHookChainClass IReGameHook_CBasePlayer_StartObserver; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBasePlayer_StartObserver; + +// CBasePlayer::GetIntoGame hook +typedef IHookChainClass IReGameHook_CBasePlayer_GetIntoGame; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_GetIntoGame; + +// CBaseAnimating::ResetSequenceInfo hook +typedef IVoidHookChainClass IReGameHook_CBaseAnimating_ResetSequenceInfo; +typedef IVoidHookChainRegistryClass IReGameHookRegistry_CBaseAnimating_ResetSequenceInfo; + +// GetForceCamera hook +typedef IHookChain IReGameHook_GetForceCamera; +typedef IHookChainRegistry IReGameHookRegistry_GetForceCamera; + +// PlayerBlind hook +typedef IVoidHookChain IReGameHook_PlayerBlind; +typedef IVoidHookChainRegistry IReGameHookRegistry_PlayerBlind; + +// RadiusFlash_TraceLine hook +typedef IVoidHookChain IReGameHook_RadiusFlash_TraceLine; +typedef IVoidHookChainRegistry IReGameHookRegistry_RadiusFlash_TraceLine; + +// RoundEnd hook +typedef IHookChain IReGameHook_RoundEnd; +typedef IHookChainRegistry IReGameHookRegistry_RoundEnd; + +// InstallGameRules hook +typedef IHookChain IReGameHook_InstallGameRules; +typedef IHookChainRegistry IReGameHookRegistry_InstallGameRules; + +// PM_Init hook +typedef IVoidHookChain IReGameHook_PM_Init; +typedef IVoidHookChainRegistry IReGameHookRegistry_PM_Init; + +// PM_Move hook +typedef IVoidHookChain IReGameHook_PM_Move; +typedef IVoidHookChainRegistry IReGameHookRegistry_PM_Move; + +// PM_AirMove hook +typedef IVoidHookChain IReGameHook_PM_AirMove; +typedef IVoidHookChainRegistry IReGameHookRegistry_PM_AirMove; + +// HandleMenu_ChooseAppearance hook +typedef IVoidHookChain IReGameHook_HandleMenu_ChooseAppearance; +typedef IVoidHookChainRegistry IReGameHookRegistry_HandleMenu_ChooseAppearance; + +// HandleMenu_ChooseTeam hook +typedef IHookChain IReGameHook_HandleMenu_ChooseTeam; +typedef IHookChainRegistry IReGameHookRegistry_HandleMenu_ChooseTeam; + +// ShowMenu hook +typedef IVoidHookChain IReGameHook_ShowMenu; +typedef IVoidHookChainRegistry IReGameHookRegistry_ShowMenu; + +// ShowVGUIMenu hook +typedef IVoidHookChain IReGameHook_ShowVGUIMenu; +typedef IVoidHookChainRegistry IReGameHookRegistry_ShowVGUIMenu; + +// BuyGunAmmo hook +typedef IHookChain IReGameHook_BuyGunAmmo; +typedef IHookChainRegistry IReGameHookRegistry_BuyGunAmmo; + +// BuyWeaponByWeaponID hook +typedef IHookChain IReGameHook_BuyWeaponByWeaponID; +typedef IHookChainRegistry IReGameHookRegistry_BuyWeaponByWeaponID; + +// InternalCommand hook +typedef IHookChain IReGameHook_InternalCommand; +typedef IHookChainRegistry IReGameHookRegistry_InternalCommand; + +// CHalfLifeMultiplay::FShouldSwitchWeapon hook +typedef IHookChain IReGameHook_CSGameRules_FShouldSwitchWeapon; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_FShouldSwitchWeapon; + +// CHalfLifeMultiplay::GetNextBestWeapon hook +typedef IHookChain IReGameHook_CSGameRules_GetNextBestWeapon; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_GetNextBestWeapon; + +// CHalfLifeMultiplay::FlPlayerFallDamage hook +typedef IHookChain IReGameHook_CSGameRules_FlPlayerFallDamage; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_FlPlayerFallDamage; + +// CHalfLifeMultiplay::FPlayerCanTakeDamage hook +typedef IHookChain IReGameHook_CSGameRules_FPlayerCanTakeDamage; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_FPlayerCanTakeDamage; + +// CHalfLifeMultiplay::PlayerSpawn hook +typedef IVoidHookChain IReGameHook_CSGameRules_PlayerSpawn; +typedef IVoidHookChainRegistry IReGameHookRegistry_CSGameRules_PlayerSpawn; + +// CHalfLifeMultiplay::FPlayerCanRespawn hook +typedef IHookChain IReGameHook_CSGameRules_FPlayerCanRespawn; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_FPlayerCanRespawn; + +// CHalfLifeMultiplay::GetPlayerSpawnSpot hook +typedef IHookChain IReGameHook_CSGameRules_GetPlayerSpawnSpot; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_GetPlayerSpawnSpot; + +// CHalfLifeMultiplay::ClientUserInfoChanged hook +typedef IVoidHookChain IReGameHook_CSGameRules_ClientUserInfoChanged; +typedef IVoidHookChainRegistry IReGameHookRegistry_CSGameRules_ClientUserInfoChanged; + +// CHalfLifeMultiplay::PlayerKilled hook +typedef IVoidHookChain IReGameHook_CSGameRules_PlayerKilled; +typedef IVoidHookChainRegistry IReGameHookRegistry_CSGameRules_PlayerKilled; + +// CHalfLifeMultiplay::DeathNotice hook +typedef IVoidHookChain IReGameHook_CSGameRules_DeathNotice; +typedef IVoidHookChainRegistry IReGameHookRegistry_CSGameRules_DeathNotice; + +// CHalfLifeMultiplay::CanHavePlayerItem hook +typedef IHookChain IReGameHook_CSGameRules_CanHavePlayerItem; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CanHavePlayerItem; + +// CHalfLifeMultiplay::DeadPlayerWeapons hook +typedef IHookChain IReGameHook_CSGameRules_DeadPlayerWeapons; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_DeadPlayerWeapons; + +// CHalfLifeMultiplay::ServerDeactivate hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_ServerDeactivate; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_ServerDeactivate; + +// CHalfLifeMultiplay::CheckMapConditions hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_CheckMapConditions; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_CheckMapConditions; + +// CHalfLifeMultiplay::CleanUpMap hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_CleanUpMap; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_CleanUpMap; + +// CHalfLifeMultiplay::RestartRound hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_RestartRound; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_RestartRound; + +// CHalfLifeMultiplay::CheckWinConditions hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_CheckWinConditions; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_CheckWinConditions; + +// CHalfLifeMultiplay::RemoveGuns hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_RemoveGuns; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_RemoveGuns; + +// CHalfLifeMultiplay::GiveC4 hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_GiveC4; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_GiveC4; + +// CHalfLifeMultiplay::ChangeLevel hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_ChangeLevel; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_ChangeLevel; + +// CHalfLifeMultiplay::GoToIntermission hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_GoToIntermission; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_GoToIntermission; + +// CHalfLifeMultiplay::BalanceTeams hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_BalanceTeams; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_BalanceTeams; + +// CHalfLifeMultiplay::OnRoundFreezeEnd hook +typedef IVoidHookChain<> IReGameHook_CSGameRules_OnRoundFreezeEnd; +typedef IVoidHookChainRegistry<> IReGameHookRegistry_CSGameRules_OnRoundFreezeEnd; + +class IReGameHookchains { +public: + virtual ~IReGameHookchains() {} + + // CBasePlayer virtual + virtual IReGameHookRegistry_CBasePlayer_Spawn* CBasePlayer_Spawn() = 0; + virtual IReGameHookRegistry_CBasePlayer_Precache* CBasePlayer_Precache() = 0; + virtual IReGameHookRegistry_CBasePlayer_ObjectCaps* CBasePlayer_ObjectCaps() = 0; + virtual IReGameHookRegistry_CBasePlayer_Classify* CBasePlayer_Classify() = 0; + virtual IReGameHookRegistry_CBasePlayer_TraceAttack* CBasePlayer_TraceAttack() = 0; + virtual IReGameHookRegistry_CBasePlayer_TakeDamage* CBasePlayer_TakeDamage() = 0; + virtual IReGameHookRegistry_CBasePlayer_TakeHealth* CBasePlayer_TakeHealth() = 0; + virtual IReGameHookRegistry_CBasePlayer_Killed* CBasePlayer_Killed() = 0; + virtual IReGameHookRegistry_CBasePlayer_AddPoints* CBasePlayer_AddPoints() = 0; + virtual IReGameHookRegistry_CBasePlayer_AddPointsToTeam* CBasePlayer_AddPointsToTeam() = 0; + virtual IReGameHookRegistry_CBasePlayer_AddPlayerItem* CBasePlayer_AddPlayerItem() = 0; + virtual IReGameHookRegistry_CBasePlayer_RemovePlayerItem* CBasePlayer_RemovePlayerItem() = 0; + virtual IReGameHookRegistry_CBasePlayer_GiveAmmo* CBasePlayer_GiveAmmo() = 0; + virtual IReGameHookRegistry_CBasePlayer_ResetMaxSpeed* CBasePlayer_ResetMaxSpeed() = 0; + virtual IReGameHookRegistry_CBasePlayer_Jump* CBasePlayer_Jump() = 0; + virtual IReGameHookRegistry_CBasePlayer_Duck* CBasePlayer_Duck() = 0; + virtual IReGameHookRegistry_CBasePlayer_PreThink* CBasePlayer_PreThink() = 0; + virtual IReGameHookRegistry_CBasePlayer_PostThink* CBasePlayer_PostThink() = 0; + virtual IReGameHookRegistry_CBasePlayer_UpdateClientData* CBasePlayer_UpdateClientData() = 0; + virtual IReGameHookRegistry_CBasePlayer_ImpulseCommands* CBasePlayer_ImpulseCommands() = 0; + virtual IReGameHookRegistry_CBasePlayer_RoundRespawn* CBasePlayer_RoundRespawn() = 0; + virtual IReGameHookRegistry_CBasePlayer_Blind* CBasePlayer_Blind() = 0; + + virtual IReGameHookRegistry_CBasePlayer_Observer_IsValidTarget* CBasePlayer_Observer_IsValidTarget() = 0; + virtual IReGameHookRegistry_CBasePlayer_SetAnimation* CBasePlayer_SetAnimation() = 0; + virtual IReGameHookRegistry_CBasePlayer_GiveDefaultItems* CBasePlayer_GiveDefaultItems() = 0; + virtual IReGameHookRegistry_CBasePlayer_GiveNamedItem* CBasePlayer_GiveNamedItem() = 0; + virtual IReGameHookRegistry_CBasePlayer_AddAccount* CBasePlayer_AddAccount() = 0; + virtual IReGameHookRegistry_CBasePlayer_GiveShield* CBasePlayer_GiveShield() = 0; + virtual IReGameHookRegistry_CBasePlayer_SetClientUserInfoModel* CBasePlayer_SetClientUserInfoModel() = 0; + virtual IReGameHookRegistry_CBasePlayer_SetClientUserInfoName* CBasePlayer_SetClientUserInfoName() = 0; + virtual IReGameHookRegistry_CBasePlayer_HasRestrictItem* CBasePlayer_HasRestrictItem() = 0; + virtual IReGameHookRegistry_CBasePlayer_DropPlayerItem* CBasePlayer_DropPlayerItem() = 0; + virtual IReGameHookRegistry_CBasePlayer_DropShield* CBasePlayer_DropShield() = 0; + virtual IReGameHookRegistry_CBasePlayer_OnSpawnEquip* CBasePlayer_OnSpawnEquip() = 0; + virtual IReGameHookRegistry_CBasePlayer_Radio* CBasePlayer_Radio() = 0; + virtual IReGameHookRegistry_CBasePlayer_Disappear* CBasePlayer_Disappear() = 0; + virtual IReGameHookRegistry_CBasePlayer_MakeVIP* CBasePlayer_MakeVIP() = 0; + virtual IReGameHookRegistry_CBasePlayer_MakeBomber* CBasePlayer_MakeBomber() = 0; + virtual IReGameHookRegistry_CBasePlayer_StartObserver* CBasePlayer_StartObserver() = 0; + virtual IReGameHookRegistry_CBasePlayer_GetIntoGame* CBasePlayer_GetIntoGame() = 0; + + virtual IReGameHookRegistry_CBaseAnimating_ResetSequenceInfo* CBaseAnimating_ResetSequenceInfo() = 0; + + virtual IReGameHookRegistry_GetForceCamera* GetForceCamera() = 0; + virtual IReGameHookRegistry_PlayerBlind* PlayerBlind() = 0; + virtual IReGameHookRegistry_RadiusFlash_TraceLine* RadiusFlash_TraceLine() = 0; + virtual IReGameHookRegistry_RoundEnd* RoundEnd() = 0; + virtual IReGameHookRegistry_InstallGameRules* InstallGameRules() = 0; + virtual IReGameHookRegistry_PM_Init* PM_Init() = 0; + virtual IReGameHookRegistry_PM_Move* PM_Move() = 0; + virtual IReGameHookRegistry_PM_AirMove* PM_AirMove() = 0; + virtual IReGameHookRegistry_HandleMenu_ChooseAppearance* HandleMenu_ChooseAppearance() = 0; + virtual IReGameHookRegistry_HandleMenu_ChooseTeam* HandleMenu_ChooseTeam() = 0; + virtual IReGameHookRegistry_ShowMenu* ShowMenu() = 0; + virtual IReGameHookRegistry_ShowVGUIMenu* ShowVGUIMenu() = 0; + virtual IReGameHookRegistry_BuyGunAmmo* BuyGunAmmo() = 0; + virtual IReGameHookRegistry_BuyWeaponByWeaponID* BuyWeaponByWeaponID() = 0; + virtual IReGameHookRegistry_InternalCommand* InternalCommand() = 0; + + virtual IReGameHookRegistry_CSGameRules_FShouldSwitchWeapon* CSGameRules_FShouldSwitchWeapon() = 0; + virtual IReGameHookRegistry_CSGameRules_GetNextBestWeapon* CSGameRules_GetNextBestWeapon() = 0; + virtual IReGameHookRegistry_CSGameRules_FlPlayerFallDamage* CSGameRules_FlPlayerFallDamage() = 0; + virtual IReGameHookRegistry_CSGameRules_FPlayerCanTakeDamage* CSGameRules_FPlayerCanTakeDamage() = 0; + virtual IReGameHookRegistry_CSGameRules_PlayerSpawn* CSGameRules_PlayerSpawn() = 0; + virtual IReGameHookRegistry_CSGameRules_FPlayerCanRespawn* CSGameRules_FPlayerCanRespawn() = 0; + virtual IReGameHookRegistry_CSGameRules_GetPlayerSpawnSpot* CSGameRules_GetPlayerSpawnSpot() = 0; + virtual IReGameHookRegistry_CSGameRules_ClientUserInfoChanged* CSGameRules_ClientUserInfoChanged() = 0; + virtual IReGameHookRegistry_CSGameRules_PlayerKilled* CSGameRules_PlayerKilled() = 0; + virtual IReGameHookRegistry_CSGameRules_DeathNotice* CSGameRules_DeathNotice() = 0; + virtual IReGameHookRegistry_CSGameRules_CanHavePlayerItem* CSGameRules_CanHavePlayerItem() = 0; + virtual IReGameHookRegistry_CSGameRules_DeadPlayerWeapons* CSGameRules_DeadPlayerWeapons() = 0; + virtual IReGameHookRegistry_CSGameRules_ServerDeactivate* CSGameRules_ServerDeactivate() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckMapConditions* CSGameRules_CheckMapConditions() = 0; + virtual IReGameHookRegistry_CSGameRules_CleanUpMap* CSGameRules_CleanUpMap() = 0; + virtual IReGameHookRegistry_CSGameRules_RestartRound* CSGameRules_RestartRound() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckWinConditions* CSGameRules_CheckWinConditions() = 0; + virtual IReGameHookRegistry_CSGameRules_RemoveGuns* CSGameRules_RemoveGuns() = 0; + virtual IReGameHookRegistry_CSGameRules_GiveC4* CSGameRules_GiveC4() = 0; + virtual IReGameHookRegistry_CSGameRules_ChangeLevel* CSGameRules_ChangeLevel() = 0; + virtual IReGameHookRegistry_CSGameRules_GoToIntermission* CSGameRules_GoToIntermission() = 0; + virtual IReGameHookRegistry_CSGameRules_BalanceTeams* CSGameRules_BalanceTeams() = 0; + virtual IReGameHookRegistry_CSGameRules_OnRoundFreezeEnd* CSGameRules_OnRoundFreezeEnd() = 0; +}; + +struct ReGameFuncs_t { + struct edict_s *(*CREATE_NAMED_ENTITY2)(string_t iClass); + void (*ChangeString)(char *&dest, const char *source); + void (*RadiusDamage)(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, float flRadius, int iClassIgnore, int bitsDamageType); + void (*ClearMultiDamage)(); + void (*ApplyMultiDamage)(entvars_t *pevInflictor, entvars_t *pevAttacker); + void (*AddMultiDamage)(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType); + class CBaseEntity *(*UTIL_FindEntityByString)(class CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue); + void (*AddEntityHashValue)(entvars_t *pev, const char *value, hash_types_e fieldType); + void (*RemoveEntityHashValue)(entvars_t *pev, const char *value, hash_types_e fieldType); + int (*Cmd_Argc)(); + const char *(*Cmd_Argv)(int i); +}; + +class IReGameApi { +public: + virtual ~IReGameApi() {} + + virtual int GetMajorVersion() = 0; + virtual int GetMinorVersion() = 0; + virtual const ReGameFuncs_t* GetFuncs() = 0; + virtual IReGameHookchains* GetHookchains() = 0; + + virtual class CGameRules* GetGameRules() = 0; + virtual struct WeaponInfoStruct* GetWeaponInfo(int weaponID) = 0; + virtual struct WeaponInfoStruct* GetWeaponInfo(const char* weaponName) = 0; + virtual struct playermove_s* GetPlayerMove() = 0; + virtual struct WeaponSlotInfo* GetWeaponSlot(WeaponIdType weaponID) = 0; + virtual struct WeaponSlotInfo* GetWeaponSlot(const char* weaponName) = 0; + virtual struct ItemInfo* GetItemInfo(WeaponIdType weaponID) = 0; + virtual struct AmmoInfo* GetAmmoInfo(AmmoType ammoID) = 0; +}; + +#define VRE_GAMEDLL_API_VERSION "VRE_GAMEDLL_API_VERSION001" diff --git a/dlls/regamedll_common.h b/dlls/regamedll_common.h new file mode 100644 index 0000000..826b6de --- /dev/null +++ b/dlls/regamedll_common.h @@ -0,0 +1,96 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#ifndef _WIN32 +#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]); +#endif + +#define Q_isspace isspace +#define Q_isalnum isalnum +#define Q_isalpha isalpha + +#define Q_malloc malloc +#define Q_calloc calloc +#define Q_alloca alloca +#define Q_free free + +#define Q_min min +#define Q_max max +#define Q_clamp clamp +#define Q_access _access +#define Q_close _close +#define Q_write _write +#define Q_memset memset +#define Q_memcpy memcpy +#define Q_strlen strlen +#define Q_memcmp memcmp +#define Q_strcpy strcpy +#define Q_strncpy strncpy +#define Q_strrchr strrchr +#define Q_strcat strcat +#define Q_strncat strncat +#define Q_strcmp strcmp +#define Q_strncmp strncmp +#define Q_sscanf sscanf +#define Q_strdup _strdup +#define Q_stricmp _stricmp +#define Q_strnicmp _strnicmp +#define Q_strstr strstr +#define Q_strchr strchr +#define Q_strrchr strrchr +#define Q_strlwr _strlwr +#define Q_sprintf sprintf +#define Q_snprintf _snprintf +#define Q_atoi atoi +#define Q_atof atof +#define Q_toupper toupper +#define Q_memmove memmove +#define Q_vsnprintf _vsnprintf +#define Q_vsnwprintf _vsnwprintf +#define Q_abs abs +#define Q_fabs fabs +#define Q_tan tan +#define Q_atan atan +#define Q_atan2 atan2 +#define Q_acos acos +#define Q_cos cos +#define Q_sin sin +#define Q_pow pow +#define Q_fmod fmod +#define Q_fopen fopen +#define Q_fwrite fwrite +#define Q_fprintf fprintf +#define Q_fclose fclose + +#ifdef REGAMEDLL_FIXES +#define Q_sqrt M_sqrt +#else +#define Q_sqrt sqrt +#endif diff --git a/dlls/regamedll_const.h b/dlls/regamedll_const.h new file mode 100644 index 0000000..36d038b --- /dev/null +++ b/dlls/regamedll_const.h @@ -0,0 +1,104 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +// These are caps bits to indicate what an object's capabilities (currently used for save/restore and level transitions) +#define FCAP_CUSTOMSAVE 0x00000001 +#define FCAP_ACROSS_TRANSITION 0x00000002 // should transfer between transitions +#define FCAP_MUST_SPAWN 0x00000004 // Spawn after restore +#define FCAP_DONT_SAVE 0x80000000 // Don't save this +#define FCAP_IMPULSE_USE 0x00000008 // can be used by the player +#define FCAP_CONTINUOUS_USE 0x00000010 // can be used by the player +#define FCAP_ONOFF_USE 0x00000020 // can be used by the player +#define FCAP_DIRECTIONAL_USE 0x00000040 // Player sends +/- 1 when using (currently only tracktrains) +#define FCAP_MASTER 0x00000080 // Can be used to "master" other entities (like multisource) + +// UNDONE: This will ignore transition volumes (trigger_transition), but not the PVS!!! +#define FCAP_FORCE_TRANSITION 0x00000080 // ALWAYS goes across transitions + +// for Classify +#define CLASS_NONE 0 +#define CLASS_MACHINE 1 +#define CLASS_PLAYER 2 +#define CLASS_HUMAN_PASSIVE 3 +#define CLASS_HUMAN_MILITARY 4 +#define CLASS_ALIEN_MILITARY 5 +#define CLASS_ALIEN_PASSIVE 6 +#define CLASS_ALIEN_MONSTER 7 +#define CLASS_ALIEN_PREY 8 +#define CLASS_ALIEN_PREDATOR 9 +#define CLASS_INSECT 10 +#define CLASS_PLAYER_ALLY 11 +#define CLASS_PLAYER_BIOWEAPON 12 // hornets and snarks.launched by players +#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks.launched by the alien menace +#define CLASS_VEHICLE 14 +#define CLASS_BARNACLE 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures. + +#define SF_NORESPAWN (1 << 30) // set this bit on guns and stuff that should never respawn. + +#define DMG_GENERIC 0 // generic damage was done +#define DMG_CRUSH (1<<0) // crushed by falling or moving object +#define DMG_BULLET (1<<1) // shot +#define DMG_SLASH (1<<2) // cut, clawed, stabbed +#define DMG_BURN (1<<3) // heat burned +#define DMG_FREEZE (1<<4) // frozen +#define DMG_FALL (1<<5) // fell too far +#define DMG_BLAST (1<<6) // explosive blast damage +#define DMG_CLUB (1<<7) // crowbar, punch, headbutt +#define DMG_SHOCK (1<<8) // electric shock +#define DMG_SONIC (1<<9) // sound pulse shockwave +#define DMG_ENERGYBEAM (1<<10) // laser or other high energy beam +#define DMG_NEVERGIB (1<<12) // with this bit OR'd in, no damage type will be able to gib victims upon death +#define DMG_ALWAYSGIB (1<<13) // with this bit OR'd in, any damage type can be made to gib victims upon death +#define DMG_DROWN (1<<14) // Drowning + +// time-based damage +#define DMG_TIMEBASED (~(0x3FFF)) // mask for time-based damage + +#define DMG_PARALYZE (1<<15) // slows affected creature down +#define DMG_NERVEGAS (1<<16) // nerve toxins, very bad +#define DMG_POISON (1<<17) // blood poisioning +#define DMG_RADIATION (1<<18) // radiation exposure +#define DMG_DROWNRECOVER (1<<19) // drowning recovery +#define DMG_ACID (1<<20) // toxic chemicals or acid burns +#define DMG_SLOWBURN (1<<21) // in an oven +#define DMG_SLOWFREEZE (1<<22) // in a subzero freezer +#define DMG_MORTAR (1<<23) // Hit by air raid (done to distinguish grenade from mortar) +#define DMG_EXPLOSION (1<<24) + +// these are the damage types that are allowed to gib corpses +#define DMG_GIB_CORPSE (DMG_CRUSH | DMG_FALL | DMG_BLAST | DMG_SONIC | DMG_CLUB) + +// these are the damage types that have client hud art +#define DMG_SHOWNHUD (DMG_POISON | DMG_ACID | DMG_FREEZE | DMG_SLOWFREEZE | DMG_DROWN | DMG_BURN | DMG_SLOWBURN | DMG_NERVEGAS | DMG_RADIATION | DMG_SHOCK) + +// when calling KILLED(), a value that governs gib behavior is expected to be +// one of these three values +#define GIB_NORMAL 0 // gib if entity was overkilled +#define GIB_NEVER 1 // never gib, no matter how much death damage is done ( freezing, etc ) +#define GIB_ALWAYS 2 // always gib ( Houndeye Shock, Barnacle Bite ) diff --git a/dlls/regamedll_interfaces.h b/dlls/regamedll_interfaces.h new file mode 100644 index 0000000..38486f6 --- /dev/null +++ b/dlls/regamedll_interfaces.h @@ -0,0 +1,301 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +class CBaseEntity; +class CBasePlayer; + +// Implementation wrapper +class CCSEntity { +public: + virtual ~CCSEntity() {} + virtual void FireBullets(int iShots, Vector &vecSrc, Vector &vecDirShooting, Vector &vecSpread, float flDistance, int iBulletType, int iTracerFreq, int iDamage, entvars_t *pevAttacker); + virtual Vector FireBullets3(Vector &vecSrc, Vector &vecDirShooting, float vecSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand); +public: + CBaseEntity *m_pContainingEntity; +}; + +class CCSDelay: public CCSEntity {}; +class CCSAnimating: public CCSDelay {}; +class CCSPlayerItem: public CCSAnimating {}; +class CCSToggle: public CCSAnimating {}; +class CCSMonster: public CCSToggle {}; +class CCSWeaponBox: public CCSEntity {}; +class CCSArmoury: public CCSEntity {}; + +class CCSPlayer: public CCSMonster { +public: + CCSPlayer() : m_bForceShowMenu(false) + { + m_szModel[0] = '\0'; + } + + virtual bool IsConnected() const; + virtual void SetAnimation(PLAYER_ANIM playerAnim); + virtual void AddAccount(int amount, RewardType type = RT_NONE, bool bTrackChange = true); + virtual CBaseEntity *GiveNamedItem(const char *pszName); + virtual CBaseEntity *GiveNamedItemEx(const char *pszName); + virtual void GiveDefaultItems(); + virtual void GiveShield(bool bDeploy = true); + virtual void DropShield(bool bDeploy = true); + virtual void DropPlayerItem(const char *pszItemName); + virtual void RemoveShield(); + virtual void RemoveAllItems(bool bRemoveSuit); + virtual bool RemovePlayerItem(const char* pszItemName); + virtual void SetPlayerModel(bool bHasC4); + virtual void SetPlayerModelEx(const char *modelName); + virtual void SetNewPlayerModel(const char *modelName); + virtual void ClientCommand(const char *cmd, const char *arg1 = nullptr, const char *arg2 = nullptr, const char *arg3 = nullptr); + virtual void SetProgressBarTime(int time); + virtual void SetProgressBarTime2(int time, float timeElapsed); + virtual struct edict_s *EntSelectSpawnPoint(); + virtual void SetBombIcon(bool bFlash = false); + virtual void SetScoreAttrib(CBasePlayer *dest); + virtual void SendItemStatus(); + virtual void ReloadWeapons(CBasePlayerItem *pWeapon = nullptr, bool bForceReload = false, bool bForceRefill = false); + virtual void Observer_SetMode(int iMode); + virtual bool SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pSpot); + virtual bool SwitchWeapon(CBasePlayerItem *pWeapon); + virtual void SwitchTeam(); + virtual bool JoinTeam(TeamName team); + virtual void StartObserver(Vector& vecPosition, Vector& vecViewAngle); + virtual void TeamChangeUpdate(); + virtual void DropSecondary(); + virtual void DropPrimary(); + virtual bool HasPlayerItem(CBasePlayerItem *pCheckItem); + virtual bool HasNamedPlayerItem(const char *pszItemName); + virtual CBasePlayerItem *GetItemById(WeaponIdType weaponID); + virtual CBasePlayerItem *GetItemByName(const char *itemName); + virtual void Disappear(); + virtual void MakeVIP(); + virtual bool MakeBomber(); + + CBasePlayer *BasePlayer() const; +public: + char m_szModel[32]; + bool m_bForceShowMenu; +}; + +class CAPI_Bot: public CCSPlayer {}; +class CAPI_CSBot: public CAPI_Bot {}; +class CCSShield: public CCSEntity {}; +class CCSDeadHEV: public CCSMonster {}; +class CCSSprayCan: public CCSEntity {}; +class CCSBloodSplat: public CCSEntity {}; +class CCSPlayerWeapon: public CCSPlayerItem {}; +class CCSWorld: public CCSEntity {}; +class CCSDecal: public CCSEntity {}; +class CCSCorpse: public CCSEntity {}; +class CCSGrenade: public CCSMonster {}; +class CCSAirtank: public CCSGrenade {}; +class CCSPlayerAmmo: public CCSEntity {}; +class CCS9MMAmmo: public CCSPlayerAmmo {}; +class CCSBuckShotAmmo: public CCSPlayerAmmo {}; +class CCS556NatoAmmo: public CCSPlayerAmmo {}; +class CCS556NatoBoxAmmo: public CCSPlayerAmmo {}; +class CCS762NatoAmmo: public CCSPlayerAmmo {}; +class CCS45ACPAmmo: public CCSPlayerAmmo {}; +class CCS50AEAmmo: public CCSPlayerAmmo {}; +class CCS338MagnumAmmo: public CCSPlayerAmmo {}; +class CCS57MMAmmo: public CCSPlayerAmmo {}; +class CCS357SIGAmmo: public CCSPlayerAmmo {}; +class CCSFuncWall: public CCSEntity {}; +class CCSFuncWallToggle: public CCSFuncWall {}; +class CCSFuncConveyor: public CCSFuncWall {}; +class CCSFuncIllusionary: public CCSToggle {}; +class CCSFuncMonsterClip: public CCSFuncWall {}; +class CCSFuncRotating: public CCSEntity {}; +class CCSPendulum: public CCSEntity {}; +class CCSPointEntity: public CCSEntity {}; +class CCSStripWeapons: public CCSPointEntity {}; +class CCSInfoIntermission: public CCSPointEntity {}; +class CCSRevertSaved: public CCSPointEntity {}; +class CCSEnvGlobal: public CCSPointEntity {}; +class CCSMultiSource: public CCSPointEntity {}; +class CCSButton: public CCSToggle {}; +class CCSRotButton: public CCSButton {}; +class CCSMomentaryRotButton: public CCSToggle {}; +class CCSEnvSpark: public CCSEntity {}; +class CCSButtonTarget: public CCSEntity {}; +class CCSDoor: public CCSToggle {}; +class CCSRotDoor: public CCSDoor {}; +class CCSMomentaryDoor: public CCSToggle {}; +class CCSGib: public CCSEntity {}; +class CCSBubbling: public CCSEntity {}; +class CCSBeam: public CCSEntity {}; +class CCSLightning: public CCSBeam {}; +class CCSLaser: public CCSBeam {}; +class CCSGlow: public CCSPointEntity {}; +class CCSSprite: public CCSPointEntity {}; +class CCSBombGlow: public CCSSprite {}; +class CCSGibShooter: public CCSDelay {}; +class CCSEnvShooter: public CCSGibShooter {}; +class CCSTestEffect: public CCSDelay {}; +class CCSBlood: public CCSPointEntity {}; +class CCSShake: public CCSPointEntity {}; +class CCSFade: public CCSPointEntity {}; +class CCSMessage: public CCSPointEntity {}; +class CCSEnvFunnel: public CCSDelay {}; +class CCSEnvBeverage: public CCSDelay {}; +class CCSItemSoda: public CCSEntity {}; +class CCSShower: public CCSEntity {}; +class CCSEnvExplosion: public CCSMonster {}; +class CCSBreakable: public CCSDelay {}; +class CCSPushable: public CCSBreakable {}; +class CCSFuncTank: public CCSEntity {}; +class CCSFuncTankGun: public CCSFuncTank {}; +class CCSFuncTankLaser: public CCSFuncTank {}; +class CCSFuncTankRocket: public CCSFuncTank {}; +class CCSFuncTankMortar: public CCSFuncTank {}; +class CCSFuncTankControls: public CCSEntity {}; +class CCSRecharge: public CCSToggle {}; +class CCSCycler: public CCSMonster {}; +class CCSGenericCycler: public CCSCycler {}; +class CCSCyclerProbe: public CCSCycler {}; +class CCSCyclerSprite: public CCSEntity {}; +class CCSWeaponCycler: public CCSPlayerWeapon {}; +class CCSWreckage: public CCSMonster {}; +class CCSWorldItem: public CCSEntity {}; +class CCSItem: public CCSEntity {}; +class CCSHealthKit: public CCSItem {}; +class CCSWallHealth: public CCSToggle {}; +class CCSItemSuit: public CCSItem {}; +class CCSItemBattery: public CCSItem {}; +class CCSItemAntidote: public CCSItem {}; +class CCSItemSecurity: public CCSItem {}; +class CCSItemLongJump: public CCSItem {}; +class CCSItemKevlar: public CCSItem {}; +class CCSItemAssaultSuit: public CCSItem {}; +class CCSItemThighPack: public CCSItem {}; +class CCSGrenCatch: public CCSEntity {}; +class CCSFuncWeaponCheck: public CCSEntity {}; +class CCSHostage: public CCSMonster {}; +class CCSLight: public CCSPointEntity {}; +class CCSEnvLight: public CCSLight {}; +class CCSRuleEntity: public CCSEntity {}; +class CCSRulePointEntity: public CCSRuleEntity {}; +class CCSRuleBrushEntity: public CCSRuleEntity {}; +class CCSGameScore: public CCSRulePointEntity {}; +class CCSGameEnd: public CCSRulePointEntity {}; +class CCSGameText: public CCSRulePointEntity {}; +class CCSGameTeamMaster: public CCSRulePointEntity {}; +class CCSGameTeamSet: public CCSRulePointEntity {}; +class CCSGamePlayerZone: public CCSRuleBrushEntity {}; +class CCSGamePlayerHurt: public CCSRulePointEntity {}; +class CCSGameCounter: public CCSRulePointEntity {}; +class CCSGameCounterSet: public CCSRulePointEntity {}; +class CCSGamePlayerEquip: public CCSRulePointEntity {}; +class CCSGamePlayerTeam: public CCSRulePointEntity {}; +class CCSFuncMortarField: public CCSToggle {}; +class CCSMortar: public CCSGrenade {}; +class CCSMapInfo: public CCSPointEntity {}; +class CCSPathCorner: public CCSPointEntity {}; +class CCSPathTrack: public CCSPointEntity {}; +class CCSFuncTrackTrain: public CCSEntity {}; +class CCSFuncVehicleControls: public CCSEntity {}; +class CCSFuncVehicle: public CCSEntity {}; +class CCSPlatTrain: public CCSToggle {}; +class CCSFuncPlat: public CCSPlatTrain {}; +class CCSPlatTrigger: public CCSEntity {}; +class CCSFuncPlatRot: public CCSFuncPlat {}; +class CCSFuncTrain: public CCSPlatTrain {}; +class CCSFuncTrainControls: public CCSEntity {}; +class CCSFuncTrackChange: public CCSFuncPlatRot {}; +class CCSFuncTrackAuto: public CCSFuncTrackChange {}; +class CCSGunTarget: public CCSMonster {}; +class CCSAmbientGeneric: public CCSEntity {}; +class CCSEnvSound: public CCSPointEntity {}; +class CCSSpeaker: public CCSEntity {}; +class CCSSoundEnt: public CCSEntity {}; +class CCSUSP: public CCSPlayerWeapon {}; +class CCSMP5N: public CCSPlayerWeapon {}; +class CCSSG552: public CCSPlayerWeapon {}; +class CCSAK47: public CCSPlayerWeapon {}; +class CCSAUG: public CCSPlayerWeapon {}; +class CCSAWP: public CCSPlayerWeapon {}; +class CCSC4: public CCSPlayerWeapon {}; +class CCSDEAGLE: public CCSPlayerWeapon {}; +class CCSFlashbang: public CCSPlayerWeapon {}; +class CCSG3SG1: public CCSPlayerWeapon {}; +class CCSGLOCK18: public CCSPlayerWeapon {}; +class CCSHEGrenade: public CCSPlayerWeapon {}; +class CCSKnife: public CCSPlayerWeapon {}; +class CCSM249: public CCSPlayerWeapon {}; +class CCSM3: public CCSPlayerWeapon {}; +class CCSM4A1: public CCSPlayerWeapon {}; +class CCSMAC10: public CCSPlayerWeapon {}; +class CCSP228: public CCSPlayerWeapon {}; +class CCSP90: public CCSPlayerWeapon {}; +class CCSSCOUT: public CCSPlayerWeapon {}; +class CCSSmokeGrenade: public CCSPlayerWeapon {}; +class CCSTMP: public CCSPlayerWeapon {}; +class CCSXM1014: public CCSPlayerWeapon {}; +class CCSELITE: public CCSPlayerWeapon {}; +class CCSFiveSeven: public CCSPlayerWeapon {}; +class CCSUMP45: public CCSPlayerWeapon {}; +class CCSSG550: public CCSPlayerWeapon {}; +class CCSGalil: public CCSPlayerWeapon {}; +class CCSFamas: public CCSPlayerWeapon {}; +class CCSNullEntity: public CCSEntity {}; +class CCSDMStart: public CCSPointEntity {}; +class CCSFrictionModifier: public CCSEntity {}; +class CCSAutoTrigger: public CCSDelay {}; +class CCSTriggerRelay: public CCSDelay {}; +class CCSMultiManager: public CCSToggle {}; +class CCSRenderFxManager: public CCSEntity {}; +class CCSTrigger: public CCSToggle {}; +class CCSTriggerHurt: public CCSTrigger {}; +class CCSTriggerMonsterJump: public CCSTrigger {}; +class CCSTriggerCDAudio: public CCSTrigger {}; +class CCSTargetCDAudio: public CCSPointEntity {}; +class CCSTriggerMultiple: public CCSTrigger {}; +class CCSTriggerOnce: public CCSTriggerMultiple {}; +class CCSTriggerCounter: public CCSTrigger {}; +class CCSTriggerVolume: public CCSPointEntity {}; +class CCSFireAndDie: public CCSDelay {}; +class CCSChangeLevel: public CCSTrigger {}; +class CCSLadder: public CCSTrigger {}; +class CCSTriggerPush: public CCSTrigger {}; +class CCSTriggerTeleport: public CCSTrigger {}; +class CCSBuyZone: public CCSTrigger {}; +class CCSBombTarget: public CCSTrigger {}; +class CCSHostageRescue: public CCSTrigger {}; +class CCSEscapeZone: public CCSTrigger {}; +class CCSVIP_SafetyZone: public CCSTrigger {}; +class CCSTriggerSave: public CCSTrigger {}; +class CCSTriggerEndSection: public CCSTrigger {}; +class CCSTriggerGravity: public CCSTrigger {}; +class CCSTriggerChangeTarget: public CCSDelay {}; +class CCSTriggerCamera: public CCSDelay {}; +class CCSWeather: public CCSTrigger {}; +class CCSClientFog: public CCSEntity {}; + +inline CBasePlayer *CCSPlayer::BasePlayer() const { + return reinterpret_cast(this->m_pContainingEntity); +} diff --git a/dlls/revert_saved.h b/dlls/revert_saved.h new file mode 100644 index 0000000..f8bb4ee --- /dev/null +++ b/dlls/revert_saved.h @@ -0,0 +1,49 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CRevertSaved: public CPointEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float Duration() const { return pev->dmg_take; } + float HoldTime() const { return pev->dmg_save; } + float MessageTime() const { return m_messageTime; } + float LoadTime() const { return m_loadTime; } + + void SetDuration(float duration) { pev->dmg_take = duration; } + void SetHoldTime(float hold) { pev->dmg_save = hold; } + void SetMessageTime(float time) { m_messageTime = time; } + void SetLoadTime(float time) { m_loadTime = time; } +public: + float m_messageTime; + float m_loadTime; +}; diff --git a/dlls/saverestore.h b/dlls/saverestore.h deleted file mode 100644 index c3761f3..0000000 --- a/dlls/saverestore.h +++ /dev/null @@ -1,169 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -// Implementation in UTIL.CPP -#ifndef SAVERESTORE_H -#define SAVERESTORE_H - -class CBaseEntity; - -class CSaveRestoreBuffer -{ -public: - CSaveRestoreBuffer( void ); - CSaveRestoreBuffer( SAVERESTOREDATA *pdata ); - ~CSaveRestoreBuffer( void ); - - int EntityIndex( entvars_t *pevLookup ); - int EntityIndex( edict_t *pentLookup ); - int EntityIndex( EOFFSET eoLookup ); - int EntityIndex( CBaseEntity *pEntity ); - - int EntityFlags( int entityIndex, int flags ) { return EntityFlagsSet( entityIndex, 0 ); } - int EntityFlagsSet( int entityIndex, int flags ); - - edict_t *EntityFromIndex( int entityIndex ); - - unsigned short TokenHash( const char *pszToken ); - -protected: - SAVERESTOREDATA *m_pdata; - void BufferRewind( int size ); - unsigned int HashString( const char *pszToken ); -}; - - -class CSave : public CSaveRestoreBuffer -{ -public: - CSave( SAVERESTOREDATA *pdata ) : CSaveRestoreBuffer( pdata ) {}; - - void WriteShort( const char *pname, const short *value, int count ); - void WriteInt( const char *pname, const int *value, int count ); // Save an int - void WriteFloat( const char *pname, const float *value, int count ); // Save a float - void WriteTime( const char *pname, const float *value, int count ); // Save a float (timevalue) - void WriteData( const char *pname, int size, const char *pdata ); // Save a binary data block - void WriteString( const char *pname, const char *pstring ); // Save a null-terminated string - void WriteString( const char *pname, const int *stringId, int count ); // Save a null-terminated string (engine string) - void WriteVector( const char *pname, const Vector &value ); // Save a vector - void WriteVector( const char *pname, const float *value, int count ); // Save a vector - void WritePositionVector( const char *pname, const Vector &value ); // Offset for landmark if necessary - void WritePositionVector( const char *pname, const float *value, int count ); // array of pos vectors - void WriteFunction( const char *pname, void **value, int count ); // Save a function pointer - int WriteEntVars( const char *pname, entvars_t *pev ); // Save entvars_t (entvars_t) - int WriteFields( const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ); - -private: - int DataEmpty( const char *pdata, int size ); - void BufferField( const char *pname, int size, const char *pdata ); - void BufferString( char *pdata, int len ); - void BufferData( const char *pdata, int size ); - void BufferHeader( const char *pname, int size ); -}; - -typedef struct -{ - unsigned short size; - unsigned short token; - char *pData; -} HEADER; - -class CRestore : public CSaveRestoreBuffer -{ -public: - CRestore( SAVERESTOREDATA *pdata ) : CSaveRestoreBuffer( pdata ) { m_global = 0; m_precache = TRUE; } - int ReadEntVars( const char *pname, entvars_t *pev ); // entvars_t - int ReadFields( const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount ); - int ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount, int startField, int size, char *pName, void *pData ); - int ReadInt( void ); - short ReadShort( void ); - int ReadNamedInt( const char *pName ); - char *ReadNamedString( const char *pName ); - int Empty( void ) { return (m_pdata == NULL) || ((m_pdata->pCurrentData-m_pdata->pBaseData)>=m_pdata->bufferSize); } - inline void SetGlobalMode( int global ) { m_global = global; } - void PrecacheMode( BOOL mode ) { m_precache = mode; } - -private: - char *BufferPointer( void ); - void BufferReadBytes( char *pOutput, int size ); - void BufferSkipBytes( int bytes ); - int BufferSkipZString( void ); - int BufferCheckZString( const char *string ); - - void BufferReadHeader( HEADER *pheader ); - - int m_global; // Restoring a global entity? - BOOL m_precache; -}; - -#define MAX_ENTITYARRAY 64 - -//#define ARRAYSIZE(p) (sizeof(p)/sizeof(p[0])) - -#define IMPLEMENT_SAVERESTORE(derivedClass,baseClass) \ - int derivedClass::Save( CSave &save )\ - {\ - if ( !baseClass::Save(save) )\ - return 0;\ - return save.WriteFields( #derivedClass, this, m_SaveData, ARRAYSIZE(m_SaveData) );\ - }\ - int derivedClass::Restore( CRestore &restore )\ - {\ - if ( !baseClass::Restore(restore) )\ - return 0;\ - return restore.ReadFields( #derivedClass, this, m_SaveData, ARRAYSIZE(m_SaveData) );\ - } - - -typedef enum { GLOBAL_OFF = 0, GLOBAL_ON = 1, GLOBAL_DEAD = 2 } GLOBALESTATE; - -typedef struct globalentity_s globalentity_t; - -struct globalentity_s -{ - char name[64]; - char levelName[32]; - GLOBALESTATE state; - globalentity_t *pNext; -}; - -class CGlobalState -{ -public: - CGlobalState(); - void Reset( void ); - void ClearStates( void ); - void EntityAdd( string_t globalname, string_t mapName, GLOBALESTATE state ); - void EntitySetState( string_t globalname, GLOBALESTATE state ); - void EntityUpdate( string_t globalname, string_t mapname ); - const globalentity_t *EntityFromTable( string_t globalname ); - GLOBALESTATE EntityGetState( string_t globalname ); - int EntityInTable( string_t globalname ) { return (Find( globalname ) != NULL) ? 1 : 0; } - int Save( CSave &save ); - int Restore( CRestore &restore ); - static TYPEDESCRIPTION m_SaveData[]; - -//#ifdef _DEBUG - void DumpGlobals( void ); -//#endif - -private: - globalentity_t *Find( string_t globalname ); - globalentity_t *m_pList; - int m_listCount; -}; - -extern CGlobalState gGlobalState; - -#endif //SAVERESTORE_H diff --git a/dlls/schedule.h b/dlls/schedule.h deleted file mode 100644 index 0c09441..0000000 --- a/dlls/schedule.h +++ /dev/null @@ -1,290 +0,0 @@ -/*** -* -* 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. -* -****/ -//========================================================= -// Scheduling -//========================================================= - -#ifndef SCHEDULE_H -#define SCHEDULE_H - -#define TASKSTATUS_NEW 0 // Just started -#define TASKSTATUS_RUNNING 1 // Running task & movement -#define TASKSTATUS_RUNNING_MOVEMENT 2 // Just running movement -#define TASKSTATUS_RUNNING_TASK 3 // Just running task -#define TASKSTATUS_COMPLETE 4 // Completed, get next task - - -//========================================================= -// These are the schedule types -//========================================================= -typedef enum -{ - SCHED_NONE = 0, - SCHED_IDLE_STAND, - SCHED_IDLE_WALK, - SCHED_WAKE_ANGRY, - SCHED_WAKE_CALLED, - SCHED_ALERT_FACE, - SCHED_ALERT_SMALL_FLINCH, - SCHED_ALERT_BIG_FLINCH, - SCHED_ALERT_STAND, - SCHED_INVESTIGATE_SOUND, - SCHED_COMBAT_FACE, - SCHED_COMBAT_STAND, - SCHED_CHASE_ENEMY, - SCHED_CHASE_ENEMY_FAILED, - SCHED_VICTORY_DANCE, - SCHED_TARGET_FACE, - SCHED_TARGET_CHASE, - SCHED_SMALL_FLINCH, - SCHED_TAKE_COVER_FROM_ENEMY, - SCHED_TAKE_COVER_FROM_BEST_SOUND, - SCHED_TAKE_COVER_FROM_ORIGIN, - SCHED_COWER, // usually a last resort! - SCHED_MELEE_ATTACK1, - SCHED_MELEE_ATTACK2, - SCHED_RANGE_ATTACK1, - SCHED_RANGE_ATTACK2, - SCHED_SPECIAL_ATTACK1, - SCHED_SPECIAL_ATTACK2, - SCHED_STANDOFF, - SCHED_ARM_WEAPON, - SCHED_RELOAD, - SCHED_GUARD, - SCHED_AMBUSH, - SCHED_DIE, - SCHED_WAIT_TRIGGER, - SCHED_FOLLOW, - SCHED_SLEEP, - SCHED_WAKE, - SCHED_BARNACLE_VICTIM_GRAB, - SCHED_BARNACLE_VICTIM_CHOMP, - SCHED_AISCRIPT, - SCHED_FAIL, - - LAST_COMMON_SCHEDULE // Leave this at the bottom -} SCHEDULE_TYPE; - -//========================================================= -// These are the shared tasks -//========================================================= -typedef enum -{ - TASK_INVALID = 0, - TASK_WAIT, - TASK_WAIT_FACE_ENEMY, - TASK_WAIT_PVS, - TASK_SUGGEST_STATE, - TASK_WALK_TO_TARGET, - TASK_RUN_TO_TARGET, - TASK_MOVE_TO_TARGET_RANGE, - TASK_GET_PATH_TO_ENEMY, - TASK_GET_PATH_TO_ENEMY_LKP, - TASK_GET_PATH_TO_ENEMY_CORPSE, - TASK_GET_PATH_TO_LEADER, - TASK_GET_PATH_TO_SPOT, - TASK_GET_PATH_TO_TARGET, - TASK_GET_PATH_TO_HINTNODE, - TASK_GET_PATH_TO_LASTPOSITION, - TASK_GET_PATH_TO_BESTSOUND, - TASK_GET_PATH_TO_BESTSCENT, - TASK_RUN_PATH, - TASK_WALK_PATH, - TASK_STRAFE_PATH, - TASK_CLEAR_MOVE_WAIT, - TASK_STORE_LASTPOSITION, - TASK_CLEAR_LASTPOSITION, - TASK_PLAY_ACTIVE_IDLE, - TASK_FIND_HINTNODE, - TASK_CLEAR_HINTNODE, - TASK_SMALL_FLINCH, - TASK_FACE_IDEAL, - TASK_FACE_ROUTE, - TASK_FACE_ENEMY, - TASK_FACE_HINTNODE, - TASK_FACE_TARGET, - TASK_FACE_LASTPOSITION, - TASK_RANGE_ATTACK1, - TASK_RANGE_ATTACK2, - TASK_MELEE_ATTACK1, - TASK_MELEE_ATTACK2, - TASK_RELOAD, - TASK_RANGE_ATTACK1_NOTURN, - TASK_RANGE_ATTACK2_NOTURN, - TASK_MELEE_ATTACK1_NOTURN, - TASK_MELEE_ATTACK2_NOTURN, - TASK_RELOAD_NOTURN, - TASK_SPECIAL_ATTACK1, - TASK_SPECIAL_ATTACK2, - TASK_CROUCH, - TASK_STAND, - TASK_GUARD, - TASK_STEP_LEFT, - TASK_STEP_RIGHT, - TASK_STEP_FORWARD, - TASK_STEP_BACK, - TASK_DODGE_LEFT, - TASK_DODGE_RIGHT, - TASK_SOUND_ANGRY, - TASK_SOUND_DEATH, - TASK_SET_ACTIVITY, - TASK_SET_SCHEDULE, - TASK_SET_FAIL_SCHEDULE, - TASK_CLEAR_FAIL_SCHEDULE, - TASK_PLAY_SEQUENCE, - TASK_PLAY_SEQUENCE_FACE_ENEMY, - TASK_PLAY_SEQUENCE_FACE_TARGET, - TASK_SOUND_IDLE, - TASK_SOUND_WAKE, - TASK_SOUND_PAIN, - TASK_SOUND_DIE, - TASK_FIND_COVER_FROM_BEST_SOUND,// tries lateral cover first, then node cover - TASK_FIND_COVER_FROM_ENEMY,// tries lateral cover first, then node cover - TASK_FIND_LATERAL_COVER_FROM_ENEMY, - TASK_FIND_NODE_COVER_FROM_ENEMY, - TASK_FIND_NEAR_NODE_COVER_FROM_ENEMY,// data for this one is the MAXIMUM acceptable distance to the cover. - TASK_FIND_FAR_NODE_COVER_FROM_ENEMY,// data for this one is there MINIMUM aceptable distance to the cover. - TASK_FIND_COVER_FROM_ORIGIN, - TASK_EAT, - TASK_DIE, - TASK_WAIT_FOR_SCRIPT, - TASK_PLAY_SCRIPT, - TASK_ENABLE_SCRIPT, - TASK_PLANT_ON_SCRIPT, - TASK_FACE_SCRIPT, - TASK_WAIT_RANDOM, - TASK_WAIT_INDEFINITE, - TASK_STOP_MOVING, - TASK_TURN_LEFT, - TASK_TURN_RIGHT, - TASK_REMEMBER, - TASK_FORGET, - TASK_WAIT_FOR_MOVEMENT, // wait until MovementIsComplete() - LAST_COMMON_TASK, // LEAVE THIS AT THE BOTTOM!! (sjb) -} SHARED_TASKS; - - -// These go in the flData member of the TASK_WALK_TO_TARGET, TASK_RUN_TO_TARGET -enum -{ - TARGET_MOVE_NORMAL = 0, - TARGET_MOVE_SCRIPTED = 1, -}; - - -// A goal should be used for a task that requires several schedules to complete. -// The goal index should indicate which schedule (ordinally) the monster is running. -// That way, when tasks fail, the AI can make decisions based on the context of the -// current goal and sequence rather than just the current schedule. -enum -{ - GOAL_ATTACK_ENEMY, - GOAL_MOVE, - GOAL_TAKE_COVER, - GOAL_MOVE_TARGET, - GOAL_EAT, -}; - -// an array of tasks is a task list -// an array of schedules is a schedule list -struct Task_t -{ - - int iTask; - float flData; -}; - -struct Schedule_t -{ - - Task_t *pTasklist; - int cTasks; - int iInterruptMask;// a bit mask of conditions that can interrupt this schedule - - // a more specific mask that indicates which TYPES of sounds will interrupt the schedule in the - // event that the schedule is broken by COND_HEAR_SOUND - int iSoundMask; - const char *pName; -}; - -// an array of waypoints makes up the monster's route. -// !!!LATER- this declaration doesn't belong in this file. -struct WayPoint_t -{ - Vector vecLocation; - int iType; -}; - -// these MoveFlag values are assigned to a WayPoint's TYPE in order to demonstrate the -// type of movement the monster should use to get there. -#define bits_MF_TO_TARGETENT ( 1 << 0 ) // local move to targetent. -#define bits_MF_TO_ENEMY ( 1 << 1 ) // local move to enemy -#define bits_MF_TO_COVER ( 1 << 2 ) // local move to a hiding place -#define bits_MF_TO_DETOUR ( 1 << 3 ) // local move to detour point. -#define bits_MF_TO_PATHCORNER ( 1 << 4 ) // local move to a path corner -#define bits_MF_TO_NODE ( 1 << 5 ) // local move to a node -#define bits_MF_TO_LOCATION ( 1 << 6 ) // local move to an arbitrary point -#define bits_MF_IS_GOAL ( 1 << 7 ) // this waypoint is the goal of the whole move. -#define bits_MF_DONT_SIMPLIFY ( 1 << 8 ) // Don't let the route code simplify this waypoint - -// If you define any flags that aren't _TO_ flags, add them here so we can mask -// them off when doing compares. -#define bits_MF_NOT_TO_MASK (bits_MF_IS_GOAL | bits_MF_DONT_SIMPLIFY) - -#define MOVEGOAL_NONE (0) -#define MOVEGOAL_TARGETENT (bits_MF_TO_TARGETENT) -#define MOVEGOAL_ENEMY (bits_MF_TO_ENEMY) -#define MOVEGOAL_PATHCORNER (bits_MF_TO_PATHCORNER) -#define MOVEGOAL_LOCATION (bits_MF_TO_LOCATION) -#define MOVEGOAL_NODE (bits_MF_TO_NODE) - -// these bits represent conditions that may befall the monster, of which some are allowed -// to interrupt certain schedules. -#define bits_COND_NO_AMMO_LOADED ( 1 << 0 ) // weapon needs to be reloaded! -#define bits_COND_SEE_HATE ( 1 << 1 ) // see something that you hate -#define bits_COND_SEE_FEAR ( 1 << 2 ) // see something that you are afraid of -#define bits_COND_SEE_DISLIKE ( 1 << 3 ) // see something that you dislike -#define bits_COND_SEE_ENEMY ( 1 << 4 ) // target entity is in full view. -#define bits_COND_ENEMY_OCCLUDED ( 1 << 5 ) // target entity occluded by the world -#define bits_COND_SMELL_FOOD ( 1 << 6 ) -#define bits_COND_ENEMY_TOOFAR ( 1 << 7 ) -#define bits_COND_LIGHT_DAMAGE ( 1 << 8 ) // hurt a little -#define bits_COND_HEAVY_DAMAGE ( 1 << 9 ) // hurt a lot -#define bits_COND_CAN_RANGE_ATTACK1 ( 1 << 10) -#define bits_COND_CAN_MELEE_ATTACK1 ( 1 << 11) -#define bits_COND_CAN_RANGE_ATTACK2 ( 1 << 12) -#define bits_COND_CAN_MELEE_ATTACK2 ( 1 << 13) -// #define bits_COND_CAN_RANGE_ATTACK3 ( 1 << 14) -#define bits_COND_PROVOKED ( 1 << 15) -#define bits_COND_NEW_ENEMY ( 1 << 16) -#define bits_COND_HEAR_SOUND ( 1 << 17) // there is an interesting sound -#define bits_COND_SMELL ( 1 << 18) // there is an interesting scent -#define bits_COND_ENEMY_FACING_ME ( 1 << 19) // enemy is facing me -#define bits_COND_ENEMY_DEAD ( 1 << 20) // enemy was killed. If you get this in combat, try to find another enemy. If you get it in alert, victory dance. -#define bits_COND_SEE_CLIENT ( 1 << 21) // see a client -#define bits_COND_SEE_NEMESIS ( 1 << 22) // see my nemesis - -#define bits_COND_SPECIAL1 ( 1 << 28) // Defined by individual monster -#define bits_COND_SPECIAL2 ( 1 << 29) // Defined by individual monster - -#define bits_COND_TASK_FAILED ( 1 << 30) -#define bits_COND_SCHEDULE_DONE ( 1 << 31) - - -#define bits_COND_ALL_SPECIAL (bits_COND_SPECIAL1 | bits_COND_SPECIAL2) - -#define bits_COND_CAN_ATTACK (bits_COND_CAN_RANGE_ATTACK1 | bits_COND_CAN_MELEE_ATTACK1 | bits_COND_CAN_RANGE_ATTACK2 | bits_COND_CAN_MELEE_ATTACK2) - -#endif // SCHEDULE_H diff --git a/dlls/scriptevent.h b/dlls/scriptevent.h deleted file mode 100644 index 42377cf..0000000 --- a/dlls/scriptevent.h +++ /dev/null @@ -1,29 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -#ifndef SCRIPTEVENT_H -#define SCRIPTEVENT_H - -#define SCRIPT_EVENT_DEAD 1000 // character is now dead -#define SCRIPT_EVENT_NOINTERRUPT 1001 // does not allow interrupt -#define SCRIPT_EVENT_CANINTERRUPT 1002 // will allow interrupt -#define SCRIPT_EVENT_FIREEVENT 1003 // event now fires -#define SCRIPT_EVENT_SOUND 1004 // Play named wave file (on CHAN_BODY) -#define SCRIPT_EVENT_SENTENCE 1005 // Play named sentence -#define SCRIPT_EVENT_INAIR 1006 // Leave the character in air at the end of the sequence (don't find the floor) -#define SCRIPT_EVENT_ENDANIMATION 1007 // Set the animation by name after the sequence completes -#define SCRIPT_EVENT_SOUND_VOICE 1008 // Play named wave file (on CHAN_VOICE) -#define SCRIPT_EVENT_SENTENCE_RND1 1009 // Play sentence group 25% of the time -#define SCRIPT_EVENT_NOT_DEAD 1010 // Bring back to life (for life/death sequences) -#endif //SCRIPTEVENT_H diff --git a/dlls/skill.h b/dlls/skill.h index 5ec320c..95e2084 100644 --- a/dlls/skill.h +++ b/dlls/skill.h @@ -1,147 +1,53 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -//========================================================= -// skill.h - skill level concerns -//========================================================= +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define SKILL_EASY 1 +#define SKILL_MEDIUM 2 +#define SKILL_HARD 3 struct skilldata_t { - - int iSkillLevel; // game skill level - -// Monster Health & Damage - float agruntHealth; - float agruntDmgPunch; - - float apacheHealth; - - float barneyHealth; - - float bigmommaHealthFactor; // Multiply each node's health by this - float bigmommaDmgSlash; // melee attack damage - float bigmommaDmgBlast; // mortar attack damage - float bigmommaRadiusBlast; // mortar attack radius - - float bullsquidHealth; - float bullsquidDmgBite; - float bullsquidDmgWhip; - float bullsquidDmgSpit; - - float gargantuaHealth; - float gargantuaDmgSlash; - float gargantuaDmgFire; - float gargantuaDmgStomp; - - float hassassinHealth; - - float headcrabHealth; - float headcrabDmgBite; - - float hgruntHealth; - float hgruntDmgKick; - float hgruntShotgunPellets; - float hgruntGrenadeSpeed; - - float houndeyeHealth; - float houndeyeDmgBlast; - - float slaveHealth; - float slaveDmgClaw; - float slaveDmgClawrake; - float slaveDmgZap; - - float ichthyosaurHealth; - float ichthyosaurDmgShake; - - float leechHealth; - float leechDmgBite; - - float controllerHealth; - float controllerDmgZap; - float controllerSpeedBall; - float controllerDmgBall; - - float nihilanthHealth; - float nihilanthZap; - - float scientistHealth; - - float snarkHealth; - float snarkDmgBite; - float snarkDmgPop; - - float zombieHealth; - float zombieDmgOneSlash; - float zombieDmgBothSlash; - - float turretHealth; - float miniturretHealth; - float sentryHealth; - - -// Player Weapons - float plrDmgCrowbar; + int iSkillLevel; float plrDmg9MM; float plrDmg357; float plrDmgMP5; float plrDmgM203Grenade; float plrDmgBuckshot; float plrDmgCrossbowClient; - float plrDmgCrossbowMonster; float plrDmgRPG; - float plrDmgGauss; - float plrDmgEgonNarrow; - float plrDmgEgonWide; - float plrDmgHornet; - float plrDmgHandGrenade; - float plrDmgSatchel; - float plrDmgTripmine; - -// weapons shared by monsters float monDmg9MM; float monDmgMP5; float monDmg12MM; - float monDmgHornet; - -// health/suit charge float suitchargerCapacity; float batteryCapacity; float healthchargerCapacity; float healthkitCapacity; - float scientistHeal; - -// monster damage adj - float monHead; - float monChest; - float monStomach; - float monLeg; - float monArm; - -// player damage adj - float plrHead; - float plrChest; - float plrStomach; - float plrLeg; - float plrArm; }; -extern DLL_GLOBAL skilldata_t gSkillData; -float GetSkillCvar( char *pName ); - -extern DLL_GLOBAL int g_iSkillLevel; - -#define SKILL_EASY 1 -#define SKILL_MEDIUM 2 -#define SKILL_HARD 3 +extern skilldata_t gSkillData; diff --git a/dlls/sound.h b/dlls/sound.h new file mode 100644 index 0000000..c4e636c --- /dev/null +++ b/dlls/sound.h @@ -0,0 +1,141 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define CSENTENCEG_MAX 200 // max number of sentence groups +#define CSENTENCE_LRU_MAX 32 // max number of elements per sentence group +#define CDPVPRESETMAX 27 + +// spawnflags +#define AMBIENT_SOUND_STATIC 0 // medium radius attenuation +#define AMBIENT_SOUND_EVERYWHERE 1 +#define AMBIENT_SOUND_SMALLRADIUS 2 +#define AMBIENT_SOUND_MEDIUMRADIUS 4 +#define AMBIENT_SOUND_LARGERADIUS 8 +#define AMBIENT_SOUND_START_SILENT 16 +#define AMBIENT_SOUND_NOT_LOOPING 32 + +#define ANNOUNCE_MINUTES_MIN 0.25 +#define ANNOUNCE_MINUTES_MAX 2.25 + +#define SPEAKER_START_SILENT 1 // wait for trigger 'on' to start announcements + +#define LFO_SQUARE 1 // square +#define LFO_TRIANGLE 2 // triangle +#define LFO_RANDOM 3 // random + +// group of related sentences +struct sentenceg +{ + char szgroupname[16]; + int count; + unsigned char rgblru[ CSENTENCE_LRU_MAX ]; +}; + +// runtime pitch shift and volume fadein/out structure + +// NOTE: IF YOU CHANGE THIS STRUCT YOU MUST CHANGE THE SAVE/RESTORE VERSION NUMBER +// SEE BELOW (in the typedescription for the class) +typedef struct dynpitchvol +{ + // NOTE: do not change the order of these parameters + // NOTE: unless you also change order of rgdpvpreset array elements! + int preset; + + int pitchrun; // pitch shift % when sound is running 0 - 255 + int pitchstart; // pitch shift % when sound stops or starts 0 - 255 + int spinup; // spinup time 0 - 100 + int spindown; // spindown time 0 - 100 + + int volrun; // volume change % when sound is running 0 - 10 + int volstart; // volume change % when sound stops or starts 0 - 10 + int fadein; // volume fade in time 0 - 100 + int fadeout; // volume fade out time 0 - 100 + + // Low Frequency Oscillator + int lfotype; // 0) off 1) square 2) triangle 3) random + int lforate; // 0 - 1000, how fast lfo osciallates + + int lfomodpitch; // 0-100 mod of current pitch. 0 is off. + int lfomodvol; // 0-100 mod of current volume. 0 is off. + + int cspinup; // each trigger hit increments counter and spinup pitch + + int cspincount; + int pitch; + int spinupsav; + int spindownsav; + int pitchfrac; + int vol; + int fadeinsav; + int fadeoutsav; + int volfrac; + int lfofrac; + int lfomult; + +} dynpitchvol_t; + +class CAmbientGeneric: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; +public: + float m_flAttenuation; // attenuation value + dynpitchvol_t m_dpv; + BOOL m_fActive; // only TRUE when the entity is playing a looping sound + BOOL m_fLooping; // TRUE when the sound played will loop +}; + +class CEnvSound: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Think() = 0; +public: + float m_flRadius; + float m_flRoomtype; +}; + +class CSpeaker: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; +public: + int m_preset; // preset number +}; diff --git a/dlls/soundent.h b/dlls/soundent.h deleted file mode 100644 index 150daac..0000000 --- a/dlls/soundent.h +++ /dev/null @@ -1,95 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -//========================================================= -// Soundent.h - the entity that spawns when the world -// spawns, and handles the world's active and free sound -// lists. -//========================================================= - -#define MAX_WORLD_SOUNDS 64 // maximum number of sounds handled by the world at one time. - -#define bits_SOUND_NONE 0 -#define bits_SOUND_COMBAT ( 1 << 0 )// gunshots, explosions -#define bits_SOUND_WORLD ( 1 << 1 )// door opening/closing, glass breaking -#define bits_SOUND_PLAYER ( 1 << 2 )// all noises generated by player. walking, shooting, falling, splashing -#define bits_SOUND_CARCASS ( 1 << 3 )// dead body -#define bits_SOUND_MEAT ( 1 << 4 )// gib or pork chop -#define bits_SOUND_DANGER ( 1 << 5 )// pending danger. Grenade that is about to explode, explosive barrel that is damaged, falling crate -#define bits_SOUND_GARBAGE ( 1 << 6 )// trash cans, banana peels, old fast food bags. - -#define bits_ALL_SOUNDS 0xFFFFFFFF - -#define SOUNDLIST_EMPTY -1 - -#define SOUNDLISTTYPE_FREE 1// identifiers passed to functions that can operate on either list, to indicate which list to operate on. -#define SOUNDLISTTYPE_ACTIVE 2 - -#define SOUND_NEVER_EXPIRE -1 // with this set as a sound's ExpireTime, the sound will never expire. - -//========================================================= -// CSound - an instance of a sound in the world. -//========================================================= -class CSound -{ -public: - - void Clear ( void ); - void Reset ( void ); - - Vector m_vecOrigin; // sound's location in space - int m_iType; // what type of sound this is - int m_iVolume; // how loud the sound is - float m_flExpireTime; // when the sound should be purged from the list - int m_iNext; // index of next sound in this list ( Active or Free ) - int m_iNextAudible; // temporary link that monsters use to build a list of audible sounds - - BOOL FIsSound( void ); - BOOL FIsScent( void ); -}; - -//========================================================= -// CSoundEnt - a single instance of this entity spawns when -// the world spawns. The SoundEnt's job is to update the -// world's Free and Active sound lists. -//========================================================= -class CSoundEnt : public CBaseEntity -{ -public: - - void Precache ( void ); - void Spawn( void ); - void Think( void ); - void Initialize ( void ); - - static void InsertSound ( int iType, const Vector &vecOrigin, int iVolume, float flDuration ); - static void FreeSound ( int iSound, int iPrevious ); - static int ActiveList( void );// return the head of the active list - static int FreeList( void );// return the head of the free list - static CSound* SoundPointerForIndex( int iIndex );// return a pointer for this index in the sound list - static int ClientSoundIndex ( edict_t *pClient ); - - BOOL IsEmpty( void ) { return m_iActiveSound == SOUNDLIST_EMPTY; } - int ISoundsInList ( int iListType ); - int IAllocSound ( void ); - virtual int ObjectCaps( void ) { return FCAP_DONT_SAVE; } - - int m_iFreeSound; // index of the first sound in the free sound list - int m_iActiveSound; // indes of the first sound in the active sound list - int m_cLastActiveSounds; // keeps track of the number of active sounds at the last update. (for diagnostic work) - BOOL m_fShowReport; // if true, dump information about free/active sounds. - -private: - CSound m_SoundPool[ MAX_WORLD_SOUNDS ]; -}; diff --git a/dlls/spectator.h b/dlls/spectator.h index 2f755d6..d42e05a 100644 --- a/dlls/spectator.h +++ b/dlls/spectator.h @@ -1,27 +1,33 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -// Spectator.h +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -class CBaseSpectator : public CBaseEntity -{ +class CBaseSpectator: public CBaseEntity { public: - void Spawn(); - void SpectatorConnect(void); - void SpectatorDisconnect(void); - void SpectatorThink(void); - -private: - void SpectatorImpulseCommand(void); + virtual void Spawn(); }; diff --git a/dlls/subs.h b/dlls/subs.h new file mode 100644 index 0000000..8cae347 --- /dev/null +++ b/dlls/subs.h @@ -0,0 +1,40 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +class CNullEntity: public CBaseEntity { +public: + virtual void Spawn() = 0; +}; + +class CBaseDMStart: public CPointEntity { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual BOOL IsTriggered(CBaseEntity *pEntity) = 0; +}; diff --git a/dlls/talkmonster.h b/dlls/talkmonster.h deleted file mode 100644 index 25c1fc6..0000000 --- a/dlls/talkmonster.h +++ /dev/null @@ -1,26 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ - -#ifndef TALKMONSTER_H -#define TALKMONSTER_H - -class CTalkMonster : public CBaseMonster -{ -public: - static float g_talkWaitTime; - -}; - -#endif //TALKMONSTER_H diff --git a/dlls/teamplay_gamerules.h b/dlls/teamplay_gamerules.h deleted file mode 100644 index 5d4246b..0000000 --- a/dlls/teamplay_gamerules.h +++ /dev/null @@ -1,57 +0,0 @@ -/*** -* -* Copyright (c) 1996-2002, 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. -* -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. -* -****/ -// -// teamplay_gamerules.h -// - -#define MAX_TEAMNAME_LENGTH 16 -#define MAX_TEAMS 32 - -#define TEAMPLAY_TEAMLISTLENGTH MAX_TEAMS*MAX_TEAMNAME_LENGTH - -class CHalfLifeTeamplay : public CHalfLifeMultiplay -{ -public: - CHalfLifeTeamplay(); - - virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ); - virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ); - virtual BOOL IsTeamplay( void ); - virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker ); - virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); - virtual const char *GetTeamID( CBaseEntity *pEntity ); - virtual BOOL ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target ); - virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ); - virtual void InitHUD( CBasePlayer *pl ); - virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor ); - virtual const char *GetGameDescription( void ) { return "HL Teamplay"; } // this is the game name that gets seen in the server browser - virtual void UpdateGameMode( CBasePlayer *pPlayer ); // the client needs to be informed of the current game mode - virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); - virtual void Think ( void ); - virtual int GetTeamIndex( const char *pTeamName ); - virtual const char *GetIndexedTeamName( int teamIndex ); - virtual BOOL IsValidTeam( const char *pTeamName ); - const char *SetDefaultPlayerTeam( CBasePlayer *pPlayer ); - virtual void ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib ); - -private: - void RecountTeams( bool bResendInfo = FALSE ); - const char *TeamWithFewestPlayers( void ); - - BOOL m_DisableDeathMessages; - BOOL m_DisableDeathPenalty; - BOOL m_teamLimit; // This means the server set only some teams as valid - char m_szTeamList[TEAMPLAY_TEAMLISTLENGTH]; -}; diff --git a/dlls/training_gamerules.h b/dlls/training_gamerules.h new file mode 100644 index 0000000..079e2be --- /dev/null +++ b/dlls/training_gamerules.h @@ -0,0 +1,84 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class CHalfLifeTraining: public CHalfLifeMultiplay { +protected: + virtual ~CHalfLifeTraining() {}; +public: + virtual BOOL IsMultiplayer() = 0; + virtual BOOL IsDeathmatch() = 0; + virtual void InitHUD(CBasePlayer *pl) = 0; + virtual void PlayerSpawn(CBasePlayer *pPlayer) = 0; + virtual void PlayerThink(CBasePlayer *pPlayer) = 0; + virtual BOOL FPlayerCanRespawn(CBasePlayer *pPlayer) = 0; + virtual edict_t *GetPlayerSpawnSpot(CBasePlayer *pPlayer) = 0; + virtual void PlayerKilled(CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor) = 0; + virtual int ItemShouldRespawn(CItem *pItem) = 0; + virtual void CheckMapConditions() = 0; + virtual void CheckWinConditions() = 0; +public: + float FillAccountTime; + float ServerRestartTime; + BOOL fInBuyArea; + BOOL fVisitedBuyArea; + bool fVGUIMenus; +}; + +class CBaseGrenCatch: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Think() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +public: + int m_NeedGrenadeType; + string_t sTriggerOnGrenade; + string_t sDisableOnGrenade; + bool m_fSmokeTouching; + bool m_fFlashTouched; +}; + +class CFuncWeaponCheck: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +private: + string_t sTriggerWithItems; + string_t sTriggerNoItems; + string_t sMaster; + unsigned int sItemName[32]; + int iItemCount; + int iAnyWeapon; +}; diff --git a/dlls/trains.h b/dlls/trains.h index 87aec76..10927b6 100644 --- a/dlls/trains.h +++ b/dlls/trains.h @@ -1,19 +1,31 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef TRAINS_H -#define TRAINS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once // Tracktrain spawn flags #define SF_TRACKTRAIN_NOPITCH 0x0001 @@ -25,103 +37,113 @@ #define SF_PATH_DISABLED 0x00000001 #define SF_PATH_FIREONCE 0x00000002 #define SF_PATH_ALTREVERSE 0x00000004 -#define SF_PATH_DISABLE_TRAIN 0x00000008 +#define SF_PATH_DISABLE_TRAIN 0x00000008 #define SF_PATH_ALTERNATE 0x00008000 // Spawnflags of CPathCorner -#define SF_CORNER_WAITFORTRIG 0x001 +#define SF_CORNER_WAITFORTRIG 0x001 #define SF_CORNER_TELEPORT 0x002 #define SF_CORNER_FIREONCE 0x004 -//#define PATH_SPARKLE_DEBUG 1 // This makes a particle effect around path_track entities for debugging -class CPathTrack : public CPointEntity -{ +class CPathTrack: public CPointEntity { public: - void Spawn( void ); - void Activate( void ); - void KeyValue( KeyValueData* pkvd); - - void SetPrevious( CPathTrack *pprevious ); - void Link( void ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - - CPathTrack *ValidPath( CPathTrack *ppath, int testFlag ); // Returns ppath if enabled, NULL otherwise - void Project( CPathTrack *pstart, CPathTrack *pend, Vector *origin, float dist ); - - static CPathTrack *Instance( edict_t *pent ); - - CPathTrack *LookAhead( Vector *origin, float dist, int move ); - CPathTrack *Nearest( Vector origin ); - - CPathTrack *GetNext( void ); - CPathTrack *GetPrevious( void ); - - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; -#if PATH_SPARKLE_DEBUG - void EXPORT Sparkle(void); -#endif - - float m_length; - string_t m_altName; - CPathTrack *m_pnext; - CPathTrack *m_pprevious; - CPathTrack *m_paltpath; + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData* pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual void Activate() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + float m_length; + string_t m_altName; + CPathTrack *m_pnext; + CPathTrack *m_pprevious; + CPathTrack *m_paltpath; }; - -class CFuncTrackTrain : public CBaseEntity -{ +class CFuncTrackTrain: public CBaseEntity { public: - void Spawn( void ); - void Precache( void ); - - void Blocked( CBaseEntity *pOther ); - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void KeyValue( KeyValueData* pkvd ); - - void EXPORT Next( void ); - void EXPORT Find( void ); - void EXPORT NearestPath( void ); - void EXPORT DeadEnd( void ); - - void NextThink( float thinkTime, BOOL alwaysThink ); - - void SetTrack( CPathTrack *track ) { m_ppath = track->Nearest(pev->origin); } - void SetControls( entvars_t *pevControls ); - BOOL OnControls( entvars_t *pev ); - - void StopSound ( void ); - void UpdateSound ( void ); - - static CFuncTrackTrain *Instance( edict_t *pent ); - - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; - virtual int ObjectCaps( void ) { return (CBaseEntity :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DIRECTIONAL_USE; } - - virtual void OverrideReset( void ); - - CPathTrack *m_ppath; - float m_length; - float m_height; - float m_speed; - float m_dir; - float m_startSpeed; - Vector m_controlMins; - Vector m_controlMaxs; - int m_soundPlaying; - int m_sounds; - float m_flVolume; - float m_flBank; - float m_oldSpeed; + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData* pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void OverrideReset() = 0; + virtual BOOL OnControls(entvars_t *pev) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + CPathTrack *m_ppath; + float m_length; + float m_height; + float m_speed; + float m_dir; + float m_startSpeed; + Vector m_controlMins; + Vector m_controlMaxs; + int m_soundPlaying; + int m_sounds; + float m_flVolume; + float m_flBank; + float m_oldSpeed; + float m_fTurnAngle; + float m_flSteeringWheelDecay; + float m_flAcceleratorDecay; private: unsigned short m_usAdjustPitch; }; -#endif +class CFuncVehicle: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual int Classify() = 0; + virtual void OverrideReset() = 0; + virtual BOOL OnControls(entvars_t *pev) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual void Blocked(CBaseEntity *pOther) = 0; +public: + CPathTrack *m_ppath; + float m_length; + float m_width; + float m_height; + float m_speed; + float m_dir; + float m_startSpeed; + Vector m_controlMins; + Vector m_controlMaxs; + int m_soundPlaying; + int m_sounds; + int m_acceleration; + float m_flVolume; + float m_flBank; + float m_oldSpeed; + int m_iTurnAngle; + float m_flSteeringWheelDecay; + float m_flAcceleratorDecay; + float m_flTurnStartTime; + float m_flLaunchTime; + float m_flLastNormalZ; + float m_flCanTurnNow; + float m_flUpdateSound; + Vector m_vFrontLeft; + Vector m_vFront; + Vector m_vFrontRight; + Vector m_vBackLeft; + Vector m_vBack; + Vector m_vBackRight; + Vector m_vSurfaceNormal; + Vector m_vVehicleDirection; + CBaseEntity *m_pDriver; + +private: + unsigned short m_usAdjustPitch; +}; diff --git a/dlls/triggers.h b/dlls/triggers.h new file mode 100644 index 0000000..e71cb1e --- /dev/null +++ b/dlls/triggers.h @@ -0,0 +1,367 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define GRENADETYPE_SMOKE 1 +#define GRENADETYPE_FLASH 2 + +#define MAX_ITEM_COUNTS 32 +#define MAX_ENTITY 512 // We can only ever move 512 entities across a transition + +// triggers +#define SF_TRIGGER_ALLOWMONSTERS 1 // monsters allowed to fire this trigger +#define SF_TRIGGER_NOCLIENTS 2 // players not allowed to fire this trigger +#define SF_TRIGGER_PUSHABLES 4 // only pushables can fire this trigger +#define SF_TRIGGER_NO_RESET 64 // it is not allowed to be restarted on a new round + +#define SF_TRIGGER_PUSH_ONCE 1 +#define SF_TRIGGER_PUSH_START_OFF 2 // spawnflag that makes trigger_push spawn turned OFF + +#define SF_TRIGGER_HURT_TARGETONCE 1 // Only fire hurt target once +#define SF_TRIGGER_HURT_START_OFF 2 // spawnflag that makes trigger_push spawn turned OFF +#define SF_TRIGGER_HURT_NO_CLIENTS 8 // spawnflag that makes trigger_push spawn turned OFF +#define SF_TRIGGER_HURT_CLIENTONLYFIRE 16 // trigger hurt will only fire its target if it is hurting a client +#define SF_TRIGGER_HURT_CLIENTONLYTOUCH 32 // only clients may touch this trigger. + +#define SF_AUTO_FIREONCE 0x0001 +#define SF_AUTO_NO_RESET 0x0002 + +#define SF_RELAY_FIREONCE 0x0001 +#define SF_ENDSECTION_USEONLY 0x0001 + +#define SF_MULTIMAN_CLONE 0x80000000 +#define SF_MULTIMAN_THREAD 0x00000001 + +#define SF_CHANGELEVEL_USEONLY 0x0002 +#define SF_CAMERA_PLAYER_POSITION 1 +#define SF_CAMERA_PLAYER_TARGET 2 +#define SF_CAMERA_PLAYER_TAKECONTROL 4 + +// Flags to indicate masking off various render parameters that are normally copied to the targets +#define SF_RENDER_MASKFX (1 << 0) +#define SF_RENDER_MASKAMT (1 << 1) +#define SF_RENDER_MASKMODE (1 << 2) +#define SF_RENDER_MASKCOLOR (1 << 3) + +class CFrictionModifier: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; +public: + float m_frictionFraction; +}; + +// This trigger will fire when the level spawns (or respawns if not fire once) +// It will check a global state before firing. It supports delay and killtargets +class CAutoTrigger: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Think() = 0; +public: + int m_globalstate; + USE_TYPE triggerType; +}; + +class CTriggerRelay: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + USE_TYPE triggerType; +}; + +// The Multimanager Entity - when fired, will fire up to 16 targets +// at specified times. +// FLAG: THREAD (create clones when triggered) +// FLAG: CLONE (this is a clone for a threaded execution) +class CMultiManager: public CBaseToggle { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual BOOL HasTarget(string_t targetname) = 0; +public: + int m_cTargets; + int m_index; + float m_startTime; + int m_iTargetName[MAX_MULTI_TARGETS]; + float m_flTargetDelay[MAX_MULTI_TARGETS]; +}; + +// Render parameters trigger +// +// This entity will copy its render parameters (renderfx, rendermode, rendercolor, renderamt) +// to its targets when triggered. +class CRenderFxManager: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +class CBaseTrigger: public CBaseToggle { +public: + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int ObjectCaps() = 0; +}; + +// trigger_hurt - hurts anything that touches it. if the trigger has a targetname, firing it will toggle state +// int gfToggleState = 0; // used to determine when all radiation trigger hurts have called 'RadiationThink' +class CTriggerHurt: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; + virtual int ObjectCaps() = 0; +}; + +class CTriggerMonsterJump: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void Think() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +}; + +// trigger_cdaudio - starts/stops cd audio tracks +class CTriggerCDAudio: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void Touch(CBaseEntity *pOther) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +// This plays a CD track when fired or when the player enters it's radius +class CTargetCDAudio: public CPointEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Think() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +}; + +// QUAKED trigger_multiple (.5 .5 .5) ? notouch +// Variable sized repeatable trigger. Must be targeted at one or more entities. +// If "health" is set, the trigger must be killed to activate each time. +// If "delay" is set, the trigger waits some time after activating before firing. +// "wait" : Seconds between triggerings. (.2 default) +// If notouch is set, the trigger is only fired by other entities, not by touching. +// NOTOUCH has been obsoleted by trigger_relay! +// sounds +// 1) secret +// 2) beep beep +// 3) large switch +// 4) +// NEW +// if a trigger has a NETNAME, that NETNAME will become the TARGET of the triggered object. +class CTriggerMultiple: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +// QUAKED trigger_once (.5 .5 .5) ? notouch +// Variable sized trigger. Triggers once, then removes itself. You must set the key "target" to the name of another object in the level that has a matching +// "targetname". If "health" is set, the trigger must be killed to activate. +// If notouch is set, the trigger is only fired by other entities, not by touching. +// if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired. +// if "angle" is set, the trigger will only fire when someone is facing the direction of the angle. Use "360" for an angle of 0. +// sounds +// 1) secret +// 2) beep beep +// 3) large switch +// 4) +class CTriggerOnce: public CTriggerMultiple { +public: + virtual void Spawn() = 0; + virtual void Restart() = 0; +}; + +// QUAKED trigger_counter (.5 .5 .5) ? nomessage +// Acts as an intermediary for an action that takes multiple inputs. +// If nomessage is not set, it will print "1 more.. " etc when triggered and +// "sequence complete" when finished. After the counter has been triggered "cTriggersLeft" +// times (default 2), it will fire all of it's targets and remove itself. +class CTriggerCounter: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +// Derive from point entity so this doesn't move across levels +class CTriggerVolume: public CPointEntity { +public: + virtual void Spawn() = 0; +}; + +// Fires a target after level transition and then dies +class CFireAndDie: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int ObjectCaps() = 0; // Always go across transitions + virtual void Think() = 0; +}; + +// QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION +// When the player touches this, he gets sent to the map listed in the "map" variable. Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats. +class CChangeLevel: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; +public: + char m_szMapName[cchMapNameMost]; // trigger_changelevel only: next map + char m_szLandmarkName[cchMapNameMost]; // trigger_changelevel only: landmark on next map + int m_changeTarget; + float m_changeTargetDelay; +}; + +class CLadder: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +}; + +class CTriggerPush: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Touch(CBaseEntity *pOther) = 0; +}; + +class CTriggerTeleport: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CBuyZone: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CBombTarget: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CHostageRescue: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CEscapeZone: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CVIP_SafetyZone: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CTriggerSave: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CTriggerEndSection: public CBaseTrigger { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +}; + +class CTriggerGravity: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +// this is a really bad idea. +class CTriggerChangeTarget: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +private: + int m_iszNewTarget; +}; + +class CTriggerCamera: public CBaseDelay { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual int Save(CSave &save) = 0; + virtual int Restore(CRestore &restore) = 0; + virtual int ObjectCaps() = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; +public: + EHANDLE m_hPlayer; + EHANDLE m_hTarget; + CBaseEntity *m_pentPath; + int m_sPath; + float m_flWait; + float m_flReturnTime; + float m_flStopTime; + float m_moveDistance; + float m_targetSpeed; + float m_initialSpeed; + float m_acceleration; + float m_deceleration; + int m_state; +}; + +class CWeather: public CBaseTrigger { +public: + virtual void Spawn() = 0; +}; + +class CClientFog: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; +public: + int m_iStartDist; + int m_iEndDist; + float m_fDensity; +}; diff --git a/dlls/unisignals.h b/dlls/unisignals.h new file mode 100644 index 0000000..054bdc5 --- /dev/null +++ b/dlls/unisignals.h @@ -0,0 +1,57 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#ifndef UNISIGNALS_H +#define UNISIGNALS_H +#ifdef _WIN32 +#pragma once +#endif + +class CUnifiedSignals +{ +public: + CUnifiedSignals() + { + m_flSignal = 0; + m_flState = 0; + } +public: + void Update() + { + m_flState = m_flSignal; + m_flSignal = 0; + } + void Signal(int flags) { m_flSignal |= flags; } + int GetSignal() const { return m_flSignal; } + int GetState() const { return m_flState; } +public: + int m_flSignal; + int m_flState; +}; + +#endif // UNISIGNALS_H diff --git a/dlls/util.h b/dlls/util.h index f1a2a19..8e36d48 100644 --- a/dlls/util.h +++ b/dlls/util.h @@ -1,399 +1,83 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#include "archtypes.h" // DAL +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -// -// Misc utility code -// -#ifndef ACTIVITY_H -#include "activity.h" -#endif - -#ifndef ENGINECALLBACK_H #include "enginecallback.h" -#endif -inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent ); // implementation later in this file -extern globalvars_t *gpGlobals; +#define eoNullEntity 0 // Testing the three types of "entity" for nullity +#define iStringNull 0 // Testing strings for nullity + +#define cchMapNameMost 32 + +#define CBSENTENCENAME_MAX 16 +#define CVOXFILESENTENCEMAX 1536 // max number of sentences in game. NOTE: this must match CVOXFILESENTENCEMAX in engine\sound.h + +#define GROUP_OP_AND 0 +#define GROUP_OP_NAND 1 + +extern globalvars_t *gpGlobals; // Use this instead of ALLOC_STRING on constant strings #define STRING(offset) ((const char *)(gpGlobals->pStringBase + (unsigned int)(offset))) #define MAKE_STRING(str) ((uint64)(str) - (uint64)(STRING(0))) -inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName) -{ - return FIND_ENTITY_BY_STRING(entStart, "classname", pszName); -} - -inline edict_t *FIND_ENTITY_BY_TARGETNAME(edict_t *entStart, const char *pszName) -{ - return FIND_ENTITY_BY_STRING(entStart, "targetname", pszName); -} - -// for doing a reverse lookup. Say you have a door, and want to find its button. -inline edict_t *FIND_ENTITY_BY_TARGET(edict_t *entStart, const char *pszName) -{ - return FIND_ENTITY_BY_STRING(entStart, "target", pszName); -} - -// Keeps clutter down a bit, when writing key-value pairs -#define WRITEKEY_INT(pf, szKeyName, iKeyValue) ENGINE_FPRINTF(pf, "\"%s\" \"%d\"\n", szKeyName, iKeyValue) -#define WRITEKEY_FLOAT(pf, szKeyName, flKeyValue) \ - ENGINE_FPRINTF(pf, "\"%s\" \"%f\"\n", szKeyName, flKeyValue) -#define WRITEKEY_STRING(pf, szKeyName, szKeyValue) \ - ENGINE_FPRINTF(pf, "\"%s\" \"%s\"\n", szKeyName, szKeyValue) -#define WRITEKEY_VECTOR(pf, szKeyName, flX, flY, flZ) \ - ENGINE_FPRINTF(pf, "\"%s\" \"%f %f %f\"\n", szKeyName, flX, flY, flZ) - -// Keeps clutter down a bit, when using a float as a bit-vector -#define SetBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) | (bits)) -#define ClearBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) & ~(bits)) -#define FBitSet(flBitVector, bit) ((int)(flBitVector) & (bit)) - -// Makes these more explicit, and easier to find -#define FILE_GLOBAL static -#define DLL_GLOBAL - -// Until we figure out why "const" gives the compiler problems, we'll just have to use -// this bogus "empty" define to mark things as constant. -#define CONSTANT - -// More explicit than "int" -typedef int EOFFSET; - -// In case it's not alread defined -typedef int BOOL; - -// In case this ever changes -#define M_PI 3.14159265358979323846 - -// Keeps clutter down a bit, when declaring external entity/global method prototypes -#define DECLARE_GLOBAL_METHOD(MethodName) extern void UTIL_DLLEXPORT MethodName( void ) -#define GLOBAL_METHOD(funcname) void UTIL_DLLEXPORT funcname(void) - -#ifndef UTIL_DLLEXPORT -#ifdef _WIN32 -#define UTIL_DLLEXPORT _declspec( dllexport ) -#else -#define UTIL_DLLEXPORT __attribute__ ((visibility("default"))) -#endif -#endif - -// This is the glue that hooks .MAP entity class names to our CPP classes -// The _declspec forces them to be exported by name so we can do a lookup with GetProcAddress() -// The function is used to intialize / allocate the object for the entity -#define LINK_ENTITY_TO_CLASS(mapClassName,DLLClassName) \ - extern "C" UTIL_DLLEXPORT void mapClassName( entvars_t *pev ); \ - void mapClassName( entvars_t *pev ) { GetClassPtr( (DLLClassName *)pev ); } - - -// -// Conversion among the three types of "entity", including identity-conversions. -// -#ifdef DEBUG - extern edict_t *DBG_EntOfVars(const entvars_t *pev); - inline edict_t *ENT(const entvars_t *pev) { return DBG_EntOfVars(pev); } -#else - inline edict_t *ENT(const entvars_t *pev) { return pev->pContainingEntity; } -#endif -inline edict_t *ENT(edict_t *pent) { return pent; } -inline edict_t *ENT(EOFFSET eoffset) { return (*g_engfuncs.pfnPEntityOfEntOffset)(eoffset); } -inline EOFFSET OFFSET(EOFFSET eoffset) { return eoffset; } -inline EOFFSET OFFSET(const edict_t *pent) -{ -#if _DEBUG - if ( !pent ) - ALERT( at_error, "Bad ent in OFFSET()\n" ); -#endif - return (*g_engfuncs.pfnEntOffsetOfPEntity)(pent); -} -inline EOFFSET OFFSET(entvars_t *pev) -{ -#if _DEBUG - if ( !pev ) - ALERT( at_error, "Bad pev in OFFSET()\n" ); -#endif - return OFFSET(ENT(pev)); -} -inline entvars_t *VARS(entvars_t *pev) { return pev; } - -inline entvars_t *VARS(edict_t *pent) -{ - if ( !pent ) - return NULL; - - return &pent->v; -} - -inline entvars_t* VARS(EOFFSET eoffset) { return VARS(ENT(eoffset)); } -inline int ENTINDEX(edict_t *pEdict) { return (*g_engfuncs.pfnIndexOfEdict)(pEdict); } -inline edict_t* INDEXENT( int iEdictNum ) { return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); } -inline void MESSAGE_BEGIN( int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent ) { - (*g_engfuncs.pfnMessageBegin)(msg_dest, msg_type, pOrigin, ENT(ent)); -} - -// Testing the three types of "entity" for nullity -#define eoNullEntity 0 -inline BOOL FNullEnt(EOFFSET eoffset) { return eoffset == 0; } -inline BOOL FNullEnt(const edict_t* pent) { return pent == NULL || FNullEnt(OFFSET(pent)); } -inline BOOL FNullEnt(entvars_t* pev) { return pev == NULL || FNullEnt(OFFSET(pev)); } - -// Testing strings for nullity -#define iStringNull 0 -inline BOOL FStringNull(int iString) { return iString == iStringNull; } - -#define cchMapNameMost 32 - // Dot products for view cone checking -#define VIEW_FIELD_FULL (float)-1.0 // +-180 degrees -#define VIEW_FIELD_WIDE (float)-0.7 // +-135 degrees 0.1 // +-85 degrees, used for full FOV checks -#define VIEW_FIELD_NARROW (float)0.7 // +-45 degrees, more narrow check used to set up ranged attacks -#define VIEW_FIELD_ULTRA_NARROW (float)0.9 // +-25 degrees, more narrow check used to set up ranged attacks +#define VIEW_FIELD_FULL -1.0 // +-180 degrees +#define VIEW_FIELD_WIDE -0.7 // +-135 degrees 0.1 // +-85 degrees, used for full FOV checks +#define VIEW_FIELD_NARROW 0.7 // +-45 degrees, more narrow check used to set up ranged attacks +#define VIEW_FIELD_ULTRA_NARROW 0.9 // +-25 degrees, more narrow check used to set up ranged attacks -// All monsters need this data -#define DONT_BLEED -1 -#define BLOOD_COLOR_RED (BYTE)247 -#define BLOOD_COLOR_YELLOW (BYTE)195 -#define BLOOD_COLOR_GREEN BLOOD_COLOR_YELLOW - -typedef enum -{ - - MONSTERSTATE_NONE = 0, - MONSTERSTATE_IDLE, - MONSTERSTATE_COMBAT, - MONSTERSTATE_ALERT, - MONSTERSTATE_HUNT, - MONSTERSTATE_PRONE, - MONSTERSTATE_SCRIPT, - MONSTERSTATE_PLAYDEAD, - MONSTERSTATE_DEAD - -} MONSTERSTATE; - - - -// Things that toggle (buttons/triggers/doors) need this -typedef enum - { - TS_AT_TOP, - TS_AT_BOTTOM, - TS_GOING_UP, - TS_GOING_DOWN - } TOGGLE_STATE; - -// Misc useful -inline BOOL FStrEq(const char*sz1, const char*sz2) - { return (strcmp(sz1, sz2) == 0); } -inline BOOL FClassnameIs(edict_t* pent, const char* szClassname) - { return FStrEq(STRING(VARS(pent)->classname), szClassname); } -inline BOOL FClassnameIs(entvars_t* pev, const char* szClassname) - { return FStrEq(STRING(pev->classname), szClassname); } - -class CBaseEntity; - -// Misc. Prototypes -extern void UTIL_SetSize (entvars_t* pev, const Vector &vecMin, const Vector &vecMax); -extern float UTIL_VecToYaw (const Vector &vec); -extern Vector UTIL_VecToAngles (const Vector &vec); -extern float UTIL_AngleMod (float a); -extern float UTIL_AngleDiff ( float destAngle, float srcAngle ); - -extern CBaseEntity *UTIL_FindEntityInSphere(CBaseEntity *pStartEntity, const Vector &vecCenter, float flRadius); -extern CBaseEntity *UTIL_FindEntityByString(CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue ); -extern CBaseEntity *UTIL_FindEntityByClassname(CBaseEntity *pStartEntity, const char *szName ); -extern CBaseEntity *UTIL_FindEntityByTargetname(CBaseEntity *pStartEntity, const char *szName ); -extern CBaseEntity *UTIL_FindEntityGeneric(const char *szName, Vector &vecSrc, float flRadius ); - -// returns a CBaseEntity pointer to a player by index. Only returns if the player is spawned and connected -// otherwise returns NULL -// Index is 1 based -extern CBaseEntity *UTIL_PlayerByIndex( int playerIndex ); - -#define UTIL_EntitiesInPVS(pent) (*g_engfuncs.pfnEntitiesInPVS)(pent) -extern void UTIL_MakeVectors (const Vector &vecAngles); - -// Pass in an array of pointers and an array size, it fills the array and returns the number inserted -extern int UTIL_MonstersInSphere( CBaseEntity **pList, int listMax, const Vector ¢er, float radius ); -extern int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask ); - -inline void UTIL_MakeVectorsPrivate( const Vector &vecAngles, float *p_vForward, float *p_vRight, float *p_vUp ) -{ - g_engfuncs.pfnAngleVectors( vecAngles, p_vForward, p_vRight, p_vUp ); -} - -extern void UTIL_MakeAimVectors ( const Vector &vecAngles ); // like MakeVectors, but assumes pitch isn't inverted -extern void UTIL_MakeInvVectors ( const Vector &vec, globalvars_t *pgv ); - -extern void UTIL_SetOrigin ( entvars_t* pev, const Vector &vecOrigin ); -extern void UTIL_EmitAmbientSound ( edict_t *entity, const Vector &vecOrigin, const char *samp, float vol, float attenuation, int fFlags, int pitch ); -extern void UTIL_ParticleEffect ( const Vector &vecOrigin, const Vector &vecDirection, ULONG ulColor, ULONG ulCount ); -extern void UTIL_ScreenShake ( const Vector ¢er, float amplitude, float frequency, float duration, float radius ); -extern void UTIL_ScreenShakeAll ( const Vector ¢er, float amplitude, float frequency, float duration ); -extern void UTIL_ShowMessage ( const char *pString, CBaseEntity *pPlayer ); -extern void UTIL_ShowMessageAll ( const char *pString ); -extern void UTIL_ScreenFadeAll ( const Vector &color, float fadeTime, float holdTime, int alpha, int flags ); -extern void UTIL_ScreenFade ( CBaseEntity *pEntity, const Vector &color, float fadeTime, float fadeHold, int alpha, int flags ); - -typedef enum { ignore_monsters=1, dont_ignore_monsters=0, missile=2 } IGNORE_MONSTERS; -typedef enum { ignore_glass=1, dont_ignore_glass=0 } IGNORE_GLASS; -extern void UTIL_TraceLine (const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, edict_t *pentIgnore, TraceResult *ptr); -extern void UTIL_TraceLine (const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, IGNORE_GLASS ignoreGlass, edict_t *pentIgnore, TraceResult *ptr); -typedef enum { point_hull=0, human_hull=1, large_hull=2, head_hull=3 } __HLSDK_HULL_TYPE; -extern void UTIL_TraceHull (const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, int hullNumber, edict_t *pentIgnore, TraceResult *ptr); -extern TraceResult UTIL_GetGlobalTrace (void); -extern void UTIL_TraceModel (const Vector &vecStart, const Vector &vecEnd, int hullNumber, edict_t *pentModel, TraceResult *ptr); -extern Vector UTIL_GetAimVector (edict_t* pent, float flSpeed); -extern int UTIL_PointContents (const Vector &vec); - -extern int UTIL_IsMasterTriggered (string_t sMaster, CBaseEntity *pActivator); -extern void UTIL_BloodStream( const Vector &origin, const Vector &direction, int color, int amount ); -extern void UTIL_BloodDrips( const Vector &origin, const Vector &direction, int color, int amount ); -extern Vector UTIL_RandomBloodVector( void ); -extern BOOL UTIL_ShouldShowBlood( int bloodColor ); -extern void UTIL_BloodDecalTrace( TraceResult *pTrace, int bloodColor ); -extern void UTIL_DecalTrace( TraceResult *pTrace, int decalNumber ); -extern void UTIL_PlayerDecalTrace( TraceResult *pTrace, int playernum, int decalNumber, BOOL bIsCustom ); -extern void UTIL_GunshotDecalTrace( TraceResult *pTrace, int decalNumber ); -extern void UTIL_Sparks( const Vector &position ); -extern void UTIL_Ricochet( const Vector &position, float scale ); -extern void UTIL_StringToVector( float *pVector, const char *pString ); -extern void UTIL_StringToIntArray( int *pVector, int count, const char *pString ); -extern Vector UTIL_ClampVectorToBox( const Vector &input, const Vector &clampSize ); -extern float UTIL_Approach( float target, float value, float speed ); -extern float UTIL_ApproachAngle( float target, float value, float speed ); -extern float UTIL_AngleDistance( float next, float cur ); - -extern char *UTIL_VarArgs( char *format, ... ); -extern void UTIL_Remove( CBaseEntity *pEntity ); -extern BOOL UTIL_IsValidEntity( edict_t *pent ); -extern BOOL UTIL_TeamsMatch( const char *pTeamName1, const char *pTeamName2 ); - -// Use for ease-in, ease-out style interpolation (accel/decel) -extern float UTIL_SplineFraction( float value, float scale ); - -// Search for water transition along a vertical line -extern float UTIL_WaterLevel( const Vector &position, float minz, float maxz ); -extern void UTIL_Bubbles( Vector mins, Vector maxs, int count ); -extern void UTIL_BubbleTrail( Vector from, Vector to, int count ); - -// allows precacheing of other entities -extern void UTIL_PrecacheOther( const char *szClassname ); - -// prints a message to each client -extern void UTIL_ClientPrintAll( int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL ); -inline void UTIL_CenterPrintAll( const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL ) -{ - UTIL_ClientPrintAll( HUD_PRINTCENTER, msg_name, param1, param2, param3, param4 ); -} - -class CBasePlayerItem; -class CBasePlayer; -extern BOOL UTIL_GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ); - -// prints messages through the HUD -extern void ClientPrint( entvars_t *client, int msg_dest, const char *msg_name, const char *param1 = NULL, const char *param2 = NULL, const char *param3 = NULL, const char *param4 = NULL ); - -// prints a message to the HUD say (chat) -extern void UTIL_SayText( const char *pText, CBaseEntity *pEntity ); -extern void UTIL_SayTextAll( const char *pText, CBaseEntity *pEntity ); - - -typedef struct hudtextparms_s -{ - float x; - float y; - int effect; - byte r1, g1, b1, a1; - byte r2, g2, b2, a2; - float fadeinTime; - float fadeoutTime; - float holdTime; - float fxTime; - int channel; -} hudtextparms_t; - -// prints as transparent 'title' to the HUD -extern void UTIL_HudMessageAll( const hudtextparms_t &textparms, const char *pMessage ); -extern void UTIL_HudMessage( CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage ); - -// for handy use with ClientPrint params -extern char *UTIL_dtos1( int d ); -extern char *UTIL_dtos2( int d ); -extern char *UTIL_dtos3( int d ); -extern char *UTIL_dtos4( int d ); - -// Writes message to console with timestamp and FragLog header. -extern void UTIL_LogPrintf( char *fmt, ... ); -extern void UTIL_ServerPrintf( const char *fmt, ... ); - -// Sorta like FInViewCone, but for nonmonsters. -extern float UTIL_DotPoints ( const Vector &vecSrc, const Vector &vecCheck, const Vector &vecDir ); - -extern void UTIL_StripToken( const char *pKey, char *pDest );// for redundant keynames - -// Misc functions -extern void SetMovedir(entvars_t* pev); -extern Vector VecBModelOrigin( entvars_t* pevBModel ); -extern int BuildChangeList( LEVELLIST *pLevelList, int maxList ); - -// -// How did I ever live without ASSERT? -// -#ifdef DEBUG -void DBG_AssertFunction(BOOL fExpr, const char* szExpr, const char* szFile, int szLine, const char* szMessage); -#define ASSERT(f) DBG_AssertFunction(f, #f, __FILE__, __LINE__, NULL) -#define ASSERTSZ(f, sz) DBG_AssertFunction(f, #f, __FILE__, __LINE__, sz) -#else // !DEBUG -#define ASSERT(f) -#define ASSERTSZ(f, sz) -#endif // !DEBUG - - -extern DLL_GLOBAL const Vector g_vecZero; - -// -// Constants that were used only by QC (maybe not used at all now) -// -// Un-comment only as needed -// -#define LANGUAGE_ENGLISH 0 -#define LANGUAGE_GERMAN 1 -#define LANGUAGE_FRENCH 2 -#define LANGUAGE_BRITISH 3 - -extern DLL_GLOBAL int g_Language; - -#define AMBIENT_SOUND_STATIC 0 // medium radius attenuation -#define AMBIENT_SOUND_EVERYWHERE 1 -#define AMBIENT_SOUND_SMALLRADIUS 2 -#define AMBIENT_SOUND_MEDIUMRADIUS 4 -#define AMBIENT_SOUND_LARGERADIUS 8 -#define AMBIENT_SOUND_START_SILENT 16 -#define AMBIENT_SOUND_NOT_LOOPING 32 - -#define SPEAKER_START_SILENT 1 // wait for trigger 'on' to start announcements - -#define SND_SPAWNING (1<<8) // duplicated in protocol.h we're spawing, used in some cases for ambients -#define SND_STOP (1<<5) // duplicated in protocol.h stop sound +#define SND_SPAWNING (1<<8) // duplicated in protocol.h we're spawing, used in some cases for ambients +#define SND_STOP (1<<5) // duplicated in protocol.h stop sound #define SND_CHANGE_VOL (1<<6) // duplicated in protocol.h change sound vol #define SND_CHANGE_PITCH (1<<7) // duplicated in protocol.h change sound pitch -#define LFO_SQUARE 1 -#define LFO_TRIANGLE 2 -#define LFO_RANDOM 3 +// All monsters need this data +#define DONT_BLEED -1 +#define BLOOD_COLOR_RED (byte)247 +#define BLOOD_COLOR_YELLOW (byte)195 +#define BLOOD_COLOR_GREEN BLOOD_COLOR_YELLOW + +#define GERMAN_GIB_COUNT 4 +#define HUMAN_GIB_COUNT 6 +#define ALIEN_GIB_COUNT 4 + +#define LANGUAGE_ENGLISH 0 +#define LANGUAGE_GERMAN 1 +#define LANGUAGE_FRENCH 2 +#define LANGUAGE_BRITISH 3 + +#define SVC_TEMPENTITY 23 +#define SVC_INTERMISSION 30 +#define SVC_CDTRACK 32 +#define SVC_WEAPONANIM 35 +#define SVC_ROOMTYPE 37 +#define SVC_DIRECTOR 51 // func_rotating #define SF_BRUSH_ROTATE_Y_AXIS 0 @@ -402,146 +86,105 @@ extern DLL_GLOBAL int g_Language; #define SF_BRUSH_ROTATE_Z_AXIS 4 #define SF_BRUSH_ROTATE_X_AXIS 8 #define SF_PENDULUM_AUTO_RETURN 16 -#define SF_PENDULUM_PASSABLE 32 - +#define SF_PENDULUM_PASSABLE 32 #define SF_BRUSH_ROTATE_SMALLRADIUS 128 -#define SF_BRUSH_ROTATE_MEDIUMRADIUS 256 -#define SF_BRUSH_ROTATE_LARGERADIUS 512 +#define SF_BRUSH_ROTATE_MEDIUMRADIUS 256 +#define SF_BRUSH_ROTATE_LARGERADIUS 512 -#define PUSH_BLOCK_ONLY_X 1 -#define PUSH_BLOCK_ONLY_Y 2 +#define SPAWNFLAG_NOMESSAGE 1 +#define SPAWNFLAG_NOTOUCH 1 +#define SPAWNFLAG_DROIDONLY 4 + +#define VEC_HULL_MIN_Z Vector(0, 0, -36) +#define VEC_DUCK_HULL_MIN_Z Vector(0, 0, -18) #define VEC_HULL_MIN Vector(-16, -16, -36) -#define VEC_HULL_MAX Vector( 16, 16, 36) -#define VEC_HUMAN_HULL_MIN Vector( -16, -16, 0 ) -#define VEC_HUMAN_HULL_MAX Vector( 16, 16, 72 ) -#define VEC_HUMAN_HULL_DUCK Vector( 16, 16, 36 ) +#define VEC_HULL_MAX Vector(16, 16, 36) -#define VEC_VIEW Vector( 0, 0, 28 ) +#define VEC_VIEW Vector(0, 0, 17) -#define VEC_DUCK_HULL_MIN Vector(-16, -16, -18 ) -#define VEC_DUCK_HULL_MAX Vector( 16, 16, 18) -#define VEC_DUCK_VIEW Vector( 0, 0, 12 ) +#define VEC_DUCK_HULL_MIN Vector(-16, -16, -18) +#define VEC_DUCK_HULL_MAX Vector(16, 16, 32) +#define VEC_DUCK_VIEW Vector(0, 0, 12) -#define SVC_TEMPENTITY 23 -#define SVC_INTERMISSION 30 -#define SVC_CDTRACK 32 -#define SVC_WEAPONANIM 35 -#define SVC_ROOMTYPE 37 -#define SVC_DIRECTOR 51 +#define PRECACHE_SOUND_ARRAY(a) \ + { for (int i = 0; i < ARRAYSIZE(a); ++i) PRECACHE_SOUND((char *)a[i]); } +// Inlines +inline edict_t *FIND_ENTITY_BY_CLASSNAME(edict_t *entStart, const char *pszName) { return FIND_ENTITY_BY_STRING(entStart, "classname", pszName); } +inline edict_t *FIND_ENTITY_BY_TARGETNAME(edict_t *entStart, const char *pszName) { return FIND_ENTITY_BY_STRING(entStart, "targetname", pszName); } +inline edict_t *ENT(const entvars_t *pev) { return pev->pContainingEntity; } +inline edict_t *ENT(EOFFSET eoffset) { return (*g_engfuncs.pfnPEntityOfEntOffset)(eoffset); } +inline EOFFSET OFFSET(const edict_t *pent) { return (*g_engfuncs.pfnEntOffsetOfPEntity)(pent); } +inline EOFFSET OFFSET(const entvars_t *pev) { return OFFSET(ENT(pev)); } -// triggers -#define SF_TRIGGER_ALLOWMONSTERS 1// monsters allowed to fire this trigger -#define SF_TRIGGER_NOCLIENTS 2// players not allowed to fire this trigger -#define SF_TRIGGER_PUSHABLES 4// only pushables can fire this trigger +inline entvars_t *VARS(edict_t *pent) +{ + if (!pent) + return NULL; -// func breakable -#define SF_BREAK_TRIGGER_ONLY 1// may only be broken by trigger -#define SF_BREAK_TOUCH 2// can be 'crashed through' by running player (plate glass) -#define SF_BREAK_PRESSURE 4// can be broken by a player standing on it -#define SF_BREAK_CROWBAR 256// instant break if hit with crowbar + return &pent->v; +} -// func_pushable (it's also func_breakable, so don't collide with those flags) -#define SF_PUSH_BREAKABLE 128 +inline entvars_t *VARS(EOFFSET eoffset) +{ + return VARS(ENT(eoffset)); +} -#define SF_LIGHT_START_OFF 1 +#ifndef ENTINDEX +inline int ENTINDEX(const edict_t *pEdict) { return (*g_engfuncs.pfnIndexOfEdict)(pEdict); } +inline int ENTINDEX(const entvars_t *pev) { return (*g_engfuncs.pfnIndexOfEdict)(ENT(pev)); } +#endif // ENTINDEX -#define SPAWNFLAG_NOMESSAGE 1 -#define SPAWNFLAG_NOTOUCH 1 -#define SPAWNFLAG_DROIDONLY 4 +#ifndef INDEXENT +inline edict_t *INDEXENT(int iEdictNum) { return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); } +#endif // INDEXENT -#define SPAWNFLAG_USEONLY 1 // can't be touched, must be used (buttons) +inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent) { MESSAGE_BEGIN(msg_dest, msg_type, pOrigin, ENT(ent)); } +inline BOOL FNullEnt(EOFFSET eoffset) { return (eoffset == 0); } +inline BOOL FNullEnt(entvars_t *pev) { return (pev == NULL || FNullEnt(OFFSET(pev))); } +inline BOOL FNullEnt(const edict_t *pent) { return (pent == NULL || FNullEnt(OFFSET(pent))); } +inline BOOL FStringNull(int iString) { return (iString == iStringNull); } +inline BOOL FStrEq(const char *sz1, const char *sz2) { return (strcmp(sz1, sz2) == 0); } +inline BOOL FClassnameIs(entvars_t *pev, const char *szClassname) { return FStrEq(STRING(pev->classname), szClassname); } +inline BOOL FClassnameIs(edict_t *pent, const char *szClassname) { return FStrEq(STRING(VARS(pent)->classname), szClassname); } -#define TELE_PLAYER_ONLY 1 -#define TELE_SILENT 2 - -#define SF_TRIG_PUSH_ONCE 1 - - -// Sound Utilities - -// sentence groups -#define CBSENTENCENAME_MAX 16 -#define CVOXFILESENTENCEMAX 1536 // max number of sentences in game. NOTE: this must match - // CVOXFILESENTENCEMAX in engine\sound.h!!! - -extern char gszallsentencenames[CVOXFILESENTENCEMAX][CBSENTENCENAME_MAX]; -extern int gcallsentences; - -int USENTENCEG_Pick(int isentenceg, char *szfound); -int USENTENCEG_PickSequential(int isentenceg, char *szfound, int ipick, int freset); -void USENTENCEG_InitLRU(unsigned char *plru, int count); - -void SENTENCEG_Init(); -void SENTENCEG_Stop(edict_t *entity, int isentenceg, int ipick); -int SENTENCEG_PlayRndI(edict_t *entity, int isentenceg, float volume, float attenuation, int flags, int pitch); -int SENTENCEG_PlayRndSz(edict_t *entity, const char *szrootname, float volume, float attenuation, int flags, int pitch); -int SENTENCEG_PlaySequentialSz(edict_t *entity, const char *szrootname, float volume, float attenuation, int flags, int pitch, int ipick, int freset); -int SENTENCEG_GetIndex(const char *szrootname); -int SENTENCEG_Lookup(const char *sample, char *sentencenum); - -void TEXTURETYPE_Init(); -char TEXTURETYPE_Find(char *name); -float TEXTURETYPE_PlaySound(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int iBulletType); +inline void UTIL_MakeVectorsPrivate(Vector vecAngles, float *p_vForward, float *p_vRight, float *p_vUp) { g_engfuncs.pfnAngleVectors(vecAngles, p_vForward, p_vRight, p_vUp); } // NOTE: use EMIT_SOUND_DYN to set the pitch of a sound. Pitch of 100 // is no pitch shift. Pitch > 100 up to 255 is a higher pitch, pitch < 100 // down to 1 is a lower pitch. 150 to 70 is the realistic range. // EMIT_SOUND_DYN with pitch != 100 should be used sparingly, as it's not quite as // fast as EMIT_SOUND (the pitchshift mixer is not native coded). - -void EMIT_SOUND_DYN(edict_t *entity, int channel, const char *sample, float volume, float attenuation, - int flags, int pitch); - - inline void EMIT_SOUND(edict_t *entity, int channel, const char *sample, float volume, float attenuation) { - EMIT_SOUND_DYN(entity, channel, sample, volume, attenuation, 0, PITCH_NORM); + EMIT_SOUND_DYN2(entity, channel, sample, volume, attenuation, 0, PITCH_NORM); } inline void STOP_SOUND(edict_t *entity, int channel, const char *sample) { - EMIT_SOUND_DYN(entity, channel, sample, 0, 0, SND_STOP, PITCH_NORM); + EMIT_SOUND_DYN2(entity, channel, sample, 0, 0, SND_STOP, PITCH_NORM); } -void EMIT_SOUND_SUIT(edict_t *entity, const char *sample); -void EMIT_GROUPID_SUIT(edict_t *entity, int isentenceg); -void EMIT_GROUPNAME_SUIT(edict_t *entity, const char *groupname); - -#define PRECACHE_SOUND_ARRAY( a ) \ - { for (int i = 0; i < ARRAYSIZE( a ); i++ ) PRECACHE_SOUND((char *) a [i]); } - -#define EMIT_SOUND_ARRAY_DYN( chan, array ) \ - EMIT_SOUND_DYN ( ENT(pev), chan , array [ RANDOM_LONG(0,ARRAYSIZE( array )-1) ], 1.0, ATTN_NORM, 0, RANDOM_LONG(95,105) ); - -#define RANDOM_SOUND_ARRAY( array ) (array) [ RANDOM_LONG(0,ARRAYSIZE( (array) )-1) ] - -#define PLAYBACK_EVENT( flags, who, index ) PLAYBACK_EVENT_FULL( flags, who, index, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0 ); -#define PLAYBACK_EVENT_DELAY( flags, who, index, delay ) PLAYBACK_EVENT_FULL( flags, who, index, delay, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0 ); - -#define GROUP_OP_AND 0 -#define GROUP_OP_NAND 1 - -extern int g_groupmask; -extern int g_groupop; - -class UTIL_GroupTrace +inline void UTIL_SetSize(entvars_t *pev, const Vector &vecMin, const Vector &vecMax) { -public: - UTIL_GroupTrace( int groupmask, int op ); - ~UTIL_GroupTrace( void ); + SET_SIZE(ENT(pev), vecMin, vecMax); +} -private: - int m_oldgroupmask, m_oldgroupop; -}; +inline void UTIL_SetOrigin(entvars_t *pev, const Vector &vecOrigin) +{ + edict_t *ent = ENT(pev); -void UTIL_SetGroupTrace( int groupmask, int op ); -void UTIL_UnsetGroupTrace( void ); + if (ent != NULL) + SET_ORIGIN(ent, vecOrigin); +} -int UTIL_SharedRandomLong( unsigned int seed, int low, int high ); -float UTIL_SharedRandomFloat( unsigned int seed, float low, float high ); +inline void UTIL_TraceLine(const Vector &vecStart, const Vector &vecEnd, IGNORE_MONSTERS igmon, edict_t *pentIgnore, TraceResult *ptr) +{ + TRACE_LINE(vecStart, vecEnd, (igmon == ignore_monsters), pentIgnore, ptr); +} -float UTIL_WeaponTimeBase( void ); +extern char *UTIL_VarArgs(char *format, ...); +extern void UTIL_LogPrintf(const char *fmt, ...); diff --git a/dlls/vector.h b/dlls/vector.h index de8924f..6427e1e 100644 --- a/dlls/vector.h +++ b/dlls/vector.h @@ -1,113 +1,176 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once -#ifndef VECTOR_H -#define VECTOR_H - - -//========================================================= // 2DVector - used for many pathfinding and many other // operations that are treated as planar rather than 3d. -//========================================================= -class Vector2D -{ +class Vector2D { public: - inline Vector2D(void): x(0.0), y(0.0) { } - inline Vector2D(float X, float Y): x(0.0), y(0.0) { x = X; y = Y; } - inline Vector2D operator+(const Vector2D& v) const { return Vector2D(x+v.x, y+v.y); } - inline Vector2D operator-(const Vector2D& v) const { return Vector2D(x-v.x, y-v.y); } - inline Vector2D operator*(float fl) const { return Vector2D(x*fl, y*fl); } - inline Vector2D operator/(float fl) const { return Vector2D(x/fl, y/fl); } - - inline float Length(void) const { return sqrt(x*x + y*y ); } + inline Vector2D() : x(), y() {} + inline Vector2D(float X, float Y) : x(X), y(Y) {} + inline Vector2D(const Vector2D &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; } + inline Vector2D operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); } + inline Vector2D operator-(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); } + inline Vector2D operator*(float fl) const { return Vector2D(x * fl, y * fl); } + inline Vector2D operator/(float fl) const { return Vector2D(x / fl, y / fl); } + inline Vector2D operator/=(float fl) const { return Vector2D(x / fl, y / fl); } - inline Vector2D Normalize ( void ) const + inline float Length() const { return sqrt(x * x + y * y); } + inline float LengthSquared() const { return (x * x + y * y); } + + operator float*() { return &x; } + operator const float*() const { return &x; } + + inline Vector2D Normalize() const { - // Vector2D vec2; - float flLen = Length(); - if ( flLen == 0 ) + if (flLen == 0) + return Vector2D(0, 0); + + flLen = 1 / flLen; + return Vector2D(x * flLen, y * flLen); + } + + inline bool IsLengthLessThan(float length) const { return (LengthSquared() < length * length); } + inline bool IsLengthGreaterThan(float length) const { return (LengthSquared() > length * length); } + inline float NormalizeInPlace() + { + float flLen = Length(); + if (flLen == 0) { - return Vector2D( 0, 0 ); + x = 1; y = 0; } else { flLen = 1 / flLen; - return Vector2D( x * flLen, y * flLen ); + x *= flLen; y *= flLen; } + + return flLen; + } + inline bool IsZero(float tolerance = 0.01f) const + { + return (x > -tolerance && x < tolerance && + y > -tolerance && y < tolerance); } - vec_t x, y; + // Members + vec_t x, y; }; -inline float DotProduct(const Vector2D& a, const Vector2D& b) { return( a.x*b.x + a.y*b.y ); } -inline Vector2D operator*(float fl, const Vector2D& v) { return v * fl; } +inline float DotProduct(const Vector2D &a, const Vector2D &b) { return (a.x * b.x + a.y * b.y); } +inline Vector2D operator*(float fl, const Vector2D &v) { return v * fl; } -//========================================================= // 3D Vector -//========================================================= -class Vector // same data-layout as engine's vec3_t, -{ // which is a vec_t[3] +// same data-layout as engine's vec3_t, which is a vec_t[3] +class Vector { public: // Construction/destruction - inline Vector(void): x(0.0), y(0.0), z(0.0) { } - inline Vector(float X, float Y, float Z): x(0.0), y(0.0), z(0.0) { x = X; y = Y; z = Z; } - //inline Vector(double X, double Y, double Z) { x = (float)X; y = (float)Y; z = (float)Z; } - //inline Vector(int X, int Y, int Z) { x = (float)X; y = (float)Y; z = (float)Z; } - inline Vector(const Vector& v): x(0.0), y(0.0), z(0.0) { x = v.x; y = v.y; z = v.z; } - inline Vector(float rgfl[3]): x(0.0), y(0.0), z(0.0) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; } + inline Vector() : x(), y(), z() {} + inline Vector(float X, float Y, float Z) : x(X), y(Y), z(Z) {} + inline Vector(const Vector &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; *(int*)&z = *(int*)&v.z; } + inline Vector(const float rgfl[3]) { *(int*)&x = *(int*)&rgfl[0]; *(int*)&y = *(int*)&rgfl[1]; *(int*)&z = *(int*)&rgfl[2]; } // Operators - inline Vector operator-(void) const { return Vector(-x,-y,-z); } - inline int operator==(const Vector& v) const { return x==v.x && y==v.y && z==v.z; } - inline int operator!=(const Vector& v) const { return !(*this==v); } - inline Vector operator+(const Vector& v) const { return Vector(x+v.x, y+v.y, z+v.z); } - inline Vector operator-(const Vector& v) const { return Vector(x-v.x, y-v.y, z-v.z); } - inline Vector operator*(float fl) const { return Vector(x*fl, y*fl, z*fl); } - inline Vector operator/(float fl) const { return Vector(x/fl, y/fl, z/fl); } - + inline Vector operator-() const { return Vector(-x, -y, -z); } + inline int operator==(const Vector &v) const { return x == v.x && y == v.y && z == v.z; } + inline int operator!=(const Vector &v) const { return !(*this == v); } + inline Vector operator+(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); } + inline Vector operator-(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); } + inline Vector operator*(float fl) const { return Vector(x * fl, y * fl, z * fl); } + inline Vector operator/(float fl) const { return Vector(x / fl, y / fl, z / fl); } + inline Vector operator/=(float fl) const{ return Vector(x / fl, y / fl, z / fl); } + // Methods - inline void CopyToArray(float* rgfl) const { rgfl[0] = x, rgfl[1] = y, rgfl[2] = z; } - inline float Length(void) const { return sqrt(x*x + y*y + z*z); } - operator float *() { return &x; } // Vectors will now automatically convert to float * when needed - operator const float *() const { return &x; } // Vectors will now automatically convert to float * when needed - inline Vector Normalize(void) const + inline void CopyToArray(float *rgfl) const { *(int*)&rgfl[0] = *(int*)&x; *(int*)&rgfl[1] = *(int*)&y; *(int*)&rgfl[2] = *(int*)&z; } + inline float Length() const { return sqrt(x * x + y * y + z * z); } + inline float LengthSquared() const { return (x * x + y * y + z * z); } + + operator float*() { return &x; } // Vectors will now automatically convert to float * when needed + operator const float*() const { return &x; } // Vectors will now automatically convert to float * when needed + + inline Vector Normalize() { float flLen = Length(); - if (flLen == 0) return Vector(0,0,1); // ???? + if (flLen == 0) + return Vector(0, 0, 1); + flLen = 1 / flLen; return Vector(x * flLen, y * flLen, z * flLen); } - - inline Vector2D Make2D ( void ) const + inline Vector2D Make2D() const { - Vector2D Vec2; - - Vec2.x = x; - Vec2.y = y; - + Vector2D Vec2; + *(int*)&Vec2.x = *(int*)&x; + *(int*)&Vec2.y = *(int*)&y; return Vec2; } - inline float Length2D(void) const { return sqrt(x*x + y*y); } + + inline float Length2D() const { return sqrt(x * x + y * y); } + + inline bool IsLengthLessThan(float length) const { return (LengthSquared() < length * length); } + inline bool IsLengthGreaterThan(float length) const { return (LengthSquared() > length * length); } + + inline float NormalizeInPlace() + { + float flLen = Length(); + if (flLen == 0) + { + x = 0; y = 0; z = 1; + } + else + { + flLen = 1 / flLen; + x *= flLen; y *= flLen; z *= flLen; + } + + return flLen; + } + inline bool IsZero(float tolerance = 0.01f) const + { + return (x > -tolerance && x < tolerance && + y > -tolerance && y < tolerance && + z > -tolerance && z < tolerance); + } // Members vec_t x, y, z; }; -inline Vector operator*(float fl, const Vector& v) { return v * fl; } -inline float DotProduct(const Vector& a, const Vector& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); } -inline Vector CrossProduct(const Vector& a, const Vector& b) { return Vector( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x ); } +inline Vector operator*(float fl, const Vector &v) { return v * fl; } +inline float DotProduct(const Vector &a, const Vector &b) { return (a.x * b.x + a.y * b.y + a.z * b.z); } +inline float DotProduct2D(const Vector &a, const Vector &b) { return (a.x * b.x + a.y * b.y); } +inline Vector CrossProduct(const Vector &a, const Vector &b) { return Vector(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } -#endif +template +inline void SWAP(T &first, T &second) +{ + T temp = first; + first = second; + second = temp; +} diff --git a/dlls/vehicle.h b/dlls/vehicle.h new file mode 100644 index 0000000..8b7a0d0 --- /dev/null +++ b/dlls/vehicle.h @@ -0,0 +1,53 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#define VEHICLE_SPEED0_ACCELERATION 0.005000000000000000 +#define VEHICLE_SPEED1_ACCELERATION 0.002142857142857143 +#define VEHICLE_SPEED2_ACCELERATION 0.003333333333333334 +#define VEHICLE_SPEED3_ACCELERATION 0.004166666666666667 +#define VEHICLE_SPEED4_ACCELERATION 0.004000000000000000 +#define VEHICLE_SPEED5_ACCELERATION 0.003800000000000000 +#define VEHICLE_SPEED6_ACCELERATION 0.004500000000000000 +#define VEHICLE_SPEED7_ACCELERATION 0.004250000000000000 +#define VEHICLE_SPEED8_ACCELERATION 0.002666666666666667 +#define VEHICLE_SPEED9_ACCELERATION 0.002285714285714286 +#define VEHICLE_SPEED10_ACCELERATION 0.001875000000000000 +#define VEHICLE_SPEED11_ACCELERATION 0.001444444444444444 +#define VEHICLE_SPEED12_ACCELERATION 0.001200000000000000 +#define VEHICLE_SPEED13_ACCELERATION 0.000916666666666666 + +#define VEHICLE_STARTPITCH 60 +#define VEHICLE_MAXPITCH 200 +#define VEHICLE_MAXSPEED 1500 + +class CFuncVehicleControls: public CBaseEntity { +public: + virtual void Spawn() = 0; + virtual int ObjectCaps() = 0; +}; diff --git a/dlls/weapons.h b/dlls/weapons.h index be407f5..c4da501 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -1,1019 +1,909 @@ -/*** +/* * -* Copyright (c) 1996-2002, 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 program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. * -* Use, distribution, and modification of this source code and/or resulting -* object code is restricted to non-commercial enhancements to products from -* Valve LLC. All other use, distribution, or modification is prohibited -* without written permission from Valve LLC. +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. * -****/ -#ifndef WEAPONS_H -#define WEAPONS_H +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ -#include "effects.h" +#pragma once + +#include "weapontype.h" class CBasePlayer; -extern int gmsgWeapPickup; - -void DeactivateSatchels( CBasePlayer *pOwner ); - -// Contact Grenade / Timed grenade / Satchel Charge -class CGrenade : public CBaseMonster -{ -public: - void Spawn( void ); - - typedef enum { SATCHEL_DETONATE = 0, SATCHEL_RELEASE } SATCHELCODE; - - static CGrenade *ShootTimed( entvars_t *pevOwner, Vector vecStart, Vector vecVelocity, float time ); - static CGrenade *ShootContact( entvars_t *pevOwner, Vector vecStart, Vector vecVelocity ); - static CGrenade *ShootSatchelCharge( entvars_t *pevOwner, Vector vecStart, Vector vecVelocity ); - static void UseSatchelCharges( entvars_t *pevOwner, SATCHELCODE code ); - - void Explode( Vector vecSrc, Vector vecAim ); - void Explode( TraceResult *pTrace, int bitsDamageType ); - void EXPORT Smoke( void ); - - void EXPORT BounceTouch( CBaseEntity *pOther ); - void EXPORT SlideTouch( CBaseEntity *pOther ); - void EXPORT ExplodeTouch( CBaseEntity *pOther ); - void EXPORT DangerSoundThink( void ); - void EXPORT PreDetonate( void ); - void EXPORT Detonate( void ); - void EXPORT DetonateUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void EXPORT TumbleThink( void ); - - virtual void BounceSound( void ); - virtual int BloodColor( void ) { return DONT_BLEED; } - virtual void Killed( entvars_t *pevAttacker, int iGib ); - - BOOL m_fRegisteredSound;// whether or not this grenade has issued its DANGER sound to the world sound list yet. -}; - - -// constant items -#define ITEM_HEALTHKIT 1 -#define ITEM_ANTIDOTE 2 -#define ITEM_SECURITY 3 -#define ITEM_BATTERY 4 - -#define WEAPON_NONE 0 -#define WEAPON_CROWBAR 1 -#define WEAPON_GLOCK 2 -#define WEAPON_PYTHON 3 -#define WEAPON_MP5 4 -#define WEAPON_CHAINGUN 5 -#define WEAPON_CROSSBOW 6 -#define WEAPON_SHOTGUN 7 -#define WEAPON_RPG 8 -#define WEAPON_GAUSS 9 -#define WEAPON_EGON 10 -#define WEAPON_HORNETGUN 11 -#define WEAPON_HANDGRENADE 12 -#define WEAPON_TRIPMINE 13 -#define WEAPON_SATCHEL 14 -#define WEAPON_SNARK 15 - -#define WEAPON_ALLWEAPONS (~(1<absmin = pev->origin + Vector(-16, -16, -5); - pev->absmax = pev->origin + Vector(16, 16, 28); - } - - void PrimaryAttack( void ); - BOOL Deploy( void ); - void Holster( int skiplocal = 0 ); - void WeaponIdle( void ); - - virtual BOOL UseDecrement( void ) - { -#if defined( CLIENT_WEAPONS ) - return TRUE; -#else - return FALSE; -#endif - } - + int m_iShell; + unsigned short GetEventID() const { return m_usFireAWP; } private: - unsigned short m_usTripFire; - + unsigned short m_usFireAWP; }; -class CSqueak : public CBasePlayerWeapon -{ +// for usermsg BombDrop +#define BOMB_FLAG_DROPPED 0 // if the bomb was dropped due to voluntary dropping or death/disconnect +#define BOMB_FLAG_PLANTED 1 // if the bomb has been planted will also trigger the round timer to hide will also show where the dropped bomb on the Terrorist team's radar. + +class CC4: public CBasePlayerWeapon { public: - void Spawn( void ); - void Precache( void ); - int iItemSlot( void ) { return 5; } - int GetItemInfo(ItemInfo *p); - - void PrimaryAttack( void ); - void SecondaryAttack( void ); - BOOL Deploy( void ); - void Holster( int skiplocal = 0 ); - void WeaponIdle( void ); - int m_fJustThrown; - - virtual BOOL UseDecrement( void ) - { -#if defined( CLIENT_WEAPONS ) - return TRUE; -#else - return FALSE; -#endif - } - + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual void KeyValue(KeyValueData *pkvd) = 0; + virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal) = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + bool m_bStartedArming; + bool m_bBombPlacedAnimation; + float m_fArmedTime; + bool HasShield() const { return m_bHasShield; } private: - unsigned short m_usSnarkFire; + bool m_bHasShield; }; +class CDEAGLE: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireDeagle; } +private: + unsigned short m_usFireDeagle; +}; -#endif // WEAPONS_H +class CFlashbang: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL CanDeploy() = 0; + virtual BOOL CanDrop() = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal) = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +}; + +class CG3SG1: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireG3SG1; } +private: + unsigned short m_usFireG3SG1; +}; + +class CGLOCK18: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +public: + int m_iShell; + bool m_bBurstFire; +}; + +class CHEGrenade: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL CanDeploy() = 0; + virtual BOOL CanDrop() = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal) = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + unsigned short m_usCreateExplosion; +}; + +class CKnife: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL CanDrop() = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal) = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual BOOL UseDecrement() = 0; + virtual void WeaponIdle() = 0; +public: + TraceResult m_trHit; + unsigned short m_usKnife; +}; + +class CM249: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireM249; } +private: + unsigned short m_usFireM249; +}; + +class CM3: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + float m_flPumpTime; + unsigned short GetEventID() const { return m_usFireM3; } +private: + unsigned short m_usFireM3; +}; + +class CM4A1: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireM4A1; } +private: + unsigned short m_usFireM4A1; +}; + +class CMAC10: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireMAC10; } +private: + unsigned short m_usFireMAC10; +}; + +class CP228: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireP228; } +private: + unsigned short m_usFireP228; +}; + +class CP90: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireP90; } +private: + unsigned short m_usFireP90; +}; + +class CSCOUT: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireScout; } +private: + unsigned short m_usFireScout; +}; + +class CSmokeGrenade: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL CanDeploy() = 0; + virtual BOOL CanDrop() = 0; + virtual BOOL Deploy() = 0; + virtual void Holster(int skiplocal) = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + unsigned short m_usCreateSmoke; +}; + +class CTMP: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireTMP; } +private: + unsigned short m_usFireTMP; +}; + +class CXM1014: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + float m_flPumpTime; + unsigned short GetEventID() const { return m_usFireXM1014; } +private: + unsigned short m_usFireXM1014; +}; + +class CELITE: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +public: + int m_iShell; + unsigned short GetEventID_Left() const { return m_usFireELITE_LEFT; } + unsigned short GetEventID_Right() const { return m_usFireELITE_RIGHT; } +private: + unsigned short m_usFireELITE_LEFT; + unsigned short m_usFireELITE_RIGHT; +}; + +class CFiveSeven: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; + virtual BOOL IsPistol() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireFiveSeven; } +private: + unsigned short m_usFireFiveSeven; +}; + +class CUMP45: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireUMP45; } +private: + unsigned short m_usFireUMP45; +}; + +class CSG550: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + unsigned short GetEventID() const { return m_usFireSG550; } +private: + unsigned short m_usFireSG550; +}; + +class CGalil: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; + unsigned short GetEventID() const { return m_usFireGalil; } +private: + unsigned short m_usFireGalil; +}; + +class CFamas: public CBasePlayerWeapon { +public: + virtual void Spawn() = 0; + virtual void Precache() = 0; + virtual int GetItemInfo(ItemInfo *p) = 0; + virtual BOOL Deploy() = 0; + virtual float GetMaxSpeed() = 0; + virtual int iItemSlot() = 0; + virtual void PrimaryAttack() = 0; + virtual void SecondaryAttack() = 0; + virtual void Reload() = 0; + virtual void WeaponIdle() = 0; + virtual BOOL UseDecrement() = 0; +public: + int m_iShell; + int iShellOn; +}; diff --git a/dlls/weapontype.h b/dlls/weapontype.h new file mode 100644 index 0000000..784f804 --- /dev/null +++ b/dlls/weapontype.h @@ -0,0 +1,417 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +enum WeaponIdType +{ + WEAPON_NONE, + WEAPON_P228, + WEAPON_GLOCK, + WEAPON_SCOUT, + WEAPON_HEGRENADE, + WEAPON_XM1014, + WEAPON_C4, + WEAPON_MAC10, + WEAPON_AUG, + WEAPON_SMOKEGRENADE, + WEAPON_ELITE, + WEAPON_FIVESEVEN, + WEAPON_UMP45, + WEAPON_SG550, + WEAPON_GALIL, + WEAPON_FAMAS, + WEAPON_USP, + WEAPON_GLOCK18, + WEAPON_AWP, + WEAPON_MP5N, + WEAPON_M249, + WEAPON_M3, + WEAPON_M4A1, + WEAPON_TMP, + WEAPON_G3SG1, + WEAPON_FLASHBANG, + WEAPON_DEAGLE, + WEAPON_SG552, + WEAPON_AK47, + WEAPON_KNIFE, + WEAPON_P90, + WEAPON_SHIELDGUN = 99 +}; + +enum AutoBuyClassType +{ + AUTOBUYCLASS_NONE = 0, + AUTOBUYCLASS_PRIMARY = (1 << 0), + AUTOBUYCLASS_SECONDARY = (1 << 1), + AUTOBUYCLASS_AMMO = (1 << 2), + AUTOBUYCLASS_ARMOR = (1 << 3), + AUTOBUYCLASS_DEFUSER = (1 << 4), + AUTOBUYCLASS_PISTOL = (1 << 5), + AUTOBUYCLASS_SMG = (1 << 6), + AUTOBUYCLASS_RIFLE = (1 << 7), + AUTOBUYCLASS_SNIPERRIFLE = (1 << 8), + AUTOBUYCLASS_SHOTGUN = (1 << 9), + AUTOBUYCLASS_MACHINEGUN = (1 << 10), + AUTOBUYCLASS_GRENADE = (1 << 11), + AUTOBUYCLASS_NIGHTVISION = (1 << 12), + AUTOBUYCLASS_SHIELD = (1 << 13), +}; + +enum AmmoCostType +{ + AMMO_338MAG_PRICE = 125, + AMMO_357SIG_PRICE = 50, + AMMO_45ACP_PRICE = 25, + AMMO_50AE_PRICE = 40, + AMMO_556MM_PRICE = 60, + AMMO_57MM_PRICE = 50, + AMMO_762MM_PRICE = 80, + AMMO_9MM_PRICE = 20, + AMMO_BUCKSHOT_PRICE = 65, +}; + +enum WeaponCostType +{ + AK47_PRICE = 2500, + AWP_PRICE = 4750, + DEAGLE_PRICE = 650, + G3SG1_PRICE = 5000, + SG550_PRICE = 4200, + GLOCK18_PRICE = 400, + M249_PRICE = 5750, + M3_PRICE = 1700, + M4A1_PRICE = 3100, + AUG_PRICE = 3500, + MP5NAVY_PRICE = 1500, + P228_PRICE = 600, + P90_PRICE = 2350, + UMP45_PRICE = 1700, + MAC10_PRICE = 1400, + SCOUT_PRICE = 2750, + SG552_PRICE = 3500, + TMP_PRICE = 1250, + USP_PRICE = 500, + ELITE_PRICE = 800, + FIVESEVEN_PRICE = 750, + XM1014_PRICE = 3000, + GALIL_PRICE = 2000, + FAMAS_PRICE = 2250, + SHIELDGUN_PRICE = 2200, +}; + +enum WeaponState +{ + WPNSTATE_USP_SILENCED = (1 << 0), + WPNSTATE_GLOCK18_BURST_MODE = (1 << 1), + WPNSTATE_M4A1_SILENCED = (1 << 2), + WPNSTATE_ELITE_LEFT = (1 << 3), + WPNSTATE_FAMAS_BURST_MODE = (1 << 4), + WPNSTATE_SHIELD_DRAWN = (1 << 5), +}; + +// custom enum +// the default amount of ammo that comes with each gun when it spawns +enum ClipGiveDefault +{ + P228_DEFAULT_GIVE = 13, + GLOCK18_DEFAULT_GIVE = 20, + SCOUT_DEFAULT_GIVE = 10, + HEGRENADE_DEFAULT_GIVE = 1, + XM1014_DEFAULT_GIVE = 7, + C4_DEFAULT_GIVE = 1, + MAC10_DEFAULT_GIVE = 30, + AUG_DEFAULT_GIVE = 30, + SMOKEGRENADE_DEFAULT_GIVE = 1, + ELITE_DEFAULT_GIVE = 30, + FIVESEVEN_DEFAULT_GIVE = 20, + UMP45_DEFAULT_GIVE = 25, + SG550_DEFAULT_GIVE = 30, + GALIL_DEFAULT_GIVE = 35, + FAMAS_DEFAULT_GIVE = 25, + USP_DEFAULT_GIVE = 12, + AWP_DEFAULT_GIVE = 10, + MP5NAVY_DEFAULT_GIVE = 30, + M249_DEFAULT_GIVE = 100, + M3_DEFAULT_GIVE = 8, + M4A1_DEFAULT_GIVE = 30, + TMP_DEFAULT_GIVE = 30, + G3SG1_DEFAULT_GIVE = 20, + FLASHBANG_DEFAULT_GIVE = 1, + DEAGLE_DEFAULT_GIVE = 7, + SG552_DEFAULT_GIVE = 30, + AK47_DEFAULT_GIVE = 30, + /*KNIFE_DEFAULT_GIVE = 1,*/ + P90_DEFAULT_GIVE = 50, +}; + +enum ClipSizeType +{ + P228_MAX_CLIP = 13, + GLOCK18_MAX_CLIP = 20, + SCOUT_MAX_CLIP = 10, + XM1014_MAX_CLIP = 7, + MAC10_MAX_CLIP = 30, + AUG_MAX_CLIP = 30, + ELITE_MAX_CLIP = 30, + FIVESEVEN_MAX_CLIP = 20, + UMP45_MAX_CLIP = 25, + SG550_MAX_CLIP = 30, + GALIL_MAX_CLIP = 35, + FAMAS_MAX_CLIP = 25, + USP_MAX_CLIP = 12, + AWP_MAX_CLIP = 10, + MP5N_MAX_CLIP = 30, + M249_MAX_CLIP = 100, + M3_MAX_CLIP = 8, + M4A1_MAX_CLIP = 30, + TMP_MAX_CLIP = 30, + G3SG1_MAX_CLIP = 20, + DEAGLE_MAX_CLIP = 7, + SG552_MAX_CLIP = 30, + AK47_MAX_CLIP = 30, + P90_MAX_CLIP = 50, +}; + +enum WeightWeapon +{ + P228_WEIGHT = 5, + GLOCK18_WEIGHT = 5, + SCOUT_WEIGHT = 30, + HEGRENADE_WEIGHT = 2, + XM1014_WEIGHT = 20, + C4_WEIGHT = 3, + MAC10_WEIGHT = 25, + AUG_WEIGHT = 25, + SMOKEGRENADE_WEIGHT = 1, + ELITE_WEIGHT = 5, + FIVESEVEN_WEIGHT = 5, + UMP45_WEIGHT = 25, + SG550_WEIGHT = 20, + GALIL_WEIGHT = 25, + FAMAS_WEIGHT = 75, + USP_WEIGHT = 5, + AWP_WEIGHT = 30, + MP5NAVY_WEIGHT = 25, + M249_WEIGHT = 25, + M3_WEIGHT = 20, + M4A1_WEIGHT = 25, + TMP_WEIGHT = 25, + G3SG1_WEIGHT = 20, + FLASHBANG_WEIGHT = 1, + DEAGLE_WEIGHT = 7, + SG552_WEIGHT = 25, + AK47_WEIGHT = 25, + P90_WEIGHT = 26, + KNIFE_WEIGHT = 0, +}; + +enum MaxAmmoType +{ + MAX_AMMO_BUCKSHOT = 32, + MAX_AMMO_9MM = 120, + MAX_AMMO_556NATO = 90, + MAX_AMMO_556NATOBOX = 200, + MAX_AMMO_762NATO = 90, + MAX_AMMO_45ACP = 100, + MAX_AMMO_50AE = 35, + MAX_AMMO_338MAGNUM = 30, + MAX_AMMO_57MM = 100, + MAX_AMMO_357SIG = 52, + + // custom + MAX_AMMO_SMOKEGRENADE = 1, + MAX_AMMO_HEGRENADE = 1, + MAX_AMMO_FLASHBANG = 2, +}; + +enum AmmoType +{ + AMMO_NONE, + AMMO_338MAGNUM, + AMMO_762NATO, + AMMO_556NATOBOX, + AMMO_556NATO, + AMMO_BUCKSHOT, + AMMO_45ACP, + AMMO_57MM, + AMMO_50AE, + AMMO_357SIG, + AMMO_9MM, + AMMO_FLASHBANG, + AMMO_HEGRENADE, + AMMO_SMOKEGRENADE, + AMMO_C4, + + AMMO_MAX_TYPES +}; + +enum WeaponClassType +{ + WEAPONCLASS_NONE, + WEAPONCLASS_KNIFE, + WEAPONCLASS_PISTOL, + WEAPONCLASS_GRENADE, + WEAPONCLASS_SUBMACHINEGUN, + WEAPONCLASS_SHOTGUN, + WEAPONCLASS_MACHINEGUN, + WEAPONCLASS_RIFLE, + WEAPONCLASS_SNIPERRIFLE, + WEAPONCLASS_MAX, +}; + +enum AmmoBuyAmount +{ + AMMO_338MAG_BUY = 10, + AMMO_357SIG_BUY = 13, + AMMO_45ACP_BUY = 12, + AMMO_50AE_BUY = 7, + AMMO_556NATO_BUY = 30, + AMMO_556NATOBOX_BUY = 30, + AMMO_57MM_BUY = 50, + AMMO_762NATO_BUY = 30, + AMMO_9MM_BUY = 30, + AMMO_BUCKSHOT_BUY = 8, +}; + +enum ItemCostType +{ + ASSAULTSUIT_PRICE = 1000, + FLASHBANG_PRICE = 200, + HEGRENADE_PRICE = 300, + SMOKEGRENADE_PRICE = 300, + KEVLAR_PRICE = 650, + HELMET_PRICE = 350, + NVG_PRICE = 1250, + DEFUSEKIT_PRICE = 200, +}; + +enum shieldgun_e +{ + SHIELDGUN_IDLE, + SHIELDGUN_SHOOT1, + SHIELDGUN_SHOOT2, + SHIELDGUN_SHOOT_EMPTY, + SHIELDGUN_RELOAD, + SHIELDGUN_DRAW, + SHIELDGUN_DRAWN_IDLE, + SHIELDGUN_UP, + SHIELDGUN_DOWN, +}; + +// custom +enum shieldgren_e +{ + SHIELDREN_IDLE = 4, + SHIELDREN_UP, + SHIELDREN_DOWN +}; + +enum InventorySlotType +{ + NONE_SLOT, + PRIMARY_WEAPON_SLOT, + PISTOL_SLOT, + KNIFE_SLOT, + GRENADE_SLOT, + C4_SLOT, +}; + +enum Bullet +{ + BULLET_NONE, + BULLET_PLAYER_9MM, + BULLET_PLAYER_MP5, + BULLET_PLAYER_357, + BULLET_PLAYER_BUCKSHOT, + BULLET_PLAYER_CROWBAR, + BULLET_MONSTER_9MM, + BULLET_MONSTER_MP5, + BULLET_MONSTER_12MM, + BULLET_PLAYER_45ACP, + BULLET_PLAYER_338MAG, + BULLET_PLAYER_762MM, + BULLET_PLAYER_556MM, + BULLET_PLAYER_50AE, + BULLET_PLAYER_57MM, + BULLET_PLAYER_357SIG, +}; + +struct WeaponStruct +{ + int m_type; + int m_price; + int m_side; + int m_slot; + int m_ammoPrice; +}; + +struct AutoBuyInfoStruct +{ + AutoBuyClassType m_class; + char *m_command; + char *m_classname; +}; + +struct WeaponAliasInfo +{ + char *alias; + WeaponIdType id; +}; + +struct WeaponBuyAliasInfo +{ + char *alias; + WeaponIdType id; + char *failName; +}; + +struct WeaponClassAliasInfo +{ + char *alias; + WeaponClassType id; +}; + +struct WeaponInfoStruct +{ + int id; + int cost; + int clipCost; + int buyClipSize; + int gunClipSize; + int maxRounds; + int ammoType; + char *entityName; + const char *ammoName; +}; + +struct WeaponSlotInfo +{ + WeaponIdType id; + InventorySlotType slot; + const char *weaponName; +}; diff --git a/dlls/wpn_shared.h b/dlls/wpn_shared.h new file mode 100644 index 0000000..1ed2eea --- /dev/null +++ b/dlls/wpn_shared.h @@ -0,0 +1,598 @@ +#pragma once + +//AK47 +#define AK47_MAX_SPEED 221 +#define AK47_DAMAGE 36 +#define AK47_RANGE_MODIFER 0.98 +#define AK47_RELOAD_TIME 2.45 + +enum ak47_e +{ + AK47_IDLE1, + AK47_RELOAD, + AK47_DRAW, + AK47_SHOOT1, + AK47_SHOOT2, + AK47_SHOOT3 +}; + + + +//AUG +#define AUG_MAX_SPEED 240 +#define AUG_DAMAGE 32 +#define AUG_RANGE_MODIFER 0.96 +#define AUG_RELOAD_TIME 3.3 + +enum aug_e +{ + AUG_IDLE1, + AUG_RELOAD, + AUG_DRAW, + AUG_SHOOT1, + AUG_SHOOT2, + AUG_SHOOT3 +}; + + + +//AWP +#define AWP_MAX_SPEED 210 +#define AWP_MAX_SPEED_ZOOM 150 +#define AWP_DAMAGE 115 +#define AWP_RANGE_MODIFER 0.99 +#define AWP_RELOAD_TIME 2.5 + +enum awp_e +{ + AWP_IDLE, + AWP_SHOOT, + AWP_SHOOT2, + AWP_SHOOT3, + AWP_RELOAD, + AWP_DRAW, +}; + + + +//C4 +#define C4_MAX_AMMO 1 +#define C4_MAX_SPEED 250.0 +#define C4_ARMING_ON_TIME 3.0 + +enum c4_e +{ + C4_IDLE1, + C4_DRAW, + C4_DROP, + C4_ARM +}; + + + +//Deagle +#define DEAGLE_MAX_SPEED 250 +#define DEAGLE_DAMAGE 54 +#define DEAGLE_RANGE_MODIFER 0.81 +#define DEAGLE_RELOAD_TIME 2.2 + +enum deagle_e +{ + DEAGLE_IDLE1, + DEAGLE_SHOOT1, + DEAGLE_SHOOT2, + DEAGLE_SHOOT_EMPTY, + DEAGLE_RELOAD, + DEAGLE_DRAW +}; + + + +//Elites +#define ELITE_MAX_SPEED 250 +#define ELITE_RELOAD_TIME 4.5 +#define ELITE_DAMAGE 36 +#define ELITE_RANGE_MODIFER 0.75 + +enum elite_e +{ + ELITE_IDLE, + ELITE_IDLE_LEFTEMPTY, + ELITE_SHOOTLEFT1, + ELITE_SHOOTLEFT2, + ELITE_SHOOTLEFT3, + ELITE_SHOOTLEFT4, + ELITE_SHOOTLEFT5, + ELITE_SHOOTLEFTLAST, + ELITE_SHOOTRIGHT1, + ELITE_SHOOTRIGHT2, + ELITE_SHOOTRIGHT3, + ELITE_SHOOTRIGHT4, + ELITE_SHOOTRIGHT5, + ELITE_SHOOTRIGHTLAST, + ELITE_RELOAD, + ELITE_DRAW +}; + + + +//Famas +#define FAMAS_MAX_SPEED 240 +#define FAMAS_RELOAD_TIME 3.3 +#define FAMAS_DAMAGE 30 +#define FAMAS_DAMAGE_BURST 34 +#define FAMAS_RANGE_MODIFER 0.96 + +enum famas_e +{ + FAMAS_IDLE1, + FAMAS_RELOAD, + FAMAS_DRAW, + FAMAS_SHOOT1, + FAMAS_SHOOT2, + FAMAS_SHOOT3 +}; + + + +//Fiveseven +#define FIVESEVEN_MAX_SPEED 250 +#define FIVESEVEN_DAMAGE 20 +#define FIVESEVEN_RANGE_MODIFER 0.885 +#define FIVESEVEN_RELOAD_TIME 2.7 + +enum fiveseven_e +{ + FIVESEVEN_IDLE, + FIVESEVEN_SHOOT1, + FIVESEVEN_SHOOT2, + FIVESEVEN_SHOOT_EMPTY, + FIVESEVEN_RELOAD, + FIVESEVEN_DRAW +}; + + + +//Flashbang +#define FLASHBANG_MAX_SPEED 250 +#define FLASHBANG_MAX_SPEED_SHIELD 180 + +enum flashbang_e +{ + FLASHBANG_IDLE, + FLASHBANG_PULLPIN, + FLASHBANG_THROW, + FLASHBANG_DRAW +}; + + + +//g3sg1 +#define G3SG1_MAX_SPEED 210 +#define G3SG1_MAX_SPEED_ZOOM 150 +#define G3SG1_DAMAGE 80 +#define G3SG1_RANGE_MODIFER 0.98 +#define G3SG1_RELOAD_TIME 3.5 + +enum g3sg1_e +{ + G3SG1_IDLE, + G3SG1_SHOOT, + G3SG1_SHOOT2, + G3SG1_RELOAD, + G3SG1_DRAW +}; + + + +//galil +#define GALIL_MAX_SPEED 240 +#define GALIL_DAMAGE 30 +#define GALIL_RANGE_MODIFER 0.98 +#define GALIL_RELOAD_TIME 2.45 + +enum galil_e +{ + GALIL_IDLE1, + GALIL_RELOAD, + GALIL_DRAW, + GALIL_SHOOT1, + GALIL_SHOOT2, + GALIL_SHOOT3 +}; + + + +//glock18 +#define GLOCK18_MAX_SPEED 250 +#define GLOCK18_DAMAGE 25 +#define GLOCK18_RANGE_MODIFER 0.75 +#define GLOCK18_RELOAD_TIME 2.2 + +enum glock18_e +{ + GLOCK18_IDLE1, + GLOCK18_IDLE2, + GLOCK18_IDLE3, + GLOCK18_SHOOT, + GLOCK18_SHOOT2, + GLOCK18_SHOOT3, + GLOCK18_SHOOT_EMPTY, + GLOCK18_RELOAD, + GLOCK18_DRAW, + GLOCK18_HOLSTER, + GLOCK18_ADD_SILENCER, + GLOCK18_DRAW2, + GLOCK18_RELOAD2 +}; + +enum glock18_shield_e +{ + GLOCK18_SHIELD_IDLE1, + GLOCK18_SHIELD_SHOOT, + GLOCK18_SHIELD_SHOOT2, + GLOCK18_SHIELD_SHOOT_EMPTY, + GLOCK18_SHIELD_RELOAD, + GLOCK18_SHIELD_DRAW, + GLOCK18_SHIELD_IDLE, + GLOCK18_SHIELD_UP, + GLOCK18_SHIELD_DOWN +}; + + + +//hegrenade +#define HEGRENADE_MAX_SPEED 250 +#define HEGRENADE_MAX_SPEED_SHIELD 180 + +enum hegrenade_e +{ + HEGRENADE_IDLE, + HEGRENADE_PULLPIN, + HEGRENADE_THROW, + HEGRENADE_DRAW +}; + + + +//knife +#define KNIFE_BODYHIT_VOLUME 128 +#define KNIFE_WALLHIT_VOLUME 512 +#define KNIFE_MAX_SPEED 250 +#define KNIFE_MAX_SPEED_SHIELD 180 + +enum knife_e +{ + KNIFE_IDLE, + KNIFE_ATTACK1HIT, + KNIFE_ATTACK2HIT, + KNIFE_DRAW, + KNIFE_STABHIT, + KNIFE_STABMISS, + KNIFE_MIDATTACK1HIT, + KNIFE_MIDATTACK2HIT +}; + +enum knife_shield_e +{ + KNIFE_SHIELD_IDLE, + KNIFE_SHIELD_SLASH, + KNIFE_SHIELD_ATTACKHIT, + KNIFE_SHIELD_DRAW, + KNIFE_SHIELD_UPIDLE, + KNIFE_SHIELD_UP, + KNIFE_SHIELD_DOWN +}; + + + +//m3 +#define M3_MAX_SPEED 230 +#define M3_CONE_VECTOR Vector(0.0675, 0.0675, 0.0) // special shotgun spreads + +enum m3_e +{ + M3_IDLE, + M3_FIRE1, + M3_FIRE2, + M3_RELOAD, + M3_PUMP, + M3_START_RELOAD, + M3_DRAW, + M3_HOLSTER +}; + + + +//m4a1 +#define M4A1_MAX_SPEED 230 +#define M4A1_DAMAGE 32 +#define M4A1_DAMAGE_SIL 33 +#define M4A1_RANGE_MODIFER 0.97 +#define M4A1_RANGE_MODIFER_SIL 0.95 +#define M4A1_RELOAD_TIME 3.05 + +enum m4a1_e +{ + M4A1_IDLE, + M4A1_SHOOT1, + M4A1_SHOOT2, + M4A1_SHOOT3, + M4A1_RELOAD, + M4A1_DRAW, + M4A1_ATTACH_SILENCER, + M4A1_UNSIL_IDLE, + M4A1_UNSIL_SHOOT1, + M4A1_UNSIL_SHOOT2, + M4A1_UNSIL_SHOOT3, + M4A1_UNSIL_RELOAD, + M4A1_UNSIL_DRAW, + M4A1_DETACH_SILENCER +}; + + + +//m249 +#define M249_MAX_SPEED 220 +#define M249_DAMAGE 32 +#define M249_RANGE_MODIFER 0.97 +#define M249_RELOAD_TIME 4.7 + +enum m249_e +{ + M249_IDLE1, + M249_SHOOT1, + M249_SHOOT2, + M249_RELOAD, + M249_DRAW +}; + + + +//mac10 +#define MAC10_MAX_SPEED 250 +#define MAC10_DAMAGE 29 +#define MAC10_RANGE_MODIFER 0.82 +#define MAC10_RELOAD_TIME 3.15 + +enum mac10_e +{ + MAC10_IDLE1, + MAC10_RELOAD, + MAC10_DRAW, + MAC10_SHOOT1, + MAC10_SHOOT2, + MAC10_SHOOT3 +}; + + + +//mp5navy +#define MP5N_MAX_SPEED 250 +#define MP5N_DAMAGE 26 +#define MP5N_RANGE_MODIFER 0.84 +#define MP5N_RELOAD_TIME 2.63 + +enum mp5n_e +{ + MP5N_IDLE1, + MP5N_RELOAD, + MP5N_DRAW, + MP5N_SHOOT1, + MP5N_SHOOT2, + MP5N_SHOOT3 +}; + + + +//p90 +#define P90_MAX_SPEED 245 +#define P90_DAMAGE 21 +#define P90_RANGE_MODIFER 0.885 +#define P90_RELOAD_TIME 3.4 + +enum p90_e +{ + P90_IDLE1, + P90_RELOAD, + P90_DRAW, + P90_SHOOT1, + P90_SHOOT2, + P90_SHOOT3 +}; + + + +//p228 +#define P228_MAX_SPEED 250 +#define P228_DAMAGE 32 +#define P228_RANGE_MODIFER 0.8 +#define P228_RELOAD_TIME 2.7 + +enum p228_e +{ + P228_IDLE, + P228_SHOOT1, + P228_SHOOT2, + P228_SHOOT3, + P228_SHOOT_EMPTY, + P228_RELOAD, + P228_DRAW +}; + +enum p228_shield_e +{ + P228_SHIELD_IDLE, + P228_SHIELD_SHOOT1, + P228_SHIELD_SHOOT2, + P228_SHIELD_SHOOT_EMPTY, + P228_SHIELD_RELOAD, + P228_SHIELD_DRAW, + P228_SHIELD_IDLE_UP, + P228_SHIELD_UP, + P228_SHIELD_DOWN +}; + + + +//scout +#define SCOUT_MAX_SPEED 260 +#define SCOUT_MAX_SPEED_ZOOM 220 +#define SCOUT_DAMAGE 75 +#define SCOUT_RANGE_MODIFER 0.98 +#define SCOUT_RELOAD_TIME 2 + +enum scout_e +{ + SCOUT_IDLE, + SCOUT_SHOOT, + SCOUT_SHOOT2, + SCOUT_RELOAD, + SCOUT_DRAW +}; + + + +//sg550 +#define SG550_MAX_SPEED 210 +#define SG550_MAX_SPEED_ZOOM 150 +#define SG550_DAMAGE 70 +#define SG550_RANGE_MODIFER 0.98 +#define SG550_RELOAD_TIME 3.35 + +enum sg550_e +{ + SG550_IDLE, + SG550_SHOOT, + SG550_SHOOT2, + SG550_RELOAD, + SG550_DRAW +}; + + + +//sg552 +#define SG552_MAX_SPEED 235 +#define SG552_MAX_SPEED_ZOOM 200 +#define SG552_DAMAGE 33 +#define SG552_RANGE_MODIFER 0.955 +#define SG552_RELOAD_TIME 3 + +enum sg552_e +{ + SG552_IDLE1, + SG552_RELOAD, + SG552_DRAW, + SG552_SHOOT1, + SG552_SHOOT2, + SG552_SHOOT3 +}; + + + +//smokegrenade +#define SMOKEGRENADE_MAX_SPEED 250 +#define SMOKEGRENADE_MAX_SPEED_SHIELD 180 + +enum smokegrenade_e +{ + SMOKEGRENADE_IDLE, + SMOKEGRENADE_PINPULL, + SMOKEGRENADE_THROW, + SMOKEGRENADE_DRAW +}; + + + +//tmp +#define TMP_MAX_SPEED 250 +#define TMP_DAMAGE 20 +#define TMP_RANGE_MODIFER 0.85 +#define TMP_RELOAD_TIME 2.12 + +enum tmp_e +{ + TMP_IDLE1, + TMP_RELOAD, + TMP_DRAW, + TMP_SHOOT1, + TMP_SHOOT2, + TMP_SHOOT3 +}; + + + +//ump45 +#define UMP45_MAX_SPEED 250 +#define UMP45_DAMAGE 30 +#define UMP45_RANGE_MODIFER 0.82 +#define UMP45_RELOAD_TIME 3.5 + +enum ump45_e +{ + UMP45_IDLE1, + UMP45_RELOAD, + UMP45_DRAW, + UMP45_SHOOT1, + UMP45_SHOOT2, + UMP45_SHOOT3 +}; + + + +//tmp +#define USP_MAX_SPEED 250 +#define USP_DAMAGE 34 +#define USP_DAMAGE_SIL 30 +#define USP_RANGE_MODIFER 0.79 +#define USP_RELOAD_TIME 2.7 + +enum usp_e +{ + USP_IDLE, + USP_SHOOT1, + USP_SHOOT2, + USP_SHOOT3, + USP_SHOOT_EMPTY, + USP_RELOAD, + USP_DRAW, + USP_ATTACH_SILENCER, + USP_UNSIL_IDLE, + USP_UNSIL_SHOOT1, + USP_UNSIL_SHOOT2, + USP_UNSIL_SHOOT3, + USP_UNSIL_SHOOT_EMPTY, + USP_UNSIL_RELOAD, + USP_UNSIL_DRAW, + USP_DETACH_SILENCER +}; + +enum usp_shield_e +{ + USP_SHIELD_IDLE, + USP_SHIELD_SHOOT1, + USP_SHIELD_SHOOT2, + USP_SHIELD_SHOOT_EMPTY, + USP_SHIELD_RELOAD, + USP_SHIELD_DRAW, + USP_SHIELD_UP_IDLE, + USP_SHIELD_UP, + USP_SHIELD_DOWN +}; + + + +//xm1014 +#define XM1014_MAX_SPEED 240 +#define XM1014_CONE_VECTOR Vector(0.0725, 0.0725, 0.0) // special shotgun spreads + +enum xm1014_e +{ + XM1014_IDLE, + XM1014_FIRE1, + XM1014_FIRE2, + XM1014_RELOAD, + XM1014_PUMP, + XM1014_START_RELOAD, + XM1014_DRAW +}; diff --git a/engine/bspfile.h b/engine/bspfile.h index fd3ae92..b6d498c 100644 --- a/engine/bspfile.h +++ b/engine/bspfile.h @@ -27,46 +27,47 @@ */ #pragma once -#define BSPVERSION 30 +// header +#define Q1BSP_VERSION 29 // quake1 regular version (beta is 28) +#define HLBSP_VERSION 30 // half-life regular version + #define MAX_MAP_HULLS 4 #define CONTENTS_ORIGIN -7 // removed at csg time #define CONTENTS_CLIP -8 // changed to contents_solid -#define CONTENTS_CURRENT_0 -9 -#define CONTENTS_CURRENT_90 -10 +#define CONTENTS_CURRENT_0 -9 +#define CONTENTS_CURRENT_90 -10 #define CONTENTS_CURRENT_180 -11 #define CONTENTS_CURRENT_270 -12 -#define CONTENTS_CURRENT_UP -13 +#define CONTENTS_CURRENT_UP -13 #define CONTENTS_CURRENT_DOWN -14 #define CONTENTS_TRANSLUCENT -15 -#define LUMP_ENTITIES 0 +#define LUMP_ENTITIES 0 #define LUMP_PLANES 1 -#define LUMP_TEXTURES 2 -#define LUMP_VERTEXES 3 -#define LUMP_VISIBILITY 4 +#define LUMP_TEXTURES 2 +#define LUMP_VERTEXES 3 +#define LUMP_VISIBILITY 4 #define LUMP_NODES 5 -#define LUMP_TEXINFO 6 +#define LUMP_TEXINFO 6 #define LUMP_FACES 7 -#define LUMP_LIGHTING 8 -#define LUMP_CLIPNODES 9 +#define LUMP_LIGHTING 8 +#define LUMP_CLIPNODES 9 #define LUMP_LEAFS 10 -#define LUMP_MARKSURFACES 11 +#define LUMP_MARKSURFACES 11 #define LUMP_EDGES 12 -#define LUMP_SURFEDGES 13 +#define LUMP_SURFEDGES 13 #define LUMP_MODELS 14 -#define HEADER_LUMPS 15 +#define HEADER_LUMPS 15 -/* ../engine/bspfile.h:41 */ -typedef struct lump_s +typedef struct lump_s { int fileofs; int filelen; } lump_t; -/* ../engine/bspfile.h:64 */ typedef struct dmodel_s { float mins[3], maxs[3]; @@ -76,21 +77,18 @@ typedef struct dmodel_s int firstface, numfaces; } dmodel_t; -/* ../engine/bspfile.h:73 */ typedef struct dheader_s { int version; lump_t lumps[15]; } dheader_t; -/* <485b2> ../engine/bspfile.h:79 */ typedef struct dmiptexlump_s { int _nummiptex; int dataofs[4]; } dmiptexlump_t; -/* <1ce18> ../engine/bspfile.h:86 */ typedef struct miptex_s { char name[16]; @@ -99,13 +97,11 @@ typedef struct miptex_s unsigned offsets[4]; } miptex_t; -/* <48652> ../engine/bspfile.h:94 */ typedef struct dvertex_s { float point[3]; } dvertex_t; -/* <48674> ../engine/bspfile.h:110 */ typedef struct dplane_s { float normal[3]; @@ -113,7 +109,6 @@ typedef struct dplane_s int type; } dplane_t; -/* <486b2> ../engine/bspfile.h:132 */ typedef struct dnode_s { int planenum; @@ -124,14 +119,12 @@ typedef struct dnode_s unsigned short numfaces; } dnode_t; -/* ../engine/bspfile.h:142 */ typedef struct dclipnode_s { int planenum; short children[2]; // negative numbers are contents } dclipnode_t; -/* <4876a> ../engine/bspfile.h:149 */ typedef struct texinfo_s { float vecs[2][4]; @@ -139,13 +132,11 @@ typedef struct texinfo_s int flags; } texinfo_t; -/* <487c2> ../engine/bspfile.h:159 */ typedef struct dedge_s { unsigned short v[2]; } dedge_t; -/* <487f2> ../engine/bspfile.h:165 */ typedef struct dface_s { short planenum; diff --git a/engine/cmd_rehlds.h b/engine/cmd_rehlds.h index fe3b701..efa8393 100644 --- a/engine/cmd_rehlds.h +++ b/engine/cmd_rehlds.h @@ -29,10 +29,7 @@ #include "archtypes.h" -/* <8f1> ../engine/cmd.h:65 */ typedef void(*xcommand_t)(void); - -/* <904> ../engine/cmd.h:71 */ typedef struct cmd_function_s { struct cmd_function_s *next; @@ -41,7 +38,6 @@ typedef struct cmd_function_s int flags; } cmd_function_t; -/* <95a> ../engine/cmd.h:80 */ typedef enum cmd_source_s { src_client = 0, // came in over a net connection as a clc_stringcmd. host_client will be valid during this state. diff --git a/engine/common_rehlds.h b/engine/common_rehlds.h index c7c4ed7..64a5d18 100644 --- a/engine/common_rehlds.h +++ b/engine/common_rehlds.h @@ -47,7 +47,6 @@ #define COM_COPY_CHUNK_SIZE 1024 #define COM_MAX_CMD_LINE 256 -/* <6ae> ../common/common.h:82 */ typedef struct sizebuf_s { const char *buffername; @@ -57,7 +56,6 @@ typedef struct sizebuf_s int cursize; } sizebuf_t; -/* <270aa> ../common/common.h:297 */ typedef struct downloadtime_s { qboolean bUsed; @@ -65,7 +63,6 @@ typedef struct downloadtime_s int nBytesRemaining; } downloadtime_t; -/* <19fa2> ../common/common.h:303 */ typedef struct incomingtransfer_s { qboolean doneregistering; diff --git a/engine/d_local.h b/engine/d_local.h index 8bf396d..c2d2f59 100644 --- a/engine/d_local.h +++ b/engine/d_local.h @@ -28,19 +28,16 @@ #pragma once - - -/* <82286> ../engine/d_local.h:20 */ typedef struct surfcache_s { struct surfcache_s *next; struct surfcache_s **owner; - int lightadj[4]; - int dlight; - int size; - unsigned width; - unsigned height; - float mipscale; + int lightadj[4]; + int dlight; + int size; + unsigned width; + unsigned height; + float mipscale; struct texture_s *texture; - unsigned char data[4]; + unsigned char data[4]; } surfcache_t; diff --git a/engine/eiface.h b/engine/eiface.h index c4e7937..e377975 100644 --- a/engine/eiface.h +++ b/engine/eiface.h @@ -299,7 +299,7 @@ typedef struct enginefuncs_s void(*pfnQueryClientCvarValue2) (const edict_t *player, const char *cvarName, int requestID); // Added 2009/06/19 (no SDK update): - //int(*pfnEngCheckParm) (const char *pchCmdLineToken, char **ppnext); + int(*pfnEngCheckParm) (const char *pchCmdLineToken, char **ppnext); } enginefuncs_t; diff --git a/engine/hookchains.h b/engine/hookchains.h index 599c4c7..197b8a3 100644 --- a/engine/hookchains.h +++ b/engine/hookchains.h @@ -48,13 +48,24 @@ public: virtual void callOriginal(t_args... args) = 0; }; +// Specifies priorities for hooks call order in the chain. +// For equal priorities first registered hook will be called first. +enum HookChainPriority +{ + HC_PRIORITY_UNINTERRUPTABLE = 255, // Hook will be called before other hooks. + HC_PRIORITY_HIGH = 192, // Hook will be called before hooks with default priority. + HC_PRIORITY_DEFAULT = 128, // Default hook call priority. + HC_PRIORITY_MEDIUM = 64, // Hook will be called after hooks with default priority. + HC_PRIORITY_LOW = 0, // Hook will be called after all other hooks. +}; + // Hook chain registry(for hooks [un]registration) template class IHookChainRegistry { public: typedef t_ret(*hookfunc_t)(IHookChain*, t_args...); - virtual void registerHook(hookfunc_t hook) = 0; + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; virtual void unregisterHook(hookfunc_t hook) = 0; }; @@ -64,6 +75,6 @@ class IVoidHookChainRegistry { public: typedef void(*hookfunc_t)(IVoidHookChain*, t_args...); - virtual void registerHook(hookfunc_t hook) = 0; + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; virtual void unregisterHook(hookfunc_t hook) = 0; }; diff --git a/engine/model.h b/engine/model.h index 2c155d5..ba5d638 100644 --- a/engine/model.h +++ b/engine/model.h @@ -33,14 +33,21 @@ #include "bspfile.h" #include "crc.h" #include "com_model.h" +#include "commonmacros.h" -#define SURF_PLANEBACK 2 -#define SURF_DRAWSKY 4 +// header +#define ALIAS_MODEL_VERSION 0x006 +#define IDPOLYHEADER MAKEID('I', 'D', 'P', 'O') // little-endian "IDPO" + +#define MAX_LBM_HEIGHT 480 +#define MAX_ALIAS_MODEL_VERTS 2000 + +#define SURF_PLANEBACK 2 +#define SURF_DRAWSKY 4 #define SURF_DRAWSPRITE 8 #define SURF_DRAWTURB 0x10 #define SURF_DRAWTILED 0x20 -#define SURF_DRAWBACKGROUND 0x40 -#define ALIAS_MODEL_VERSION 0x006 +#define SURF_DRAWBACKGROUND 0x40 #define MAX_MODEL_NAME 64 #define MIPLEVELS 4 @@ -48,13 +55,11 @@ #define MAXLIGHTMAPS 4 #define MAX_KNOWN_MODELS 1024 -/* <6816> ../engine/model.h:27 */ typedef struct mvertex_s { vec3_t position; } mvertex_t; -/* <6838> ../engine/model.h:39 */ typedef struct mplane_s { vec3_t normal; // surface normal @@ -64,30 +69,39 @@ typedef struct mplane_s byte pad[2]; } mplane_t; -/* <68a6> ../engine/model.h:48 */ typedef struct texture_s { char name[16]; unsigned width, height; + +#ifndef SWDS + int gl_texturenum; + struct msurface_s * texturechain; +#endif + int anim_total; // total tenths in sequence ( 0 = no) int anim_min, anim_max; // time for this frame min <=time< max struct texture_s *anim_next; // in the animation sequence struct texture_s *alternate_anims; // bmodels in frame 1 use these unsigned offsets[MIPLEVELS]; // four mip maps stored + +#ifdef SWDS unsigned paloffset; +#else + byte *pPal; +#endif + } texture_t; -/* <6950> ../engine/model.h:71 */ typedef struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } medge_t; -/* <697e> ../engine/model.h:78 */ typedef struct mtexinfo_s { - float vecs[2][4]; // [s/t] unit vectors in world space. + float vecs[2][4]; // [s/t] unit vectors in world space. // [i][3] is the s/t offset relative to the origin. // s or t = dot(3Dpoint,vecs[i])+vecs[i][3] float mipadjust; // ?? mipmap limits for very small surfaces @@ -96,13 +110,10 @@ typedef struct mtexinfo_s } mtexinfo_t; #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision -/* <69d0> ../engine/model.h:91 */ typedef struct msurface_s msurface_t; -/* <1db66> ../engine/model.h:92 */ typedef struct decal_s decal_t; // JAY: Compress this as much as possible -/* <1db71> ../engine/model.h:96 */ struct decal_s { decal_t *pnext; // linked list for each surface @@ -116,7 +127,6 @@ struct decal_s short entityIndex; // Entity this is attached to }; -/* <69db> ../engine/model.h:118 */ struct msurface_s { int visframe; // should be drawn when node is crossed @@ -148,7 +158,6 @@ struct msurface_s decal_t *pdecals; }; -/* <6b6c> ../engine/model.h:149 */ typedef struct mnode_s { // common with leaf @@ -167,7 +176,6 @@ typedef struct mnode_s unsigned short numsurfaces; } mnode_t; -/* <1dcd4> ../engine/model.h:169 */ typedef struct mleaf_s { // common with node @@ -188,7 +196,6 @@ typedef struct mleaf_s byte ambient_sound_level[NUM_AMBIENTS]; } mleaf_t; -/* <1ddbe> ../engine/model.h:190 */ typedef struct hull_s { dclipnode_t *clipnodes; @@ -198,7 +205,6 @@ typedef struct hull_s vec3_t clip_mins, clip_maxs; } hull_t; -/* <4b3fe> ../engine/model.h:210 */ typedef struct mspriteframe_t { int width; @@ -208,7 +214,6 @@ typedef struct mspriteframe_t byte pixels[4]; } mspriteframe_s; -/* <4b485> ../engine/model.h:219 */ typedef struct mspritegroup_s { int numframes; @@ -216,14 +221,12 @@ typedef struct mspritegroup_s mspriteframe_t *frames[1]; } mspritegroup_t; -/* <4b4df> ../engine/model.h:226 */ typedef struct mspriteframedesc_s { spriteframetype_t type; mspriteframe_t *frameptr; } mspriteframedesc_t; -/* <4b50f> ../engine/model.h:232 */ typedef struct msprite_s { short int type; @@ -236,7 +239,6 @@ typedef struct msprite_s mspriteframedesc_t frames[1]; } msprite_t; -/* <4b5b5> ../engine/model.h:255 */ typedef struct maliasframedesc_s { aliasframetype_t type; @@ -245,7 +247,6 @@ typedef struct maliasframedesc_s char name[16]; } maliasframedesc_t; -/* <4b615> ../engine/model.h:264 */ typedef struct maliasskindesc_s { aliasskintype_t type; @@ -253,14 +254,12 @@ typedef struct maliasskindesc_s int skin; } maliasskindesc_t; -/* <4b658> ../engine/model.h:271 */ typedef struct maliasgroupframedesc_s { trivertx_t bboxmin, bboxmax; int frame; } maliasgroupframedesc_t; -/* <4b69b> ../engine/model.h:278 */ typedef struct maliasgroup_s { int numframes; @@ -268,7 +267,6 @@ typedef struct maliasgroup_s maliasgroupframedesc_t frames[1]; } maliasgroup_t; -/* <4b6ee> ../engine/model.h:285 */ typedef struct maliasskingroup_s { int numskins; @@ -276,14 +274,12 @@ typedef struct maliasskingroup_s maliasskindesc_t skindescs[1]; } maliasskingroup_t; -/* <4b741> ../engine/model.h:293 */ typedef struct mtriangle_s { int facesfront; int vertindex[3]; } mtriangle_t; -/* <4b779> ../engine/model.h:298 */ typedef struct aliashdr_s { int model; @@ -294,23 +290,21 @@ typedef struct aliashdr_s maliasframedesc_t frames[1]; } aliashdr_t; -/* <1de30> ../engine/model.h:315 */ typedef enum modtype_e { + mod_bad = -1, mod_brush, mod_sprite, mod_alias, mod_studio, } modtype_t; -/* <1de5e> ../engine/model.h:331 */ typedef struct model_s { char name[MAX_MODEL_NAME]; - //TODO: qboolean? seriously? int needload; // bmodels and sprites don't cache normally - + modtype_t type; int numframes; synctype_t synctype; diff --git a/engine/modelgen.h b/engine/modelgen.h index 3d90bdd..48fd9b8 100644 --- a/engine/modelgen.h +++ b/engine/modelgen.h @@ -32,30 +32,24 @@ #pragma once #endif - -/* <67f6> ../engine/modelgen.h:37 */ typedef enum synctype_e { ST_SYNC = 0, ST_RAND = 1, } synctype_t; -/* <4abae> ../engine/modelgen.h:40 */ typedef enum aliasframetype_s { ALIAS_SINGLE = 0, ALIAS_GROUP = 1, } aliasframetype_t; -/* 203 */ -/* <4abce> ../engine/modelgen.h:42 */ typedef enum aliasskintype_s { ALIAS_SKIN_SINGLE = 0, ALIAS_SKIN_GROUP = 1, } aliasskintype_t; -/* <4abee> ../engine/modelgen.h:44 */ typedef struct mdl_s { int ident; @@ -75,7 +69,6 @@ typedef struct mdl_s float size; } mdl_t; -/* <4acd4> ../engine/modelgen.h:64 */ typedef struct stvert_s { int onseam; @@ -83,59 +76,50 @@ typedef struct stvert_s int t; } stvert_t; -/* <4ad0e> ../engine/modelgen.h:70 */ typedef struct dtriangle_s { int facesfront; int vertindex[3]; } dtriangle_t; -/* <4ad42> ../engine/modelgen.h:80 */ typedef struct trivertx_s { byte v[3]; byte lightnormalindex; } trivertx_t; -/* <4ad80> ../engine/modelgen.h:85 */ typedef struct daliasframe_s { trivertx_t bboxmin, bboxmax; char name[16]; } daliasframe_t; -/* <4adbe> ../engine/modelgen.h:91 */ typedef struct daliasgroup_s { int numframes; trivertx_t bboxmin, bboxmax; } daliasgroup_t; -/* <4adfc> ../engine/modelgen.h:97 */ typedef struct daliasskingroup_s { int numskins; } daliasskingroup_t; -/* <4ae1e> ../engine/modelgen.h:101 */ typedef struct daliasinterval_s { float interval; } daliasinterval_t; -/* <4ae40> ../engine/modelgen.h:105 */ typedef struct daliasskininterval_s { float interval; } daliasskininterval_t; -/* <4ae62> ../engine/modelgen.h:109 */ typedef struct daliasframetype_s { aliasframetype_t type; } daliasframetype_t; -/* <4ae84> ../engine/modelgen.h:113 */ typedef struct daliasskintype_s { aliasskintype_t type; diff --git a/engine/osconfig.h b/engine/osconfig.h index bb45a62..2e43293 100644 --- a/engine/osconfig.h +++ b/engine/osconfig.h @@ -189,6 +189,4 @@ #define EXT_FUNC FORCE_STACK_ALIGN -extern void __declspec(noreturn) rehlds_syserror(const char* fmt, ...); - #endif // _OSCONFIG_H diff --git a/engine/rehlds_api.h b/engine/rehlds_api.h index 0e3ada2..2f4a115 100644 --- a/engine/rehlds_api.h +++ b/engine/rehlds_api.h @@ -34,8 +34,8 @@ #include "interface.h" #include "model.h" -#define REHLDS_API_VERSION_MAJOR 2 -#define REHLDS_API_VERSION_MINOR 12 +#define REHLDS_API_VERSION_MAJOR 3 +#define REHLDS_API_VERSION_MINOR 0 //Steam_NotifyClientConnect hook typedef IHookChain IRehldsHook_Steam_NotifyClientConnect; @@ -122,8 +122,8 @@ typedef IVoidHookChain I typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EmitEvents; //EV_PlayReliableEvent hook -typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; -typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; +typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; +typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; //SV_StartSound hook typedef IVoidHookChain IRehldsHook_SV_StartSound; @@ -257,7 +257,7 @@ struct RehldsFuncs_t { cmd_source_t*(*GetCmdSource)(); void(*Log)(const char* prefix, const char* msg); DLL_FUNCTIONS *(*GetEntityInterface)(); - void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, short unsigned int eventindex, float delay, struct event_args_s *pargs); + void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, unsigned short eventindex, float delay, struct event_args_s *pargs); int(*SV_LookupSoundIndex)(const char *sample); void(*MSG_StartBitWriting)(sizebuf_t *buf); void(*MSG_WriteBits)(uint32 data, int numbits); @@ -280,6 +280,8 @@ struct RehldsFuncs_t { void(*Steam_NotifyClientDisconnect)(IGameClient* cl); void(*SV_StartSound)(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int flags, int pitch); bool(*SV_EmitSound2)(edict_t *entity, IGameClient *receiver, int channel, const char *sample, float volume, float attenuation, int flags, int pitch, int emitFlags, const float *pOrigin); + void(*SV_UpdateUserInfo)(IGameClient *pGameClient); + bool(*StripUnprintableAndSpace)(char *pch); }; class IRehldsApi { @@ -295,4 +297,4 @@ public: virtual IRehldsFlightRecorder* GetFlightRecorder() = 0; }; -#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" +#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" \ No newline at end of file diff --git a/engine/spritegn.h b/engine/spritegn.h index 96d8b03..f6145d7 100644 --- a/engine/spritegn.h +++ b/engine/spritegn.h @@ -33,11 +33,10 @@ #endif #include "modelgen.h" +#include "commonmacros.h" - -#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I') -#define SPRITE_VERSION 2 - +#define SPRITE_VERSION 2 // Half-Life sprites +#define IDSPRITEHEADER MAKEID('I', 'D', 'S', 'P') // little-endian "IDSP" typedef enum spriteframetype_e { @@ -46,7 +45,6 @@ typedef enum spriteframetype_e SPR_ANGLED } spriteframetype_t; -/* <4aea6> ../engine/spritegn.h:50 */ typedef struct dsprite_s { int ident; @@ -61,7 +59,6 @@ typedef struct dsprite_s synctype_t synctype; } dsprite_t; -/* <4af46> ../engine/spritegn.h:74 */ typedef struct dspriteframe_s { int origin[2]; @@ -69,19 +66,16 @@ typedef struct dspriteframe_s int height; } dspriteframe_t; -/* <4af84> ../engine/spritegn.h:80 */ typedef struct dspritegroup_s { int numframes; } dspritegroup_t; -/* <4afa6> ../engine/spritegn.h:84 */ typedef struct dspriteinterval_s { float interval; } dspriteinterval_t; -/* <4afe8> ../engine/spritegn.h:90 */ typedef struct dspriteframetype_s { spriteframetype_t type; diff --git a/engine/static_map.h b/engine/static_map.h index 593cc39..7138aff 100644 --- a/engine/static_map.h +++ b/engine/static_map.h @@ -44,7 +44,7 @@ private: // this was a root node unsigned int rootId = GetRoodNodeId(node->key); if (m_RootNodes[rootId] != node) { - util_syserror("%s: invlid root node", __FUNCTION__); + Sys_Error(__FUNCTION__ ": invalid root node"); return; } diff --git a/engine/studio.h b/engine/studio.h index 1da691e..412543e 100644 --- a/engine/studio.h +++ b/engine/studio.h @@ -310,10 +310,13 @@ typedef struct } mstudiotrivert_t; #endif +#define STUDIO_DYNAMIC_LIGHT 0x0100 // dynamically get lighting from floor or ceil (flying monsters) +#define STUDIO_TRACE_HITBOX 0x0200 // always use hitbox trace instead of bbox + // lighting options #define STUDIO_NF_FLATSHADE 0x0001 #define STUDIO_NF_CHROME 0x0002 -#define STUDIO_NF_FULLBRIGHT 0x0004 +#define STUDIO_NF_FULLBRIGHT 0x0004 #define STUDIO_NF_NOMIPS 0x0008 #define STUDIO_NF_ALPHA 0x0010 #define STUDIO_NF_ADDITIVE 0x0020 @@ -321,7 +324,7 @@ typedef struct // motion flags #define STUDIO_X 0x0001 -#define STUDIO_Y 0x0002 +#define STUDIO_Y 0x0002 #define STUDIO_Z 0x0004 #define STUDIO_XR 0x0008 #define STUDIO_YR 0x0010 diff --git a/engine/userid_rehlds.h b/engine/userid_rehlds.h index ff73c5d..53b76f4 100644 --- a/engine/userid_rehlds.h +++ b/engine/userid_rehlds.h @@ -38,7 +38,6 @@ enum AUTH_IDTYPE AUTH_IDTYPE_LOCAL = 3 }; -/* <2e915> ../engine/userid.h:22 */ typedef struct USERID_s { int idtype; diff --git a/metamod/sdk_util.h b/metamod/sdk_util.h index 5b70010..76631d3 100644 --- a/metamod/sdk_util.h +++ b/metamod/sdk_util.h @@ -52,16 +52,6 @@ #include - -// Add overloaded ENTINDEX() version for const edict_t pointer. -// The pfnIndexOfEdict() function takes a const edict_t pointer -// as parameter anyway, so there is no reason why ENTINDEX() -// shouldn't. -inline int ENTINDEX(const edict_t *pEdict) { - return (*g_engfuncs.pfnIndexOfEdict)(pEdict); -} - - // Also, create some nice inlines for engine callback combos. // Get a setinfo value from a player entity. diff --git a/msvc/rechecker.vcxproj b/msvc/rechecker.vcxproj index ded7358..8e64b5b 100644 --- a/msvc/rechecker.vcxproj +++ b/msvc/rechecker.vcxproj @@ -178,7 +178,9 @@ true true - + + Use + diff --git a/public/asmlib.h b/public/asmlib.h new file mode 100644 index 0000000..c1bc9af --- /dev/null +++ b/public/asmlib.h @@ -0,0 +1,123 @@ +/*************************** asmlib.h *************************************** +* Author: Agner Fog +* Date created: 2003-12-12 +* Last modified: 2013-10-04 +* Project: asmlib.zip +* Source URL: www.agner.org/optimize +* +* Description: +* Header file for the asmlib function library. +* This library is available in many versions for different platforms. +* See asmlib-instructions.pdf for details. +* +* (c) Copyright 2003 - 2013 by Agner Fog. +* GNU General Public License http://www.gnu.org/licenses/gpl.html +*****************************************************************************/ + + +#ifndef ASMLIB_H +#define ASMLIB_H + + +/*********************************************************************** +Define compiler-specific types and directives +***********************************************************************/ + +// Define type size_t +#ifndef _SIZE_T_DEFINED +#include "stddef.h" +#endif + +// Define integer types with known size: int32_t, uint32_t, int64_t, uint64_t. +// If this doesn't work then insert compiler-specific definitions here: +#if defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1600) + // Compilers supporting C99 or C++0x have stdint.h defining these integer types + #include + #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers +#elif defined(_MSC_VER) + // Older Microsoft compilers have their own definition + typedef signed __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef signed __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef signed __int64 int64_t; + typedef unsigned __int64 uint64_t; + #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers +#else + // This works with most compilers + typedef signed short int int16_t; + typedef unsigned short int uint16_t; + typedef signed int int32_t; + typedef unsigned int uint32_t; + typedef long long int64_t; + typedef unsigned long long uint64_t; + #define INT64_SUPPORTED // Remove this if the compiler doesn't support 64-bit integers +#endif + + +// Turn off name mangling +#ifdef __cplusplus +extern "C" { +#endif + +/*********************************************************************** +Function prototypes, memory and string functions +***********************************************************************/ +void * A_memcpy (void * dest, const void * src, size_t count); // Copy count bytes from src to dest +void * A_memmove(void * dest, const void * src, size_t count); // Same as memcpy, allows overlap between src and dest +void * A_memset (void * dest, int c, size_t count); // Set count bytes in dest to (char)c +int A_memcmp (const void * buf1, const void * buf2, size_t num); // Compares two blocks of memory +size_t GetMemcpyCacheLimit(void); // Data blocks bigger than this will be copied uncached by memcpy and memmove +void SetMemcpyCacheLimit(size_t); // Change limit in GetMemcpyCacheLimit +size_t GetMemsetCacheLimit(void); // Data blocks bigger than this will be stored uncached by memset +void SetMemsetCacheLimit(size_t); // Change limit in GetMemsetCacheLimit +char * A_strcat (char * dest, const char * src); // Concatenate strings dest and src. Store result in dest +char * A_strcpy (char * dest, const char * src); // Copy string src to dest +size_t A_strlen (const char * str); // Get length of zero-terminated string +int A_strcmp (const char * a, const char * b); // Compare strings. Case sensitive +int A_stricmp (const char *string1, const char *string2); // Compare strings. Case insensitive for A-Z only +char * A_strstr (char * haystack, const char * needle); // Search for substring in string +void A_strtolower(char * string); // Convert string to lower case for A-Z only +void A_strtoupper(char * string); // Convert string to upper case for a-z only +size_t A_substring(char * dest, const char * source, size_t pos, size_t len); // Copy a substring for source into dest +size_t A_strspn (const char * str, const char * set); // Find span of characters that belong to set +size_t A_strcspn(const char * str, const char * set); // Find span of characters that don't belong to set +size_t strCountInSet(const char * str, const char * set); // Count characters that belong to set +size_t strcount_UTF8(const char * str); // Counts the number of characters in a UTF-8 encoded string + + +/*********************************************************************** +Function prototypes, miscellaneous functions +***********************************************************************/ +uint32_t A_popcount(uint32_t x); // Count 1-bits in 32-bit integer +int RoundD (double x); // Round to nearest or even +int RoundF (float x); // Round to nearest or even +int InstructionSet(void); // Tell which instruction set is supported +char * ProcessorName(void); // ASCIIZ text describing microprocessor +void CpuType(int * vendor, int * family, int * model); // Get CPU vendor, family and model +size_t DataCacheSize(int level); // Get size of data cache +void A_DebugBreak(void); // Makes a debug breakpoint +#ifdef INT64_SUPPORTED + uint64_t ReadTSC(void); // Read microprocessor internal clock (64 bits) +#else + uint32_t ReadTSC(void); // Read microprocessor internal clock (only 32 bits supported by compiler) +#endif +void cpuid_ex (int abcd[4], int eax, int ecx); // call CPUID instruction +static inline void cpuid_abcd (int abcd[4], int eax) { + cpuid_ex(abcd, eax, 0);} + +#ifdef __cplusplus +} // end of extern "C" + +// Define overloaded versions if compiling as C++ + +static inline int Round (double x) { // Overload name Round + return RoundD(x);} +static inline int Round (float x) { // Overload name Round + return RoundF(x);} +static inline const char * A_strstr(const char * haystack, const char * needle) { + return A_strstr((char*)haystack, needle);} // Overload A_strstr with const char * version + +#endif // __cplusplus + +#endif // ASMLIB_H diff --git a/public/basetypes.h b/public/basetypes.h new file mode 100644 index 0000000..a953ffe --- /dev/null +++ b/public/basetypes.h @@ -0,0 +1,287 @@ +//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef BASETYPES_H +#define BASETYPES_H +#ifdef _WIN32 +#pragma once +#endif + +#include "osconfig.h" +#include "protected_things.h" +#include "commonmacros.h" + + +// For backward compatibilty only... +#include "tier0/platform.h" + +// stdio.h +#ifndef NULL +#define NULL 0 +#endif + + +#define ExecuteNTimes( nTimes, x ) \ + { \ + static int __executeCount=0;\ + if ( __executeCount < nTimes )\ + { \ + x; \ + ++__executeCount; \ + } \ + } + + +#define ExecuteOnce( x ) ExecuteNTimes( 1, x ) + + +// Pad a number so it lies on an N byte boundary. +// So PAD_NUMBER(0,4) is 0 and PAD_NUMBER(1,4) is 4 +#define PAD_NUMBER(number, boundary) \ + ( ((number) + ((boundary)-1)) / (boundary) ) * (boundary) + +#ifndef MATHLIB_H +// In case this ever changes +#define M_PI 3.14159265358979323846 + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#endif // MATHLIB_H + +#ifndef FALSE +#define FALSE 0 +#define TRUE (!FALSE) +#endif + + +typedef int BOOL; +typedef int qboolean; +typedef unsigned long ULONG; +typedef unsigned char BYTE; +typedef unsigned char byte; +typedef unsigned short word; + +typedef float vec_t; + + +// FIXME: this should move +#ifndef __cplusplus +#define true TRUE +#define false FALSE +#endif + +//----------------------------------------------------------------------------- +// look for NANs, infinities, and underflows. +// This assumes the ANSI/IEEE 754-1985 standard +//----------------------------------------------------------------------------- + +#ifdef __cplusplus + +inline unsigned long& FloatBits(vec_t& f) +{ + return *reinterpret_cast(&f); +} + +inline unsigned long const& FloatBits(vec_t const& f) +{ + return *reinterpret_cast(&f); +} + +inline vec_t BitsToFloat(unsigned long i) +{ + return *reinterpret_cast(&i); +} + +inline bool IsFinite(vec_t f) +{ + return ((FloatBits(f) & 0x7F800000) != 0x7F800000); +} + +inline unsigned long FloatAbsBits(vec_t f) +{ + return FloatBits(f) & 0x7FFFFFFF; +} + +inline float FloatMakeNegative(vec_t f) +{ + return BitsToFloat(FloatBits(f) | 0x80000000); +} + +#if defined( WIN32 ) + +//#include +// Just use prototype from math.h +#ifdef __cplusplus +extern "C" +{ +#endif + double __cdecl fabs(double); +#ifdef __cplusplus +} +#endif + +// In win32 try to use the intrinsic fabs so the optimizer can do it's thing inline in the code +#pragma intrinsic( fabs ) +// Also, alias float make positive to use fabs, too +// NOTE: Is there a perf issue with double<->float conversion? +inline float FloatMakePositive(vec_t f) +{ + return fabs(f); +} +#else +inline float FloatMakePositive(vec_t f) +{ + return BitsToFloat(FloatBits(f) & 0x7FFFFFFF); +} +#endif + +inline float FloatNegate(vec_t f) +{ + return BitsToFloat(FloatBits(f) ^ 0x80000000); +} + + +#define FLOAT32_NAN_BITS (unsigned long)0x7FC00000 // not a number! +#define FLOAT32_NAN BitsToFloat( FLOAT32_NAN_BITS ) + +#define VEC_T_NAN FLOAT32_NAN + +#endif + +// FIXME: why are these here? Hardly anyone actually needs them. +struct valve_color24 +{ + byte r, g, b; +}; + +typedef struct valve_color32_s +{ + bool operator!=(const struct valve_color32_s &other) const; + + byte r, g, b, a; +} valve_color32; + +inline bool valve_color32::operator!=(const valve_color32 &other) const +{ + return r != other.r || g != other.g || b != other.b || a != other.a; +} + +struct valve_colorRGBExp32 +{ + byte r, g, b; + signed char exponent; +}; + +struct valve_colorVec +{ + unsigned r, g, b, a; +}; + + +#ifndef UNUSED +#define UNUSED(x) (x = x) // for pesky compiler / lint warnings +#endif + +#ifdef __cplusplus + +struct vrect_t +{ + int x, y, width, height; + vrect_t *pnext; +}; + +#endif + + +//----------------------------------------------------------------------------- +// MaterialRect_t struct - used for DrawDebugText +//----------------------------------------------------------------------------- +struct Rect_t +{ + int x, y; + int width, height; +}; + + +//----------------------------------------------------------------------------- +// Declares a type-safe handle type; you can't assign one handle to the next +//----------------------------------------------------------------------------- + +// 32-bit pointer handles. + +// Typesafe 8-bit and 16-bit handles. +template< class HandleType > +class CBaseIntHandle +{ +public: + + inline bool operator==(const CBaseIntHandle &other) { return m_Handle == other.m_Handle; } + inline bool operator!=(const CBaseIntHandle &other) { return m_Handle != other.m_Handle; } + + // Only the code that doles out these handles should use these functions. + // Everyone else should treat them as a transparent type. + inline HandleType GetHandleValue() { return m_Handle; } + inline void SetHandleValue(HandleType val) { m_Handle = val; } + + typedef HandleType HANDLE_TYPE; + +protected: + + HandleType m_Handle; +}; + +template< class DummyType > +class CIntHandle16 : public CBaseIntHandle < unsigned short > +{ +public: + inline CIntHandle16() {} + + static inline CIntHandle16 MakeHandle(HANDLE_TYPE val) + { + return CIntHandle16(val); + } + +protected: + inline CIntHandle16(HANDLE_TYPE val) + { + m_Handle = val; + } +}; + + +template< class DummyType > +class CIntHandle32 : public CBaseIntHandle < unsigned long > +{ +public: + inline CIntHandle32() {} + + static inline CIntHandle32 MakeHandle(HANDLE_TYPE val) + { + return CIntHandle32(val); + } + +protected: + inline CIntHandle32(HANDLE_TYPE val) + { + m_Handle = val; + } +}; + + +// NOTE: This macro is the same as windows uses; so don't change the guts of it +#define DECLARE_HANDLE_16BIT(name) typedef CIntHandle16< struct name##__handle * > name; +#define DECLARE_HANDLE_32BIT(name) typedef CIntHandle32< struct name##__handle * > name; + +#define DECLARE_POINTER_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name +#define FORWARD_DECLARE_HANDLE(name) typedef struct name##__ *name + +#endif // BASETYPES_H diff --git a/public/commonmacros.h b/public/commonmacros.h new file mode 100644 index 0000000..e82bfd6 --- /dev/null +++ b/public/commonmacros.h @@ -0,0 +1,30 @@ +#ifndef COMMONMACROS_H +#define COMMONMACROS_H +#pragma once + + +// ------------------------------------------------------- +// +// commonmacros.h +// +// This should contain ONLY general purpose macros that are +// appropriate for use in engine/launcher/all tools +// +// ------------------------------------------------------- + +#include "osconfig.h" +// Makes a 4-byte "packed ID" int out of 4 characters +#define MAKEID(d,c,b,a) ( ((int)(a) << 24) | ((int)(b) << 16) | ((int)(c) << 8) | ((int)(d)) ) + +// Compares a string with a 4-byte packed ID constant +#define STRING_MATCHES_ID( p, id ) ( (*((int *)(p)) == (id) ) ? true : false ) +#define ID_TO_STRING( id, p ) ( (p)[3] = (((id)>>24) & 0xFF), (p)[2] = (((id)>>16) & 0xFF), (p)[1] = (((id)>>8) & 0xFF), (p)[0] = (((id)>>0) & 0xFF) ) + +#define ARRAYSIZE(p) (sizeof(p)/sizeof(p[0])) + +// Keeps clutter down a bit, when using a float as a bit-vector +#define SetBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) | (bits)) +#define ClearBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) & ~(bits)) +#define FBitSet(flBitVector, bit) ((int)(flBitVector) & (bit)) + +#endif // COMMONMACROS_H diff --git a/public/engine_hlds_api.h b/public/engine_hlds_api.h new file mode 100644 index 0000000..3147083 --- /dev/null +++ b/public/engine_hlds_api.h @@ -0,0 +1,45 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#include "maintypes.h" +#include "interface.h" + +class IDedicatedServerAPI : public IBaseInterface +{ +public: + + virtual bool Init(char *basedir, char *cmdline, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0; + virtual int Shutdown(void) = 0; + virtual bool RunFrame(void) = 0; + virtual void AddConsoleText(char *text) = 0; + virtual void UpdateStatus(float *fps, int *nActive, int *nMaxPlayers, char *pszMap) = 0; +}; + +#define VENGINE_HLDS_API_VERSION "VENGINE_HLDS_API_VERSION002" diff --git a/public/engine_launcher_api.h b/public/engine_launcher_api.h new file mode 100644 index 0000000..74f1b69 --- /dev/null +++ b/public/engine_launcher_api.h @@ -0,0 +1,44 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#ifndef ENGINE_LAUNCHER_API_H +#define ENGINE_LAUNCHER_API_H +#ifdef _WIN32 +#pragma once +#endif + +#include "maintypes.h" +#include "interface.h" + +class IEngineAPI : public IBaseInterface +{ +public: + virtual int Run(void *instance, char *basedir, char *cmdline, char *postRestartCmdLineArgs, CreateInterfaceFn launcherFactory, CreateInterfaceFn filesystemFactory) = 0; +}; + +#endif // ENGINE_LAUNCHER_API_H diff --git a/public/idedicatedexports.h b/public/idedicatedexports.h new file mode 100644 index 0000000..2f6e255 --- /dev/null +++ b/public/idedicatedexports.h @@ -0,0 +1,25 @@ +//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef IDEDICATEDEXPORTS_H +#define IDEDICATEDEXPORTS_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" + +class IDedicatedExports : IBaseInterface +{ +public: + virtual ~IDedicatedExports() { }; + virtual void Sys_Printf(char *text) = 0; +}; + +#define VENGINE_DEDICATEDEXPORTS_API_VERSION "VENGINE_DEDICATEDEXPORTS_API_VERSION001" + +#endif // IDEDICATEDEXPORTS_H diff --git a/public/interface.cpp b/public/interface.cpp index e6f258d..67c3748 100644 --- a/public/interface.cpp +++ b/public/interface.cpp @@ -1,6 +1,5 @@ #include "precompiled.h" - #if !defined ( _WIN32 ) // Linux doesn't have this function so this emulates its functionality // diff --git a/public/iosutil.h b/public/iosutil.h new file mode 100644 index 0000000..34e56d8 --- /dev/null +++ b/public/iosutil.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +class IosFlagSaver { +public: + explicit IosFlagSaver(std::ostream& _ios) : + ios(_ios), + f(_ios.flags()) { + } + ~IosFlagSaver() { + ios.flags(f); + } + + IosFlagSaver(const IosFlagSaver &rhs) = delete; + IosFlagSaver& operator= (const IosFlagSaver& rhs) = delete; + +private: + std::ostream& ios; + std::ios::fmtflags f; +}; diff --git a/public/iregistry.h b/public/iregistry.h new file mode 100644 index 0000000..3e77ab2 --- /dev/null +++ b/public/iregistry.h @@ -0,0 +1,40 @@ +//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#if !defined( UTIL_REGISTRY_H ) +#define UTIL_REGISTRY_H +#ifdef _WIN32 +#pragma once +#endif + +//----------------------------------------------------------------------------- +// Purpose: Interface to registry +//----------------------------------------------------------------------------- +class IRegistry +{ +public: + // Init/shutdown + virtual void Init(void) = 0; + virtual void Shutdown(void) = 0; + + // Read/write integers + virtual int ReadInt(const char *key, int defaultValue = 0) = 0; + virtual void WriteInt(const char *key, int value) = 0; + + // Read/write strings + virtual const char *ReadString(const char *key, const char *defaultValue = NULL) = 0; + virtual void WriteString(const char *key, const char *value) = 0; +}; + + +#ifdef HOOK_ENGINE +#define registry (*pregistry) +#endif // HOOK_ENGINE + +extern IRegistry *registry; + +#endif // UTIL_REGISTRY_H diff --git a/public/keydefs.h b/public/keydefs.h new file mode 100644 index 0000000..590367b --- /dev/null +++ b/public/keydefs.h @@ -0,0 +1,124 @@ +// keydefs.h +#ifndef KEYDEFS_H +#define KEYDEFS_H +#ifdef _WIN32 +#pragma once +#endif + +// +// these are the key numbers that should be passed to Key_Event +// +#define K_TAB 9 +#define K_ENTER 13 +#define K_ESCAPE 27 +#define K_SPACE 32 + +// normal keys should be passed as lowercased ascii + +#define K_BACKSPACE 127 +#define K_UPARROW 128 +#define K_DOWNARROW 129 +#define K_LEFTARROW 130 +#define K_RIGHTARROW 131 + +#define K_ALT 132 +#define K_CTRL 133 +#define K_SHIFT 134 +#define K_F1 135 +#define K_F2 136 +#define K_F3 137 +#define K_F4 138 +#define K_F5 139 +#define K_F6 140 +#define K_F7 141 +#define K_F8 142 +#define K_F9 143 +#define K_F10 144 +#define K_F11 145 +#define K_F12 146 +#define K_INS 147 +#define K_DEL 148 +#define K_PGDN 149 +#define K_PGUP 150 +#define K_HOME 151 +#define K_END 152 + +#define K_KP_HOME 160 +#define K_KP_UPARROW 161 +#define K_KP_PGUP 162 +#define K_KP_LEFTARROW 163 +#define K_KP_5 164 +#define K_KP_RIGHTARROW 165 +#define K_KP_END 166 +#define K_KP_DOWNARROW 167 +#define K_KP_PGDN 168 +#define K_KP_ENTER 169 +#define K_KP_INS 170 +#define K_KP_DEL 171 +#define K_KP_SLASH 172 +#define K_KP_MINUS 173 +#define K_KP_PLUS 174 +#define K_CAPSLOCK 175 +#define K_KP_MUL 176 +#define K_WIN 177 + + +// +// joystick buttons +// +#define K_JOY1 203 +#define K_JOY2 204 +#define K_JOY3 205 +#define K_JOY4 206 + +// +// aux keys are for multi-buttoned joysticks to generate so they can use +// the normal binding process +// +#define K_AUX1 207 +#define K_AUX2 208 +#define K_AUX3 209 +#define K_AUX4 210 +#define K_AUX5 211 +#define K_AUX6 212 +#define K_AUX7 213 +#define K_AUX8 214 +#define K_AUX9 215 +#define K_AUX10 216 +#define K_AUX11 217 +#define K_AUX12 218 +#define K_AUX13 219 +#define K_AUX14 220 +#define K_AUX15 221 +#define K_AUX16 222 +#define K_AUX17 223 +#define K_AUX18 224 +#define K_AUX19 225 +#define K_AUX20 226 +#define K_AUX21 227 +#define K_AUX22 228 +#define K_AUX23 229 +#define K_AUX24 230 +#define K_AUX25 231 +#define K_AUX26 232 +#define K_AUX27 233 +#define K_AUX28 234 +#define K_AUX29 235 +#define K_AUX30 236 +#define K_AUX31 237 +#define K_AUX32 238 +#define K_MWHEELDOWN 239 +#define K_MWHEELUP 240 + +#define K_PAUSE 255 + +// +// mouse buttons generate virtual keys +// +#define K_MOUSE1 241 +#define K_MOUSE2 242 +#define K_MOUSE3 243 +#define K_MOUSE4 244 +#define K_MOUSE5 245 + +#endif // KEYDEFS_H \ No newline at end of file diff --git a/public/particleman.h b/public/particleman.h new file mode 100644 index 0000000..0f9b702 --- /dev/null +++ b/public/particleman.h @@ -0,0 +1,101 @@ +#ifndef PARTICLEMAN_H +#define PARTICLEMAN_H + +#include "interface.h" +#include "pman_triangleffect.h" + +#define PARTICLEMAN_INTERFACE "create_particleman" + +#ifdef _WIN32 +#define PARTICLEMAN_DLLNAME "cl_dlls/particleman.dll" +#elif defined(OSX) +#define PARTICLEMAN_DLLNAME "cl_dlls/particleman.dylib" +#elif defined(LINUX) +#define PARTICLEMAN_DLLNAME "cl_dlls/particleman.so" +#else +#error +#endif + +class CBaseParticle; + +class IParticleMan : public IBaseInterface +{ + +protected: + virtual ~IParticleMan() {} + +public: + + virtual void SetUp( cl_enginefunc_t *pEnginefuncs ) = 0; + virtual void Update ( void ) = 0; + virtual void SetVariables ( float flGravity, Vector vViewAngles ) = 0; + virtual void ResetParticles ( void ) = 0; + virtual void ApplyForce ( Vector vOrigin, Vector vDirection, float flRadius, float flStrength, float flDuration ) = 0; + virtual void AddCustomParticleClassSize ( unsigned long lSize ) = 0; + + //Use this if you want to create a new particle without any overloaded functions, Think, Touch, etc. + //Just call this function, set the particle's behavior and let it rip. + virtual CBaseParticle *CreateParticle( Vector org, Vector normal, model_s * sprite, float size, float brightness, const char *classname ) = 0; + + //Use this to take a block from the mempool for custom particles ( used in new ). + virtual char *RequestNewMemBlock( int iSize ) = 0; + + //These ones are used along a custom Create for new particles you want to override their behavior. + //You can call these whenever you want, but they are mainly used by CBaseParticle. + virtual void CoreInitializeSprite ( CCoreTriangleEffect *pParticle, Vector org, Vector normal, model_s *sprite, float size, float brightness ) = 0; //Only use this for TrianglePlanes + virtual void CoreThink( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreDraw( CCoreTriangleEffect *pParticle ) = 0; + virtual void CoreAnimate( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreAnimateAndDie( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreExpand ( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreContract ( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreFade ( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreSpin ( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreCalculateVelocity( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreCheckCollision( CCoreTriangleEffect *pParticle, float time ) = 0; + virtual void CoreTouch ( CCoreTriangleEffect *pParticle, Vector pos, Vector normal, int index ) = 0; + virtual void CoreDie ( CCoreTriangleEffect *pParticle ) = 0; + virtual void CoreForce ( CCoreTriangleEffect *pParticle ) = 0; + virtual bool CoreCheckVisibility ( CCoreTriangleEffect *pParticle ) = 0; + virtual void SetRender( int iRender ) = 0; +}; + +extern IParticleMan *g_pParticleMan; + +class CBaseParticle : public CCoreTriangleEffect +{ +public: + virtual void Think( float time ){ g_pParticleMan->CoreThink( this, time ); } + virtual void Draw( void ) { g_pParticleMan->CoreDraw( this ); } + virtual void Animate( float time ) { g_pParticleMan->CoreAnimate( this, time ); } + virtual void AnimateAndDie( float time ) { g_pParticleMan->CoreAnimateAndDie( this, time ); } + virtual void Expand( float time ) { g_pParticleMan->CoreExpand( this, time ); } + virtual void Contract( float time ) { g_pParticleMan->CoreContract( this, time ); } + virtual void Fade( float time ) { g_pParticleMan->CoreFade( this, time ); } + virtual void Spin( float time ) { g_pParticleMan->CoreSpin( this, time ); } + virtual void CalculateVelocity( float time ) { g_pParticleMan->CoreCalculateVelocity( this, time ); } + virtual void CheckCollision( float time ) { g_pParticleMan->CoreCheckCollision( this, time ); } + virtual void Touch(Vector pos, Vector normal, int index) { g_pParticleMan->CoreTouch( this, pos, normal, index ); } + virtual void Die ( void ) { g_pParticleMan->CoreDie( this ); } + virtual void Force ( void ) { g_pParticleMan->CoreForce( this ); } + virtual bool CheckVisibility ( void ) { return g_pParticleMan->CoreCheckVisibility( this ); } + + virtual void InitializeSprite( Vector org, Vector normal, model_s *sprite, float size, float brightness ) + { + g_pParticleMan->CoreInitializeSprite ( this, org, normal, sprite, size, brightness ); + } + + void * operator new( size_t size ) //this asks for a new block of memory from the MiniMem class + { + return( g_pParticleMan->RequestNewMemBlock( size ) ); + } +#ifdef POSIX + void * operator new( size_t size, const std::nothrow_t&) throw() //this asks for a new block of memory from the MiniMem class + { + return( g_pParticleMan->RequestNewMemBlock( size ) ); + } +#endif +}; + + +#endif //PARTICLEMAN_H diff --git a/public/pman_particlemem.h b/public/pman_particlemem.h new file mode 100644 index 0000000..6ccb971 --- /dev/null +++ b/public/pman_particlemem.h @@ -0,0 +1,197 @@ +#ifndef PARTICLEMEM_H__ +#define PARTICLEMEM_H__ + +#ifdef _WIN32 +#pragma once +#endif + +#include + +class CCoreTriangleEffect; + +#define TRIANGLE_FPS 30 + +typedef struct visibleparticles_s +{ + CCoreTriangleEffect *pVisibleParticle; +} visibleparticles_t; + +//--------------------------------------------------------------------------- +// Memory block record. +class MemoryBlock +{ +private: + char *m_pData; + //bool m_bBlockIsInUse; +public: + MemoryBlock(long lBlockSize) + : next(NULL), prev(NULL) + //m_bBlockIsInUse(false) // Initialize block to 'free' state. + { + // Allocate memory here. + m_pData = new char[lBlockSize]; + } + + virtual ~MemoryBlock() + { + // Free memory. + delete[] m_pData; + } + + inline char *Memory(void) { return m_pData; } + + MemoryBlock * next; + MemoryBlock * prev; +}; + +class MemList +{ +public: + MemList() : m_pHead(NULL) {} + + ~MemList() { Reset(); } + + void Push(MemoryBlock * newItem) + { + if(!m_pHead) + { + m_pHead = newItem; + newItem->next = NULL; + newItem->prev = NULL; + return; + } + + MemoryBlock * temp = m_pHead; + m_pHead = newItem; + m_pHead->next = temp; + m_pHead->prev = NULL; + + temp->prev = m_pHead; + } + + + MemoryBlock * Front( void ) + { + return(m_pHead); + } + + MemoryBlock * Pop( void ) + { + if(!m_pHead) + return(NULL); + + MemoryBlock * temp = m_pHead; + + m_pHead = m_pHead->next; + + if(m_pHead) + m_pHead->prev = NULL; + + temp->next = NULL; + temp->prev = NULL; + + return(temp); + } + + void Delete( MemoryBlock * pItem) + { + + if(m_pHead == pItem) + { + MemoryBlock * temp = m_pHead; + + m_pHead = m_pHead->next; + if(m_pHead) + m_pHead->prev = NULL; + + temp->next = NULL; + temp->prev = NULL; + return; + } + + MemoryBlock * prev = pItem->prev; + MemoryBlock * next = pItem->next; + + if(prev) + prev->next = next; + + if(next) + next->prev = prev; + + pItem->next = NULL; + pItem->prev = NULL; + } + + void Reset( void ) + { + while(m_pHead) + Delete(m_pHead); + } + +private: + MemoryBlock * m_pHead; +}; + + +// Some helpful typedefs. +typedef std::vector VectorOfMemoryBlocks; +typedef VectorOfMemoryBlocks::iterator MemoryBlockIterator; + +// Mini memory manager - singleton. +class CMiniMem +{ +private: + // Main memory pool. Array is fine, but vectors are + // easier. :) + static VectorOfMemoryBlocks m_vecMemoryPool; + // Size of memory blocks in pool. + static long m_lMemoryBlockSize; + static long m_lMaxBlocks; + static long m_lMemoryPoolSize; + static CMiniMem *_instance; + + int m_iTotalParticles; + int m_iParticlesDrawn; + +protected: + // private constructor and destructor. + CMiniMem(long lMemoryPoolSize, long lMaxBlockSize); + virtual ~CMiniMem(); + + // ------------ Memory pool manager calls. + // Find a free block and mark it as "in use". Return NULL + // if no free blocks found. + char *AllocateFreeBlock(void); +public: + + // Return a pointer to usable block of memory. + char *newBlock(void); + + // Mark a target memory item as no longer "in use". + void deleteBlock(MemoryBlock *p); + + // Return the remaining capacity of the memory pool as a percent. + long PercentUsed(void); + + void ProcessAll( void ); //Processes all + + void Reset( void ); //clears memory, setting all particles to not used. + + static int ApplyForce( Vector vOrigin, Vector vDirection, float flRadius, float flStrength ); + + static CMiniMem *Instance(void); + static long MaxBlockSize(void); + + bool CheckSize( int iSize ); + + int GetTotalParticles( void ) { return m_iTotalParticles; } + int GetDrawnParticles( void ) { return m_iParticlesDrawn; } + void IncreaseParticlesDrawn( void ){ m_iParticlesDrawn++; } + + void Shutdown( void ); + + visibleparticles_t *m_pVisibleParticles; +}; + + +#endif//PARTICLEMEM_H__ \ No newline at end of file diff --git a/public/pman_triangleffect.h b/public/pman_triangleffect.h new file mode 100644 index 0000000..6af4c2b --- /dev/null +++ b/public/pman_triangleffect.h @@ -0,0 +1,209 @@ +#ifndef TRIANGLEEFFECT_H__ +#define TRIANGLEEFFECT_H__ + +#ifdef _WIN32 +#pragma once +#endif + +#define TRI_COLLIDEWORLD 0x00000020 +#define TRI_COLLIDEALL 0x00001000 // will collide with world and slideboxes +#define TRI_COLLIDEKILL 0x00004000 // tent is removed upon collision with anything +#define TRI_SPIRAL 0x00008000 +#define TRI_ANIMATEDIE 0x00016000 //animate once and then die +#define TRI_WATERTRACE 0x00032000 + + +#define CULL_FRUSTUM_POINT ( 1 << 0 ) +#define CULL_FRUSTUM_SPHERE ( 1 << 1 ) +#define CULL_FRUSTUM_PLANE ( 1 << 2 ) +#define CULL_PVS ( 1 << 3 ) + +#define LIGHT_NONE ( 1 << 4 ) +#define LIGHT_COLOR ( 1 << 5 ) +#define LIGHT_INTENSITY ( 1 << 6 ) + +#define RENDER_FACEPLAYER ( 1 << 7 ) // m_vAngles == Player view angles +#define RENDER_FACEPLAYER_ROTATEZ ( 1 << 8 ) //Just like above but m_vAngles.z is untouched so the sprite can rotate. + + +#include "pman_particlemem.h" + +//pure virtual baseclass +class CCoreTriangleEffect +{ +private: + int m_iRenderFlags; + float m_flNextPVSCheck; + bool m_bInPVS; + + int m_iCollisionFlags; + float m_flPlayerDistance; //Used for sorting the particles, DO NOT TOUCH. + +public: + + void * operator new(size_t size) + { + // Requested size should match size of class. + if ( size != sizeof( CCoreTriangleEffect ) ) +#ifdef _WIN32 + throw "Error in requested size of new particle class instance."; +#else + return NULL; +#endif + + return((CCoreTriangleEffect *) CMiniMem::Instance()->newBlock()); + + }//this asks for a new block of memory from the MiniMen class + + virtual void Think( float time ) = 0; + virtual bool CheckVisibility ( void ) = 0; + virtual void Draw( void ) = 0; + virtual void Animate( float time ) = 0; + virtual void AnimateAndDie( float time ) = 0; + virtual void Expand( float time ) = 0; + virtual void Contract( float time ) = 0; + virtual void Fade( float time ) = 0; + virtual void Spin( float time ) = 0; + virtual void CalculateVelocity( float time ) = 0; + virtual void CheckCollision( float time ) = 0; + virtual void Touch(Vector pos, Vector normal, int index) = 0; + virtual void Die ( void ) = 0; + virtual void InitializeSprite( Vector org, Vector normal, model_s * sprite, float size, float brightness ) = 0; + virtual void Force ( void ) = 0; + + float m_flSize; //scale of object + float m_flScaleSpeed; //speed at which object expands + float m_flContractSpeed; //speed at which object expands + + float m_flStretchX; + float m_flStretchY; + + float m_flBrightness; //transparency of object + float m_flFadeSpeed; //speed at which object fades + + float m_flTimeCreated; //time object was instanced + float m_flDieTime; //time to remove an object + + float m_flGravity; //how effected by gravity is this object + float m_flAfterDampGrav; + float m_flDampingVelocity; + float m_flDampingTime; + + int m_iFramerate; + int m_iNumFrames; + int m_iFrame; + int m_iRendermode; + + Vector m_vOrigin; //object's position + Vector m_vAngles; //normal angles of object + + Vector m_vAVelocity; + + Vector m_vVelocity; + + Vector m_vLowLeft; + Vector m_vLowRight; + Vector m_vTopLeft; + + Vector m_vColor; + float m_flMass; + + model_s * m_pTexture; + + float m_flBounceFactor; + + char m_szClassname[32]; + + bool m_bInWater; + bool m_bAffectedByForce; + + int m_iAfterDampFlags; + + void SetLightFlag ( int iFlag ) + { + m_iRenderFlags &= ~( LIGHT_NONE | LIGHT_INTENSITY | LIGHT_COLOR ); + m_iRenderFlags |= iFlag; + } + + void SetCullFlag( int iFlag ) + { + m_iRenderFlags &= ~( CULL_PVS | CULL_FRUSTUM_POINT | CULL_FRUSTUM_PLANE | CULL_FRUSTUM_SPHERE ); + m_iRenderFlags |= iFlag; + } + + int GetRenderFlags( void ) + { + return m_iRenderFlags; + } + + bool GetParticlePVS ( void ) + { + return m_bInPVS; + } + + void SetParticlePVS ( bool bPVSStat ) + { + m_bInPVS = bPVSStat; + } + + float GetNextPVSCheck( void ) + { + return m_flNextPVSCheck; + } + + void SetNextPVSCheck( float flTime ) + { + m_flNextPVSCheck = flTime; + } + + void SetCollisionFlags ( int iFlag ) + { + m_iCollisionFlags |= iFlag; + } + + void ClearCollisionFlags ( int iFlag ) + { + m_iCollisionFlags &= ~iFlag; + } + + int GetCollisionFlags ( void ) + { + return m_iCollisionFlags; + } + + void SetRenderFlag( int iFlag ) + { + m_iRenderFlags |= iFlag; + } + + float GetPlayerDistance ( void ) { return m_flPlayerDistance; } + void SetPlayerDistance ( float flDistance ) { m_flPlayerDistance = flDistance; } + +protected: + float m_flOriginalSize; + Vector m_vOriginalAngles; + float m_flOriginalBrightness; + Vector m_vPrevOrigin; + + float m_flNextCollisionTime; + +protected: + static bool CheckSize(int size) + { + // This check will help prevent a class frome being defined later, + // that is larger than the max size MemoryPool is expecting, + // from being successfully allocated. + if (size > (unsigned long) CMiniMem::Instance()->MaxBlockSize()) + { +#ifdef _WIN32 + throw "New particle class is larger than memory pool max size, update lMaxParticleClassSize() function."; +#endif + return(false); + } + + return(true); + } +}; + + +#endif//TRIANGLEEFFECT_H__ diff --git a/public/protected_things.h b/public/protected_things.h new file mode 100644 index 0000000..201438e --- /dev/null +++ b/public/protected_things.h @@ -0,0 +1,187 @@ +//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef PROTECTED_THINGS_H +#define PROTECTED_THINGS_H +#ifdef _WIN32 +#pragma once +#endif + + +// This header tries to prevent people from using potentially dangerous functions +// (like the notorious non-null-terminating strncpy) and functions that will break +// VCR mode (like time, input, registry, etc). +// +// This header should be included by ALL of our source code. + +// Eventually, ALL of these should be protected, but one man can only accomplish so much in +// one day AND work on features too! +#if defined( PROTECT_STRING_FUNCTIONS ) +#if defined( strncpy ) +#undef strncpy +#endif +#define strncpy strncpy__HEY_YOU__USE_VSTDLIB + + +#if defined( _snprintf ) +#undef _snprintf +#endif +#define _snprintf snprintf__HEY_YOU__USE_VSTDLIB + + +#if defined( sprintf ) +#undef sprintf +#endif +#define sprintf sprintf__HEY_YOU__USE_VSTDLIB + + +#if defined( _vsnprintf ) +#undef _vsnprintf +#endif +#define _vsnprintf vsnprintf__HEY_YOU__USE_VSTDLIB + + +#if defined( strcat ) +#undef strcat +#endif +#define strcat strcat__HEY_YOU__USE_VSTDLIB +#endif + + +#if defined( PROTECT_FILEIO_FUNCTIONS ) +#if defined( fopen ) +#undef fopen +#endif +#define fopen fopen_USE_FILESYSTEM_INSTEAD +#endif + + +#if defined( PROTECTED_THINGS_ENABLE ) + +#if defined( GetTickCount ) +#undef GetTickCount +#endif +#define GetTickCount GetTickCount__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( timeGetTime ) +#undef timeGetTime +#endif +#define timeGetTime timeGetTime__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( clock ) +#undef clock +#endif +#define time time__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( recvfrom ) +#undef recvfrom +#endif +#define recvfrom recvfrom__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( GetCursorPos ) +#undef GetCursorPos +#endif +#define GetCursorPos GetCursorPos__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( ScreenToClient ) +#undef ScreenToClient +#endif +#define ScreenToClient ScreenToClient__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( GetCommandLine ) +#undef GetCommandLine +#endif +#define GetCommandLine GetCommandLine__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegOpenKeyEx ) +#undef RegOpenKeyEx +#endif +#define RegOpenKeyEx RegOpenKeyEx__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegOpenKey ) +#undef RegOpenKey +#endif +#define RegOpenKey RegOpenKey__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegSetValueEx ) +#undef RegSetValueEx +#endif +#define RegSetValueEx RegSetValueEx__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegSetValue ) +#undef RegSetValue +#endif +#define RegSetValue RegSetValue__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegQueryValueEx ) +#undef RegQueryValueEx +#endif +#define RegQueryValueEx RegQueryValueEx__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegQueryValue ) +#undef RegQueryValue +#endif +#define RegQueryValue RegQueryValue__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegCreateKeyEx ) +#undef RegCreateKeyEx +#endif +#define RegCreateKeyEx RegCreateKeyEx__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegCreateKey ) +#undef RegCreateKey +#endif +#define RegCreateKey RegCreateKey__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( RegCloseKey ) +#undef RegCloseKey +#endif +#define RegCloseKey RegCloseKey__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( GetNumberOfConsoleInputEvents ) +#undef GetNumberOfConsoleInputEvents +#endif +#define GetNumberOfConsoleInputEvents GetNumberOfConsoleInputEvents__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( ReadConsoleInput ) +#undef ReadConsoleInput +#endif +#define ReadConsoleInput ReadConsoleInput__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( GetAsyncKeyState ) +#undef GetAsyncKeyState +#endif +#define GetAsyncKeyState GetAsyncKeyState__HEY_YOU__USE_PLATFORM_LIB + + +#if defined( GetKeyState ) +#undef GetKeyState +#endif +#define GetKeyState GetKeyState__HEY_YOU__USE_PLATFORM_LIB + +#endif + + +#endif // PROTECTED_THINGS_H diff --git a/public/registry.cpp b/public/registry.cpp new file mode 100644 index 0000000..9537312 --- /dev/null +++ b/public/registry.cpp @@ -0,0 +1,264 @@ +//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "precompiled.h" + +#ifndef _WIN32 +typedef int HKEY; +#endif + +//----------------------------------------------------------------------------- +// Purpose: Exposes registry interface to rest of launcher +//----------------------------------------------------------------------------- +class CRegistry : public IRegistry +{ +public: + CRegistry(void); + virtual ~CRegistry(void); + + void Init(void); + void Shutdown(void); + + int ReadInt(const char *key, int defaultValue = 0); + void WriteInt(const char *key, int value); + + const char *ReadString(const char *key, const char *defaultValue = NULL); + void WriteString(const char *key, const char *value); + +private: + bool m_bValid; + HKEY m_hKey; +}; + +// Expose to launcher +#ifndef HOOK_ENGINE + +static CRegistry g_Registry; +IRegistry *registry = (IRegistry *)&g_Registry; + +#else + +IRegistry *registry; + +#endif + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CRegistry::CRegistry(void) +{ + // Assume failure + m_bValid = false; + m_hKey = 0; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CRegistry::~CRegistry(void) +{ +} + +//----------------------------------------------------------------------------- +// Purpose: Read integer from registry +// Input : *key - +// defaultValue - +// Output : int +//----------------------------------------------------------------------------- +int CRegistry::ReadInt(const char *key, int defaultValue /*= 0*/) +{ +#ifdef _WIN32 + LONG lResult; // Registry function result code + DWORD dwType; // Type of key + DWORD dwSize; // Size of element data + + int value; + + if (!m_bValid) + { + return defaultValue; + } + + dwSize = sizeof(DWORD); + + lResult = RegQueryValueEx( + m_hKey, // handle to key + key, // value name + 0, // reserved + &dwType, // type buffer + (LPBYTE)&value, // data buffer + &dwSize); // size of data buffer + + if (lResult != ERROR_SUCCESS) // Failure + return defaultValue; + + if (dwType != REG_DWORD) + return defaultValue; + + return value; +#else + return defaultValue; +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: Save integer to registry +// Input : *key - +// value - +//----------------------------------------------------------------------------- +void CRegistry::WriteInt(const char *key, int value) +{ +#ifdef _WIN32 + // Size of element data + DWORD dwSize; + + if (!m_bValid) + { + return; + } + + dwSize = sizeof(DWORD); + + RegSetValueEx( + m_hKey, // handle to key + key, // value name + 0, // reserved + REG_DWORD, // type buffer + (LPBYTE)&value, // data buffer + dwSize); // size of data buffer +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: Read string value from registry +// Input : *key - +// *defaultValue - +// Output : const char +//----------------------------------------------------------------------------- +const char *CRegistry::ReadString(const char *key, const char *defaultValue /* = NULL */) +{ +#ifdef _WIN32 + LONG lResult; + // Type of key + DWORD dwType; + // Size of element data + DWORD dwSize = 512; + + static char value[512]; + + value[0] = 0; + + if (!m_bValid) + { + return defaultValue; + } + + lResult = RegQueryValueEx( + m_hKey, // handle to key + key, // value name + 0, // reserved + &dwType, // type buffer + (unsigned char *)value, // data buffer + &dwSize); // size of data buffer + + if (lResult != ERROR_SUCCESS) + { + return defaultValue; + } + + if (dwType != REG_SZ) + { + return defaultValue; + } + + return value; +#else + return defaultValue; +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: Save string to registry +// Input : *key - +// *value - +//----------------------------------------------------------------------------- +void CRegistry::WriteString(const char *key, const char *value) +{ +#ifdef _WIN32 + DWORD dwSize; // Size of element data + + if (!m_bValid) + { + return; + } + + dwSize = strlen(value) + 1; + + RegSetValueEx( + m_hKey, // handle to key + key, // value name + 0, // reserved + REG_SZ, // type buffer + (LPBYTE)value, // data buffer + dwSize); // size of data buffer +#endif +} + +// FIXME: SHould be "steam" +static char *GetPlatformName(void) +{ + return "Half-Life"; +} + +//----------------------------------------------------------------------------- +// Purpose: Open default launcher key based on game directory +//----------------------------------------------------------------------------- +void CRegistry::Init(void) +{ +#ifdef _WIN32 + LONG lResult; // Registry function result code + DWORD dwDisposition; // Type of key opening event + + char szModelKey[1024]; + wsprintf(szModelKey, "Software\\Valve\\%s\\Settings\\", GetPlatformName()); + + lResult = RegCreateKeyEx( + HKEY_CURRENT_USER, // handle of open key + szModelKey, // address of name of subkey to open + 0, // DWORD ulOptions, // reserved + NULL, // Type of value + REG_OPTION_NON_VOLATILE, // Store permanently in reg. + KEY_ALL_ACCESS, // REGSAM samDesired, // security access mask + NULL, + &m_hKey, // Key we are creating + &dwDisposition); // Type of creation + + if (lResult != ERROR_SUCCESS) + { + m_bValid = false; + return; + } + + // Success + m_bValid = true; +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CRegistry::Shutdown(void) +{ +#ifdef _WIN32 + if (!m_bValid) + return; + + // Make invalid + m_bValid = false; + RegCloseKey(m_hKey); +#endif +} diff --git a/public/savegame_version.h b/public/savegame_version.h new file mode 100644 index 0000000..26749a5 --- /dev/null +++ b/public/savegame_version.h @@ -0,0 +1,20 @@ +//========= Copyright 1996-2001, Valve LLC, All rights reserved. ============ +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#if !defined( SAVEGAME_VERSION_H ) +#define SAVEGAME_VERSION_H +#ifdef _WIN32 +#pragma once +#endif + +#include "commonmacros.h" + +#define SAVEFILE_HEADER MAKEID('V','A','L','V') // little-endian "VALV" +#define SAVEGAME_HEADER MAKEID('J','S','A','V') // little-endian "JSAV" +#define SAVEGAME_VERSION 0x0071 // Version 0.71 + +#endif // SAVEGAME_VERSION_H diff --git a/public/steamid.cpp b/public/steamid.cpp new file mode 100644 index 0000000..db24cea --- /dev/null +++ b/public/steamid.cpp @@ -0,0 +1,32 @@ +#include "precompiled.h" + +bool CSteamID::SetFromSteam2String(const char *pchSteam2ID, EUniverse eUniverse) +{ + Assert(pchSteam2ID); + + // Convert the Steam2 ID string to a Steam2 ID structure + TSteamGlobalUserID steam2ID; + steam2ID.m_SteamInstanceID = 0; + steam2ID.m_SteamLocalUserID.Split.High32bits = 0; + steam2ID.m_SteamLocalUserID.Split.Low32bits = 0; + + const char *pchTSteam2ID = pchSteam2ID; + + // Customer support is fond of entering steam IDs in the following form: STEAM_n:x:y + char *pchOptionalLeadString = "STEAM_"; + if (Q_strnicmp(pchSteam2ID, pchOptionalLeadString, Q_strlen(pchOptionalLeadString)) == 0) + pchTSteam2ID = pchSteam2ID + Q_strlen(pchOptionalLeadString); + + char cExtraCharCheck = 0; + + int cFieldConverted = sscanf(pchTSteam2ID, "%hu:%u:%u%c", &steam2ID.m_SteamInstanceID, + &steam2ID.m_SteamLocalUserID.Split.High32bits, &steam2ID.m_SteamLocalUserID.Split.Low32bits, &cExtraCharCheck); + + // Validate the conversion ... a special case is steam2 instance ID 1 which is reserved for special DoD handling + if (cExtraCharCheck != 0 || cFieldConverted == EOF || cFieldConverted < 2 || (cFieldConverted < 3 && steam2ID.m_SteamInstanceID != 1)) + return false; + + // Now convert to steam ID from the Steam2 ID structure + SetFromSteam2(&steam2ID, eUniverse); + return true; +} diff --git a/public/utlbuffer.cpp b/public/utlbuffer.cpp new file mode 100644 index 0000000..c9f4508 --- /dev/null +++ b/public/utlbuffer.cpp @@ -0,0 +1,419 @@ +//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// $Header: $ +// $NoKeywords: $ +// +// Serialization buffer +//============================================================================= + +#include "precompiled.h" + +//----------------------------------------------------------------------------- +// constructors +//----------------------------------------------------------------------------- +CUtlBuffer::CUtlBuffer(int growSize, int initSize, bool text) : +m_Memory(growSize, initSize), m_Error(0) +{ + m_Get = 0; + m_Put = 0; + m_Flags = 0; + if (text) + { + m_Flags |= TEXT_BUFFER; + } +} + +CUtlBuffer::CUtlBuffer(void const* pBuffer, int size, bool text) : +m_Memory((unsigned char*)pBuffer, size), m_Error(0) +{ + m_Get = 0; + m_Put = 0; + m_Flags = 0; + if (text) + m_Flags |= TEXT_BUFFER; +} + + +//----------------------------------------------------------------------------- +// Attaches the buffer to external memory.... +//----------------------------------------------------------------------------- +void CUtlBuffer::SetExternalBuffer(void* pMemory, int numElements, bool text) +{ + m_Memory.SetExternalBuffer((unsigned char*)pMemory, numElements); + + // Reset all indices; we just changed memory + m_Get = 0; + m_Put = 0; + m_Flags = 0; + if (text) + m_Flags |= TEXT_BUFFER; +} + + +//----------------------------------------------------------------------------- +// Makes sure we've got at least this much memory +//----------------------------------------------------------------------------- +void CUtlBuffer::EnsureCapacity(int num) +{ + m_Memory.EnsureCapacity(num); +} + + +//----------------------------------------------------------------------------- +// Base get method from which all others derive +//----------------------------------------------------------------------------- +void CUtlBuffer::Get(void* pMem, int size) +{ + Assert(m_Get + size <= m_Memory.NumAllocated()); + memcpy(pMem, &m_Memory[m_Get], size); + m_Get += size; +} + + +//----------------------------------------------------------------------------- +// Eats whitespace +//----------------------------------------------------------------------------- +void CUtlBuffer::EatWhiteSpace() +{ + if (IsText() && IsValid()) + { + int lastpos = Size(); + while (m_Get < lastpos) + { + if (!isspace(*(char*)&m_Memory[m_Get])) + break; + m_Get += sizeof(char); + } + } +} + + +//----------------------------------------------------------------------------- +// Reads a null-terminated string +//----------------------------------------------------------------------------- +void CUtlBuffer::GetString(char* pString, int nMaxLen) +{ + if (!IsValid()) + { + *pString = 0; + return; + } + + if (nMaxLen == 0) + { + nMaxLen = INT_MAX; + } + + if (!IsText()) + { + int len = strlen((char*)&m_Memory[m_Get]) + 1; + if (len <= nMaxLen) + { + Get(pString, len); + } + else + { + Get(pString, nMaxLen); + pString[nMaxLen - 1] = 0; + SeekGet(SEEK_CURRENT, len - nMaxLen); + } + } + else + { + // eat all whitespace + EatWhiteSpace(); + + // Eat characters + int nCount = 0; + int nLastPos = Size(); + while (m_Get < nLastPos) + { + char c = *(char*)&m_Memory[m_Get]; + if (isspace(c) || (!c)) + break; + + if (nCount < nMaxLen - 1) + { + *pString++ = c; + } + ++nCount; + ++m_Get; + } + + // Terminate + *pString = 0; + } +} + + +//----------------------------------------------------------------------------- +// Checks if a get is ok +//----------------------------------------------------------------------------- +bool CUtlBuffer::CheckGet(int size) +{ + if (m_Error) + return false; + + if (m_Memory.NumAllocated() >= m_Get + size) + return true; + + m_Error |= GET_OVERFLOW; + return false; +} + + +//----------------------------------------------------------------------------- +// Change where I'm reading +//----------------------------------------------------------------------------- +void CUtlBuffer::SeekGet(SeekType_t type, int offset) +{ + switch (type) + { + case SEEK_HEAD: + m_Get = offset; + break; + + case SEEK_CURRENT: + m_Get += offset; + break; + + case SEEK_TAIL: + m_Get = m_Memory.NumAllocated() - offset; + break; + } +} + + +//----------------------------------------------------------------------------- +// Parse... +//----------------------------------------------------------------------------- + +#pragma warning ( disable : 4706 ) + +int CUtlBuffer::VaScanf(char const* pFmt, va_list list) +{ + Assert(pFmt); + if (m_Error || !IsText()) + return 0; + + int numScanned = 0; + + char c; + char* pEnd; + while (c = *pFmt++) + { + // Stop if we hit the end of the buffer + if (m_Get >= Size()) + { + m_Error |= GET_OVERFLOW; + break; + } + + switch (c) + { + case ' ': + // eat all whitespace + EatWhiteSpace(); + break; + + case '%': + { + // Conversion character... try to convert baby! + char type = *pFmt++; + if (type == 0) + return numScanned; + + switch (type) + { + case 'c': + { + char* ch = va_arg(list, char *); + *ch = (char)m_Memory[m_Get]; + ++m_Get; + } + break; + + case 'i': + case 'd': + { + int* i = va_arg(list, int *); + *i = strtol((char*)PeekGet(), &pEnd, 10); + if (pEnd == PeekGet()) + return numScanned; + m_Get = (int)pEnd - (int)Base(); + } + break; + + case 'x': + { + int* i = va_arg(list, int *); + *i = strtol((char*)PeekGet(), &pEnd, 16); + if (pEnd == PeekGet()) + return numScanned; + m_Get = (int)pEnd - (int)Base(); + } + break; + + case 'u': + { + unsigned int* u = va_arg(list, unsigned int *); + *u = strtoul((char*)PeekGet(), &pEnd, 10); + if (pEnd == PeekGet()) + return numScanned; + m_Get = (int)pEnd - (int)Base(); + } + break; + + case 'f': + { + float* f = va_arg(list, float *); + *f = (float)strtod((char*)PeekGet(), &pEnd); + if (pEnd == PeekGet()) + return numScanned; + m_Get = (int)pEnd - (int)Base(); + } + break; + + case 's': + { + char* s = va_arg(list, char *); + GetString(s); + } + break; + + default: + { + // unimplemented scanf type + Assert(0); + return numScanned; + } + break; + } + + ++numScanned; + } + break; + + default: + { + // Here we have to match the format string character + // against what's in the buffer or we're done. + if (c != m_Memory[m_Get]) + return numScanned; + ++m_Get; + } + } + } + return numScanned; +} + +#pragma warning ( default : 4706 ) + +int CUtlBuffer::Scanf(char const* pFmt, ...) +{ + va_list args; + + va_start(args, pFmt); + int count = VaScanf(pFmt, args); + va_end(args); + + return count; +} + + +//----------------------------------------------------------------------------- +// Serialization +//----------------------------------------------------------------------------- + +void CUtlBuffer::Put(void const* pMem, int size) +{ + if (CheckPut(size)) + { + memcpy(&m_Memory[m_Put], pMem, size); + m_Put += size; + } +} + + +//----------------------------------------------------------------------------- +// Writes a null-terminated string +//----------------------------------------------------------------------------- + +void CUtlBuffer::PutString(char const* pString) +{ + int len = strlen(pString); + + // Not text? append a null at the end. + if (!IsText()) + ++len; + + Put(pString, len); +} + +void CUtlBuffer::VaPrintf(char const* pFmt, va_list list) +{ + char temp[2048]; + int len = vsprintf(temp, pFmt, list); + Assert(len < 2048); + + // Not text? append a null at the end. + if (!IsText()) + ++len; + + Put(temp, len); +} + +void CUtlBuffer::Printf(char const* pFmt, ...) +{ + va_list args; + + va_start(args, pFmt); + VaPrintf(pFmt, args); + va_end(args); +} + + +//----------------------------------------------------------------------------- +// Checks if a put is ok +//----------------------------------------------------------------------------- + +bool CUtlBuffer::CheckPut(int size) +{ + if (m_Error) + return false; + + while (m_Memory.NumAllocated() < m_Put + size) + { + if (m_Memory.IsExternallyAllocated()) + { + m_Error |= PUT_OVERFLOW; + return false; + } + + m_Memory.Grow(); + } + return true; +} + +void CUtlBuffer::SeekPut(SeekType_t type, int offset) +{ + switch (type) + { + case SEEK_HEAD: + m_Put = offset; + break; + + case SEEK_CURRENT: + m_Put += offset; + break; + + case SEEK_TAIL: + m_Put = m_Memory.NumAllocated() - offset; + break; + } +} \ No newline at end of file diff --git a/public/utlbuffer.h b/public/utlbuffer.h new file mode 100644 index 0000000..2351249 --- /dev/null +++ b/public/utlbuffer.h @@ -0,0 +1,341 @@ +//========= Copyright © 1996-2001, Valve LLC, All rights reserved. ============ +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// $Header: $ +// $NoKeywords: $ +// +// Serialization/unserialization buffer +//============================================================================= + +#ifndef UTLBUFFER_H +#define UTLBUFFER_H + +#include "osconfig.h" +#include "utlmemory.h" +#include + +//----------------------------------------------------------------------------- +// Command parsing.. +//----------------------------------------------------------------------------- + +class CUtlBuffer +{ +public: + enum SeekType_t + { + SEEK_HEAD = 0, + SEEK_CURRENT, + SEEK_TAIL + }; + + CUtlBuffer(int growSize = 0, int initSize = 0, bool text = false); + CUtlBuffer(void const* pBuffer, int size, bool text = false); + + // Makes sure we've got at least this much memory + void EnsureCapacity(int num); + + // Attaches the buffer to external memory.... + void SetExternalBuffer(void* pMemory, int numElements, bool text = false); + + // Read stuff out. + // Binary mode: it'll just read the bits directly in, and characters will be + // read for strings until a null character is reached. + // Text mode: it'll parse the file, turning text #s into real numbers. + // GetString will read a string until a space is reaced + char GetChar(); + unsigned char GetUnsignedChar(); + short GetShort(); + unsigned short GetUnsignedShort(); + int GetInt(); + int GetIntHex(); + unsigned int GetUnsignedInt(); + float GetFloat(); + double GetDouble(); + void GetString(char* pString, int nMaxLen = 0); + void Get(void* pMem, int size); + + // Just like scanf, but doesn't work in binary mode + int Scanf(char const* pFmt, ...); + int VaScanf(char const* pFmt, va_list list); + + // Eats white space, advances Get index + void EatWhiteSpace(); + + // Write stuff in + // Binary mode: it'll just write the bits directly in, and strings will be + // written with a null terminating character + // Text mode: it'll convert the numbers to text versions + // PutString will not write a terminating character + void PutChar(char c); + void PutUnsignedChar(unsigned char uc); + void PutShort(short s); + void PutUnsignedShort(unsigned short us); + void PutInt(int i); + void PutUnsignedInt(unsigned int u); + void PutFloat(float f); + void PutDouble(double d); + void PutString(char const* pString); + void Put(void const* pMem, int size); + + // Just like printf, writes a terminating zero in binary mode + void Printf(char const* pFmt, ...); + void VaPrintf(char const* pFmt, va_list list); + + // What am I writing (put)/reading (get)? + void* PeekPut(int offset = 0); + void const* PeekGet(int offset = 0) const; + + // Where am I writing (put)/reading (get)? + int TellPut() const; + int TellGet() const; + + // Change where I'm writing (put)/reading (get) + void SeekPut(SeekType_t type, int offset); + void SeekGet(SeekType_t type, int offset); + + // Buffer base + void const* Base() const; + void* Base(); + + // memory allocation size, does *not* reflect size written or read, + // use TellPut or TellGet for that + int Size() const; + + // Am I a text buffer? + inline bool IsText() const { return (m_Flags & TEXT_BUFFER) != 0; } + + // Am I valid? (overflow or underflow error), Once invalid it stays invalid + inline bool IsValid() const { return m_Error == 0; } + +private: + // error flags + enum + { + PUT_OVERFLOW = 0x1, + GET_OVERFLOW = 0x2, + }; + + // flags + enum + { + TEXT_BUFFER = 0x1, + }; + + // Checks if a get/put is ok + bool CheckPut(int size); + bool CheckGet(int size); + + CUtlMemory m_Memory; + int m_Get; + int m_Put; + unsigned char m_Error; + unsigned char m_Flags; +}; + + +//----------------------------------------------------------------------------- +// Where am I reading? +//----------------------------------------------------------------------------- + +inline int CUtlBuffer::TellGet() const +{ + return m_Get; +} + + +//----------------------------------------------------------------------------- +// What am I reading? +//----------------------------------------------------------------------------- +inline void const* CUtlBuffer::PeekGet(int offset) const +{ + return &m_Memory[m_Get + offset]; +} + + +//----------------------------------------------------------------------------- +// Unserialization +//----------------------------------------------------------------------------- +#define GET_TYPE( _type, _val, _fmt ) \ + if (!IsText()) \ + { \ + if (CheckGet( sizeof(_type) )) \ + { \ + _val = *(_type *)PeekGet(); \ + m_Get += sizeof(_type); \ + } \ + else \ + { \ + _val = 0; \ + } \ + } \ + else \ + { \ + _val = 0; \ + Scanf( _fmt, &_val ); \ + } + +inline char CUtlBuffer::GetChar() +{ + char c; + GET_TYPE(char, c, "%c"); + return c; +} + +inline unsigned char CUtlBuffer::GetUnsignedChar() +{ + unsigned char c; + GET_TYPE(unsigned char, c, "%u"); + return c; +} + +inline short CUtlBuffer::GetShort() +{ + short s; + GET_TYPE(short, s, "%d"); + return s; +} + +inline unsigned short CUtlBuffer::GetUnsignedShort() +{ + unsigned short s; + GET_TYPE(unsigned short, s, "%u"); + return s; +} + +inline int CUtlBuffer::GetInt() +{ + int i; + GET_TYPE(int, i, "%d"); + return i; +} + +inline int CUtlBuffer::GetIntHex() +{ + int i; + GET_TYPE(int, i, "%x"); + return i; +} + +inline unsigned int CUtlBuffer::GetUnsignedInt() +{ + unsigned int u; + GET_TYPE(unsigned int, u, "%u"); + return u; +} + +inline float CUtlBuffer::GetFloat() +{ + float f; + GET_TYPE(float, f, "%f"); + return f; +} + +inline double CUtlBuffer::GetDouble() +{ + double d; + GET_TYPE(double, d, "%f"); + return d; +} + + +//----------------------------------------------------------------------------- +// Where am I writing? +//----------------------------------------------------------------------------- +inline int CUtlBuffer::TellPut() const +{ + return m_Put; +} + + +//----------------------------------------------------------------------------- +// What am I reading? +//----------------------------------------------------------------------------- +inline void* CUtlBuffer::PeekPut(int offset) +{ + return &m_Memory[m_Put + offset]; +} + + +//----------------------------------------------------------------------------- +// Various put methods +//----------------------------------------------------------------------------- +#define PUT_TYPE( _type, _val, _fmt ) \ + if (!IsText()) \ + { \ + if (CheckPut( sizeof(_type) )) \ + { \ + *(_type *)PeekPut() = _val; \ + m_Put += sizeof(_type); \ + } \ + } \ + else \ + { \ + Printf( _fmt, _val ); \ + } + + +inline void CUtlBuffer::PutChar(char c) +{ + PUT_TYPE(char, c, "%c"); +} + +inline void CUtlBuffer::PutUnsignedChar(unsigned char c) +{ + PUT_TYPE(unsigned char, c, "%u"); +} + +inline void CUtlBuffer::PutShort(short s) +{ + PUT_TYPE(short, s, "%d"); +} + +inline void CUtlBuffer::PutUnsignedShort(unsigned short s) +{ + PUT_TYPE(unsigned short, s, "%u"); +} + +inline void CUtlBuffer::PutInt(int i) +{ + PUT_TYPE(int, i, "%d"); +} + +inline void CUtlBuffer::PutUnsignedInt(unsigned int u) +{ + PUT_TYPE(unsigned int, u, "%u"); +} + +inline void CUtlBuffer::PutFloat(float f) +{ + PUT_TYPE(float, f, "%f"); +} + +inline void CUtlBuffer::PutDouble(double d) +{ + PUT_TYPE(double, d, "%f"); +} + +//----------------------------------------------------------------------------- +// Buffer base and size +//----------------------------------------------------------------------------- + +inline void const* CUtlBuffer::Base() const +{ + return m_Memory.Base(); +} + +inline void* CUtlBuffer::Base() +{ + return m_Memory.Base(); +} + +inline int CUtlBuffer::Size() const +{ + return m_Memory.NumAllocated(); +} + + +#endif // UTLBUFFER_H diff --git a/public/utllinkedlist.h b/public/utllinkedlist.h new file mode 100644 index 0000000..a4d973d --- /dev/null +++ b/public/utllinkedlist.h @@ -0,0 +1,693 @@ +//======== (C) Copyright 1999, 2000 Valve, L.L.C. All rights reserved. ======== +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// Purpose: Linked list container class +// +// $Revision: $ +// $NoKeywords: $ +//============================================================================= + +#ifndef UTLLINKEDLIST_H +#define UTLLINKEDLIST_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "osconfig.h" +#include "basetypes.h" +#include "utlmemory.h" +#include "tier0/dbg.h" + + +// This is a useful macro to iterate from head to tail in a linked list. +#define FOR_EACH_LL( listName, iteratorName ) \ + for( int iteratorName=listName.Head(); iteratorName != listName.InvalidIndex(); iteratorName = listName.Next( iteratorName ) ) + +#define INVALID_LLIST_IDX ((I)~0) + +//----------------------------------------------------------------------------- +// class CUtlLinkedList: +// description: +// A lovely index-based linked list! T is the class type, I is the index +// type, which usually should be an unsigned short or smaller. +//----------------------------------------------------------------------------- + +template +class CUtlLinkedList +{ +public: + typedef T ElemType_t; + typedef I IndexType_t; + + // constructor, destructor + CUtlLinkedList(int growSize = 0, int initSize = 0); + CUtlLinkedList(void *pMemory, int memsize); + ~CUtlLinkedList(); + + // gets particular elements + T& Element(I i); + T const& Element(I i) const; + T& operator[](I i); + T const& operator[](I i) const; + + // Make sure we have a particular amount of memory + void EnsureCapacity(int num); + + // Memory deallocation + void Purge(); + + // Delete all the elements then call Purge. + void PurgeAndDeleteElements(); + + // Insertion methods.... + I InsertBefore(I before); + I InsertAfter(I after); + I AddToHead(); + I AddToTail(); + + I InsertBefore(I before, T const& src); + I InsertAfter(I after, T const& src); + I AddToHead(T const& src); + I AddToTail(T const& src); + + // Find an element and return its index or InvalidIndex() if it couldn't be found. + I Find(const T &src) const; + + // Look for the element. If it exists, remove it and return true. Otherwise, return false. + bool FindAndRemove(const T &src); + + // Removal methods + void Remove(I elem); + void RemoveAll(); + + // Allocation/deallocation methods + // If multilist == true, then list list may contain many + // non-connected lists, and IsInList and Head + Tail are meaningless... + I Alloc(bool multilist = false); + void Free(I elem); + + // list modification + void LinkBefore(I before, I elem); + void LinkAfter(I after, I elem); + void Unlink(I elem); + void LinkToHead(I elem); + void LinkToTail(I elem); + + // invalid index + inline static I InvalidIndex() { return INVALID_LLIST_IDX; } + inline static size_t ElementSize() { return sizeof(ListElem_t); } + + // list statistics + int Count() const; + I MaxElementIndex() const; + + // Traversing the list + I Head() const; + I Tail() const; + I Previous(I i) const; + I Next(I i) const; + + // Are nodes in the list or valid? + bool IsValidIndex(I i) const; + bool IsInList(I i) const; + +protected: + // What the linked list element looks like + struct ListElem_t + { + T m_Element; + I m_Previous; + I m_Next; + + private: + // No copy constructor for these... + ListElem_t(const ListElem_t&); + }; + + // constructs the class + I AllocInternal(bool multilist = false); + void ConstructList(); + + // Gets at the list element.... + ListElem_t& InternalElement(I i) { return m_Memory[i]; } + ListElem_t const& InternalElement(I i) const { return m_Memory[i]; } + + void ResetDbgInfo() + { + m_pElements = m_Memory.Base(); + } + + // copy constructors not allowed + CUtlLinkedList(CUtlLinkedList const& list) { Assert(0); } + + CUtlMemory m_Memory; + I m_Head; + I m_Tail; + I m_FirstFree; + I m_ElementCount; // The number actually in the list + I m_TotalElements; // The number allocated + + // For debugging purposes; + // it's in release builds so this can be used in libraries correctly + ListElem_t *m_pElements; +}; + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- + +template +CUtlLinkedList::CUtlLinkedList(int growSize, int initSize) : +m_Memory(growSize, initSize) +{ + ConstructList(); + ResetDbgInfo(); +} + +template +CUtlLinkedList::CUtlLinkedList(void* pMemory, int memsize) : +m_Memory((ListElem_t *)pMemory, memsize / sizeof(ListElem_t)) +{ + ConstructList(); + ResetDbgInfo(); +} + +template +CUtlLinkedList::~CUtlLinkedList() +{ + RemoveAll(); +} + +template +void CUtlLinkedList::ConstructList() +{ + m_Head = InvalidIndex(); + m_Tail = InvalidIndex(); + m_FirstFree = InvalidIndex(); + m_ElementCount = m_TotalElements = 0; +} + + +//----------------------------------------------------------------------------- +// gets particular elements +//----------------------------------------------------------------------------- + +template +inline T& CUtlLinkedList::Element(I i) +{ + return m_Memory[i].m_Element; +} + +template +inline T const& CUtlLinkedList::Element(I i) const +{ + return m_Memory[i].m_Element; +} + +template +inline T& CUtlLinkedList::operator[](I i) +{ + return m_Memory[i].m_Element; +} + +template +inline T const& CUtlLinkedList::operator[](I i) const +{ + return m_Memory[i].m_Element; +} + +//----------------------------------------------------------------------------- +// list statistics +//----------------------------------------------------------------------------- + +template +inline int CUtlLinkedList::Count() const +{ + return m_ElementCount; +} + +template +inline I CUtlLinkedList::MaxElementIndex() const +{ + return m_Memory.NumAllocated(); +} + + +//----------------------------------------------------------------------------- +// Traversing the list +//----------------------------------------------------------------------------- + +template +inline I CUtlLinkedList::Head() const +{ + return m_Head; +} + +template +inline I CUtlLinkedList::Tail() const +{ + return m_Tail; +} + +template +inline I CUtlLinkedList::Previous(I i) const +{ + Assert(IsValidIndex(i)); + return InternalElement(i).m_Previous; +} + +template +inline I CUtlLinkedList::Next(I i) const +{ + Assert(IsValidIndex(i)); + return InternalElement(i).m_Next; +} + + +//----------------------------------------------------------------------------- +// Are nodes in the list or valid? +//----------------------------------------------------------------------------- + +template +inline bool CUtlLinkedList::IsValidIndex(I i) const +{ + return (i < m_TotalElements) && (i >= 0) && + ((m_Memory[i].m_Previous != i) || (m_Memory[i].m_Next == i)); +} + +template +inline bool CUtlLinkedList::IsInList(I i) const +{ + return (i < m_TotalElements) && (i >= 0) && (Previous(i) != i); +} + +//----------------------------------------------------------------------------- +// Makes sure we have enough memory allocated to store a requested # of elements +//----------------------------------------------------------------------------- + +template< class T, class I > +void CUtlLinkedList::EnsureCapacity(int num) +{ + m_Memory.EnsureCapacity(num); + ResetDbgInfo(); +} + + +//----------------------------------------------------------------------------- +// Deallocate memory +//----------------------------------------------------------------------------- + +template +void CUtlLinkedList::Purge() +{ + RemoveAll(); + m_Memory.Purge(); + m_FirstFree = InvalidIndex(); + m_TotalElements = 0; + ResetDbgInfo(); + +} + + +template +void CUtlLinkedList::PurgeAndDeleteElements() +{ + int iNext; + for (int i = Head(); i != InvalidIndex(); i = iNext) + { + iNext = Next(i); + delete Element(i); + } + + Purge(); +} + + +//----------------------------------------------------------------------------- +// Node allocation/deallocation +//----------------------------------------------------------------------------- +template +I CUtlLinkedList::AllocInternal(bool multilist) +{ + I elem; + if (m_FirstFree == InvalidIndex()) + { + // Nothing in the free list; add. + // Since nothing is in the free list, m_TotalElements == total # of elements + // the list knows about. + if (m_TotalElements == m_Memory.NumAllocated()) + m_Memory.Grow(); + + Assert(m_TotalElements != InvalidIndex()); + + elem = (I)m_TotalElements; + ++m_TotalElements; + + if (elem == InvalidIndex()) + { + Error("CUtlLinkedList overflow!\n"); + } + } + else + { + elem = m_FirstFree; + m_FirstFree = InternalElement(m_FirstFree).m_Next; + } + + if (!multilist) + InternalElement(elem).m_Next = InternalElement(elem).m_Previous = elem; + else + InternalElement(elem).m_Next = InternalElement(elem).m_Previous = InvalidIndex(); + + ResetDbgInfo(); + + return elem; +} + +template +I CUtlLinkedList::Alloc(bool multilist) +{ + I elem = AllocInternal(multilist); + Construct(&Element(elem)); + + return elem; +} + +template +void CUtlLinkedList::Free(I elem) +{ + Assert(IsValidIndex(elem)); + Unlink(elem); + + ListElem_t &internalElem = InternalElement(elem); + Destruct(&internalElem.m_Element); + internalElem.m_Next = m_FirstFree; + m_FirstFree = elem; +} + +//----------------------------------------------------------------------------- +// Insertion methods; allocates and links (uses default constructor) +//----------------------------------------------------------------------------- + +template +I CUtlLinkedList::InsertBefore(I before) +{ + // Make a new node + I newNode = AllocInternal(); + + // Link it in + LinkBefore(before, newNode); + + // Construct the data + Construct(&Element(newNode)); + + return newNode; +} + +template +I CUtlLinkedList::InsertAfter(I after) +{ + // Make a new node + I newNode = AllocInternal(); + + // Link it in + LinkAfter(after, newNode); + + // Construct the data + Construct(&Element(newNode)); + + return newNode; +} + +template +inline I CUtlLinkedList::AddToHead() +{ + return InsertAfter(InvalidIndex()); +} + +template +inline I CUtlLinkedList::AddToTail() +{ + return InsertBefore(InvalidIndex()); +} + + +//----------------------------------------------------------------------------- +// Insertion methods; allocates and links (uses copy constructor) +//----------------------------------------------------------------------------- + +template +I CUtlLinkedList::InsertBefore(I before, T const& src) +{ + // Make a new node + I newNode = AllocInternal(); + + // Link it in + LinkBefore(before, newNode); + + // Construct the data + CopyConstruct(&Element(newNode), src); + + return newNode; +} + +template +I CUtlLinkedList::InsertAfter(I after, T const& src) +{ + // Make a new node + I newNode = AllocInternal(); + + // Link it in + LinkAfter(after, newNode); + + // Construct the data + CopyConstruct(&Element(newNode), src); + + return newNode; +} + +template +inline I CUtlLinkedList::AddToHead(T const& src) +{ + return InsertAfter(InvalidIndex(), src); +} + +template +inline I CUtlLinkedList::AddToTail(T const& src) +{ + return InsertBefore(InvalidIndex(), src); +} + + +//----------------------------------------------------------------------------- +// Removal methods +//----------------------------------------------------------------------------- + +template +I CUtlLinkedList::Find(const T &src) const +{ + for (I i = Head(); i != InvalidIndex(); i = Next(i)) + { + if (Element(i) == src) + return i; + } + return InvalidIndex(); +} + + +template +bool CUtlLinkedList::FindAndRemove(const T &src) +{ + I i = Find(src); + if (i == InvalidIndex()) + { + return false; + } + else + { + Remove(i); + return true; + } +} + + +template +void CUtlLinkedList::Remove(I elem) +{ + Free(elem); +} + +template +void CUtlLinkedList::RemoveAll() +{ + if (m_TotalElements == 0) + return; + + // Put everything into the free list + I prev = InvalidIndex(); + for (int i = (int)m_TotalElements; --i >= 0;) + { + // Invoke the destructor + if (IsValidIndex((I)i)) + Destruct(&Element((I)i)); + + // next points to the next free list item + InternalElement((I)i).m_Next = prev; + + // Indicates it's in the free list + InternalElement((I)i).m_Previous = (I)i; + prev = (I)i; + } + + // First free points to the first element + m_FirstFree = 0; + + // Clear everything else out + m_Head = InvalidIndex(); + m_Tail = InvalidIndex(); + m_ElementCount = 0; +} + + +//----------------------------------------------------------------------------- +// list modification +//----------------------------------------------------------------------------- + +template +void CUtlLinkedList::LinkBefore(I before, I elem) +{ + Assert(IsValidIndex(elem)); + + // Unlink it if it's in the list at the moment + Unlink(elem); + + ListElem_t& newElem = InternalElement(elem); + + // The element *after* our newly linked one is the one we linked before. + newElem.m_Next = before; + + if (before == InvalidIndex()) + { + // In this case, we're linking to the end of the list, so reset the tail + newElem.m_Previous = m_Tail; + m_Tail = elem; + } + else + { + // Here, we're not linking to the end. Set the prev pointer to point to + // the element we're linking. + Assert(IsInList(before)); + ListElem_t& beforeElem = InternalElement(before); + newElem.m_Previous = beforeElem.m_Previous; + beforeElem.m_Previous = elem; + } + + // Reset the head if we linked to the head of the list + if (newElem.m_Previous == InvalidIndex()) + m_Head = elem; + else + InternalElement(newElem.m_Previous).m_Next = elem; + + // one more element baby + ++m_ElementCount; +} + +template +void CUtlLinkedList::LinkAfter(I after, I elem) +{ + Assert(IsValidIndex(elem)); + + // Unlink it if it's in the list at the moment + if (IsInList(elem)) + Unlink(elem); + + ListElem_t& newElem = InternalElement(elem); + + // The element *before* our newly linked one is the one we linked after + newElem.m_Previous = after; + if (after == InvalidIndex()) + { + // In this case, we're linking to the head of the list, reset the head + newElem.m_Next = m_Head; + m_Head = elem; + } + else + { + // Here, we're not linking to the end. Set the next pointer to point to + // the element we're linking. + Assert(IsInList(after)); + ListElem_t& afterElem = InternalElement(after); + newElem.m_Next = afterElem.m_Next; + afterElem.m_Next = elem; + } + + // Reset the tail if we linked to the tail of the list + if (newElem.m_Next == InvalidIndex()) + m_Tail = elem; + else + InternalElement(newElem.m_Next).m_Previous = elem; + + // one more element baby + ++m_ElementCount; +} + +template +void CUtlLinkedList::Unlink(I elem) +{ + Assert(IsValidIndex(elem)); + if (IsInList(elem)) + { + ListElem_t *pBase = m_Memory.Base(); + ListElem_t *pOldElem = &pBase[elem]; + + // If we're the first guy, reset the head + // otherwise, make our previous node's next pointer = our next + if (pOldElem->m_Previous != INVALID_LLIST_IDX) + { + pBase[pOldElem->m_Previous].m_Next = pOldElem->m_Next; + } + else + { + m_Head = pOldElem->m_Next; + } + + // If we're the last guy, reset the tail + // otherwise, make our next node's prev pointer = our prev + if (pOldElem->m_Next != INVALID_LLIST_IDX) + { + pBase[pOldElem->m_Next].m_Previous = pOldElem->m_Previous; + } + else + { + m_Tail = pOldElem->m_Previous; + } + + // This marks this node as not in the list, + // but not in the free list either + pOldElem->m_Previous = pOldElem->m_Next = elem; + + // One less puppy + --m_ElementCount; + } +} + +template +inline void CUtlLinkedList::LinkToHead(I elem) +{ + LinkAfter(InvalidIndex(), elem); +} + +template +inline void CUtlLinkedList::LinkToTail(I elem) +{ + LinkBefore(InvalidIndex(), elem); +} + + +#endif // UTLLINKEDLIST_H diff --git a/public/utlmemory.h b/public/utlmemory.h new file mode 100644 index 0000000..071260a --- /dev/null +++ b/public/utlmemory.h @@ -0,0 +1,323 @@ +//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. =========== +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// $Header: $ +// $NoKeywords: $ +// +// A growable memory class. +//============================================================================= + +#ifndef UTLMEMORY_H +#define UTLMEMORY_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "osconfig.h" +#include "tier0/dbg.h" +#include +#include "tier0/platform.h" + +#pragma warning (disable:4100) +#pragma warning (disable:4514) + +//----------------------------------------------------------------------------- +// The CUtlMemory class: +// A growable memory class which doubles in size by default. +//----------------------------------------------------------------------------- +template< class T > +class CUtlMemory +{ +public: + // constructor, destructor + CUtlMemory(int nGrowSize = 0, int nInitSize = 0); + CUtlMemory(T* pMemory, int numElements); + ~CUtlMemory(); + + // element access + T& operator[](int i); + T const& operator[](int i) const; + T& Element(int i); + T const& Element(int i) const; + + // Can we use this index? + bool IsIdxValid(int i) const; + + // Gets the base address (can change when adding elements!) + T* Base(); + T const* Base() const; + + // Attaches the buffer to external memory.... + void SetExternalBuffer(T* pMemory, int numElements); + + // Size + int NumAllocated() const; + int Count() const; + + // Grows the memory, so that at least allocated + num elements are allocated + void Grow(int num = 1); + + // Makes sure we've got at least this much memory + void EnsureCapacity(int num); + + // Memory deallocation + void Purge(); + + // is the memory externally allocated? + bool IsExternallyAllocated() const; + + // Set the size by which the memory grows + void SetGrowSize(int size); + +private: + enum + { + EXTERNAL_BUFFER_MARKER = -1, + }; + + T* m_pMemory; + int m_nAllocationCount; + int m_nGrowSize; +}; + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +template< class T > +CUtlMemory::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemory(0), +m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize) +{ + Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER)); + if (m_nAllocationCount) + { + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + } +} + +template< class T > +CUtlMemory::CUtlMemory(T* pMemory, int numElements) : m_pMemory(pMemory), +m_nAllocationCount(numElements) +{ + // Special marker indicating externally supplied memory + m_nGrowSize = EXTERNAL_BUFFER_MARKER; +} + +template< class T > +CUtlMemory::~CUtlMemory() +{ + Purge(); +} + + +//----------------------------------------------------------------------------- +// Attaches the buffer to external memory.... +//----------------------------------------------------------------------------- +template< class T > +void CUtlMemory::SetExternalBuffer(T* pMemory, int numElements) +{ + // Blow away any existing allocated memory + Purge(); + + m_pMemory = pMemory; + m_nAllocationCount = numElements; + + // Indicate that we don't own the memory + m_nGrowSize = EXTERNAL_BUFFER_MARKER; +} + + +//----------------------------------------------------------------------------- +// element access +//----------------------------------------------------------------------------- +template< class T > +inline T& CUtlMemory::operator[](int i) +{ + Assert(IsIdxValid(i)); + return m_pMemory[i]; +} + +template< class T > +inline T const& CUtlMemory::operator[](int i) const +{ + Assert(IsIdxValid(i)); + return m_pMemory[i]; +} + +template< class T > +inline T& CUtlMemory::Element(int i) +{ + Assert(IsIdxValid(i)); + return m_pMemory[i]; +} + +template< class T > +inline T const& CUtlMemory::Element(int i) const +{ + Assert(IsIdxValid(i)); + return m_pMemory[i]; +} + + +//----------------------------------------------------------------------------- +// is the memory externally allocated? +//----------------------------------------------------------------------------- +template< class T > +bool CUtlMemory::IsExternallyAllocated() const +{ + return m_nGrowSize == EXTERNAL_BUFFER_MARKER; +} + + +template< class T > +void CUtlMemory::SetGrowSize(int nSize) +{ + Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER)); + m_nGrowSize = nSize; +} + + +//----------------------------------------------------------------------------- +// Gets the base address (can change when adding elements!) +//----------------------------------------------------------------------------- +template< class T > +inline T* CUtlMemory::Base() +{ + return m_pMemory; +} + +template< class T > +inline T const* CUtlMemory::Base() const +{ + return m_pMemory; +} + + +//----------------------------------------------------------------------------- +// Size +//----------------------------------------------------------------------------- +template< class T > +inline int CUtlMemory::NumAllocated() const +{ + return m_nAllocationCount; +} + +template< class T > +inline int CUtlMemory::Count() const +{ + return m_nAllocationCount; +} + + +//----------------------------------------------------------------------------- +// Is element index valid? +//----------------------------------------------------------------------------- +template< class T > +inline bool CUtlMemory::IsIdxValid(int i) const +{ + return (i >= 0) && (i < m_nAllocationCount); +} + + +//----------------------------------------------------------------------------- +// Grows the memory +//----------------------------------------------------------------------------- +template< class T > +void CUtlMemory::Grow(int num) +{ + Assert(num > 0); + + if (IsExternallyAllocated()) + { + // Can't grow a buffer whose memory was externally allocated + Assert(0); + return; + } + + // Make sure we have at least numallocated + num allocations. + // Use the grow rules specified for this memory (in m_nGrowSize) + int nAllocationRequested = m_nAllocationCount + num; + while (m_nAllocationCount < nAllocationRequested) + { + if (m_nAllocationCount != 0) + { + if (m_nGrowSize) + { + m_nAllocationCount += m_nGrowSize; + } + else + { + m_nAllocationCount += m_nAllocationCount; + } + } + else + { + // Compute an allocation which is at least as big as a cache line... + m_nAllocationCount = (31 + sizeof(T)) / sizeof(T); + Assert(m_nAllocationCount != 0); + } + } + + if (m_pMemory) + { + m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + } + else + { + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + } +} + + +//----------------------------------------------------------------------------- +// Makes sure we've got at least this much memory +//----------------------------------------------------------------------------- +template< class T > +inline void CUtlMemory::EnsureCapacity(int num) +{ + if (m_nAllocationCount >= num) + return; + + if (IsExternallyAllocated()) + { + // Can't grow a buffer whose memory was externally allocated + Assert(0); + return; + } + + m_nAllocationCount = num; + if (m_pMemory) + { + m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T)); + } + else + { + m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T)); + } +} + + +//----------------------------------------------------------------------------- +// Memory deallocation +//----------------------------------------------------------------------------- +template< class T > +void CUtlMemory::Purge() +{ + if (!IsExternallyAllocated()) + { + if (m_pMemory) + { + free((void*)m_pMemory); + m_pMemory = 0; + } + m_nAllocationCount = 0; + } +} + + +#endif // UTLSTORAGE_H \ No newline at end of file diff --git a/public/utlrbtree.h b/public/utlrbtree.h new file mode 100644 index 0000000..de4890a --- /dev/null +++ b/public/utlrbtree.h @@ -0,0 +1,1295 @@ +//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. =========== +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//============================================================================= + +#ifndef UTLRBTREE_H +#define UTLRBTREE_H + +//#include +#include "utlmemory.h" + +//----------------------------------------------------------------------------- +// Tool to generate a default compare function for any type that implements +// operator<, including all simple types +//----------------------------------------------------------------------------- + +template +class CDefOps +{ +public: + static bool LessFunc( const T &lhs, const T &rhs ) { return ( lhs < rhs ); } +}; + +#define DefLessFunc( type ) CDefOps::LessFunc + +//------------------------------------- + +inline bool StringLessThan( const char * const &lhs, const char * const &rhs) { return ( strcmp( lhs, rhs) < 0 ); } +inline bool CaselessStringLessThan( const char * const &lhs, const char * const &rhs ) { return ( _stricmp( lhs, rhs) < 0 ); } + +//------------------------------------- +// inline these two templates to stop multiple definitions of the same code +template <> inline bool CDefOps::LessFunc( const char * const &lhs, const char * const &rhs ) { return StringLessThan( lhs, rhs ); } +template <> inline bool CDefOps::LessFunc( char * const &lhs, char * const &rhs ) { return StringLessThan( lhs, rhs ); } + +//------------------------------------- + +template +void SetDefLessFunc( RBTREE_T &RBTree ) +{ +#ifdef _WIN32 + RBTree.SetLessFunc( DefLessFunc( RBTREE_T::KeyType_t ) ); +#elif _LINUX + RBTree.SetLessFunc( DefLessFunc( typename RBTREE_T::KeyType_t ) ); +#endif +} + +//----------------------------------------------------------------------------- +// A red-black binary search tree +//----------------------------------------------------------------------------- + +template +class CUtlRBTree +{ +public: + // Less func typedef + // Returns true if the first parameter is "less" than the second + typedef bool (*LessFunc_t)( T const &, T const & ); + + typedef T KeyType_t; + typedef T ElemType_t; + typedef I IndexType_t; + + // constructor, destructor + // Left at growSize = 0, the memory will first allocate 1 element and double in size + // at each increment. + // LessFunc_t is required, but may be set after the constructor using SetLessFunc() below + CUtlRBTree( int growSize = 0, int initSize = 0, LessFunc_t lessfunc = 0 ); + ~CUtlRBTree( ); + + // gets particular elements + T& Element( I i ); + T const &Element( I i ) const; + T& operator[]( I i ); + T const &operator[]( I i ) const; + + // Gets the root + I Root() const; + + // Num elements + unsigned int Count() const; + + // Max "size" of the vector + I MaxElement() const; + + // Gets the children + I Parent( I i ) const; + I LeftChild( I i ) const; + I RightChild( I i ) const; + + // Tests if a node is a left or right child + bool IsLeftChild( I i ) const; + bool IsRightChild( I i ) const; + + // Tests if root or leaf + bool IsRoot( I i ) const; + bool IsLeaf( I i ) const; + + // Checks if a node is valid and in the tree + bool IsValidIndex( I i ) const; + + // Checks if the tree as a whole is valid + bool IsValid() const; + + // Invalid index + static I InvalidIndex(); + + // returns the tree depth (not a very fast operation) + int Depth( I node ) const; + int Depth() const; + + // Sets the less func + void SetLessFunc( LessFunc_t func ); + + // Allocation method + I NewNode(); + + // Insert method (inserts in order) + I Insert( T const &insert ); + void Insert( const T *pArray, int nItems ); + + // Find method + I Find( T const &search ) const; + + // Remove methods + void RemoveAt( I i ); + bool Remove( T const &remove ); + void RemoveAll( ); + + // Allocation, deletion + void FreeNode( I i ); + + // Iteration + I FirstInorder() const; + I NextInorder( I i ) const; + I PrevInorder( I i ) const; + I LastInorder() const; + + I FirstPreorder() const; + I NextPreorder( I i ) const; + I PrevPreorder( I i ) const; + I LastPreorder( ) const; + + I FirstPostorder() const; + I NextPostorder( I i ) const; + + // If you change the search key, this can be used to reinsert the + // element into the tree. + void Reinsert( I elem ); + + +protected: + enum NodeColor_t + { + RED = 0, + BLACK + }; + + struct Links_t + { + I m_Left; + I m_Right; + I m_Parent; + I m_Tag; + }; + + struct Node_t : public Links_t + { + T m_Data; + }; + + // Sets the children + void SetParent( I i, I parent ); + void SetLeftChild( I i, I child ); + void SetRightChild( I i, I child ); + void LinkToParent( I i, I parent, bool isLeft ); + + // Gets at the links + Links_t const &Links( I i ) const; + Links_t &Links( I i ); + + // Checks if a link is red or black + bool IsRed( I i ) const; + bool IsBlack( I i ) const; + + // Sets/gets node color + NodeColor_t Color( I i ) const; + void SetColor( I i, NodeColor_t c ); + + // operations required to preserve tree balance + void RotateLeft(I i); + void RotateRight(I i); + void InsertRebalance(I i); + void RemoveRebalance(I i); + + // Insertion, removal + I InsertAt( I parent, bool leftchild ); + + // copy constructors not allowed + CUtlRBTree( CUtlRBTree const &tree ); + + // Inserts a node into the tree, doesn't copy the data in. + void FindInsertionPosition( T const &insert, I &parent, bool &leftchild ); + + // Remove and add back an element in the tree. + void Unlink( I elem ); + void Link( I elem ); + + // Used for sorting. + LessFunc_t m_LessFunc; + + CUtlMemory m_Elements; + I m_Root; + I m_NumElements; + I m_FirstFree; + I m_TotalElements; + + Node_t* m_pElements; + + void ResetDbgInfo() + { + m_pElements = (Node_t*)m_Elements.Base(); + } +}; + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- + +template +CUtlRBTree::CUtlRBTree( int growSize, int initSize, LessFunc_t lessfunc ) : + m_Elements( growSize, initSize ), + m_LessFunc( lessfunc ), + m_Root( InvalidIndex() ), + m_NumElements( 0 ), m_TotalElements( 0 ), + m_FirstFree( InvalidIndex() ) +{ + ResetDbgInfo(); +} + +template +CUtlRBTree::~CUtlRBTree() +{ +} + +//----------------------------------------------------------------------------- +// gets particular elements +//----------------------------------------------------------------------------- + +template +inline T &CUtlRBTree::Element( I i ) +{ + return m_Elements[i].m_Data; +} + +template +inline T const &CUtlRBTree::Element( I i ) const +{ + return m_Elements[i].m_Data; +} + +template +inline T &CUtlRBTree::operator[]( I i ) +{ + return Element(i); +} + +template +inline T const &CUtlRBTree::operator[]( I i ) const +{ + return Element(i); +} + +//----------------------------------------------------------------------------- +// +// various accessors +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Gets the root +//----------------------------------------------------------------------------- + +template +inline I CUtlRBTree::Root() const +{ + return m_Root; +} + +//----------------------------------------------------------------------------- +// Num elements +//----------------------------------------------------------------------------- + +template +inline unsigned int CUtlRBTree::Count() const +{ + return (unsigned int)m_NumElements; +} + +//----------------------------------------------------------------------------- +// Max "size" of the vector +//----------------------------------------------------------------------------- + +template +inline I CUtlRBTree::MaxElement() const +{ + return (I)m_TotalElements; +} + + +//----------------------------------------------------------------------------- +// Gets the children +//----------------------------------------------------------------------------- + +template +inline I CUtlRBTree::Parent( I i ) const +{ + return Links(i).m_Parent; +} + +template +inline I CUtlRBTree::LeftChild( I i ) const +{ + return Links(i).m_Left; +} + +template +inline I CUtlRBTree::RightChild( I i ) const +{ + return Links(i).m_Right; +} + +//----------------------------------------------------------------------------- +// Tests if a node is a left or right child +//----------------------------------------------------------------------------- + +template +inline bool CUtlRBTree::IsLeftChild( I i ) const +{ + return LeftChild(Parent(i)) == i; +} + +template +inline bool CUtlRBTree::IsRightChild( I i ) const +{ + return RightChild(Parent(i)) == i; +} + + +//----------------------------------------------------------------------------- +// Tests if root or leaf +//----------------------------------------------------------------------------- + +template +inline bool CUtlRBTree::IsRoot( I i ) const +{ + return i == m_Root; +} + +template +inline bool CUtlRBTree::IsLeaf( I i ) const +{ + return (LeftChild(i) == InvalidIndex()) && (RightChild(i) == InvalidIndex()); +} + + +//----------------------------------------------------------------------------- +// Checks if a node is valid and in the tree +//----------------------------------------------------------------------------- + +template +inline bool CUtlRBTree::IsValidIndex( I i ) const +{ + return LeftChild(i) != i; +} + + +//----------------------------------------------------------------------------- +// Invalid index +//----------------------------------------------------------------------------- + +template +I CUtlRBTree::InvalidIndex() +{ + return (I)~0; +} + + +//----------------------------------------------------------------------------- +// returns the tree depth (not a very fast operation) +//----------------------------------------------------------------------------- + +template +inline int CUtlRBTree::Depth() const +{ + return Depth(Root()); +} + +//----------------------------------------------------------------------------- +// Sets the children +//----------------------------------------------------------------------------- + +template +inline void CUtlRBTree::SetParent( I i, I parent ) +{ + Links(i).m_Parent = parent; +} + +template +inline void CUtlRBTree::SetLeftChild( I i, I child ) +{ + Links(i).m_Left = child; +} + +template +inline void CUtlRBTree::SetRightChild( I i, I child ) +{ + Links(i).m_Right = child; +} + +//----------------------------------------------------------------------------- +// Gets at the links +//----------------------------------------------------------------------------- + +template +inline typename CUtlRBTree::Links_t const &CUtlRBTree::Links( I i ) const +{ + // Sentinel node, makes life easier + static Links_t s_Sentinel = + { + InvalidIndex(), InvalidIndex(), InvalidIndex(), CUtlRBTree::BLACK + }; + + return (i != InvalidIndex()) ? *(Links_t*)&m_Elements[i] : + *(Links_t*)&s_Sentinel; +} + +template +inline typename CUtlRBTree::Links_t &CUtlRBTree::Links( I i ) +{ + Assert(i != InvalidIndex()); + return *(Links_t *)&m_Elements[i]; +} + +//----------------------------------------------------------------------------- +// Checks if a link is red or black +//----------------------------------------------------------------------------- + +template +inline bool CUtlRBTree::IsRed( I i ) const +{ + return (Links(i).m_Tag == RED); +} + +template +inline bool CUtlRBTree::IsBlack( I i ) const +{ + return (Links(i).m_Tag == BLACK); +} + + +//----------------------------------------------------------------------------- +// Sets/gets node color +//----------------------------------------------------------------------------- + +template +inline typename CUtlRBTree::NodeColor_t CUtlRBTree::Color( I i ) const +{ + return (NodeColor_t)Links(i).m_Tag; +} + +template +inline void CUtlRBTree::SetColor( I i, typename CUtlRBTree::NodeColor_t c ) +{ + Links(i).m_Tag = (I)c; +} + +//----------------------------------------------------------------------------- +// Allocates/ deallocates nodes +//----------------------------------------------------------------------------- + +template +I CUtlRBTree::NewNode() +{ + I newElem; + + // Nothing in the free list; add. + if (m_FirstFree == InvalidIndex()) + { + if (m_Elements.NumAllocated() == m_TotalElements) + m_Elements.Grow(); + newElem = m_TotalElements++; + } + else + { + newElem = m_FirstFree; + m_FirstFree = RightChild(m_FirstFree); + } + +#ifdef _DEBUG + // reset links to invalid.... + Links_t &node = Links(newElem); + node.m_Left = node.m_Right = node.m_Parent = InvalidIndex(); +#endif + + Construct( &Element(newElem) ); + ResetDbgInfo(); + + return newElem; +} + +template +void CUtlRBTree::FreeNode( I i ) +{ + Assert( IsValidIndex(i) && (i != InvalidIndex()) ); + Destruct( &Element(i) ); + SetLeftChild( i, i ); // indicates it's in not in the tree + SetRightChild( i, m_FirstFree ); + m_FirstFree = i; +} + + +//----------------------------------------------------------------------------- +// Rotates node i to the left +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::RotateLeft(I elem) +{ + I rightchild = RightChild(elem); + SetRightChild( elem, LeftChild(rightchild) ); + if (LeftChild(rightchild) != InvalidIndex()) + SetParent( LeftChild(rightchild), elem ); + + if (rightchild != InvalidIndex()) + SetParent( rightchild, Parent(elem) ); + if (!IsRoot(elem)) + { + if (IsLeftChild(elem)) + SetLeftChild( Parent(elem), rightchild ); + else + SetRightChild( Parent(elem), rightchild ); + } + else + m_Root = rightchild; + + SetLeftChild( rightchild, elem ); + if (elem != InvalidIndex()) + SetParent( elem, rightchild ); +} + + +//----------------------------------------------------------------------------- +// Rotates node i to the right +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::RotateRight(I elem) +{ + I leftchild = LeftChild(elem); + SetLeftChild( elem, RightChild(leftchild) ); + if (RightChild(leftchild) != InvalidIndex()) + SetParent( RightChild(leftchild), elem ); + + if (leftchild != InvalidIndex()) + SetParent( leftchild, Parent(elem) ); + if (!IsRoot(elem)) + { + if (IsRightChild(elem)) + SetRightChild( Parent(elem), leftchild ); + else + SetLeftChild( Parent(elem), leftchild ); + } + else + m_Root = leftchild; + + SetRightChild( leftchild, elem ); + if (elem != InvalidIndex()) + SetParent( elem, leftchild ); +} + + +//----------------------------------------------------------------------------- +// Rebalances the tree after an insertion +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::InsertRebalance(I elem) +{ + while ( !IsRoot(elem) && (Color(Parent(elem)) == RED) ) + { + I parent = Parent(elem); + I grandparent = Parent(parent); + + /* we have a violation */ + if (IsLeftChild(parent)) + { + I uncle = RightChild(grandparent); + if (IsRed(uncle)) + { + /* uncle is RED */ + SetColor(parent, BLACK); + SetColor(uncle, BLACK); + SetColor(grandparent, RED); + elem = grandparent; + } + else + { + /* uncle is BLACK */ + if (IsRightChild(elem)) + { + /* make x a left child, will change parent and grandparent */ + elem = parent; + RotateLeft(elem); + parent = Parent(elem); + grandparent = Parent(parent); + } + /* recolor and rotate */ + SetColor(parent, BLACK); + SetColor(grandparent, RED); + RotateRight(grandparent); + } + } + else + { + /* mirror image of above code */ + I uncle = LeftChild(grandparent); + if (IsRed(uncle)) + { + /* uncle is RED */ + SetColor(parent, BLACK); + SetColor(uncle, BLACK); + SetColor(grandparent, RED); + elem = grandparent; + } + else + { + /* uncle is BLACK */ + if (IsLeftChild(elem)) + { + /* make x a right child, will change parent and grandparent */ + elem = parent; + RotateRight(parent); + parent = Parent(elem); + grandparent = Parent(parent); + } + /* recolor and rotate */ + SetColor(parent, BLACK); + SetColor(grandparent, RED); + RotateLeft(grandparent); + } + } + } + SetColor( m_Root, BLACK ); +} + + +//----------------------------------------------------------------------------- +// Insert a node into the tree +//----------------------------------------------------------------------------- + +template +I CUtlRBTree::InsertAt( I parent, bool leftchild ) +{ + I i = NewNode(); + LinkToParent( i, parent, leftchild ); + ++m_NumElements; + return i; +} + +template +void CUtlRBTree::LinkToParent( I i, I parent, bool isLeft ) +{ + Links_t &elem = Links(i); + elem.m_Parent = parent; + elem.m_Left = elem.m_Right = InvalidIndex(); + elem.m_Tag = RED; + + /* insert node in tree */ + if (parent != InvalidIndex()) + { + if (isLeft) + Links(parent).m_Left = i; + else + Links(parent).m_Right = i; + } + else + { + m_Root = i; + } + + InsertRebalance(i); + + Assert(IsValid()); +} + +//----------------------------------------------------------------------------- +// Rebalance the tree after a deletion +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::RemoveRebalance(I elem) +{ + while (elem != m_Root && IsBlack(elem)) + { + I parent = Parent(elem); + + // If elem is the left child of the parent + if (elem == LeftChild(parent)) + { + // Get our sibling + I sibling = RightChild(parent); + if (IsRed(sibling)) + { + SetColor(sibling, BLACK); + SetColor(parent, RED); + RotateLeft(parent); + + // We may have a new parent now + parent = Parent(elem); + sibling = RightChild(parent); + } + if ( (IsBlack(LeftChild(sibling))) && (IsBlack(RightChild(sibling))) ) + { + if (sibling != InvalidIndex()) + SetColor(sibling, RED); + elem = parent; + } + else + { + if (IsBlack(RightChild(sibling))) + { + SetColor(LeftChild(sibling), BLACK); + SetColor(sibling, RED); + RotateRight(sibling); + + // rotation may have changed this + parent = Parent(elem); + sibling = RightChild(parent); + } + SetColor( sibling, Color(parent) ); + SetColor( parent, BLACK ); + SetColor( RightChild(sibling), BLACK ); + RotateLeft( parent ); + elem = m_Root; + } + } + else + { + // Elem is the right child of the parent + I sibling = LeftChild(parent); + if (IsRed(sibling)) + { + SetColor(sibling, BLACK); + SetColor(parent, RED); + RotateRight(parent); + + // We may have a new parent now + parent = Parent(elem); + sibling = LeftChild(parent); + } + if ( (IsBlack(RightChild(sibling))) && (IsBlack(LeftChild(sibling))) ) + { + if (sibling != InvalidIndex()) + SetColor( sibling, RED ); + elem = parent; + } + else + { + if (IsBlack(LeftChild(sibling))) + { + SetColor( RightChild(sibling), BLACK ); + SetColor( sibling, RED ); + RotateLeft( sibling ); + + // rotation may have changed this + parent = Parent(elem); + sibling = LeftChild(parent); + } + SetColor( sibling, Color(parent) ); + SetColor( parent, BLACK ); + SetColor( LeftChild(sibling), BLACK ); + RotateRight( parent ); + elem = m_Root; + } + } + } + SetColor( elem, BLACK ); +} + +template +void CUtlRBTree::Unlink( I elem ) +{ + if ( elem != InvalidIndex() ) + { + I x, y; + + if ((LeftChild(elem) == InvalidIndex()) || + (RightChild(elem) == InvalidIndex())) + { + /* y has a NIL node as a child */ + y = elem; + } + else + { + /* find tree successor with a NIL node as a child */ + y = RightChild(elem); + while (LeftChild(y) != InvalidIndex()) + y = LeftChild(y); + } + + /* x is y's only child */ + if (LeftChild(y) != InvalidIndex()) + x = LeftChild(y); + else + x = RightChild(y); + + /* remove y from the parent chain */ + if (x != InvalidIndex()) + SetParent( x, Parent(y) ); + if (!IsRoot(y)) + { + if (IsLeftChild(y)) + SetLeftChild( Parent(y), x ); + else + SetRightChild( Parent(y), x ); + } + else + m_Root = x; + + // need to store this off now, we'll be resetting y's color + NodeColor_t ycolor = Color(y); + if (y != elem) + { + // Standard implementations copy the data around, we cannot here. + // Hook in y to link to the same stuff elem used to. + SetParent( y, Parent(elem) ); + SetRightChild( y, RightChild(elem) ); + SetLeftChild( y, LeftChild(elem) ); + + if (!IsRoot(elem)) + if (IsLeftChild(elem)) + SetLeftChild( Parent(elem), y ); + else + SetRightChild( Parent(elem), y ); + else + m_Root = y; + + if (LeftChild(y) != InvalidIndex()) + SetParent( LeftChild(y), y ); + if (RightChild(y) != InvalidIndex()) + SetParent( RightChild(y), y ); + + SetColor( y, Color(elem) ); + } + + if ((x != InvalidIndex()) && (ycolor == BLACK)) + RemoveRebalance(x); + } +} + +template +void CUtlRBTree::Link( I elem ) +{ + if ( elem != InvalidIndex() ) + { + I parent; + bool leftchild; + + FindInsertionPosition( Element( elem ), parent, leftchild ); + + LinkToParent( elem, parent, leftchild ); + } +} + +//----------------------------------------------------------------------------- +// Delete a node from the tree +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::RemoveAt(I elem) +{ + if ( elem != InvalidIndex() ) + { + Unlink( elem ); + + FreeNode(elem); + --m_NumElements; + } +} + + +//----------------------------------------------------------------------------- +// remove a node in the tree +//----------------------------------------------------------------------------- + +template bool CUtlRBTree::Remove( T const &search ) +{ + I node = Find( search ); + if (node != InvalidIndex()) + { + RemoveAt(node); + return true; + } + return false; +} + + +//----------------------------------------------------------------------------- +// Removes all nodes from the tree +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::RemoveAll() +{ + // Just iterate through the whole list and add to free list + // much faster than doing all of the rebalancing + // also, do it so the free list is pointing to stuff in order + // to get better cache coherence when re-adding stuff to this tree. + I prev = InvalidIndex(); + for (int i = (int)m_TotalElements; --i >= 0; ) + { + I idx = (I)i; + if (IsValidIndex(idx)) + Destruct( &Element(idx) ); + SetRightChild( idx, prev ); + SetLeftChild( idx, idx ); + prev = idx; + } + m_FirstFree = m_TotalElements ? (I)0 : InvalidIndex(); + m_Root = InvalidIndex(); + m_NumElements = 0; +} + + +//----------------------------------------------------------------------------- +// iteration +//----------------------------------------------------------------------------- + +template +I CUtlRBTree::FirstInorder() const +{ + I i = m_Root; + while (LeftChild(i) != InvalidIndex()) + i = LeftChild(i); + return i; +} + +template +I CUtlRBTree::NextInorder( I i ) const +{ + Assert(IsValidIndex(i)); + + if (RightChild(i) != InvalidIndex()) + { + i = RightChild(i); + while (LeftChild(i) != InvalidIndex()) + i = LeftChild(i); + return i; + } + + I parent = Parent(i); + while (IsRightChild(i)) + { + i = parent; + if (i == InvalidIndex()) break; + parent = Parent(i); + } + return parent; +} + +template +I CUtlRBTree::PrevInorder( I i ) const +{ + Assert(IsValidIndex(i)); + + if (LeftChild(i) != InvalidIndex()) + { + i = LeftChild(i); + while (RightChild(i) != InvalidIndex()) + i = RightChild(i); + return i; + } + + I parent = Parent(i); + while (IsLeftChild(i)) + { + i = parent; + if (i == InvalidIndex()) break; + parent = Parent(i); + } + return parent; +} + +template +I CUtlRBTree::LastInorder() const +{ + I i = m_Root; + while (RightChild(i) != InvalidIndex()) + i = RightChild(i); + return i; +} + +template +I CUtlRBTree::FirstPreorder() const +{ + return m_Root; +} + +template +I CUtlRBTree::NextPreorder( I i ) const +{ + if (LeftChild(i) != InvalidIndex()) + return LeftChild(i); + + if (RightChild(i) != InvalidIndex()) + return RightChild(i); + + I parent = Parent(i); + while( parent != InvalidIndex()) + { + if (IsLeftChild(i) && (RightChild(parent) != InvalidIndex())) + return RightChild(parent); + i = parent; + parent = Parent(parent); + } + return InvalidIndex(); +} + +template +I CUtlRBTree::PrevPreorder( I i ) const +{ + Assert(0); // not implemented yet + return InvalidIndex(); +} + +template +I CUtlRBTree::LastPreorder() const +{ + I i = m_Root; + while (1) + { + while (RightChild(i) != InvalidIndex()) + i = RightChild(i); + + if (LeftChild(i) != InvalidIndex()) + i = LeftChild(i); + else + break; + } + return i; +} + +template +I CUtlRBTree::FirstPostorder() const +{ + I i = m_Root; + while (!IsLeaf(i)) + { + if (LeftChild(i)) + i = LeftChild(i); + else + i = RightChild(i); + } + return i; +} + +template +I CUtlRBTree::NextPostorder( I i ) const +{ + I parent = Parent(i); + if (parent == InvalidIndex()) + return InvalidIndex(); + + if (IsRightChild(i)) + return parent; + + if (RightChild(parent) == InvalidIndex()) + return parent; + + i = RightChild(parent); + while (!IsLeaf(i)) + { + if (LeftChild(i)) + i = LeftChild(i); + else + i = RightChild(i); + } + return i; +} + + +template +void CUtlRBTree::Reinsert( I elem ) +{ + Unlink( elem ); + Link( elem ); +} + + +//----------------------------------------------------------------------------- +// returns the tree depth (not a very fast operation) +//----------------------------------------------------------------------------- + +template +int CUtlRBTree::Depth( I node ) const +{ + if (node == InvalidIndex()) + return 0; + + int depthright = Depth( RightChild(node) ); + int depthleft = Depth( LeftChild(node) ); + return max(depthright, depthleft) + 1; +} + + +//----------------------------------------------------------------------------- +// Makes sure the tree is valid after every operation +//----------------------------------------------------------------------------- + +template +bool CUtlRBTree::IsValid() const +{ + if ( !Count() ) + return true; + + if (( Root() >= MaxElement()) || ( Parent( Root() ) != InvalidIndex() )) + goto InvalidTree; + +#ifdef UTLTREE_PARANOID + + // First check to see that mNumEntries matches reality. + // count items on the free list + int numFree = 0; + int curr = m_FirstFree; + while (curr != InvalidIndex()) + { + ++numFree; + curr = RightChild(curr); + if ( (curr > MaxElement()) && (curr != InvalidIndex()) ) + goto InvalidTree; + } + if (MaxElement() - numFree != Count()) + goto InvalidTree; + + // iterate over all elements, looking for validity + // based on the self pointers + int numFree2 = 0; + for (curr = 0; curr < MaxElement(); ++curr) + { + if (!IsValidIndex(curr)) + ++numFree2; + else + { + int right = RightChild(curr); + int left = LeftChild(curr); + if ((right == left) && (right != InvalidIndex()) ) + goto InvalidTree; + + if (right != InvalidIndex()) + { + if (!IsValidIndex(right)) + goto InvalidTree; + if (Parent(right) != curr) + goto InvalidTree; + if (IsRed(curr) && IsRed(right)) + goto InvalidTree; + } + + if (left != InvalidIndex()) + { + if (!IsValidIndex(left)) + goto InvalidTree; + if (Parent(left) != curr) + goto InvalidTree; + if (IsRed(curr) && IsRed(left)) + goto InvalidTree; + } + } + } + if (numFree2 != numFree) + goto InvalidTree; + +#endif // UTLTREE_PARANOID + + return true; + +InvalidTree: + return false; +} + + +//----------------------------------------------------------------------------- +// Sets the less func +//----------------------------------------------------------------------------- + +template +void CUtlRBTree::SetLessFunc( typename CUtlRBTree::LessFunc_t func ) +{ + if (!m_LessFunc) + m_LessFunc = func; + else + { + // need to re-sort the tree here.... + Assert(0); + } +} + + +//----------------------------------------------------------------------------- +// inserts a node into the tree +//----------------------------------------------------------------------------- + +// Inserts a node into the tree, doesn't copy the data in. +template +void CUtlRBTree::FindInsertionPosition( T const &insert, I &parent, bool &leftchild ) +{ + Assert( m_LessFunc ); + + /* find where node belongs */ + I current = m_Root; + parent = InvalidIndex(); + leftchild = false; + while (current != InvalidIndex()) + { + parent = current; + if (m_LessFunc( insert, Element(current) )) + { + leftchild = true; current = LeftChild(current); + } + else + { + leftchild = false; current = RightChild(current); + } + } +} + +template +I CUtlRBTree::Insert( T const &insert ) +{ + // use copy constructor to copy it in + I parent; + bool leftchild; + FindInsertionPosition( insert, parent, leftchild ); + I newNode = InsertAt( parent, leftchild ); + CopyConstruct( &Element( newNode ), insert ); + return newNode; +} + + +template +void CUtlRBTree::Insert( const T *pArray, int nItems ) +{ + while ( nItems-- ) + { + Insert( *pArray++ ); + } +} + +//----------------------------------------------------------------------------- +// finds a node in the tree +//----------------------------------------------------------------------------- + +template +I CUtlRBTree::Find( T const &search ) const +{ + Assert( m_LessFunc ); + + I current = m_Root; + while (current != InvalidIndex()) + { + if (m_LessFunc( search, Element(current) )) + current = LeftChild(current); + else if (m_LessFunc( Element(current), search )) + current = RightChild(current); + else + break; + } + return current; +} + + + + + +#endif // UTLRBTREE_H diff --git a/public/utlvector.h b/public/utlvector.h new file mode 100644 index 0000000..5181a64 --- /dev/null +++ b/public/utlvector.h @@ -0,0 +1,574 @@ +//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. =========== +// +// The copyright to the contents herein is the property of Valve, L.L.C. +// The contents may be used and/or copied only with the written permission of +// Valve, L.L.C., or in accordance with the terms and conditions stipulated in +// the agreement/contract under which the contents have been supplied. +// +// $Header: $ +// $NoKeywords: $ +// +// A growable memory class. +//============================================================================= + +#ifndef UTLVECTOR_H +#define UTLVECTOR_H +#ifdef _WIN32 +#pragma once +#endif + +#include "utlmemory.h" +#include "tier0/platform.h" + +template +class CUtlVector +{ +public: + typedef T ElemType_t; + + // constructor, destructor + CUtlVector( int growSize = 0, int initSize = 0 ); + CUtlVector( T* pMemory, int numElements ); + ~CUtlVector(); + + // Copy the array. + CUtlVector& operator=( const CUtlVector &other ); + + // element access + T& operator[]( int i ); + T const& operator[]( int i ) const; + T& Element( int i ); + T const& Element( int i ) const; + + // Gets the base address (can change when adding elements!) + T* Base(); + T const* Base() const; + + // Returns the number of elements in the vector + // SIZE IS DEPRECATED! + int Count() const; + int Size() const; // don't use me! + + // Is element index valid? + bool IsValidIndex( int i ) const; + static int InvalidIndex( void ); + + // Adds an element, uses default constructor + int AddToHead(); + int AddToTail(); + int InsertBefore( int elem ); + int InsertAfter( int elem ); + + // Adds an element, uses copy constructor + int AddToHead( T const& src ); + int AddToTail( T const& src ); + int InsertBefore( int elem, T const& src ); + int InsertAfter( int elem, T const& src ); + + // Adds multiple elements, uses default constructor + int AddMultipleToHead( int num ); + int AddMultipleToTail( int num, const T *pToCopy=NULL ); + int InsertMultipleBefore( int elem, int num, const T *pToCopy=NULL ); // If pToCopy is set, then it's an array of length 'num' and + int InsertMultipleAfter( int elem, int num ); + + // Calls RemoveAll() then AddMultipleToTail. + void SetSize( int size ); + void SetCount( int count ); + + // Calls SetSize and copies each element. + void CopyArray( T const *pArray, int size ); + + // Add the specified array to the tail. + int AddVectorToTail( CUtlVector const &src ); + + // Finds an element (element needs operator== defined) + int Find( T const& src ) const; + + bool HasElement( T const& src ); + + // Makes sure we have enough memory allocated to store a requested # of elements + void EnsureCapacity( int num ); + + // Makes sure we have at least this many elements + void EnsureCount( int num ); + + // Element removal + void FastRemove( int elem ); // doesn't preserve order + void Remove( int elem ); // preserves order, shifts elements + void FindAndRemove( T const& src ); // removes first occurrence of src, preserves order, shifts elements + void RemoveMultiple( int elem, int num ); // preserves order, shifts elements + void RemoveAll(); // doesn't deallocate memory + + // Memory deallocation + void Purge(); + + // Purges the list and calls delete on each element in it. + void PurgeAndDeleteElements(); + + // Set the size by which it grows when it needs to allocate more memory. + void SetGrowSize( int size ); + +protected: + // Can't copy this unless we explicitly do it! + CUtlVector( CUtlVector const& vec ) { assert(0); + } + + // Grows the vector + void GrowVector( int num = 1 ); + + // Shifts elements.... + void ShiftElementsRight( int elem, int num = 1 ); + void ShiftElementsLeft( int elem, int num = 1 ); + + // For easier access to the elements through the debugger + void ResetDbgInfo(); + + CUtlMemory m_Memory; + int m_Size; + + // For easier access to the elements through the debugger + // it's in release builds so this can be used in libraries correctly + T *m_pElements; +}; + +//----------------------------------------------------------------------------- +// For easier access to the elements through the debugger +//----------------------------------------------------------------------------- +template< class T > +inline void CUtlVector::ResetDbgInfo() +{ + m_pElements = m_Memory.Base(); +} + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +template< class T > +inline CUtlVector::CUtlVector( int growSize, int initSize ) : + m_Memory(growSize, initSize), m_Size(0) +{ + ResetDbgInfo(); +} + +template< class T > +inline CUtlVector::CUtlVector( T* pMemory, int numElements ) : + m_Memory(pMemory, numElements), m_Size(0) +{ + ResetDbgInfo(); +} + +template< class T > +inline CUtlVector::~CUtlVector() +{ + Purge(); +} + +template +inline CUtlVector& CUtlVector::operator=( const CUtlVector &other ) +{ + CopyArray( other.Base(), other.Count() ); + return *this; +} + +//----------------------------------------------------------------------------- +// element access +//----------------------------------------------------------------------------- +template< class T > +inline T& CUtlVector::operator[]( int i ) +{ + assert( IsValidIndex(i) ); + return m_Memory[i]; +} + +template< class T > +inline T const& CUtlVector::operator[]( int i ) const +{ + assert( IsValidIndex(i) ); + return m_Memory[i]; +} + +template< class T > +inline T& CUtlVector::Element( int i ) +{ + assert( IsValidIndex(i) ); + return m_Memory[i]; +} + +template< class T > +inline T const& CUtlVector::Element( int i ) const +{ + assert( IsValidIndex(i) ); + return m_Memory[i]; +} + +//----------------------------------------------------------------------------- +// Gets the base address (can change when adding elements!) +//----------------------------------------------------------------------------- +template< class T > +inline T* CUtlVector::Base() +{ + return m_Memory.Base(); +} + +template< class T > +inline T const* CUtlVector::Base() const +{ + return m_Memory.Base(); +} + +//----------------------------------------------------------------------------- +// Count +//----------------------------------------------------------------------------- +template< class T > +inline int CUtlVector::Size() const +{ + return m_Size; +} + +template< class T > +inline int CUtlVector::Count() const +{ + return m_Size; +} + +//----------------------------------------------------------------------------- +// Is element index valid? +//----------------------------------------------------------------------------- +template< class T > +inline bool CUtlVector::IsValidIndex( int i ) const +{ + return (i >= 0) && (i < m_Size); +} + +//----------------------------------------------------------------------------- +// Returns in invalid index +//----------------------------------------------------------------------------- +template< class T > +inline int CUtlVector::InvalidIndex( void ) +{ + return -1; +} + +//----------------------------------------------------------------------------- +// Grows the vector +//----------------------------------------------------------------------------- +template< class T > +void CUtlVector::GrowVector( int num ) +{ + if (m_Size + num - 1 >= m_Memory.NumAllocated()) + { + m_Memory.Grow( m_Size + num - m_Memory.NumAllocated() ); + } + + m_Size += num; + ResetDbgInfo(); +} + +//----------------------------------------------------------------------------- +// Makes sure we have enough memory allocated to store a requested # of elements +//----------------------------------------------------------------------------- +template< class T > +void CUtlVector::EnsureCapacity( int num ) +{ + m_Memory.EnsureCapacity(num); + ResetDbgInfo(); +} + +//----------------------------------------------------------------------------- +// Makes sure we have at least this many elements +//----------------------------------------------------------------------------- +template< class T > +void CUtlVector::EnsureCount( int num ) +{ + if (Count() < num) + AddMultipleToTail( num - Count() ); +} + +//----------------------------------------------------------------------------- +// Shifts elements +//----------------------------------------------------------------------------- +template< class T > +void CUtlVector::ShiftElementsRight( int elem, int num ) +{ + assert( IsValidIndex(elem) || ( m_Size == 0 ) || ( num == 0 )); + int numToMove = m_Size - elem - num; + if ((numToMove > 0) && (num > 0)) + memmove( &Element(elem+num), &Element(elem), numToMove * sizeof(T) ); +} + +template< class T > +void CUtlVector::ShiftElementsLeft( int elem, int num ) +{ + assert( IsValidIndex(elem) || ( m_Size == 0 ) || ( num == 0 )); + int numToMove = m_Size - elem - num; + if ((numToMove > 0) && (num > 0)) + { + memmove( &Element(elem), &Element(elem+num), numToMove * sizeof(T) ); + +#ifdef _DEBUG + memset( &Element(m_Size-num), 0xDD, num * sizeof(T) ); +#endif + } +} + +//----------------------------------------------------------------------------- +// Adds an element, uses default constructor +//----------------------------------------------------------------------------- + +template< class T > +inline int CUtlVector::AddToHead() +{ + return InsertBefore(0); +} + +template< class T > +inline int CUtlVector::AddToTail() +{ + return InsertBefore( m_Size ); +} + +template< class T > +inline int CUtlVector::InsertAfter( int elem ) +{ + return InsertBefore( elem + 1 ); +} + +template< class T > +int CUtlVector::InsertBefore( int elem ) +{ + // Can insert at the end + assert( (elem == Count()) || IsValidIndex(elem) ); + + GrowVector(); + ShiftElementsRight(elem); + Construct( &Element(elem) ); + return elem; +} + +//----------------------------------------------------------------------------- +// Adds an element, uses copy constructor +//----------------------------------------------------------------------------- + +template< class T > +inline int CUtlVector::AddToHead( T const& src ) +{ + return InsertBefore( 0, src ); +} + +template< class T > +inline int CUtlVector::AddToTail( T const& src ) +{ + return InsertBefore( m_Size, src ); +} + +template< class T > +inline int CUtlVector::InsertAfter( int elem, T const& src ) +{ + return InsertBefore( elem + 1, src ); +} + +template< class T > +int CUtlVector::InsertBefore( int elem, T const& src ) +{ + // Can insert at the end + assert( (elem == Count()) || IsValidIndex(elem) ); + + GrowVector(); + ShiftElementsRight(elem); + CopyConstruct( &Element(elem), src ); + return elem; +} + + +//----------------------------------------------------------------------------- +// Adds multiple elements, uses default constructor +//----------------------------------------------------------------------------- + +template< class T > +inline int CUtlVector::AddMultipleToHead( int num ) +{ + return InsertMultipleBefore( 0, num ); +} + +template< class T > +inline int CUtlVector::AddMultipleToTail( int num, const T *pToCopy ) +{ + return InsertMultipleBefore( m_Size, num, pToCopy ); +} + +template< class T > +int CUtlVector::InsertMultipleAfter( int elem, int num ) +{ + return InsertMultipleBefore( elem + 1, num ); +} + + +template< class T > +void CUtlVector::SetCount( int count ) +{ + RemoveAll(); + AddMultipleToTail( count ); +} + +template< class T > +inline void CUtlVector::SetSize( int size ) +{ + SetCount( size ); +} + +template< class T > +void CUtlVector::CopyArray( T const *pArray, int size ) +{ + SetSize( size ); + for( int i=0; i < size; i++ ) + (*this)[i] = pArray[i]; +} + +template< class T > +int CUtlVector::AddVectorToTail( CUtlVector const &src ) +{ + int base = Count(); + + // Make space. + AddMultipleToTail( src.Count() ); + + // Copy the elements. + for ( int i=0; i < src.Count(); i++ ) + (*this)[base + i] = src[i]; + + return base; +} + +template< class T > +inline int CUtlVector::InsertMultipleBefore( int elem, int num, const T *pToInsert ) +{ + if( num == 0 ) + return elem; + + // Can insert at the end + assert( (elem == Count()) || IsValidIndex(elem) ); + + GrowVector(num); + ShiftElementsRight(elem, num); + + // Invoke default constructors + for (int i = 0; i < num; ++i) + Construct( &Element(elem+i) ); + + // Copy stuff in? + if ( pToInsert ) + { + for ( int i=0; i < num; i++ ) + { + Element( elem+i ) = pToInsert[i]; + } + } + + return elem; +} + +//----------------------------------------------------------------------------- +// Finds an element (element needs operator== defined) +//----------------------------------------------------------------------------- +template< class T > +int CUtlVector::Find( T const& src ) const +{ + for ( int i = 0; i < Count(); ++i ) + { + if (Element(i) == src) + return i; + } + return -1; +} + +template< class T > +bool CUtlVector::HasElement( T const& src ) +{ + return ( Find(src) >= 0 ); +} + +//----------------------------------------------------------------------------- +// Element removal +//----------------------------------------------------------------------------- + +template< class T > +void CUtlVector::FastRemove( int elem ) +{ + assert( IsValidIndex(elem) ); + + Destruct( &Element(elem) ); + if (m_Size > 0) + { + memcpy( &Element(elem), &Element(m_Size-1), sizeof(T) ); + --m_Size; + } +} + +template< class T > +void CUtlVector::Remove( int elem ) +{ + Destruct( &Element(elem) ); + ShiftElementsLeft(elem); + --m_Size; +} + +template< class T > +void CUtlVector::FindAndRemove( T const& src ) +{ + int elem = Find( src ); + if ( elem != -1 ) + { + Remove( elem ); + } +} + +template< class T > +void CUtlVector::RemoveMultiple( int elem, int num ) +{ + assert( IsValidIndex(elem) ); + assert( elem + num <= Count() ); + + for (int i = elem + num; --i >= elem; ) + Destruct(&Element(i)); + + ShiftElementsLeft(elem, num); + m_Size -= num; +} + +template< class T > +void CUtlVector::RemoveAll() +{ + for (int i = m_Size; --i >= 0; ) + Destruct(&Element(i)); + + m_Size = 0; +} + +//----------------------------------------------------------------------------- +// Memory deallocation +//----------------------------------------------------------------------------- + +template< class T > +void CUtlVector::Purge() +{ + RemoveAll(); + m_Memory.Purge( ); + ResetDbgInfo(); +} + +template +inline void CUtlVector::PurgeAndDeleteElements() +{ + for( int i=0; i < m_Size; i++ ) + delete Element(i); + + Purge(); +} + +template< class T > +void CUtlVector::SetGrowSize( int size ) +{ + m_Memory.SetGrowSize( size ); +} + +#endif // CCVECTOR_H diff --git a/src/cmdexec.cpp b/src/cmdexec.cpp index fdf42ea..92a6110 100644 --- a/src/cmdexec.cpp +++ b/src/cmdexec.cpp @@ -22,13 +22,13 @@ void CExecMngr::AddElement(IGameClient *pClient, CResourceBuffer *pResource, uin void StringReplace(char *src, const char *strold, const char *strnew) { - if (strnew == NULL) + if (!strnew) return; char *p = src; int oldLen = strlen(strold), newLen = strlen(strnew); - while ((p = strstr(p, strold)) != NULL) + while ((p = strstr(p, strold)) != nullptr) { if (oldLen != newLen) memmove(p + newLen, p + oldLen, strlen(p) - oldLen + 1); @@ -46,8 +46,8 @@ char *GetExecCmdPrepare(IGameClient *pClient, CResourceBuffer *pResource, uint32 static char string[256]; // check cmdexec is empty - if (pResource->GetCmdExec() == NULL) - return NULL; + if (!pResource->GetCmdExec()) + return nullptr; strncpy(string, pResource->GetCmdExec(), sizeof(string) - 1); string[sizeof(string) - 1] = '\0'; @@ -115,8 +115,7 @@ void CExecMngr::CommandExecute(IGameClient *pClient) if (!bBreak) { char *cmdExec = GetExecCmdPrepare(pClient, pRes, pExec->GetClientHash()); - - if (cmdExec != NULL && cmdExec[0] != '\0') + if (cmdExec && cmdExec[0] != '\0') { g_RecheckerHookchains.m_CmdExec.callChain(CmdExec_hook, pClient, pRes, cmdExec, _byteswap_ulong(pExec->GetClientHash())); } @@ -132,7 +131,7 @@ void CExecMngr::CommandExecute(IGameClient *pClient) void CExecMngr::Clear(IGameClient *pClient) { - if (pClient == NULL) + if (!pClient) { m_execList.clear(); return; diff --git a/src/hookchains_impl.cpp b/src/hookchains_impl.cpp index 87b3020..f5a0004 100644 --- a/src/hookchains_impl.cpp +++ b/src/hookchains_impl.cpp @@ -22,25 +22,65 @@ AbstractHookChainRegistry::AbstractHookChainRegistry() { memset(m_Hooks, 0, sizeof(m_Hooks)); + memset(m_Priorities, 0, sizeof(m_Priorities)); + m_NumHooks = 0; } -void AbstractHookChainRegistry::addHook(void* hookFunc) { - if (m_NumHooks >= MAX_HOOKS_IN_CHAIN) { - Sys_Error("MAX_HOOKS_IN_CHAIN limit hit"); +bool AbstractHookChainRegistry::findHook(void* hookFunc) const +{ + for (auto i = 0; i < m_NumHooks; i++) { + if (m_Hooks[i] == hookFunc) + return true; } - m_Hooks[m_NumHooks++] = hookFunc; + return false; +} + +void AbstractHookChainRegistry::addHook(void* hookFunc, int priority) +{ + if (!hookFunc) { + Sys_Error(__FUNCTION__ " Parameter hookFunc can't be a nullptr"); + } + + if (findHook(hookFunc)) { + Sys_Error(__FUNCTION__ " The same handler can't be used twice on the hookchain."); + } + + for (auto i = 0; i < MAX_HOOKS_IN_CHAIN; i++) + { + if (m_Hooks[i] && priority <= m_Priorities[i]) + continue; + + auto swapHookFunc = m_Hooks[i]; + auto swapPriority = m_Priorities[i]; + + m_Hooks[i] = hookFunc; + m_Priorities[i] = priority; + + hookFunc = swapHookFunc; + priority = swapPriority; + } + + if (m_NumHooks >= MAX_HOOKS_IN_CHAIN) { + Sys_Error(__FUNCTION__ " MAX_HOOKS_IN_CHAIN limit hit"); + } + + m_NumHooks++; } void AbstractHookChainRegistry::removeHook(void* hookFunc) { // erase hook - for (int i = 0; i < m_NumHooks; i++) { - if (hookFunc == m_Hooks[i]) { - if (--m_NumHooks != i) + for (auto i = 0; i < m_NumHooks; i++) + { + if (hookFunc == m_Hooks[i]) + { + --m_NumHooks; + if (m_NumHooks != i) { memmove(&m_Hooks[i], &m_Hooks[i + 1], (m_NumHooks - i) * sizeof(m_Hooks[0])); + memmove(&m_Priorities[i], &m_Priorities[i + 1], (m_NumHooks - i) * sizeof(m_Priorities[0])); m_Hooks[m_NumHooks] = NULL; } else diff --git a/src/hookchains_impl.h b/src/hookchains_impl.h index 5bf176d..cab3340 100644 --- a/src/hookchains_impl.h +++ b/src/hookchains_impl.h @@ -28,9 +28,7 @@ #pragma once #include "hookchains.h" -#define MAX_HOOKS_IN_CHAIN 10 - -extern void __declspec(noreturn) Sys_Error(const char* fmt, ...); +#define MAX_HOOKS_IN_CHAIN 19 // Implementation for chains in modules template @@ -42,7 +40,7 @@ public: IHookChainImpl(void** hooks, origfunc_t orig) : m_Hooks(hooks), m_OriginalFunc(orig) { if (orig == NULL) - Sys_Error("Non-void HookChain without original function."); + Sys_Error(__FUNCTION__ ": Non-void HookChain without original function."); } virtual ~IHookChainImpl() {} @@ -94,8 +92,8 @@ public: } virtual void callOriginal(t_args... args) { - origfunc_t origfunc = (origfunc_t)m_OriginalFunc; - origfunc(args...); + if (m_OriginalFunc) + m_OriginalFunc(args...); } private: @@ -106,10 +104,12 @@ private: class AbstractHookChainRegistry { protected: void* m_Hooks[MAX_HOOKS_IN_CHAIN + 1]; // +1 for null + int m_Priorities[MAX_HOOKS_IN_CHAIN + 1]; int m_NumHooks; protected: - void addHook(void* hookFunc); + void addHook(void* hookFunc, int priority); + bool findHook(void* hookFunc) const; void removeHook(void* hookFunc); public: @@ -129,8 +129,8 @@ public: return chain.callNext(args...); } - virtual void registerHook(hookfunc_t hook) { - addHook((void*)hook); + virtual void registerHook(hookfunc_t hook, int priority) { + addHook((void*)hook, priority); } virtual void unregisterHook(hookfunc_t hook) { removeHook((void*)hook); @@ -150,8 +150,8 @@ public: chain.callNext(args...); } - virtual void registerHook(hookfunc_t hook) { - addHook((void*)hook); + virtual void registerHook(hookfunc_t hook, int priority) { + addHook((void*)hook, priority); } virtual void unregisterHook(hookfunc_t hook) { diff --git a/src/main.h b/src/main.h index 9c2ee64..a3dae97 100644 --- a/src/main.h +++ b/src/main.h @@ -6,3 +6,4 @@ int SV_TransferConsistencyInfo(IRehldsHook_SV_TransferConsistencyInfo *chain); extern void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index); extern qboolean (*SV_FileInConsistencyList)(const char *filename, consistency_t **ppconsist); +extern DLL_FUNCTIONS *gMetaEntityInterface; diff --git a/src/meta_api.cpp b/src/meta_api.cpp index 26f6929..ae2d3e9 100644 --- a/src/meta_api.cpp +++ b/src/meta_api.cpp @@ -4,7 +4,7 @@ plugin_info_t Plugin_info = { META_INTERFACE_VERSION, "Rechecker", - "2.1", + "2.2", __DATE__, "s1lent", "http://www.dedicated-server.ru/", @@ -17,9 +17,7 @@ meta_globals_t *gpMetaGlobals; gamedll_funcs_t *gpGamedllFuncs; mutil_funcs_t *gpMetaUtilFuncs; -DLL_FUNCTIONS gpFunctionTable; -DLL_FUNCTIONS gpFunctionTable_Post; - +DLL_FUNCTIONS *gMetaEntityInterface; META_FUNCTIONS gMetaFunctionTable; extern bool OnMetaAttach(); @@ -42,12 +40,13 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m { return FALSE; } - + gMetaFunctionTable.pfnGetEntityAPI2 = GetEntityAPI2; gMetaFunctionTable.pfnGetEntityAPI2_Post = GetEntityAPI2_Post; - memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); + GET_HOOK_TABLES(PLID, NULL, &gMetaEntityInterface, NULL); + memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS)); return TRUE; } diff --git a/src/precompiled.h b/src/precompiled.h index ead838a..96db285 100644 --- a/src/precompiled.h +++ b/src/precompiled.h @@ -1,16 +1,8 @@ #pragma once -#ifdef _WIN32 // WINDOWS - #pragma warning(disable : 4005) - #define EXT_FUNC /**/ -#else +#ifndef _WIN32 #define _stricmp strcasecmp #define _mkdir mkdir - #ifdef __FUNCTION__ - #undef __FUNCTION__ - #endif - #define __FUNCTION__ __func__ - #define EXT_FUNC __attribute__((force_align_arg_pointer)) #endif // _WIN32 #define MAX_PATH_LENGTH 260 @@ -46,13 +38,16 @@ #ifdef _WIN32 #define DLLEXPORT __declspec(dllexport) #define NOINLINE __declspec(noinline) +#define NORETURN __declspec(noreturn) #else #define DLLEXPORT __attribute__((visibility("default"))) #define NOINLINE __attribute__((noinline)) +#define NORETURN __attribute__((noreturn)) #define WINAPI /* */ #endif // _WIN32 + extern void UTIL_Printf(const char *fmt, ...); extern void UTIL_LogPrintf(const char *fmt, ...); extern char *UTIL_VarArgs(const char *format, ...); -extern void __declspec(noreturn) Sys_Error(const char* fmt, ...); +extern void NORETURN Sys_Error(const char *error, ...); diff --git a/public/rechecker_api.h b/src/rechecker_api.h similarity index 79% rename from public/rechecker_api.h rename to src/rechecker_api.h index a52d383..d84f60b 100644 --- a/public/rechecker_api.h +++ b/src/rechecker_api.h @@ -45,8 +45,8 @@ enum flag_type_resources class IResourceBuffer; // FileConsistencyProcess hook -typedef IHookChain IRecheckerHook_FileConsistencyProcess; -typedef IHookChainRegistry IRecheckerHookRegistry_FileConsistencyProcess; +typedef IVoidHookChain IRecheckerHook_FileConsistencyProcess; +typedef IVoidHookChainRegistry IRecheckerHookRegistry_FileConsistencyProcess; // CmdExec hook typedef IVoidHookChain IRecheckerHook_CmdExec; @@ -54,10 +54,10 @@ typedef IVoidHookChainRegistry class IRecheckerHookchains { public: - virtual ~IRecheckerHookchains() { } + virtual ~IRecheckerHookchains() {} - virtual IRecheckerHookRegistry_FileConsistencyProcess* FileConsistencyProcess() = 0; - virtual IRecheckerHookRegistry_CmdExec* CmdExec() = 0; + virtual IRecheckerHookRegistry_FileConsistencyProcess *FileConsistencyProcess() = 0; + virtual IRecheckerHookRegistry_CmdExec *CmdExec() = 0; }; class IResourceBuffer { @@ -71,9 +71,9 @@ public: virtual const char *GetCmdExec() const = 0; virtual int GetLine() const = 0; - virtual bool IsBreak() const = 0; - virtual bool IsDuplicate() const = 0; - virtual void SetDuplicate() = 0; + virtual bool IsBreak() const = 0; // is have do not check a next files + virtual bool IsDuplicate() const = 0; // it is already have in resourcelist + virtual bool IsAddEx() const = 0; // if it added via API }; class IResourceFile { @@ -86,7 +86,7 @@ public: }; struct RecheckerFuncs_t { - void(*AddElement)(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak); + IResourceBuffer *(*AddElement)(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak); IResourceBuffer*(*FindElement)(char *filename); IResourceFile*(*GetResourceFile)(); }; diff --git a/src/rechecker_api_impl.cpp b/src/rechecker_api_impl.cpp index cb8d292..0057063 100644 --- a/src/rechecker_api_impl.cpp +++ b/src/rechecker_api_impl.cpp @@ -36,9 +36,15 @@ RecheckerFuncs_t g_RecheckerApiFuncs = &GetResourceFile_api }; -void EXT_FUNC AddElement_api(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak) +IResourceBuffer *EXT_FUNC AddElement_api(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak) { - g_pResource->AddElement(filename, cmdExec, flag, hash, 0, bBreak); + auto nRes = g_pResource->AddElement(filename, cmdExec, flag, hash, 0, bBreak); + if (!nRes->IsDuplicate()) { + // resource was added via the API + nRes->SetAddEx(); + } + + return nRes; } IResourceBuffer *EXT_FUNC FindElement_api(char *filename) diff --git a/src/rechecker_api_impl.h b/src/rechecker_api_impl.h index e58ccf1..cdc6df5 100644 --- a/src/rechecker_api_impl.h +++ b/src/rechecker_api_impl.h @@ -28,8 +28,8 @@ #pragma once // FileConsistencyProcess hook -typedef IHookChainImpl CRecheckerHook_FileConsistencyProcess; -typedef IHookChainRegistryImpl CRecheckerHookRegistry_FileConsistencyProcess; +typedef IVoidHookChainImpl CRecheckerHook_FileConsistencyProcess; +typedef IVoidHookChainRegistryImpl CRecheckerHookRegistry_FileConsistencyProcess; // CmdExec hook typedef IVoidHookChainImpl CRecheckerHook_CmdExec; @@ -58,6 +58,6 @@ public: }; void Rechecker_Api_Init(); -void AddElement_api(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak); +IResourceBuffer *AddElement_api(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, bool bBreak); IResourceBuffer *FindElement_api(char *filename); IResourceFile *GetResourceFile_api(); diff --git a/src/resource.cpp b/src/resource.cpp index bedc97a..147ddf3 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -1,10 +1,10 @@ #include "precompiled.h" CResourceFile *g_pResource = nullptr; -std::vector StringsCache; +CResourceFile::StringList CResourceFile::m_StringsCache; -cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, NULL }; -cvar_t *pcv_rch_log = NULL; +cvar_t cv_rch_log = { "rch_log", "0", 0, 0.0f, nullptr }; +cvar_t *pcv_rch_log = nullptr; const char *szTypeNames[] = { "none", "exists", "missing", "ignore", "hash_any" }; @@ -25,7 +25,9 @@ CResourceFile::~CResourceFile() int CResourceFile::CreateResourceList() { - int startIndex = 4095; + // max value of 12 bits + // we need to go over the threshold + int startIndex = (1 << RESOURCE_INDEX_BITS) - 1; int nCustomConsistency = 0; ComputeConsistencyFiles(); @@ -44,7 +46,7 @@ int CResourceFile::CreateResourceList() } // not allow to add a resource if the index is larger than 1024 or we will get Bad file data. - // https://github.com/dreamstalker/rehlds/blob/beaeb6513893760b231b01a981cecd48f50baa81/rehlds/engine/sv_user.cpp#L374 + // https://github.com/dreamstalker/rehlds/blob/beaeb65/rehlds/engine/sv_user.cpp#L374 if (nCustomConsistency + m_ConsistencyNum >= MAX_RANGE_CONSISTENCY) { UTIL_Printf(__FUNCTION__ ": can't add consistency \"%s\" on line %d; index out of bounds '%d'\n", res->GetFileName(), res->GetLine(), MAX_RANGE_CONSISTENCY); @@ -69,8 +71,8 @@ int CResourceFile::CreateResourceList() // sort std::sort(sortList.begin(), sortList.end(), [](const resource_t &a, const resource_t &b) { - bool a_cons = (a.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(a.szFileName, NULL); - bool b_cons = (b.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(b.szFileName, NULL); + bool a_cons = (a.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(a.szFileName, nullptr); + bool b_cons = (b.ucFlags & RES_CHECKFILE) || SV_FileInConsistencyList(b.szFileName, nullptr); if (a_cons && !b_cons) return true; @@ -97,42 +99,36 @@ void CResourceFile::ComputeConsistencyFiles() for (int i = 0; i < g_RehldsServerData->GetResourcesNum(); ++i) { - resource_t *r = g_RehldsServerData->GetResource(i); - - if (r->ucFlags == (RES_CUSTOM | RES_REQUESTED | RES_UNK_6) || (r->ucFlags & RES_CHECKFILE)) + auto res = g_RehldsServerData->GetResource(i); + if (res->ucFlags == (RES_CUSTOM | RES_REQUESTED | RES_UNK_6) || (res->ucFlags & RES_CHECKFILE)) continue; - if (SV_FileInConsistencyList(r->szFileName, NULL)) + if (SV_FileInConsistencyList(res->szFileName, nullptr)) ++m_ConsistencyNum; } } void CResourceFile::Clear(IGameClient *pClient) { - if (pClient != NULL) + if (pClient) { - auto iter = m_responseList.begin(); - int nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); - - while (iter != m_responseList.end()) - { - CResponseBuffer *pFiles = (*iter); - - if (pFiles->GetUserID() != nUserID) - { - iter++; - continue; - } - - // erase cmdexec - delete pFiles; - iter = m_responseList.erase(iter); - } + // remove each entries by pClient + auto nUserID = g_engfuncs.pfnGetPlayerUserId(pClient->GetEdict()); + m_responseList.erase( + std::remove_if( + m_responseList.begin(), + m_responseList.end(), + [nUserID](const CResponseBuffer *pFiles) -> bool { + return (pFiles->GetUserID() == nUserID); + } + ), m_responseList.end() + ); m_PrevHash = 0; return; } + // remove all m_PrevHash = 0; m_ConsistencyNum = 0; @@ -159,15 +155,14 @@ void CResourceFile::Log(flag_type_log type, const char *fmt, ...) fp = fopen(m_LogFilePath, "r"); - if (fp != NULL) + if (fp) { bFirst = true; fclose(fp); } fp = fopen(m_LogFilePath, "a"); - - if (fp == NULL) + if (!fp) { return; } @@ -179,7 +174,7 @@ void CResourceFile::Log(flag_type_log type, const char *fmt, ...) strcat(string, "\n"); - td = time(NULL); + td = time(nullptr); lt = localtime(&td); strftime(dateLog, sizeof(dateLog), "%m/%d/%Y - %H:%M:%S", lt); @@ -187,7 +182,7 @@ void CResourceFile::Log(flag_type_log type, const char *fmt, ...) if (!bFirst) { file = strrchr(m_LogFilePath, '/'); - if (file == NULL) + if (file == nullptr) file = ""; fprintf(fp, "L %s: Log file started (file \"%s\") (version \"%s\")\n", dateLog, file, Plugin_info.version); @@ -251,8 +246,7 @@ inline bool invalidchar(const char c) bool IsValidFilename(char *psrc, char &pchar) { char *pch = strrchr(psrc, '/'); - - if (pch == NULL) + if (!pch) pch = psrc; while (*pch++) @@ -271,15 +265,14 @@ bool IsFileHasExtension(char *psrc) { // find the extension filename char *pch = strrchr(psrc, '.'); - - if (pch == NULL) + if (!pch) return false; // the size extension if (strlen(&pch[1]) <= 0) return false; - return strchr(pch, '/') == NULL; + return strchr(pch, '/') == nullptr; } void CResourceFile::LogPrepare() @@ -289,11 +282,11 @@ void CResourceFile::LogPrepare() time_t td; tm *lt; - td = time(NULL); + td = time(nullptr); lt = localtime(&td); // remove path to log file - if ((pos = strrchr(m_LogFilePath, '/')) != NULL) + if ((pos = strrchr(m_LogFilePath, '/')) != nullptr) { *(pos + 1) = '\0'; } @@ -318,7 +311,7 @@ void CResourceFile::LoadResources() fp = fopen(m_PathDir, "r"); - if (fp == NULL) + if (!fp) { UTIL_Printf(__FUNCTION__ ": can't find path to " FILE_INI_RESOURCES "\n"); return; @@ -341,7 +334,7 @@ void CResourceFile::LoadResources() memset(hash, 0, sizeof(hash)); - while (pToken != NULL && argc <= MAX_PARSE_ARGUMENT) + while (pToken && argc <= MAX_PARSE_ARGUMENT) { len = strlen(pToken); @@ -417,7 +410,7 @@ void CResourceFile::LoadResources() pToken = GetNextToken(&pos); - if (++argc == ARG_TYPE_FLAG && pToken == NULL) + if (++argc == ARG_TYPE_FLAG && pToken == nullptr) { // go to next argument argc++; @@ -454,7 +447,7 @@ void CResourceFile::LoadResources() AddElement(filename, cmdBufExec, flag, *(uint32 *)&hash[0], cline, bBreak); } - else if (pToken != NULL || argc > ARG_TYPE_FILE_NAME) + else if (pToken || argc > ARG_TYPE_FILE_NAME) { LOG_PRINT_FAILED("parsing not enough arguments on line %d (got '%d', expected '%d')\n", cline, argc, MAX_PARSE_ARGUMENT); } @@ -468,7 +461,7 @@ const char *CResourceFile::GetNextToken(char **pbuf) { char *rpos = *pbuf; if (*rpos == '\0') - return NULL; + return nullptr; // skip spaces at the beginning while (*rpos != '\0' && isspace(*rpos)) @@ -477,7 +470,7 @@ const char *CResourceFile::GetNextToken(char **pbuf) if (*rpos == '\0') { *pbuf = rpos; - return NULL; + return nullptr; } const char *res = rpos; @@ -529,7 +522,7 @@ const char *CResourceFile::GetNextToken(char **pbuf) return res; } -void CResourceFile::AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak) +CResourceBuffer *CResourceFile::AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak) { auto nRes = new CResourceBuffer(filename, cmdExec, flag, hash, line, bBreak); @@ -545,6 +538,7 @@ void CResourceFile::AddElement(char *filename, char *cmdExec, flag_type_resource } m_resourceList.push_back(nRes); + return nRes; } void CResourceFile::AddFileResponse(IGameClient *pSenderClient, char *filename, uint32 hash) @@ -552,8 +546,24 @@ void CResourceFile::AddFileResponse(IGameClient *pSenderClient, char *filename, m_responseList.push_back(new CResponseBuffer(pSenderClient, filename, hash)); } -bool EXT_FUNC FileConsistencyProcess_hook(IGameClient *pSenderClient, IResourceBuffer *res, flag_type_resources typeFind, uint32 hash) { - return true; +void EXT_FUNC FileConsistencyProcess_hook(IGameClient *pSenderClient, IResourceBuffer *res, flag_type_resources typeFind, uint32 hash) +{ + if (typeFind == FLAG_TYPE_NONE) + return; + + auto nRes = static_cast(res); + + // push exec cmd + Exec.AddElement(pSenderClient, nRes, hash); + g_pResource->PrintLog(pSenderClient, nRes, typeFind, hash); +} + +void CResourceFile::PrintLog(IGameClient *pSenderClient, CResourceBuffer *res, flag_type_resources typeFind, uint32 hash) +{ + flag_type_log type = (typeFind == FLAG_TYPE_IGNORE) ? LOG_DETAILED : LOG_NORMAL; + Log(type, " -> file: (%s), exphash: (%x), got: (%x), typeFind: (%s), prevhash: (%x), (#%u)(%s), prevfile: (%s), findathash: (%s), md5hex: (%x)", + res->GetFileName(), res->GetFileHash(), hash, szTypeNames[ typeFind ], m_PrevHash, g_engfuncs.pfnGetPlayerUserId(pSenderClient->GetEdict()), + pSenderClient->GetName(), FindFilenameOfHash(m_PrevHash), FindFilenameOfHash(hash), _byteswap_ulong(hash)); } bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash) @@ -623,21 +633,7 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource break; } - if (g_RecheckerHookchains.m_FileConsistencyProcess.callChain(FileConsistencyProcess_hook, pSenderClient, res, typeFind, hash)) - { - //FileConsistencyProcess - if (typeFind != FLAG_TYPE_NONE) - { - // push exec cmd - Exec.AddElement(pSenderClient, res, hash); - - flag_type_log type = (typeFind == FLAG_TYPE_IGNORE) ? LOG_DETAILED : LOG_NORMAL; - Log(type, " -> file: (%s), exphash: (%x), got: (%x), typeFind: (%s), prevhash: (%x), (#%u)(%s), prevfile: (%s), findathash: (%s), md5hex: (%x)", - res->GetFileName(), res->GetFileHash(), hash, szTypeNames[ typeFind ], m_PrevHash, g_engfuncs.pfnGetPlayerUserId(pSenderClient->GetEdict()), - pSenderClient->GetName(), FindFilenameOfHash(m_PrevHash), FindFilenameOfHash(hash), _byteswap_ulong(hash)); - } - } - + g_RecheckerHookchains.m_FileConsistencyProcess.callChain(FileConsistencyProcess_hook, pSenderClient, res, typeFind, hash); bHandled = true; } @@ -646,31 +642,31 @@ bool CResourceFile::FileConsistencyResponse(IGameClient *pSenderClient, resource return !bHandled; } -const char *DuplicateString(const char *str) +const char *CResourceFile::DuplicateString(const char *str) { - for (auto string : StringsCache) + for (auto string : m_StringsCache) { if (!strcmp(string, str)) return string; } const char *s = strcpy(new char[strlen(str) + 1], str); - StringsCache.push_back(s); + m_StringsCache.push_back(s); return s; } -void ClearStringsCache() +void CResourceFile::ClearStringsCache() { - for (auto string : StringsCache) + for (auto string : m_StringsCache) delete [] string; - StringsCache.clear(); + m_StringsCache.clear(); } CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak) { - m_FileName = DuplicateString(filename); - m_CmdExec = (cmdExec[0] != '\0') ? DuplicateString(cmdExec) : NULL; + m_FileName = CResourceFile::DuplicateString(filename); + m_CmdExec = (cmdExec[0] != '\0') ? CResourceFile::DuplicateString(cmdExec) : nullptr; m_Duplicate = false; @@ -678,6 +674,7 @@ CResourceBuffer::CResourceBuffer(char *filename, char *cmdExec, flag_type_resour m_FileHash = hash; m_Line = line; m_Break = bBreak; + m_AddEx = false; } CResourceFile::CResponseBuffer::CResponseBuffer(IGameClient *pSenderClient, char *filename, uint32 hash) diff --git a/src/resource.h b/src/resource.h index 8eea3dc..527db8c 100644 --- a/src/resource.h +++ b/src/resource.h @@ -39,7 +39,10 @@ public: bool IsBreak() const { return m_Break; }; bool IsDuplicate() const { return m_Duplicate; }; + bool IsAddEx() const { return m_AddEx; }; + void SetDuplicate() { m_Duplicate = true; }; + void SetAddEx() { m_AddEx = true; }; private: uint32 m_FileHash; @@ -52,6 +55,7 @@ private: bool m_Duplicate; // for to check for duplicate bool m_Break; // do not check a next files + bool m_AddEx; // external add file }; class CResourceFile: public IResourceFile @@ -65,8 +69,12 @@ public: void LoadResources(); int CreateResourceList(); void Log(flag_type_log type, const char *fmt, ...); - + void PrintLog(IGameClient *pSenderClient, CResourceBuffer *res, flag_type_resources typeFind, uint32 hash); bool FileConsistencyResponse(IGameClient *pSenderClient, resource_t *resource, uint32 hash); + + static const char *DuplicateString(const char *str); + static void ClearStringsCache(); + private: // buffer for response list class CResponseBuffer @@ -110,11 +118,14 @@ private: char m_PathDir[MAX_PATH_LENGTH]; char m_LogFilePath[MAX_PATH_LENGTH]; // log data + typedef std::vector StringList; + static StringList m_StringsCache; + public: const char *FindFilenameOfHash(uint32 hash); int GetConsistencyNum() const { return m_ConsistencyNum; } uint32 GetPrevHash() const { return m_PrevHash; } - void AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak); + CResourceBuffer *AddElement(char *filename, char *cmdExec, flag_type_resources flag, uint32 hash, int line, bool bBreak); const ResourceList *GetResourceList() const { return &m_resourceList; } }; diff --git a/src/sdk_util.cpp b/src/sdk_util.cpp index 6831f2e..9372250 100644 --- a/src/sdk_util.cpp +++ b/src/sdk_util.cpp @@ -38,20 +38,23 @@ char *UTIL_VarArgs(const char *format, ...) return string; } -void __declspec(noreturn) Sys_Error(const char* fmt, ...) +void NORETURN Sys_Error(const char *error, ...) { va_list argptr; - static char string[8192]; + static char text[1024]; - va_start(argptr, fmt); - vsnprintf(string, sizeof(string), fmt, argptr); + va_start(argptr, error); + vsnprintf(text, ARRAYSIZE(text), error, argptr); va_end(argptr); - printf("%s\n", string); +#ifdef _WIN32 + MessageBox(GetForegroundWindow(), text, "Fatal error - Dedicated server", MB_ICONERROR | MB_OK); +#endif // _WIN32 - FILE *fl = fopen("rehlds_error.txt", "w"); - fprintf(fl, "%s\n", string); - fclose(fl); + if (gMetaEntityInterface && gMetaEntityInterface->pfnSys_Error) + gMetaEntityInterface->pfnSys_Error(text); + + UTIL_Printf("FATAL ERROR (shutting down): %s\n", text); //TerminateProcess(GetCurrentProcess(), 1); *((int*)NULL) = 0;