355 lines
11 KiB
C
Raw Normal View History

2013-12-02 19:31:46 -08:00
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef TRIGGERS_H
#define TRIGGERS_H
#ifdef _WIN32
#pragma once
#endif
#ifdef MAPBASE
#include "baseentity.h"
#else
2013-12-02 19:31:46 -08:00
#include "basetoggle.h"
#endif
2013-12-02 19:31:46 -08:00
#include "entityoutput.h"
//
// Spawnflags
//
enum
{
SF_TRIGGER_ALLOW_CLIENTS = 0x01, // Players can fire this trigger
SF_TRIGGER_ALLOW_NPCS = 0x02, // NPCS can fire this trigger
SF_TRIGGER_ALLOW_PUSHABLES = 0x04, // Pushables can fire this trigger
SF_TRIGGER_ALLOW_PHYSICS = 0x08, // Physics objects can fire this trigger
SF_TRIGGER_ONLY_PLAYER_ALLY_NPCS = 0x10, // *if* NPCs can fire this trigger, this flag means only player allies do so
SF_TRIGGER_ONLY_CLIENTS_IN_VEHICLES = 0x20, // *if* Players can fire this trigger, this flag means only players inside vehicles can
SF_TRIGGER_ALLOW_ALL = 0x40, // Everything can fire this trigger EXCEPT DEBRIS!
SF_TRIGGER_ONLY_CLIENTS_OUT_OF_VEHICLES = 0x200, // *if* Players can fire this trigger, this flag means only players outside vehicles can
SF_TRIG_PUSH_ONCE = 0x80, // trigger_push removes itself after firing once
SF_TRIG_PUSH_AFFECT_PLAYER_ON_LADDER = 0x100, // if pushed object is player on a ladder, then this disengages them from the ladder (HL2only)
SF_TRIG_TOUCH_DEBRIS = 0x400, // Will touch physics debris objects
SF_TRIGGER_ONLY_NPCS_IN_VEHICLES = 0X800, // *if* NPCs can fire this trigger, only NPCs in vehicles do so (respects player ally flag too)
SF_TRIGGER_DISALLOW_BOTS = 0x1000, // Bots are not allowed to fire this trigger
#ifdef MAPBASE
SF_TRIGGER_ALLOW_ITEMS = 0x2000, // MOVETYPE_FLYGRAVITY (Weapons, items, flares, etc.) can fire this trigger
#endif
2013-12-02 19:31:46 -08:00
};
// DVS TODO: get rid of CBaseToggle
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
#ifdef MAPBASE
#define CBaseToggle CBaseEntity
#endif
2013-12-02 19:31:46 -08:00
class CBaseTrigger : public CBaseToggle
{
DECLARE_CLASS( CBaseTrigger, CBaseToggle );
#ifdef MAPBASE
#undef CBaseToggle
#endif
2013-12-02 19:31:46 -08:00
public:
CBaseTrigger();
void Activate( void );
virtual void PostClientActive( void );
void InitTrigger( void );
void Enable( void );
void Disable( void );
void Spawn( void );
void UpdateOnRemove( void );
void TouchTest( void );
// Input handlers
virtual void InputEnable( inputdata_t &inputdata );
virtual void InputDisable( inputdata_t &inputdata );
virtual void InputToggle( inputdata_t &inputdata );
virtual void InputTouchTest ( inputdata_t &inputdata );
virtual void InputStartTouch( inputdata_t &inputdata );
virtual void InputEndTouch( inputdata_t &inputdata );
virtual bool UsesFilter( void ){ return ( m_hFilter.Get() != NULL ); }
virtual bool PassesTriggerFilters(CBaseEntity *pOther);
virtual void StartTouch(CBaseEntity *pOther);
virtual void EndTouch(CBaseEntity *pOther);
bool IsTouching( CBaseEntity *pOther );
vscript additions and fixes: baseanimating.h baseanimating.cpp - Added CBaseAnimating::SequenceDuration (ScriptSequenceDuration) - Added CBaseAnimating::GetPlaybackRate - Added CBaseAnimating::SetPlaybackRate - Added CBaseAnimating::GetCycle - Added CBaseAnimating::SetCycle triggers.h triggers.cpp - Fixed CTriggerCamera::ScriptSetFov setting player FOV while disabled - Added CBaseTrigger::Enable - Added CBaseTrigger::Disable - Added CBaseTrigger::TouchTest - Added CBaseTrigger::IsTouching (ScriptIsTouching) vscript_server.nut vscript_server.cpp - Added CEntities::FindByClassnameWithinBox - Added ::SendToConsoleServer - Added ::CancelEntityIOEvent - Added ::GetEntityIOEventTimeLeft - Moved ScriptDispatchParticleEffect to shared code eventqueue.h cbase.h cbase.cpp - Set entity I/O con output colour - Added (CEventQueue::CancelEventsByInput) - Added (CEventQueue::RemoveEvent) - Added (CEventQueue::GetTimeLeft) baseentity.h baseentity.cpp - Added CBaseEntity::SetTransmitState - Added CBaseEntity::GetTransmitState - Added CBaseEntity::AcceptInput (ScriptAcceptInput) - Added CBaseEntity::FireOutput (ScriptFireOutput) - Added CBaseEntity::GetMaxOutputDelay - Added CBaseEntity::CancelEventsByInput - Added player_use event on InputUse - Fixed InputKill on players ivscript.h vscript_squirrel.cpp - Added IScriptVM::ArrayAppend - Fixed buffer overflow crash - Increased print buffer to 2048 from 256 - Set vscript print output colour vscript_funcs_shared.cpp - Added CNetMsgScriptHelper (CScriptGameEventListener) - Added ::ListenToGameEvent - Added ::StopListeningToGameEvent - Added ::StopListeningToAllGameEvents - Added ::FireGameEvent - Added ::FireGameEventLocal (CScriptSaveRestoreUtil) - Added ::SaveTable - Added ::RestoreTable - Added ::ClearSavedTable - Added callbacks ::OnSave, ::OnRestore (CScriptReadWriteFile) - Added ::StringToFile - Added ::FileToString - Added GlobalSys::GetCommandLine - Added GlobalSys::CommandLineCheck - Added GlobalSys::CommandLineCheckStr - Added GlobalSys::CommandLineCheckFloat - Added GlobalSys::CommandLineCheckInt - Added ::GetCPUUsage - Added ::NXPrint - Added ::Msg (ScriptMsg) - Removed misplaced condition checks - Fixed ScriptEntitiesInBox, *AtPoint, *InSphere logic_eventlistener.cpp - Removed redundant dev msg gamestringpool.cpp - Fixed string pool dump sort
2020-10-27 02:22:18 +03:00
#ifdef MAPBASE_VSCRIPT
bool ScriptIsTouching( HSCRIPT hOther );
#endif
2013-12-02 19:31:46 -08:00
CBaseEntity *GetTouchedEntityOfType( const char *sClassName );
int DrawDebugTextOverlays(void);
// by default, triggers don't deal with TraceAttack
void TraceAttack(CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType) {}
bool PointIsWithin( const Vector &vecPoint );
Mapbase v6.0 - Fixed path_track paths saving as pointers instead of handles - Fixed player animations not falling to base class correctly - Fixed logic_externaldata creating garbage in trailing spaces - Added "SetHandModelSkin" input - Added unique colors for various types of console message, adjustable via convars - Added the ability to use map-specific weapon scripts - Added a way to display (placeholder) text entirely from Faceposer scenes - Added "autobreak" keyvalue to game_text, which automatically breaks long text into different lines - Added the ability to change a game_text's font (very limited) - Added LightToggle input to point_spotlight - Added Enable/DisableSprites on npc_manhack - Added ai_goal_police behavior from metrocops to Combine soldiers and citizens - Added func_precipitation particle rain systems from the Alien Swarm SDK - Added new func_precipitation spawnflags for controlling behavior in particle types - Added "mapbase_version" cvar which shows the version of Mapbase a mod might be running on - Fixed an oversight with NPC crouch activities which was causing npc_metropolice to stop firing in standoffs - Added toggleable patches to npc_combine AI which make soldiers less likely to stand around without shooting or rush to melee when not needed - Added key for custom logo font on env_credits scripts - Added SetSpeed and SetPushDir inputs for trigger_push - Added a bunch of I/O/KV to func_fish_pool to allow for more control over the fish - Added OnLostEnemy/Player support for npc_combine_camera - Added enhanced save/restore for the Response System, toggleable via convar - Added a convar which allows users to disable weapon autoswitching when picking up ammo - Split VScript base script into its own file - Added VScript descriptions for NPC squads and the manager class which handles them - Moved several classes, functions, etc. to the VScript library itself for future usage in other projects, like VBSP - Added VScript to VBSP with basic map file interfacing - Made some VScript documentation more clear due to deprecation of online documentation - Added VScript "hook" registration, creating a standardized system which shows up in script_help documentation - Added VScript-driven custom weapons - Added clientside VScript scopes - Added a bunch of weapon-related VScript functions - Split a bunch of cluttered VScript stuff into different files - Added VScript functions for "following" entities/bonemerging - Added VScript functions for grenades - Added a few more VScript trigger functions - Added OnDeath hook for VScript - Fixed documentation for aliased functions in VScript - Fixed $bumpmask not working on SDK_LightmappedGeneric - Made vertex blend swapping in Hammer use a constant instead of a combo (makes it easier to compile the shader, especially for $bumpmask's sake) - Fixed brush phong, etc. causing SDK_WorldVertexTransition to stop working - Added limited support for $envmapmask in the bumpmapping shader - Fixed more issues with parallax corrected cubemaps and instances - Made instance variable recursion consistent with VMFII
2020-11-26 02:26:55 +00:00
#ifdef MAPBASE_VSCRIPT
bool ScriptPassesTriggerFilters( HSCRIPT hOther ) { return ToEnt(hOther) ? PassesTriggerFilters( ToEnt(hOther) ) : NULL; }
HSCRIPT ScriptGetTouchedEntityOfType( const char *sClassName ) { return ToHScript( GetTouchedEntityOfType(sClassName) ); }
void ScriptGetTouchingEntities( HSCRIPT hTable );
#endif
2013-12-02 19:31:46 -08:00
bool m_bDisabled;
string_t m_iFilterName;
CHandle<class CBaseFilter> m_hFilter;
protected:
// Outputs
COutputEvent m_OnStartTouch;
COutputEvent m_OnStartTouchAll;
COutputEvent m_OnEndTouch;
COutputEvent m_OnEndTouchAll;
COutputEvent m_OnTouching;
COutputEvent m_OnNotTouching;
// Entities currently being touched by this trigger
CUtlVector< EHANDLE > m_hTouchingEntities;
#ifdef MAPBASE
// We don't descend from CBaseToggle anymore. These have to be defined here now.
EHANDLE m_hActivator;
float m_flWait;
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.
virtual float GetDelay( void ) { return m_flWait; }
#endif
2013-12-02 19:31:46 -08:00
DECLARE_DATADESC();
vscript additions and fixes: baseanimating.h baseanimating.cpp - Added CBaseAnimating::SequenceDuration (ScriptSequenceDuration) - Added CBaseAnimating::GetPlaybackRate - Added CBaseAnimating::SetPlaybackRate - Added CBaseAnimating::GetCycle - Added CBaseAnimating::SetCycle triggers.h triggers.cpp - Fixed CTriggerCamera::ScriptSetFov setting player FOV while disabled - Added CBaseTrigger::Enable - Added CBaseTrigger::Disable - Added CBaseTrigger::TouchTest - Added CBaseTrigger::IsTouching (ScriptIsTouching) vscript_server.nut vscript_server.cpp - Added CEntities::FindByClassnameWithinBox - Added ::SendToConsoleServer - Added ::CancelEntityIOEvent - Added ::GetEntityIOEventTimeLeft - Moved ScriptDispatchParticleEffect to shared code eventqueue.h cbase.h cbase.cpp - Set entity I/O con output colour - Added (CEventQueue::CancelEventsByInput) - Added (CEventQueue::RemoveEvent) - Added (CEventQueue::GetTimeLeft) baseentity.h baseentity.cpp - Added CBaseEntity::SetTransmitState - Added CBaseEntity::GetTransmitState - Added CBaseEntity::AcceptInput (ScriptAcceptInput) - Added CBaseEntity::FireOutput (ScriptFireOutput) - Added CBaseEntity::GetMaxOutputDelay - Added CBaseEntity::CancelEventsByInput - Added player_use event on InputUse - Fixed InputKill on players ivscript.h vscript_squirrel.cpp - Added IScriptVM::ArrayAppend - Fixed buffer overflow crash - Increased print buffer to 2048 from 256 - Set vscript print output colour vscript_funcs_shared.cpp - Added CNetMsgScriptHelper (CScriptGameEventListener) - Added ::ListenToGameEvent - Added ::StopListeningToGameEvent - Added ::StopListeningToAllGameEvents - Added ::FireGameEvent - Added ::FireGameEventLocal (CScriptSaveRestoreUtil) - Added ::SaveTable - Added ::RestoreTable - Added ::ClearSavedTable - Added callbacks ::OnSave, ::OnRestore (CScriptReadWriteFile) - Added ::StringToFile - Added ::FileToString - Added GlobalSys::GetCommandLine - Added GlobalSys::CommandLineCheck - Added GlobalSys::CommandLineCheckStr - Added GlobalSys::CommandLineCheckFloat - Added GlobalSys::CommandLineCheckInt - Added ::GetCPUUsage - Added ::NXPrint - Added ::Msg (ScriptMsg) - Removed misplaced condition checks - Fixed ScriptEntitiesInBox, *AtPoint, *InSphere logic_eventlistener.cpp - Removed redundant dev msg gamestringpool.cpp - Fixed string pool dump sort
2020-10-27 02:22:18 +03:00
#ifdef MAPBASE_VSCRIPT
DECLARE_ENT_SCRIPTDESC();
#endif
2013-12-02 19:31:46 -08:00
};
//-----------------------------------------------------------------------------
// Purpose: Variable sized repeatable trigger. Must be targeted at one or more entities.
// If "delay" is set, the trigger waits some time after activating before firing.
// "wait" : Seconds between triggerings. (.2 default/minimum)
//-----------------------------------------------------------------------------
class CTriggerMultiple : public CBaseTrigger
{
DECLARE_CLASS( CTriggerMultiple, CBaseTrigger );
public:
void Spawn( void );
void MultiTouch( CBaseEntity *pOther );
void MultiWaitOver( void );
void ActivateMultiTrigger(CBaseEntity *pActivator);
DECLARE_DATADESC();
// Outputs
COutputEvent m_OnTrigger;
};
// Global list of triggers that care about weapon fire
extern CUtlVector< CHandle<CTriggerMultiple> > g_hWeaponFireTriggers;
//------------------------------------------------------------------------------
// Base VPhysics trigger implementation
// NOTE: This uses vphysics to compute touch events. It doesn't do a per-frame Touch call, so the
// Entity I/O is different from a regular trigger
//------------------------------------------------------------------------------
#define SF_VPHYSICS_MOTION_MOVEABLE 0x1000
class CBaseVPhysicsTrigger : public CBaseEntity
{
DECLARE_CLASS( CBaseVPhysicsTrigger , CBaseEntity );
public:
DECLARE_DATADESC();
virtual void Spawn();
virtual void UpdateOnRemove();
virtual bool CreateVPhysics();
virtual void Activate( void );
virtual bool PassesTriggerFilters(CBaseEntity *pOther);
// UNDONE: Pass trigger event in or change Start/EndTouch. Add ITriggerVPhysics perhaps?
// BUGBUG: If a player touches two of these, his movement will screw up.
// BUGBUG: If a player uses crouch/uncrouch it will generate touch events and clear the motioncontroller flag
virtual void StartTouch( CBaseEntity *pOther );
virtual void EndTouch( CBaseEntity *pOther );
void InputToggle( inputdata_t &inputdata );
void InputEnable( inputdata_t &inputdata );
void InputDisable( inputdata_t &inputdata );
protected:
bool m_bDisabled;
string_t m_iFilterName;
CHandle<class CBaseFilter> m_hFilter;
};
//-----------------------------------------------------------------------------
// Purpose: Hurts anything that touches it. If the trigger has a targetname,
// firing it will toggle state.
//-----------------------------------------------------------------------------
class CTriggerHurt : public CBaseTrigger
{
public:
CTriggerHurt()
{
// This field came along after levels were built so the field defaults to 20 here in the constructor.
m_flDamageCap = 20.0f;
#ifdef MAPBASE
// Uh, same here.
m_flHurtRate = 0.5f;
#endif
2013-12-02 19:31:46 -08:00
}
DECLARE_CLASS( CTriggerHurt, CBaseTrigger );
void Spawn( void );
void RadiationThink( void );
void HurtThink( void );
void Touch( CBaseEntity *pOther );
void EndTouch( CBaseEntity *pOther );
bool HurtEntity( CBaseEntity *pOther, float damage );
int HurtAllTouchers( float dt );
#ifdef MAPBASE
bool KeyValue( const char *szKeyName, const char *szValue );
#endif
2013-12-02 19:31:46 -08:00
DECLARE_DATADESC();
float m_flOriginalDamage; // Damage as specified by the level designer.
float m_flDamage; // Damage per second.
float m_flDamageCap; // Maximum damage per second.
float m_flLastDmgTime; // Time that we last applied damage.
float m_flDmgResetTime; // For forgiveness, the time to reset the counter that accumulates damage.
int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does
int m_damageModel;
bool m_bNoDmgForce; // Should damage from this trigger impart force on what it's hurting
#ifdef MAPBASE
float m_flHurtRate;
#endif
2013-12-02 19:31:46 -08:00
enum
{
DAMAGEMODEL_NORMAL = 0,
DAMAGEMODEL_DOUBLE_FORGIVENESS,
};
// Outputs
COutputEvent m_OnHurt;
COutputEvent m_OnHurtPlayer;
CUtlVector<EHANDLE> m_hurtEntities;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CTriggerCamera : public CBaseEntity
{
public:
DECLARE_CLASS( CTriggerCamera, CBaseEntity );
// script description
DECLARE_ENT_SCRIPTDESC();
#ifdef MAPBASE
CTriggerCamera();
void UpdateOnRemove();
#endif
void Spawn( void );
bool KeyValue( const char *szKeyName, const char *szValue );
void Enable( void );
void Disable( void );
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void FollowTarget( void );
void StartCameraShot( const char *pszShotType, CBaseEntity *pSceneEntity, CBaseEntity *pActor1, CBaseEntity *pActor2, float duration );
int ScriptGetFov(void);
void ScriptSetFov(int iFOV, float rate);
#ifdef MAPBASE
void MoveThink( void );
#endif
void Move(void);
// Always transmit to clients so they know where to move the view to
virtual int UpdateTransmitState();
DECLARE_DATADESC();
// Input handlers
void InputEnable( inputdata_t &inputdata );
void InputDisable( inputdata_t &inputdata );
#ifdef MAPBASE
void InputSetFOV( inputdata_t &inputdata );
void InputSetFOVRate( inputdata_t &inputdata );
#endif
private:
EHANDLE m_hPlayer;
EHANDLE m_hTarget;
// used for moving the camera along a path (rail rides)
CBaseEntity *m_pPath;
string_t 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;
Vector m_vecMoveDir;
#ifdef MAPBASE
float m_fov;
float m_fovSpeed;
bool m_bDontSetPlayerView;
#endif
string_t m_iszTargetAttachment;
int m_iAttachmentIndex;
bool m_bSnapToGoal;
#if HL2_EPISODIC
bool m_bInterpolatePosition;
// these are interpolation vars used for interpolating the camera over time
Vector m_vStartPos, m_vEndPos;
float m_flInterpStartTime;
const static float kflPosInterpTime; // seconds
#endif
int m_nPlayerButtons;
int m_nOldTakeDamage;
private:
COutputEvent m_OnEndFollow;
#ifdef MAPBASE
COutputEvent m_OnStartFollow;
#endif
};
2013-12-02 19:31:46 -08:00
#endif // TRIGGERS_H