diff --git a/.gitignore b/.gitignore index 30855510..ceeca319 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ config.cfg # shader files *.tmp +*.vcs # Unnecessary files *.lib @@ -75,3 +76,14 @@ sp/src/game/server/Release_mod_episodic/ sp/src/game/server/Release_mod_hl2/ sp/src/*/Debug/ sp/src/*/Release/ +sp/game/*.dll +sp/game/*.pdb +sp/game/*.exe +sp/src/utils/*.dll +sp/src/utils/*.pdb +sp/src/utils/*.exe +sp/src/utils/*.res +sp/src/materialsystem/*.dll +sp/src/materialsystem/*.pdb +sp/src/vgui2/*.dll +sp/src/vgui2/*.pdb diff --git a/sp/src/game/client/client_mapbase.vpc b/sp/src/game/client/client_mapbase.vpc index 793c9aed..cdb07dfd 100644 --- a/sp/src/game/client/client_mapbase.vpc +++ b/sp/src/game/client/client_mapbase.vpc @@ -33,6 +33,8 @@ $Project $File "$SRCDIR\game\shared\mapbase\MapEdit.h" $File "$SRCDIR\game\shared\mapbase\matchers.cpp" $File "$SRCDIR\game\shared\mapbase\matchers.h" + $File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.cpp" [$MAPBASE_VSCRIPT] + $File "$SRCDIR\game\shared\mapbase\vscript_funcs_hl2.cpp" [$MAPBASE_VSCRIPT && ($HL2||$EPISODIC)] $File "mapbase\c_func_clientclip.cpp" } diff --git a/sp/src/game/client/vscript_client.cpp b/sp/src/game/client/vscript_client.cpp index de113970..a62ebbf5 100644 --- a/sp/src/game/client/vscript_client.cpp +++ b/sp/src/game/client/vscript_client.cpp @@ -113,10 +113,16 @@ bool VScriptClientInit() //g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" ); +#ifdef MAPBASE_VSCRIPT + IGameSystem::RegisterVScriptAllSystems(); + + RegisterSharedScriptFunctions(); +#else if ( scriptLanguage == SL_SQUIRREL ) { //g_pScriptVM->Run( g_Script_vscript_client ); } +#endif VScriptRunScript( "mapspawn", false ); diff --git a/sp/src/game/server/ai_baseactor.cpp b/sp/src/game/server/ai_baseactor.cpp index 224cf42d..2ddc60f7 100644 --- a/sp/src/game/server/ai_baseactor.cpp +++ b/sp/src/game/server/ai_baseactor.cpp @@ -98,6 +98,15 @@ BEGIN_DATADESC( CAI_BaseActor ) END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CAI_BaseActor, CAI_BaseNPC, "The base class for NPCs which act in complex choreo scenes." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptAddLookTarget, "AddLookTarget", "Add a potential look target for this actor." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptAddLookTargetPos, "AddLookTargetPos", "Add a potential look target position for this actor." ) + +END_SCRIPTDESC(); +#endif + BEGIN_SIMPLE_DATADESC( CAI_InterestTarget_t ) DEFINE_FIELD( m_eType, FIELD_INTEGER ), diff --git a/sp/src/game/server/ai_baseactor.h b/sp/src/game/server/ai_baseactor.h index b2c8c5ca..c51391f3 100644 --- a/sp/src/game/server/ai_baseactor.h +++ b/sp/src/game/server/ai_baseactor.h @@ -170,6 +170,15 @@ public: void ClearExpression(); const char * GetExpression(); +#ifdef MAPBASE_VSCRIPT + //--------------------------------- + + void ScriptAddLookTarget( HSCRIPT pTarget, float flImportance, float flDuration, float flRamp = 0.0 ) { AddLookTarget(ToEnt(pTarget), flImportance, flDuration, flRamp); } + void ScriptAddLookTargetPos( const Vector &vecPosition, float flImportance, float flDuration, float flRamp = 0.0 ) { AddLookTarget(vecPosition, flImportance, flDuration, flRamp); } + + //--------------------------------- +#endif + enum { SCENE_AI_BLINK = 1, @@ -190,6 +199,9 @@ public: DECLARE_DATADESC(); +#ifdef MAPBASE_VSCRIPT + DECLARE_ENT_SCRIPTDESC(); +#endif private: enum { diff --git a/sp/src/game/server/ai_basenpc.cpp b/sp/src/game/server/ai_basenpc.cpp index 1a5f36b7..232cbf4f 100644 --- a/sp/src/game/server/ai_basenpc.cpp +++ b/sp/src/game/server/ai_basenpc.cpp @@ -689,6 +689,118 @@ void CAI_BaseNPC::InputSetFriendlyFire( inputdata_t &inputdata ) } #endif +#ifdef MAPBASE_VSCRIPT +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CAI_BaseNPC::VScriptGetEnemy() +{ + return ToHScript( GetEnemy() ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CAI_BaseNPC::VScriptSetEnemy( HSCRIPT pEnemy ) +{ + SetEnemy( ToEnt( pEnemy ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +Vector CAI_BaseNPC::VScriptGetEnemyLKP() +{ + return GetEnemyLKP(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CAI_BaseNPC::VScriptFindEnemyMemory( HSCRIPT pEnemy ) +{ + HSCRIPT hScript = NULL; + AI_EnemyInfo_t *info = GetEnemies()->Find( ToEnt(pEnemy) ); + if (info) + { + hScript = g_pScriptVM->RegisterInstance( info ); + } + + return hScript; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int CAI_BaseNPC::VScriptGetState() +{ + return (int)GetState(); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +const char *CAI_BaseNPC::VScriptGetSchedule() +{ + const char *pName = NULL; + pName = GetCurSchedule()->GetName(); + if (!pName) + pName = "Unknown"; + + return pName; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CAI_BaseNPC::VScriptSetSchedule( const char *szSchedule ) +{ + SetSchedule( GetScheduleID( szSchedule ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +const char *CAI_BaseNPC::VScriptGetTask() +{ + const Task_t *pTask = GetTask(); + const char *pName = NULL; + if (pTask) + pName = TaskName( pTask->iTask ); + else + pName = "None"; + + return pName; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool CAI_BaseNPC::VScriptHasCondition( const char *szCondition ) +{ + return HasCondition( GetConditionID( szCondition ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CAI_BaseNPC::VScriptSetCondition( const char *szCondition ) +{ + SetCondition( GetConditionID( szCondition ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CAI_BaseNPC::VScriptClearCondition( const char *szCondition ) +{ + ClearCondition( GetConditionID( szCondition ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CAI_BaseNPC::VScriptGetExpresser() +{ + HSCRIPT hScript = NULL; + CAI_Expresser *pExpresser = GetExpresser(); + if (pExpresser) + { + hScript = g_pScriptVM->RegisterInstance( pExpresser ); + } + + return hScript; +} +#endif + bool CAI_BaseNPC::PassesDamageFilter( const CTakeDamageInfo &info ) { if ( ai_block_damage.GetBool() ) @@ -6403,6 +6515,34 @@ Activity CAI_BaseNPC::NPC_TranslateActivity( Activity eNewActivity ) break; } } + +#ifdef MAPBASE_VSCRIPT + if ( m_ScriptScope.IsInitialized() ) + { + g_pScriptVM->SetValue( "activity", GetActivityName(eNewActivity) ); + g_pScriptVM->SetValue( "activity_id", (int)eNewActivity ); + + ScriptVariant_t functionReturn; + if( CallScriptFunction( "NPC_TranslateActivity", &functionReturn ) ) + { + if (functionReturn.m_type == FIELD_INTEGER) + { + Activity activity = (Activity)functionReturn.m_int; + if (activity != ACT_INVALID) + eNewActivity = (Activity)functionReturn.m_int; + } + else + { + Activity activity = (Activity)GetActivityID( functionReturn.m_pszString ); + if (activity != ACT_INVALID) + eNewActivity = activity; + } + } + + g_pScriptVM->ClearValue( "activity" ); + g_pScriptVM->ClearValue( "activity_id" ); + } +#endif #else Assert( eNewActivity != ACT_INVALID ); @@ -11758,6 +11898,48 @@ BEGIN_DATADESC( CAI_BaseNPC ) END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CAI_BaseNPC, CBaseCombatCharacter, "The base class shared all NPCs derive from." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetEnemy, "GetEnemy", "Get the NPC's current enemy." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptSetEnemy, "SetEnemy", "Set the NPC's current enemy." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptGetEnemyLKP, "GetEnemyLKP", "Get the last known position of the NPC's current enemy." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptFindEnemyMemory, "FindEnemyMemory", "Get information about the NPC's current enemy." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetHintGroup, "GetHintGroup", "Get the name of the NPC's hint group." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetState, "GetNPCState", "Get the NPC's current state." ) + + DEFINE_SCRIPTFUNC( CapabilitiesGet, "Get the capabilities the NPC currently possesses." ) + DEFINE_SCRIPTFUNC( CapabilitiesAdd, "Add capabilities to the NPC." ) + DEFINE_SCRIPTFUNC( CapabilitiesRemove, "Remove capabilities from the NPC." ) + DEFINE_SCRIPTFUNC( CapabilitiesClear, "Clear capabilities for the NPC." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetSchedule, "GetSchedule", "Get the NPC's current schedule." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptGetScheduleID, "GetScheduleID", "Get the NPC's current schedule ID." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptSetSchedule, "SetSchedule", "Set the NPC's current schedule." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptSetScheduleID, "SetScheduleID", "Set the NPC's current schedule ID." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptGetTask, "GetTask", "Get the NPC's current task." ) + DEFINE_SCRIPTFUNC( ClearSchedule, "Clear the NPC's current schedule for the specified reason." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptHasCondition, "HasCondition", "Get whether the NPC has a condition." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptHasConditionID, "HasConditionID", "Get whether the NPC has a condition ID." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptSetCondition, "SetCondition", "Set a condition on the NPC." ) + DEFINE_SCRIPTFUNC_NAMED( SetCondition, "SetConditionID", "Set a condition on the NPC by ID." ) + DEFINE_SCRIPTFUNC_NAMED( VScriptClearCondition, "ClearCondition", "Clear a condition on the NPC." ) + DEFINE_SCRIPTFUNC_NAMED( ClearCondition, "ClearConditionID", "Clear a condition on the NPC by ID." ) + + DEFINE_SCRIPTFUNC( IsMoving, "Check if the NPC is moving." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetExpresser, "GetExpresser", "Get a handle for this NPC's expresser." ) + + DEFINE_SCRIPTFUNC( IsCommandable, "Check if the NPC is commandable." ) + DEFINE_SCRIPTFUNC( IsInPlayerSquad, "Check if the NPC is in the player's squad." ) + +END_SCRIPTDESC(); +#endif + BEGIN_SIMPLE_DATADESC( AIScheduleState_t ) DEFINE_FIELD( iCurTask, FIELD_INTEGER ), DEFINE_FIELD( fTaskStatus, FIELD_INTEGER ), diff --git a/sp/src/game/server/ai_basenpc.h b/sp/src/game/server/ai_basenpc.h index d05b4a2f..df5c2824 100644 --- a/sp/src/game/server/ai_basenpc.h +++ b/sp/src/game/server/ai_basenpc.h @@ -547,6 +547,9 @@ public: DECLARE_DATADESC(); DECLARE_SERVERCLASS(); +#ifdef MAPBASE_VSCRIPT + DECLARE_ENT_SCRIPTDESC(); +#endif virtual int Save( ISave &save ); virtual int Restore( IRestore &restore ); @@ -1207,6 +1210,32 @@ public: virtual void AddGrenades( int inc, CBaseEntity *pLastGrenade = NULL ) { ; } #endif +#ifdef MAPBASE_VSCRIPT + // VScript stuff uses "VScript" instead of just "Script" to avoid + // confusion with NPC_STATE_SCRIPT or StartScripting + HSCRIPT VScriptGetEnemy(); + void VScriptSetEnemy( HSCRIPT pEnemy ); + Vector VScriptGetEnemyLKP(); + + HSCRIPT VScriptFindEnemyMemory( HSCRIPT pEnemy ); + + int VScriptGetState(); + const char* VScriptGetHintGroup() { return STRING( GetHintGroup() ); } + + const char *VScriptGetSchedule(); + int VScriptGetScheduleID() { return GetCurSchedule()->GetId(); } + void VScriptSetSchedule( const char *szSchedule ); + void VScriptSetScheduleID( int iSched ) { SetSchedule( iSched ); } + const char *VScriptGetTask(); + + bool VScriptHasCondition( const char *szCondition ); + bool VScriptHasConditionID( int iCondition ) { return HasCondition( iCondition ); } + void VScriptSetCondition( const char *szCondition ); + void VScriptClearCondition( const char *szCondition ); + + HSCRIPT VScriptGetExpresser(); +#endif + //----------------------------------------------------- // Dynamic scripted NPC interactions //----------------------------------------------------- diff --git a/sp/src/game/server/ai_default.cpp b/sp/src/game/server/ai_default.cpp index e80817ad..e436fa4e 100644 --- a/sp/src/game/server/ai_default.cpp +++ b/sp/src/game/server/ai_default.cpp @@ -386,6 +386,44 @@ CAI_Schedule *CAI_BaseNPC::GetScheduleOfType( int scheduleType ) scheduleType = TranslateSchedule( scheduleType ); AI_PROFILE_SCOPE_END(); +#ifdef MAPBASE_VSCRIPT + if ( m_ScriptScope.IsInitialized() ) + { + // Some of this code should know if there's a function first, so look + // up the function beforehand instead of using CallScriptFunction() + HSCRIPT hFunc = m_ScriptScope.LookupFunction( "NPC_TranslateSchedule" ); + if (hFunc) + { + int newSchedule = scheduleType; + if ( AI_IdIsLocal( newSchedule ) ) + { + newSchedule = GetClassScheduleIdSpace()->ScheduleLocalToGlobal(newSchedule); + } + + g_pScriptVM->SetValue( "schedule", GetSchedulingSymbols()->ScheduleIdToSymbol( newSchedule ) ); + g_pScriptVM->SetValue( "schedule_id", newSchedule ); + + ScriptVariant_t functionReturn; + m_ScriptScope.Call( hFunc, &functionReturn ); + + if (functionReturn.m_type == FIELD_INTEGER) + { + newSchedule = functionReturn.m_int; + } + else + { + newSchedule = GetScheduleID( functionReturn.m_pszString ); + } + + if (newSchedule != scheduleType && newSchedule > -1) + scheduleType = newSchedule; + + g_pScriptVM->ClearValue( "schedule" ); + g_pScriptVM->ClearValue( "schedule_id" ); + } + } +#endif + // Get a pointer to that schedule CAI_Schedule *schedule = GetSchedule(scheduleType); diff --git a/sp/src/game/server/ai_hint.cpp b/sp/src/game/server/ai_hint.cpp index 644e054f..1f8ec4d1 100644 --- a/sp/src/game/server/ai_hint.cpp +++ b/sp/src/game/server/ai_hint.cpp @@ -900,6 +900,23 @@ BEGIN_DATADESC( CAI_Hint ) END_DATADESC( ); +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CAI_Hint, CBaseEntity, "An entity which gives contextual pointers for NPCs." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetHintType, "GetHintType", "Get the hint's type ID." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetUser, "GetUser", "Get the hint's current user." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetHintGroup, "GetHintGroup", "Get the name of the hint's group." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetHintActivity, "GetHintActivity", "Get the name of the hint activity." ) + + DEFINE_SCRIPTFUNC( IsDisabled, "Check if the hint is disabled." ) + DEFINE_SCRIPTFUNC( IsLocked, "Check if the hint is locked." ) + DEFINE_SCRIPTFUNC( GetNodeId, "Get the hint's node ID." ) + DEFINE_SCRIPTFUNC( Yaw, "Get the hint's yaw." ) + DEFINE_SCRIPTFUNC( GetDirection, "Get the hint's direction." ) + +END_SCRIPTDESC(); +#endif + //------------------------------------------------------------------------------ // Purpose : //------------------------------------------------------------------------------ diff --git a/sp/src/game/server/ai_hint.h b/sp/src/game/server/ai_hint.h index e88d8021..25fd4fdb 100644 --- a/sp/src/game/server/ai_hint.h +++ b/sp/src/game/server/ai_hint.h @@ -312,6 +312,13 @@ public: void NPCHandleStartNav( CAI_BaseNPC *pNPC, bool bDefaultFacing ); #endif +#ifdef MAPBASE_VSCRIPT + int ScriptGetHintType() { return (int)HintType(); } + HSCRIPT ScriptGetUser() { return ToHScript( User() ); } + const char* ScriptGetHintGroup() { return STRING( GetGroup() ); } + const char* ScriptGetHintActivity() { return STRING( HintActivityName() ); } +#endif + private: void Spawn( void ); virtual void Activate(); @@ -343,6 +350,9 @@ private: friend class CAI_HintManager; DECLARE_DATADESC(); +#ifdef MAPBASE_VSCRIPT + DECLARE_ENT_SCRIPTDESC(); +#endif }; #define SF_ALLOW_JUMP_UP 65536 diff --git a/sp/src/game/server/ai_memory.cpp b/sp/src/game/server/ai_memory.cpp index 7ac69311..46cd09f8 100644 --- a/sp/src/game/server/ai_memory.cpp +++ b/sp/src/game/server/ai_memory.cpp @@ -146,6 +146,29 @@ BEGIN_SIMPLE_DATADESC( AI_EnemyInfo_t ) // NOT SAVED nextEMemory END_DATADESC() +#ifdef MAPBASE_VSCRIPT +#define DEFINE_ENEMY_INFO_SCRIPTFUNCS(name, desc) \ + DEFINE_SCRIPTFUNC_NAMED( Get##name, #name, "Get " desc ) \ + DEFINE_SCRIPTFUNC( Set##name, "Set " desc ) + +BEGIN_SCRIPTDESC_ROOT( AI_EnemyInfo_t, "Accessor for information about an enemy." ) + DEFINE_SCRIPTFUNC( Enemy, "Get the enemy." ) + DEFINE_SCRIPTFUNC( SetEnemy, "Set the enemy." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( LastKnownLocation, "the enemy's last known location." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( LastSeenLocation, "the enemy's last seen location." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastSeen, "the last time the enemy was seen." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeFirstSeen, "the first time the enemy was seen." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastReacquired, "the last time the enemy was reaquired." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeValidEnemy, "the time at which the enemy can be selected (reaction delay)." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeLastReceivedDamageFrom, "the last time damage was received from this enemy." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( TimeAtFirstHand, "the time at which the enemy was seen firsthand." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( DangerMemory, "the memory of danger position w/o enemy pointer." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( EludedMe, "whether the enemy is not at the last known location." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( Unforgettable, "whether the enemy is unfortgettable." ) + DEFINE_ENEMY_INFO_SCRIPTFUNCS( MobbedMe, "whether the enemy was part of a mob at some point." ) +END_SCRIPTDESC(); +#endif + //----------------------------------------------------------------------------- CAI_Enemies::CAI_Enemies(void) diff --git a/sp/src/game/server/ai_memory.h b/sp/src/game/server/ai_memory.h index d348c53e..faa482a2 100644 --- a/sp/src/game/server/ai_memory.h +++ b/sp/src/game/server/ai_memory.h @@ -45,6 +45,29 @@ struct AI_EnemyInfo_t bool bUnforgettable; bool bMobbedMe; // True if enemy was part of a mob at some point +#ifdef MAPBASE_VSCRIPT + // Script functions. + #define ENEMY_INFO_SCRIPT_FUNCS(type, name, var) \ + type Get##name() { return var; } \ + void Set##name( type v ) { var = v; } + + HSCRIPT Enemy() { return ToHScript(hEnemy); } + void SetEnemy( HSCRIPT ent ) { hEnemy = ToEnt(ent); } + + ENEMY_INFO_SCRIPT_FUNCS( Vector, LastKnownLocation, vLastKnownLocation ); + ENEMY_INFO_SCRIPT_FUNCS( Vector, LastSeenLocation, vLastSeenLocation ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastSeen, timeLastSeen ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeFirstSeen, timeFirstSeen ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastReacquired, timeLastReacquired ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeValidEnemy, timeValidEnemy ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeLastReceivedDamageFrom, timeLastReceivedDamageFrom ); + ENEMY_INFO_SCRIPT_FUNCS( float, TimeAtFirstHand, timeAtFirstHand ); + ENEMY_INFO_SCRIPT_FUNCS( bool, DangerMemory, bDangerMemory ); + ENEMY_INFO_SCRIPT_FUNCS( bool, EludedMe, bEludedMe ); + ENEMY_INFO_SCRIPT_FUNCS( bool, Unforgettable, bUnforgettable ); + ENEMY_INFO_SCRIPT_FUNCS( bool, MobbedMe, bMobbedMe ); +#endif + DECLARE_SIMPLE_DATADESC(); }; diff --git a/sp/src/game/server/ai_network.cpp b/sp/src/game/server/ai_network.cpp index 78b7a53f..16d8a7fa 100644 --- a/sp/src/game/server/ai_network.cpp +++ b/sp/src/game/server/ai_network.cpp @@ -16,6 +16,9 @@ #include "ai_navigator.h" #include "world.h" #include "ai_moveprobe.h" +#ifdef MAPBASE_VSCRIPT +#include "ai_hint.h" +#endif // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -31,6 +34,53 @@ extern float MOVE_HEIGHT_EPSILON; // later point we will probabaly have multiple AINetworkds per level CAI_Network* g_pBigAINet; +#ifdef MAPBASE_VSCRIPT +BEGIN_SCRIPTDESC_ROOT( CAI_Network, SCRIPT_SINGLETON "The global list of AI nodes." ) + DEFINE_SCRIPTFUNC( NumNodes, "Number of nodes in the level" ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetNodePosition, "GetNodePosition", "Get position of node using a generic human hull" ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetNodePositionWithHull, "GetNodePositionWithHull", "Get position of node using the specified hull" ) + DEFINE_SCRIPTFUNC( GetNodeYaw, "Get yaw of node" ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptNearestNodeToPoint, "NearestNodeToPoint", "Get ID of nearest node" ) + DEFINE_SCRIPTFUNC_NAMED( ScriptNearestNodeToPointWithNPC, "NearestNodeToPointForNPC", "Get ID of nearest node using the specified NPC's properties" ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetNodeType, "GetNodeType", "Get a node's type" ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetNodeHint, "GetNodeHint", "Get a node's hint" ) +END_SCRIPTDESC(); + +HSCRIPT CAI_Network::ScriptGetNodeHint( int nodeID ) +{ + CAI_Node *pNode = GetNode( nodeID ); + if (!pNode) + return NULL; + + return ToHScript( pNode->GetHint() ); +} + +int CAI_Network::ScriptGetNodeType( int nodeID ) +{ + CAI_Node *pNode = GetNode( nodeID ); + if (!pNode) + return NULL; + + return (int)pNode->GetType(); +} + +int CAI_Network::ScriptNearestNodeToPointWithNPC( HSCRIPT hNPC, const Vector &vecPosition, bool bCheckVisibility ) +{ + CBaseEntity *pEnt = ToEnt( hNPC ); + if (!pEnt || !pEnt->MyNPCPointer()) + { + Warning("vscript: NearestNodeToPointWithNPC - Invalid NPC\n"); + return NO_NODE; + } + + return NearestNodeToPoint( pEnt->MyNPCPointer(), vecPosition, bCheckVisibility ); +} +#endif + //----------------------------------------------------------------------------- abstract_class INodeListFilter diff --git a/sp/src/game/server/ai_network.h b/sp/src/game/server/ai_network.h index 8cebd16a..a86d89b8 100644 --- a/sp/src/game/server/ai_network.h +++ b/sp/src/game/server/ai_network.h @@ -127,6 +127,17 @@ public: } CAI_Node** AccessNodes() const { return m_pAInode; } + +#ifdef MAPBASE_VSCRIPT + Vector ScriptGetNodePosition( int nodeID ) { return GetNodePosition( HULL_HUMAN, nodeID ); } + Vector ScriptGetNodePositionWithHull( int nodeID, int hull ) { return GetNodePosition( (Hull_t)hull, nodeID ); } + + int ScriptNearestNodeToPoint( const Vector &vecPosition, bool bCheckVisibility = true ) { return NearestNodeToPoint( NULL, vecPosition, bCheckVisibility ); } + int ScriptNearestNodeToPointWithNPC( HSCRIPT hNPC, const Vector &vecPosition, bool bCheckVisibility = true ); + + HSCRIPT ScriptGetNodeHint( int nodeID ); + int ScriptGetNodeType( int nodeID ); +#endif private: friend class CAI_NetworkManager; diff --git a/sp/src/game/server/ai_networkmanager.cpp b/sp/src/game/server/ai_networkmanager.cpp index d5bc187c..8f470a47 100644 --- a/sp/src/game/server/ai_networkmanager.cpp +++ b/sp/src/game/server/ai_networkmanager.cpp @@ -948,6 +948,13 @@ void CAI_NetworkManager::InitializeAINetworks() } } +#ifdef MAPBASE_VSCRIPT + if (g_pScriptVM) + { + g_pScriptVM->RegisterInstance( g_pBigAINet, "AINetwork" ); + } +#endif + // Reset node counter used during load CNodeEnt::m_nNodeCount = 0; diff --git a/sp/src/game/server/ai_speech.cpp b/sp/src/game/server/ai_speech.cpp index 6d47b961..c364b704 100644 --- a/sp/src/game/server/ai_speech.cpp +++ b/sp/src/game/server/ai_speech.cpp @@ -184,6 +184,20 @@ BEGIN_SIMPLE_DATADESC( CAI_Expresser ) DEFINE_FIELD( m_flLastTimeAcceptedSpeak, FIELD_TIME ), END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_SCRIPTDESC_ROOT( CAI_Expresser, "Expresser class for complex speech." ) + + DEFINE_SCRIPTFUNC( IsSpeaking, "Check if the actor is speaking." ) + DEFINE_SCRIPTFUNC( CanSpeak, "Check if the actor can speak." ) + DEFINE_SCRIPTFUNC( BlockSpeechUntil, "Block speech for a certain amount of time. This is stored in curtime." ) + DEFINE_SCRIPTFUNC( ForceNotSpeaking, "If the actor is speaking, force the system to recognize them as not speaking." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptSpeakRawScene, "SpeakRawScene", "Speak a raw, instanced VCD scene as though it were played through the Response System. Return whether the scene successfully plays." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSpeakAutoGeneratedScene, "SpeakAutoGeneratedScene", "Speak an automatically generated, instanced VCD scene for this sound as though it were played through the Response System. Return whether the scene successfully plays." ) + +END_SCRIPTDESC(); +#endif + //------------------------------------- bool CAI_Expresser::SemaphoreIsAvailable( CBaseEntity *pTalker ) diff --git a/sp/src/game/server/ai_speech.h b/sp/src/game/server/ai_speech.h index 519df955..2abb87f6 100644 --- a/sp/src/game/server/ai_speech.h +++ b/sp/src/game/server/ai_speech.h @@ -203,6 +203,12 @@ public: // Force the NPC to release the semaphore & clear next speech time void ForceNotSpeaking( void ); +#ifdef MAPBASE_VSCRIPT + bool ScriptSpeakRawScene( char const *soundname, float delay ) { return SpeakRawScene( soundname, delay, NULL ); } + bool ScriptSpeakAutoGeneratedScene( char const *soundname, float delay ) { return SpeakAutoGeneratedScene( soundname, delay ); } + bool ScriptSpeak( AIConcept_t concept, const char *modifiers ) { return Speak( concept, modifiers ); } +#endif + protected: CAI_TimedSemaphore *GetMySpeechSemaphore( CBaseEntity *pNpc ); diff --git a/sp/src/game/server/basecombatcharacter.cpp b/sp/src/game/server/basecombatcharacter.cpp index d96b9345..e6759ead 100644 --- a/sp/src/game/server/basecombatcharacter.cpp +++ b/sp/src/game/server/basecombatcharacter.cpp @@ -150,6 +150,43 @@ BEGIN_DATADESC( CBaseCombatCharacter ) END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CBaseCombatCharacter, CBaseFlex, "The base class shared by players and NPCs." ) + + DEFINE_SCRIPTFUNC_NAMED( GetScriptActiveWeapon, "GetActiveWeapon", "Get the character's active weapon entity." ) + DEFINE_SCRIPTFUNC( WeaponCount, "Get the number of weapons a character possesses." ) + DEFINE_SCRIPTFUNC_NAMED( GetScriptWeaponIndex, "GetWeapon", "Get a specific weapon in the character's inventory." ) + DEFINE_SCRIPTFUNC_NAMED( GetScriptWeaponByType, "FindWeapon", "Find a specific weapon in the character's inventory by its classname." ) + + DEFINE_SCRIPTFUNC_NAMED( Weapon_ShootPosition, "ShootPosition", "Get the character's shoot position." ) + DEFINE_SCRIPTFUNC_NAMED( Weapon_DropAll, "DropAllWeapons", "Make the character drop all of its weapons." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetAmmoCount, "GetAmmoCount", "Get the ammo count of the specified ammo type." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSetAmmoCount, "SetAmmoCount", "Set the ammo count of the specified ammo type." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptRelationType, "GetRelationship", "Get a character's relationship to a specific entity." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptRelationPriority, "GetRelationPriority", "Get a character's relationship priority for a specific entity." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSetRelationship, "SetRelationship", "Set a character's relationship with a specific entity." ) + + DEFINE_SCRIPTFUNC_NAMED( GetScriptVehicleEntity, "GetVehicleEntity", "Get the entity for a character's current vehicle if they're in one." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptInViewCone, "InViewCone", "Check if the specified position is in the character's viewcone." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptEntInViewCone, "EntInViewCone", "Check if the specified entity is in the character's viewcone." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptInAimCone, "InAimCone", "Check if the specified position is in the character's aim cone." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptEntInViewCone, "EntInAimCone", "Check if the specified entity is in the character's aim cone." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptBodyAngles, "BodyAngles", "Get the body's angles." ) + DEFINE_SCRIPTFUNC( BodyDirection2D, "Get the body's 2D direction." ) + DEFINE_SCRIPTFUNC( BodyDirection3D, "Get the body's 3D direction." ) + DEFINE_SCRIPTFUNC( HeadDirection2D, "Get the head's 2D direction." ) + DEFINE_SCRIPTFUNC( HeadDirection3D, "Get the head's 3D direction." ) + DEFINE_SCRIPTFUNC( EyeDirection2D, "Get the eyes' 2D direction." ) + DEFINE_SCRIPTFUNC( EyeDirection3D, "Get the eyes' 3D direction." ) + +END_SCRIPTDESC(); +#endif + BEGIN_SIMPLE_DATADESC( Relationship_t ) DEFINE_FIELD( entity, FIELD_EHANDLE ), @@ -4317,6 +4354,78 @@ void CBaseCombatCharacter::DoMuzzleFlash() } } +#ifdef MAPBASE_VSCRIPT // DO NOT COMMIT; WAIT UNTIL FULL MERGE (5/15/2020) +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CBaseCombatCharacter::GetScriptActiveWeapon() +{ + return ToHScript( GetActiveWeapon() ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CBaseCombatCharacter::GetScriptWeaponIndex( int i ) +{ + return ToHScript( GetWeapon( i ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CBaseCombatCharacter::GetScriptWeaponByType( const char *pszWeapon, int iSubType ) +{ + return ToHScript( Weapon_OwnsThisType( pszWeapon, iSubType ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int CBaseCombatCharacter::ScriptGetAmmoCount( const char *szName ) const +{ + return GetAmmoCount( GetAmmoDef()->Index(szName) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CBaseCombatCharacter::ScriptSetAmmoCount( const char *szName, int iCount ) +{ + int iType = GetAmmoDef()->Index( szName ); + if (iType == -1) + { + Warning("\"%s\" is not a valid ammo type\n", szName); + return; + } + + return SetAmmoCount( iCount, iType ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int CBaseCombatCharacter::ScriptRelationType( HSCRIPT pTarget ) +{ + return (int)IRelationType( ToEnt( pTarget ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int CBaseCombatCharacter::ScriptRelationPriority( HSCRIPT pTarget ) +{ + return IRelationPriority( ToEnt( pTarget ) ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CBaseCombatCharacter::ScriptSetRelationship( HSCRIPT pTarget, int disposition, int priority ) +{ + AddEntityRelationship( ToEnt( pTarget ), (Disposition_t)disposition, priority ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CBaseCombatCharacter::GetScriptVehicleEntity() +{ + return ToHScript( GetVehicleEntity() ); +} +#endif + //----------------------------------------------------------------------------- // Purpose: return true if given target cant be seen because of fog //----------------------------------------------------------------------------- diff --git a/sp/src/game/server/basecombatcharacter.h b/sp/src/game/server/basecombatcharacter.h index a9a5c815..4168381d 100644 --- a/sp/src/game/server/basecombatcharacter.h +++ b/sp/src/game/server/basecombatcharacter.h @@ -119,6 +119,9 @@ public: DECLARE_SERVERCLASS(); DECLARE_DATADESC(); DECLARE_PREDICTABLE(); +#ifdef MAPBASE_VSCRIPT + DECLARE_ENT_SCRIPTDESC(); +#endif public: @@ -407,6 +410,29 @@ public: virtual float GetSpreadBias( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget ); virtual void DoMuzzleFlash(); +#ifdef MAPBASE_VSCRIPT // DO NOT COMMIT; WAIT UNTIL FULL MERGE (5/15/2020) + HSCRIPT GetScriptActiveWeapon(); + HSCRIPT GetScriptWeaponIndex( int i ); + HSCRIPT GetScriptWeaponByType( const char *pszWeapon, int iSubType = 0 ); + + int ScriptGetAmmoCount( const char *szName ) const; + void ScriptSetAmmoCount( const char *szName, int iCount ); + + int ScriptRelationType( HSCRIPT pTarget ); + int ScriptRelationPriority( HSCRIPT pTarget ); + void ScriptSetRelationship( HSCRIPT pTarget, int disposition, int priority ); + + HSCRIPT GetScriptVehicleEntity(); + + bool ScriptInViewCone( const Vector &vecSpot ) { return FInViewCone( vecSpot ); } + bool ScriptEntInViewCone( HSCRIPT pEntity ) { return FInViewCone( ToEnt( pEntity ) ); } + + bool ScriptInAimCone( const Vector &vecSpot ) { return FInAimCone( vecSpot ); } + bool ScriptEntInAimCone( HSCRIPT pEntity ) { return FInAimCone( ToEnt( pEntity ) ); } + + const Vector& ScriptBodyAngles( void ) { static Vector vec; QAngle qa = BodyAngles(); vec.x = qa.x; vec.y = qa.y; vec.z = qa.z; return vec; } +#endif + // Interactions static void InitInteractionSystem(); diff --git a/sp/src/game/server/baseentity.cpp b/sp/src/game/server/baseentity.cpp index 69a5906c..8a620283 100644 --- a/sp/src/game/server/baseentity.cpp +++ b/sp/src/game/server/baseentity.cpp @@ -2030,6 +2030,9 @@ BEGIN_DATADESC_NO_BASE( CBaseEntity ) DEFINE_INPUTFUNC(FIELD_STRING, "RunScriptFile", InputRunScriptFile), DEFINE_INPUTFUNC(FIELD_STRING, "RunScriptCode", InputRunScript), DEFINE_INPUTFUNC(FIELD_STRING, "CallScriptFunction", InputCallScriptFunction), +#ifdef MAPBASE_VSCRIPT + DEFINE_INPUTFUNC(FIELD_STRING, "RunScriptCodeQuotable", InputRunScriptQuotable), +#endif #ifdef MAPBASE DEFINE_OUTPUT( m_OutUser1, "OutUser1" ), @@ -2190,6 +2193,17 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities" DEFINE_SCRIPTFUNC_NAMED( KeyValueFromVector, "__KeyValueFromVector", SCRIPT_HIDE ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetModelKeyValues, "GetModelKeyValues", "Get a KeyValue class instance on this entity's model") + +#ifdef MAPBASE_VSCRIPT + DEFINE_SCRIPTFUNC_NAMED( ScriptIsVisible, "IsVisible", "Check if the specified position can be visible to this entity." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptIsEntVisible, "IsEntVisible", "Check if the specified entity can be visible to this entity." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptIsVisibleWithMask, "IsVisibleWithMask", "Check if the specified position can be visible to this entity with a specific trace mask." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetContext, "GetContext", "Get a response context value" ) + DEFINE_SCRIPTFUNC_NAMED( ScriptAddContext, "AddContext", "Add a response context value" ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptClassify, "Classify", "Get Class_T class ID" ) +#endif DEFINE_SCRIPTFUNC( ValidateScriptScope, "Ensure that an entity's script scope has been created" ) DEFINE_SCRIPTFUNC( GetScriptScope, "Retrieve the script-side data associated with an entity" ) @@ -8014,6 +8028,33 @@ void CBaseEntity::InputCallScriptFunction(inputdata_t& inputdata) CallScriptFunction(inputdata.value.String(), NULL); } +#ifdef MAPBASE_VSCRIPT +//--------------------------------------------------------- +// Send the string to the VM as source code and execute it +//--------------------------------------------------------- +void CBaseEntity::InputRunScriptQuotable(inputdata_t& inputdata) +{ + CUtlStringList vecStrings; + V_SplitString( inputdata.value.String(), "''", vecStrings ); + if (vecStrings.Count() > 1) + { + char szQuotableCode[1024]; + Q_strncpy( szQuotableCode, vecStrings[0], sizeof( szQuotableCode ) ); + + for ( int i = 1; i < vecStrings.Count(); i++ ) + { + Q_snprintf( szQuotableCode, sizeof( szQuotableCode ), "%s\"%s", szQuotableCode, vecStrings[i] ); + } + + RunScript( szQuotableCode, "InputRunScriptQuotable" ); + } + else + { + RunScript( inputdata.value.String(), "InputRunScriptQuotable" ); + } +} +#endif + // #define VMPROFILE // define to profile vscript calls #ifdef VMPROFILE @@ -9474,6 +9515,29 @@ const Vector& CBaseEntity::ScriptGetBoundingMaxs(void) return m_Collision.OBBMaxs(); } +#ifdef MAPBASE_VSCRIPT +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CBaseEntity::ScriptAddContext( const char *name, const char *value, float duration ) +{ + AddContext( name, value, duration ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +const char *CBaseEntity::ScriptGetContext( const char *name ) +{ + return GetContextValue( name ); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +int CBaseEntity::ScriptClassify( void ) +{ + return (int)Classify(); +} +#endif + #ifdef MAPBASE extern int EntityFactory_AutoComplete( const char *cmdname, CUtlVector< CUtlString > &commands, CUtlRBTree< CUtlString > &symbols, char *substring, int checklen = 0 ); diff --git a/sp/src/game/server/baseentity.h b/sp/src/game/server/baseentity.h index fd045d12..d1500601 100644 --- a/sp/src/game/server/baseentity.h +++ b/sp/src/game/server/baseentity.h @@ -754,6 +754,9 @@ public: void InputRunScript(inputdata_t& inputdata); void InputRunScriptFile(inputdata_t& inputdata); void InputCallScriptFunction(inputdata_t& inputdata); +#ifdef MAPBASE_VSCRIPT + void InputRunScriptQuotable(inputdata_t& inputdata); +#endif bool RunScriptFile(const char* pScriptFile, bool bUseRootScope = false); bool RunScript(const char* pScriptText, const char* pDebugFilename = "CBaseEntity::RunScript"); @@ -1991,6 +1994,17 @@ public: const Vector& ScriptGetBoundingMins(void); const Vector& ScriptGetBoundingMaxs(void); +#ifdef MAPBASE_VSCRIPT + bool ScriptIsVisible( const Vector &vecSpot ) { return FVisible( vecSpot ); } + bool ScriptIsEntVisible( HSCRIPT pEntity ) { return FVisible( ToEnt( pEntity ) ); } + bool ScriptIsVisibleWithMask( const Vector &vecSpot, int traceMask ) { return FVisible( vecSpot, traceMask ); } + + void ScriptAddContext( const char *name, const char *value, float duration = 0.0f ); + const char *ScriptGetContext( const char *name ); + + int ScriptClassify(void); +#endif + string_t m_iszVScripts; string_t m_iszScriptThinkFunction; CScriptScope m_ScriptScope; diff --git a/sp/src/game/server/globalstate.cpp b/sp/src/game/server/globalstate.cpp index 7d50d5ce..7ade7762 100644 --- a/sp/src/game/server/globalstate.cpp +++ b/sp/src/game/server/globalstate.cpp @@ -143,6 +143,28 @@ public: return m_list.Count(); } +#ifdef MAPBASE_VSCRIPT + virtual void RegisterVScript() + { + g_pScriptVM->RegisterInstance( this, "Globals" ); + } + + int ScriptAddEntity( const char *pGlobalname, const char *pMapName, int state ) + { + return AddEntity( pGlobalname, pMapName, (GLOBALESTATE)state ); + } + + void ScriptSetState( int globalIndex, int state ) + { + SetState( globalIndex, (GLOBALESTATE)state ); + } + + int ScriptGetState( int globalIndex ) + { + return (int)GetState( globalIndex ); + } +#endif + void Reset( void ); int Save( ISave &save ); int Restore( IRestore &restore ); @@ -323,3 +345,15 @@ CON_COMMAND(server_game_time, "Gives the game time in seconds (server's curtime) ShowServerGameTime(); } + +#ifdef MAPBASE_VSCRIPT +BEGIN_SCRIPTDESC_ROOT( CGlobalState, SCRIPT_SINGLETON "Global state system." ) + DEFINE_SCRIPTFUNC( GetIndex, "Gets the index of the specified global name. Returns -1 if it does not exist." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptAddEntity, "AddGlobal", "Adds a new global with a specific map name and state. Returns its index." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetState, "GetState", "Gets the state of the specified global." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSetState, "SetState", "Sets the state of the specified global." ) + DEFINE_SCRIPTFUNC( GetCounter, "Gets the counter of the specified global." ) + DEFINE_SCRIPTFUNC( SetCounter, "Sets the counter of the specified global." ) + DEFINE_SCRIPTFUNC( AddToCounter, "Adds to the counter of the specified global." ) +END_SCRIPTDESC(); +#endif diff --git a/sp/src/game/server/mapbase/logic_externaldata.cpp b/sp/src/game/server/mapbase/logic_externaldata.cpp index ce4f4d56..de927147 100644 --- a/sp/src/game/server/mapbase/logic_externaldata.cpp +++ b/sp/src/game/server/mapbase/logic_externaldata.cpp @@ -16,6 +16,9 @@ class CLogicExternalData : public CLogicalEntity { DECLARE_CLASS( CLogicExternalData, CLogicalEntity ); DECLARE_DATADESC(); +#ifdef MAPBASE_VSCRIPT + DECLARE_ENT_SCRIPTDESC(); +#endif public: ~CLogicExternalData(); @@ -34,6 +37,16 @@ public: void InputSave( inputdata_t &inputdata ); void InputReload( inputdata_t &inputdata ); +#ifdef MAPBASE_VSCRIPT + HSCRIPT ScriptGetKeyValues( void ); + HSCRIPT ScriptGetKeyValueBlock( void ); + + void ScriptSetKeyValues( HSCRIPT hKV ); + void ScriptSetKeyValueBlock( HSCRIPT hKV ); + + void ScriptSetBlock( const char *szNewBlock, HSCRIPT hActivator = NULL, HSCRIPT hCaller = NULL ); +#endif + char m_iszFile[MAX_PATH]; // Root file @@ -76,6 +89,21 @@ BEGIN_DATADESC( CLogicExternalData ) END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CLogicExternalData, CBaseEntity, "An entity which loads keyvalues from an external data file." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValues, "GetKeyValues", "Gets the external data expressed in CScriptKeyValues." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueBlock, "GetKeyValueBlock", "Gets the current external data block expressed in CScriptKeyValues." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValues, "SetKeyValues", "Sets the external data from a CScriptKeyValues object." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueBlock, "SetKeyValues", "Sets the current external data block from a CScriptKeyValues object." ) + + DEFINE_SCRIPTFUNC( LoadFile, "Loads external data from the external file." ) + DEFINE_SCRIPTFUNC( SaveFile, "Saves the external data to the external file." ) + +END_SCRIPTDESC(); +#endif + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- @@ -243,3 +271,97 @@ void CLogicExternalData::InputReload( inputdata_t &inputdata ) { LoadFile(); } + +#ifdef MAPBASE_VSCRIPT +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CLogicExternalData::ScriptGetKeyValues( void ) +{ + if (m_bReloadBeforeEachAction) + LoadFile(); + + HSCRIPT hScript = NULL; + if (m_pRoot) + { + // Does this need to be destructed or freed? m_pScriptModelKeyValues apparently doesn't. + CScriptKeyValues *pKV = new CScriptKeyValues( m_pRoot ); + hScript = g_pScriptVM->RegisterInstance( pKV ); + } + + return hScript; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CLogicExternalData::ScriptGetKeyValueBlock( void ) +{ + if (m_bReloadBeforeEachAction) + LoadFile(); + + HSCRIPT hScript = NULL; + if (m_pBlock) + { + // Does this need to be destructed or freed? m_pScriptModelKeyValues apparently doesn't. + CScriptKeyValues *pKV = new CScriptKeyValues( m_pBlock ); + hScript = g_pScriptVM->RegisterInstance( pKV ); + } + + return hScript; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +extern CScriptKeyValues *ToScriptKeyValues( HSCRIPT hKV ); + +void CLogicExternalData::ScriptSetKeyValues( HSCRIPT hKV ) +{ + if (m_pRoot) + { + m_pRoot->deleteThis(); + m_pRoot = NULL; + } + + CScriptKeyValues *pKV = ToScriptKeyValues(hKV); + if (pKV) + { + m_pRoot = pKV->m_pKeyValues; + } +} + +void CLogicExternalData::ScriptSetKeyValueBlock( HSCRIPT hKV ) +{ + if (m_pBlock) + { + m_pBlock->deleteThis(); + m_pBlock = NULL; + } + + CScriptKeyValues *pKV = ToScriptKeyValues(hKV); + if (pKV) + { + m_pBlock = pKV->m_pKeyValues; + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CLogicExternalData::ScriptSetBlock( const char *szNewBlock, HSCRIPT hActivator, HSCRIPT hCaller ) +{ + CBaseEntity *pActivator = ToEnt( hActivator ); + CBaseEntity *pCaller = ToEnt( hCaller ); + string_t iszNewTarget = AllocPooledString(szNewBlock); + if (STRING(iszNewTarget)[0] == '!') + { + if (FStrEq(STRING(iszNewTarget), "!self")) + iszNewTarget = GetEntityName(); + else if (pActivator && FStrEq(STRING(iszNewTarget), "!activator")) + iszNewTarget = pActivator->GetEntityName(); + else if (pCaller && FStrEq(STRING(iszNewTarget), "!caller")) + iszNewTarget = pCaller->GetEntityName(); + } + + m_target = iszNewTarget; + LoadFile(); +} +#endif diff --git a/sp/src/game/server/player.cpp b/sp/src/game/server/player.cpp index 52cfe3cd..7aa65d52 100644 --- a/sp/src/game/server/player.cpp +++ b/sp/src/game/server/player.cpp @@ -478,9 +478,19 @@ BEGIN_DATADESC( CBasePlayer ) // DEFINE_UTLVECTOR( m_vecPlayerSimInfo ), END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_ENT_SCRIPTDESC( CBasePlayer, CBaseCombatCharacter, "The player entity." ) + + DEFINE_SCRIPTFUNC_NAMED( ScriptIsPlayerNoclipping, "IsNoclipping", "Returns true if the player is in noclip mode." ) + + DEFINE_SCRIPTFUNC_NAMED( VScriptGetExpresser, "GetExpresser", "Gets a handle for this player's expresser." ) + +END_SCRIPTDESC(); +#else BEGIN_ENT_SCRIPTDESC( CBasePlayer, CBaseAnimating, "The player entity." ) DEFINE_SCRIPTFUNC_NAMED( ScriptIsPlayerNoclipping, "IsNoclipping", "Returns true if the player is in noclip mode." ) END_SCRIPTDESC(); +#endif int giPrecacheGrunt = 0; @@ -6894,6 +6904,22 @@ bool CBasePlayer::ScriptIsPlayerNoclipping(void) return (GetMoveType() == MOVETYPE_NOCLIP); } +#ifdef MAPBASE_VSCRIPT +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +HSCRIPT CBasePlayer::VScriptGetExpresser() +{ + HSCRIPT hScript = NULL; + CAI_Expresser *pExpresser = GetExpresser(); + if (pExpresser) + { + hScript = g_pScriptVM->RegisterInstance( pExpresser ); + } + + return hScript; +} +#endif + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- diff --git a/sp/src/game/server/player.h b/sp/src/game/server/player.h index 261d9a26..35b19e84 100644 --- a/sp/src/game/server/player.h +++ b/sp/src/game/server/player.h @@ -390,6 +390,10 @@ public: bool ScriptIsPlayerNoclipping(void); +#ifdef MAPBASE_VSCRIPT + HSCRIPT VScriptGetExpresser(); +#endif + // View model prediction setup void CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov ); diff --git a/sp/src/game/server/server_mapbase.vpc b/sp/src/game/server/server_mapbase.vpc index dc97ec02..5868584e 100644 --- a/sp/src/game/server/server_mapbase.vpc +++ b/sp/src/game/server/server_mapbase.vpc @@ -33,6 +33,8 @@ $Project $File "$SRCDIR\game\shared\mapbase\MapEdit.h" $File "$SRCDIR\game\shared\mapbase\matchers.cpp" $File "$SRCDIR\game\shared\mapbase\matchers.h" + $File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.cpp" [$MAPBASE_VSCRIPT] + $File "$SRCDIR\game\shared\mapbase\vscript_funcs_hl2.cpp" [$MAPBASE_VSCRIPT && ($HL2||$EPISODIC)] $File "mapbase\ai_grenade.cpp" $File "mapbase\ai_grenade.h" diff --git a/sp/src/game/server/vscript_server.cpp b/sp/src/game/server/vscript_server.cpp index 259a3d52..2b28c62d 100644 --- a/sp/src/game/server/vscript_server.cpp +++ b/sp/src/game/server/vscript_server.cpp @@ -132,6 +132,24 @@ BEGIN_SCRIPTDESC_ROOT( CScriptKeyValues, "Wrapper class over KeyValues instance" DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValueString, "GetKeyString", "Given a KeyValues object and a key name, return associated string value" ); DEFINE_SCRIPTFUNC_NAMED( ScriptIsKeyValueEmpty, "IsKeyEmpty", "Given a KeyValues object and a key name, return true if key name has no value" ); DEFINE_SCRIPTFUNC_NAMED( ScriptReleaseKeyValues, "ReleaseKeyValues", "Given a root KeyValues object, release its contents" ); +#ifdef MAPBASE_VSCRIPT + DEFINE_SCRIPTFUNC_NAMED( ScriptGetName, "GetName", "Given a KeyValues object, return its name" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptGetInt, "GetInt", "Given a KeyValues object, return its own associated integer value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptGetFloat, "GetFloat", "Given a KeyValues object, return its own associated float value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptGetString, "GetString", "Given a KeyValues object, return its own associated string value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptGetBool, "GetBool", "Given a KeyValues object, return its own associated bool value" ); + + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueInt, "SetKeyInt", "Given a KeyValues object and a key name, set associated integer value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueFloat, "SetKeyFloat", "Given a KeyValues object and a key name, set associated float value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueBool, "SetKeyBool", "Given a KeyValues object and a key name, set associated bool value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetKeyValueString, "SetKeyString", "Given a KeyValues object and a key name, set associated string value" ); + + DEFINE_SCRIPTFUNC_NAMED( ScriptSetName, "SetName", "Given a KeyValues object, set its name" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetInt, "SetInt", "Given a KeyValues object, set its own associated integer value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetFloat, "SetFloat", "Given a KeyValues object, set its own associated float value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetBool, "SetBool", "Given a KeyValues object, set its own associated bool value" ); + DEFINE_SCRIPTFUNC_NAMED( ScriptSetString, "SetString", "Given a KeyValues object, set its own associated string value" ); +#endif END_SCRIPTDESC(); HSCRIPT CScriptKeyValues::ScriptFindKey( const char *pszName ) @@ -209,6 +227,84 @@ void CScriptKeyValues::ScriptReleaseKeyValues( ) m_pKeyValues = NULL; } +#ifdef MAPBASE_VSCRIPT +const char *CScriptKeyValues::ScriptGetName() +{ + const char *psz = m_pKeyValues->GetName(); + return psz; +} + +int CScriptKeyValues::ScriptGetInt() +{ + int i = m_pKeyValues->GetInt(); + return i; +} + +float CScriptKeyValues::ScriptGetFloat() +{ + float f = m_pKeyValues->GetFloat(); + return f; +} + +const char *CScriptKeyValues::ScriptGetString() +{ + const char *psz = m_pKeyValues->GetString(); + return psz; +} + +bool CScriptKeyValues::ScriptGetBool() +{ + bool b = m_pKeyValues->GetBool(); + return b; +} + + +void CScriptKeyValues::ScriptSetKeyValueInt( const char *pszName, int iValue ) +{ + m_pKeyValues->SetInt( pszName, iValue ); +} + +void CScriptKeyValues::ScriptSetKeyValueFloat( const char *pszName, float flValue ) +{ + m_pKeyValues->SetFloat( pszName, flValue ); +} + +void CScriptKeyValues::ScriptSetKeyValueString( const char *pszName, const char *pszValue ) +{ + m_pKeyValues->SetString( pszName, pszValue ); +} + +void CScriptKeyValues::ScriptSetKeyValueBool( const char *pszName, bool bValue ) +{ + m_pKeyValues->SetBool( pszName, bValue ); +} + +void CScriptKeyValues::ScriptSetName( const char *pszValue ) +{ + m_pKeyValues->SetName( pszValue ); +} + +void CScriptKeyValues::ScriptSetInt( int iValue ) +{ + m_pKeyValues->SetInt( NULL, iValue ); +} + +void CScriptKeyValues::ScriptSetFloat( float flValue ) +{ + m_pKeyValues->SetFloat( NULL, flValue ); +} + +void CScriptKeyValues::ScriptSetString( const char *pszValue ) +{ + m_pKeyValues->SetString( NULL, pszValue ); +} + +void CScriptKeyValues::ScriptSetBool( bool bValue ) +{ + m_pKeyValues->SetBool( NULL, bValue ); +} +#endif + // constructors CScriptKeyValues::CScriptKeyValues( KeyValues *pKeyValues = NULL ) @@ -438,10 +534,16 @@ bool VScriptServerInit() g_pScriptVM->RegisterInstance( &g_ScriptEntityIterator, "Entities" ); +#ifdef MAPBASE_VSCRIPT + IGameSystem::RegisterVScriptAllSystems(); + + RegisterSharedScriptFunctions(); +#else if ( scriptLanguage == SL_SQUIRREL ) { //g_pScriptVM->Run( g_Script_vscript_server ); } +#endif VScriptRunScript( "mapspawn", false ); diff --git a/sp/src/game/server/vscript_server.h b/sp/src/game/server/vscript_server.h index 83108c33..f2cd0ab3 100644 --- a/sp/src/game/server/vscript_server.h +++ b/sp/src/game/server/vscript_server.h @@ -50,6 +50,23 @@ public: bool ScriptIsKeyValueEmpty( const char *pszName ); bool ScriptGetKeyValueBool( const char *pszName ); void ScriptReleaseKeyValues( ); +#ifdef MAPBASE_VSCRIPT + const char *ScriptGetName(); + int ScriptGetInt(); + float ScriptGetFloat(); + const char *ScriptGetString(); + bool ScriptGetBool(); + + void ScriptSetKeyValueInt( const char *pszName, int iValue ); + void ScriptSetKeyValueFloat( const char *pszName, float flValue ); + void ScriptSetKeyValueString( const char *pszName, const char *pszValue ); + void ScriptSetKeyValueBool( const char *pszName, bool bValue ); + void ScriptSetName( const char *pszValue ); + void ScriptSetInt( int iValue ); + void ScriptSetFloat( float flValue ); + void ScriptSetString( const char *pszValue ); + void ScriptSetBool( bool bValue ); +#endif KeyValues *m_pKeyValues; // actual KeyValue entity }; diff --git a/sp/src/game/shared/hl2/hl2_gamerules.h b/sp/src/game/shared/hl2/hl2_gamerules.h index 1c9975b9..26d62808 100644 --- a/sp/src/game/shared/hl2/hl2_gamerules.h +++ b/sp/src/game/shared/hl2/hl2_gamerules.h @@ -79,6 +79,10 @@ public: virtual void LevelInitPreEntity(); #endif +#ifdef MAPBASE_VSCRIPT + virtual void RegisterScriptFunctions( void ); +#endif + private: // Rules change for the mega physgun CNetworkVar( bool, m_bMegaPhysgun ); diff --git a/sp/src/game/shared/igamesystem.cpp b/sp/src/game/shared/igamesystem.cpp index 6a4d7f4f..19cbc78c 100644 --- a/sp/src/game/shared/igamesystem.cpp +++ b/sp/src/game/shared/igamesystem.cpp @@ -344,6 +344,15 @@ void IGameSystem::PreClientUpdateAllSystems() #endif +#ifdef MAPBASE_VSCRIPT + +void IGameSystem::RegisterVScriptAllSystems() +{ + InvokeMethod( &IGameSystem::RegisterVScript ); +} + +#endif + //----------------------------------------------------------------------------- // Invokes a method on all installed game systems in proper order diff --git a/sp/src/game/shared/igamesystem.h b/sp/src/game/shared/igamesystem.h index 6dc98350..85621924 100644 --- a/sp/src/game/shared/igamesystem.h +++ b/sp/src/game/shared/igamesystem.h @@ -98,6 +98,13 @@ public: static CBasePlayer *RunCommandPlayer(); static CUserCmd *RunCommandUserCmd(); #endif + +#ifdef MAPBASE_VSCRIPT + // This should be abstract, but there's a lot of systems which derive from + // this interface that would need to have this declared + virtual void RegisterVScript() { ; } + static void RegisterVScriptAllSystems(); +#endif }; class IGameSystemPerFrame : public IGameSystem diff --git a/sp/src/game/shared/mapbase/mapbase_shared.cpp b/sp/src/game/shared/mapbase/mapbase_shared.cpp index 31523c1b..f2e2d2ad 100644 --- a/sp/src/game/shared/mapbase/mapbase_shared.cpp +++ b/sp/src/game/shared/mapbase/mapbase_shared.cpp @@ -244,7 +244,7 @@ public: pKV->deleteThis(); } - void AddManifestFile( const char *file, bool bDontStore = false ) + void AddManifestFile( const char *file ) { KeyValues *pKV = new KeyValues(file); if ( !pKV->LoadFromFile( filesystem, file ) ) @@ -364,6 +364,21 @@ public: } } } + +#ifdef MAPBASE_VSCRIPT + void ScriptAddManifestFile( const char *szScript ) { AddManifestFile( szScript ); } + + void LoadSoundscriptFile( const char *szScript ) { LoadFromValue(szScript, MANIFEST_SOUNDSCRIPTS, false); } +#ifndef CLIENT_DLL + void LoadTalkerFile( const char *szScript ) { LoadFromValue( szScript, MANIFEST_TALKER, false ); } + void LoadActbusyFile( const char *szScript ) { LoadFromValue( szScript, MANIFEST_ACTBUSY, false ); } +#endif + + virtual void RegisterVScript() + { + g_pScriptVM->RegisterInstance( this, "Mapbase" ); + } +#endif }; CMapbaseSystem g_MapbaseSystem; @@ -374,6 +389,17 @@ BEGIN_DATADESC_NO_BASE( CMapbaseSystem ) END_DATADESC() +#ifdef MAPBASE_VSCRIPT +BEGIN_SCRIPTDESC_ROOT( CMapbaseSystem, SCRIPT_SINGLETON "All-purpose Mapbase system primarily used for map-specific files." ) + DEFINE_SCRIPTFUNC_NAMED( ScriptAddManifestFile, "AddManifestFile", "Loads a manifest file." ) + DEFINE_SCRIPTFUNC( LoadSoundscriptFile, "Loads a custom soundscript file." ) +#ifndef CLIENT_DLL + DEFINE_SCRIPTFUNC( LoadTalkerFile, "Loads a custom talker file." ) + DEFINE_SCRIPTFUNC( LoadActbusyFile, "Loads a custom actbusy file." ) +#endif +END_SCRIPTDESC(); +#endif + #ifdef GAME_DLL static CUtlVector g_MapbaseChapterMaps; static CUtlVector g_MapbaseChapterList; @@ -437,7 +463,7 @@ ThreeState_t Flashlight_GetLegacyVersionKey() static void CC_Mapbase_LoadManifestFile( const CCommand& args ) { - g_MapbaseSystem.AddManifestFile(args[1], args[2]); + g_MapbaseSystem.AddManifestFile(args[1]); } static ConCommand mapbase_loadmanifestfile("mapbase_loadmanifestfile", CC_Mapbase_LoadManifestFile, "Loads a Mapbase manifest file. If you don't want this to be saved and found when reloaded, type a '1' after the file path." ); diff --git a/sp/src/game/shared/mapbase/vscript_funcs_hl2.cpp b/sp/src/game/shared/mapbase/vscript_funcs_hl2.cpp new file mode 100644 index 00000000..92aa86ae --- /dev/null +++ b/sp/src/game/shared/mapbase/vscript_funcs_hl2.cpp @@ -0,0 +1,68 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: VScript functions for Half-Life 2. +// +// $NoKeywords: $ +//=============================================================================// + +#include "cbase.h" + +#include "hl2_gamerules.h" +#ifndef CLIENT_DLL +#include "eventqueue.h" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +#ifndef CLIENT_DLL +extern CBaseEntity *CreatePlayerLoadSave( Vector vOrigin, float flDuration, float flHoldTime, float flLoadTime ); + +HSCRIPT ScriptGameOver( const char *pszMessage, float flDelay, float flFadeTime, float flLoadTime, int r, int g, int b ) +{ + CBaseEntity *pPlayer = AI_GetSinglePlayer(); + if (pPlayer) + { + UTIL_ShowMessage( pszMessage, ToBasePlayer( pPlayer ) ); + ToBasePlayer( pPlayer )->NotifySinglePlayerGameEnding(); + } + else + { + // TODO: How should MP handle this? + return NULL; + } + + CBaseEntity *pReload = CreatePlayerLoadSave( vec3_origin, flFadeTime, flLoadTime + 1.0f, flLoadTime ); + if (pReload) + { + pReload->SetRenderColor( r, g, b, 255 ); + g_EventQueue.AddEvent( pReload, "Reload", flDelay, pReload, pReload ); + } + + return ToHScript( pReload ); +} + +bool ScriptMegaPhyscannonActive() +{ + return HL2GameRules()->MegaPhyscannonActive(); +} +#endif + +//----------------------------------------------------------------------------- +// Purpose: Returns how much damage the given ammo type should do to the victim +// when fired by the attacker. +// Input : pAttacker - Dude what shot the gun. +// pVictim - Dude what done got shot. +// nAmmoType - What been shot out. +// Output : How much hurt to put on dude what done got shot (pVictim). +//----------------------------------------------------------------------------- +void CHalfLife2::RegisterScriptFunctions( void ) +{ + BaseClass::RegisterScriptFunctions(); + +#ifndef CLIENT_DLL + ScriptRegisterFunctionNamed( g_pScriptVM, ScriptGameOver, "GameOver", "Ends the game and reloads the last save." ); + ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMegaPhyscannonActive, "MegaPhyscannonActive", "Checks if supercharged gravity gun mode is enabled." ); +#endif +} diff --git a/sp/src/game/shared/mapbase/vscript_funcs_shared.cpp b/sp/src/game/shared/mapbase/vscript_funcs_shared.cpp new file mode 100644 index 00000000..b78fc117 --- /dev/null +++ b/sp/src/game/shared/mapbase/vscript_funcs_shared.cpp @@ -0,0 +1,112 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Due to this being a custom integration of VScript based on the Alien Swarm SDK, we don't have access to +// some of the code normally available in games like L4D2 or Valve's original VScript DLL. +// Instead, that code is recreated here, shared between server and client. +// +// It also contains other functions unique to Mapbase. +// +// $NoKeywords: $ +//=============================================================================// + +#include "cbase.h" + +#ifndef CLIENT_DLL +#include "globalstate.h" +#include "vscript_server.h" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#ifndef CLIENT_DLL +extern ConVar sv_script_think_interval; + +void AddThinkToEnt( HSCRIPT entity, const char *pszFuncName ) +{ + CBaseEntity *pEntity = ToEnt( entity ); + if (!pEntity) + return; + + if (pszFuncName == NULL || pszFuncName[0] == '\0') + pEntity->m_iszScriptThinkFunction = NULL_STRING; + else + pEntity->m_iszScriptThinkFunction = AllocPooledString(pszFuncName); + + pEntity->SetContextThink( &CBaseEntity::ScriptThink, gpGlobals->curtime + sv_script_think_interval.GetFloat(), "ScriptThink" ); +} + +HSCRIPT EntIndexToHScript( int index ) +{ + return ToHScript( UTIL_EntityByIndex( index ) ); +} +#endif + +//----------------------------------------------------------------------------- +// Mapbase-specific functions start here +//----------------------------------------------------------------------------- + +#ifndef CLIENT_DLL +inline CScriptKeyValues *ToScriptKeyValues( HSCRIPT hKV ) +{ + return (hKV) ? (CScriptKeyValues*)g_pScriptVM->GetInstanceValue( hKV, GetScriptDescForClass( CScriptKeyValues ) ) : NULL; +} + +// Since IScriptVM::GetKeyValue() is unsupported, Mapbase uses this CScriptKeyValues version +HSCRIPT SpawnEntityFromKeyValues( const char *pszClassname, HSCRIPT hKV ) +{ + CBaseEntity *pEntity = CreateEntityByName( pszClassname ); + if ( !pEntity ) + { + Assert( !"SpawnEntityFromTable: only works for CBaseEntities" ); + return NULL; + } + + gEntList.NotifyCreateEntity( pEntity ); + + CScriptKeyValues *pScriptKV = ToScriptKeyValues( hKV ); + if (pScriptKV) + { + KeyValues *pKV = pScriptKV->m_pKeyValues; + for (pKV = pKV->GetFirstSubKey(); pKV != NULL; pKV = pKV->GetNextKey()) + { + //g_pScriptVM->GetKeyValue( hKV, i, &varKey, &varValue ); + pEntity->KeyValue( pKV->GetName(), pKV->GetString() ); + } + } + + DispatchSpawn( pEntity ); + + return ToHScript( pEntity ); +} +#endif + +void RegisterSharedScriptFunctions() +{ + // + // Due to this being a custom integration of VScript based on the Alien Swarm SDK, we don't have access to + // some of the code normally available in games like L4D2 or Valve's original VScript DLL. + // Instead, that code is recreated here, shared between server and client. + // + ScriptRegisterFunction( g_pScriptVM, RandomFloat, "Generate a random floating point number within a range, inclusive." ); + ScriptRegisterFunction( g_pScriptVM, RandomInt, "Generate a random integer within a range, inclusive." ); + +#ifndef CLIENT_DLL + ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::BoxDirection, "DebugDrawBoxDirection", "Draw a debug forward box" ); + ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Text, "DebugDrawText", "Draw a debug overlay text" ); + + ScriptRegisterFunction( g_pScriptVM, AddThinkToEnt, "This will put a think function onto an entity, or pass null to remove it. This is NOT chained, so be careful." ); + ScriptRegisterFunction( g_pScriptVM, EntIndexToHScript, "Returns the script handle for the given entity index." ); +#endif + + // Functions unique to Mapbase +#ifndef CLIENT_DLL + ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromKeyValues, "Spawns an entity with the keyvalues in a CScriptKeyValues handle." ); +#endif + +#ifdef CLIENT_DLL + VScriptRunScript( "vscript_client", true ); +#else + VScriptRunScript( "vscript_server", true ); +#endif +} diff --git a/sp/src/game/shared/vscript_shared.h b/sp/src/game/shared/vscript_shared.h index 8c8ee86d..55e19a61 100644 --- a/sp/src/game/shared/vscript_shared.h +++ b/sp/src/game/shared/vscript_shared.h @@ -31,4 +31,8 @@ inline bool VScriptRunScript( const char *pszScriptName, bool bWarnMissing = fal // Only allow scripts to create entities during map initialization bool IsEntityCreationAllowedInScripts( void ); +#ifdef MAPBASE_VSCRIPT +void RegisterSharedScriptFunctions(); +#endif + #endif // VSCRIPT_SHARED_H diff --git a/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20.inc b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20.inc new file mode 100644 index 00000000..161c4c79 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nPARALLAXCORRECT; +#ifdef _DEBUG + bool m_bPARALLAXCORRECT; +#endif +public: + void SetPARALLAXCORRECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPARALLAXCORRECT = i; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } + void SetPARALLAXCORRECT( bool i ) + { + m_nPARALLAXCORRECT = i ? 1 : 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } +public: + sdk_shatteredglass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = false; +#endif // _DEBUG + m_nPARALLAXCORRECT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE && m_bPARALLAXCORRECT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCUBEMAP ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nENVMAPMASK ) + ( 16 * m_nBASEALPHAENVMAPMASK ) + ( 32 * m_nHDRTYPE ) + ( 96 * m_nPARALLAXCORRECT ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_PARALLAXCORRECT + 0 +class sdk_shatteredglass_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sdk_shatteredglass_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20b.inc b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20b.inc new file mode 100644 index 00000000..5c79bd11 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_ps20b_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nPARALLAXCORRECT; +#ifdef _DEBUG + bool m_bPARALLAXCORRECT; +#endif +public: + void SetPARALLAXCORRECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPARALLAXCORRECT = i; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } + void SetPARALLAXCORRECT( bool i ) + { + m_nPARALLAXCORRECT = i ? 1 : 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } +public: + sdk_shatteredglass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = false; +#endif // _DEBUG + m_nPARALLAXCORRECT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE && m_bPARALLAXCORRECT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCUBEMAP ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nENVMAPMASK ) + ( 16 * m_nBASEALPHAENVMAPMASK ) + ( 32 * m_nHDRTYPE ) + ( 96 * m_nPARALLAXCORRECT ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_PARALLAXCORRECT + 0 +class sdk_shatteredglass_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sdk_shatteredglass_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_vs20.inc b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_vs20.inc new file mode 100644 index 00000000..a3e18d53 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9/SDK_ShatteredGlass_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +public: + sdk_shatteredglass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nENVMAP_MASK ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + 0 +class sdk_shatteredglass_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sdk_shatteredglass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20.inc b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20.inc new file mode 100644 index 00000000..161c4c79 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nPARALLAXCORRECT; +#ifdef _DEBUG + bool m_bPARALLAXCORRECT; +#endif +public: + void SetPARALLAXCORRECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPARALLAXCORRECT = i; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } + void SetPARALLAXCORRECT( bool i ) + { + m_nPARALLAXCORRECT = i ? 1 : 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } +public: + sdk_shatteredglass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = false; +#endif // _DEBUG + m_nPARALLAXCORRECT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE && m_bPARALLAXCORRECT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCUBEMAP ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nENVMAPMASK ) + ( 16 * m_nBASEALPHAENVMAPMASK ) + ( 32 * m_nHDRTYPE ) + ( 96 * m_nPARALLAXCORRECT ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_PARALLAXCORRECT + 0 +class sdk_shatteredglass_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sdk_shatteredglass_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20b.inc b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20b.inc new file mode 100644 index 00000000..5c79bd11 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_ps20b_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nPARALLAXCORRECT; +#ifdef _DEBUG + bool m_bPARALLAXCORRECT; +#endif +public: + void SetPARALLAXCORRECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPARALLAXCORRECT = i; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } + void SetPARALLAXCORRECT( bool i ) + { + m_nPARALLAXCORRECT = i ? 1 : 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = true; +#endif + } +public: + sdk_shatteredglass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bPARALLAXCORRECT = false; +#endif // _DEBUG + m_nPARALLAXCORRECT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE && m_bPARALLAXCORRECT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCUBEMAP ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nENVMAPMASK ) + ( 16 * m_nBASEALPHAENVMAPMASK ) + ( 32 * m_nHDRTYPE ) + ( 96 * m_nPARALLAXCORRECT ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_PARALLAXCORRECT + 0 +class sdk_shatteredglass_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sdk_shatteredglass_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_vs20.inc b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_vs20.inc new file mode 100644 index 00000000..a3e18d53 --- /dev/null +++ b/sp/src/materialsystem/stdshaders/fxctmp9_tmp/SDK_ShatteredGlass_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sdk_shatteredglass_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +public: + sdk_shatteredglass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nENVMAP_MASK ) + 0; + } +}; +#define shaderStaticTest_sdk_shatteredglass_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + 0 +class sdk_shatteredglass_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sdk_shatteredglass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_sdk_shatteredglass_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/sp/src/materialsystem/stdshaders/refract_dx9_helper.cpp b/sp/src/materialsystem/stdshaders/refract_dx9_helper.cpp index 05689c24..757928bf 100644 --- a/sp/src/materialsystem/stdshaders/refract_dx9_helper.cpp +++ b/sp/src/materialsystem/stdshaders/refract_dx9_helper.cpp @@ -76,6 +76,19 @@ void InitRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, Refract_DX9 if( params[info.m_nEnvmap]->IsDefined() ) { pShader->LoadCubeMap( info.m_nEnvmap, TEXTUREFLAGS_SRGB ); + +#ifdef MAPBASE + if (mat_specular_disable_on_missing.GetBool()) + { + // Revert to defaultcubemap when the envmap texture is missing + // (should be equivalent to toolsblack in Mapbase) + if (!IS_FLAG_SET( MATERIAL_VAR_MODEL ) && params[info.m_nEnvmap]->GetTextureValue()->IsError()) + { + params[info.m_nEnvmap]->SetStringValue( "engine/defaultcubemap" ); + pShader->LoadCubeMap( info.m_nEnvmap, TEXTUREFLAGS_SRGB ); + } + } +#endif } if( params[info.m_nRefractTintTexture]->IsDefined() ) { diff --git a/sp/src/materialsystem/stdshaders/water.cpp b/sp/src/materialsystem/stdshaders/water.cpp index 74374334..27b807de 100644 --- a/sp/src/materialsystem/stdshaders/water.cpp +++ b/sp/src/materialsystem/stdshaders/water.cpp @@ -151,6 +151,19 @@ BEGIN_VS_SHADER( SDK_Water_DX90, if ( params[ENVMAP]->IsDefined() ) { LoadCubeMap( ENVMAP, TEXTUREFLAGS_SRGB ); + +#ifdef MAPBASE + if (mat_specular_disable_on_missing.GetBool()) + { + // Revert to defaultcubemap when the envmap texture is missing + // (should be equivalent to toolsblack in Mapbase) + if (params[ENVMAP]->GetTextureValue()->IsError()) + { + params[ENVMAP]->SetStringValue( "engine/defaultcubemap" ); + LoadCubeMap( ENVMAP, TEXTUREFLAGS_SRGB ); + } + } +#endif } if ( params[NORMALMAP]->IsDefined() ) { diff --git a/sp/src/utils/vbsp/cubemap.cpp b/sp/src/utils/vbsp/cubemap.cpp index 9156900e..b44e739b 100644 --- a/sp/src/utils/vbsp/cubemap.cpp +++ b/sp/src/utils/vbsp/cubemap.cpp @@ -689,7 +689,7 @@ static int Cubemap_CreateTexInfo( int originalTexInfo, int origin[3] ) #ifdef PARALLAX_CORRECTED_CUBEMAPS // Append origin info if this cubemap has a parallax OBB char originAppendedString[1024] = ""; - if (g_pParallaxObbStrs[cubemapIndex][0] != '\0') + if (g_pParallaxObbStrs[cubemapIndex] && g_pParallaxObbStrs[cubemapIndex][0] != '\0') { Q_snprintf(originAppendedString, 1024, "%s;[%d %d %d]", g_pParallaxObbStrs[cubemapIndex], origin[0], origin[1], origin[2]); }