mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-01-12 06:47:56 +03:00
Added logic_script_bsp
This commit is contained in:
parent
46b6f456af
commit
8bca4ffa05
@ -1780,6 +1780,13 @@ ChunkFileResult_t CMapFile::LoadEntityCallback(CChunkFile *pFile, int nParam)
|
||||
return ( ChunkFile_Ok );
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if ( Q_stricmp( pClassName, "logic_script_bsp" ) == 0 )
|
||||
{
|
||||
return HandleBSPScriptEnt( mapent );
|
||||
}
|
||||
#endif
|
||||
|
||||
// areaportal entities move their brushes, but don't eliminate
|
||||
// the entity
|
||||
if( IsAreaPortal( pClassName ) )
|
||||
@ -2754,6 +2761,9 @@ bool LoadMapFile( const char *pszFileName )
|
||||
{
|
||||
int index = g_Maps.AddToTail( new CMapFile() );
|
||||
g_LoadingMap = g_Maps[ index ];
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
g_LoadingMap->SetFileName( pszFileName ); // Store the file name for VScript
|
||||
#endif
|
||||
if ( g_MainMap == NULL )
|
||||
{
|
||||
g_MainMap = g_LoadingMap;
|
||||
@ -3384,13 +3394,39 @@ HSCRIPT CMapFile::GetScriptInstance()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMapFile::ScriptGetEntityKeyValues( int idx, HSCRIPT hKeyTable, HSCRIPT hValTable )
|
||||
int CMapFile::FindEntityIndexByName( int i, const char *pszName )
|
||||
{
|
||||
for( ; i < num_entities; i++ )
|
||||
{
|
||||
const char *pName = ValueForKey( &entities[i], "targetname" );
|
||||
if (stricmp( pName, pszName ) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CMapFile::FindEntityIndexByClass( int i, const char *pszClassName )
|
||||
{
|
||||
for( ; i < num_entities; i++ )
|
||||
{
|
||||
const char *pClass = ValueForKey( &entities[i], "classname" );
|
||||
if (stricmp( pClass, pszClassName ) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMapFile::ScriptGetEntityKeyValues( int idx, HSCRIPT hTable )
|
||||
{
|
||||
epair_t *curPair = entities[idx].epairs;
|
||||
while (curPair)
|
||||
{
|
||||
g_pScriptVM->ArrayAppend( hKeyTable, curPair->key );
|
||||
g_pScriptVM->ArrayAppend( hValTable, curPair->value );
|
||||
g_pScriptVM->SetValue( hTable, curPair->key, curPair->value );
|
||||
|
||||
curPair = curPair->next;
|
||||
}
|
||||
|
@ -347,6 +347,9 @@ public:
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT GetScriptInstance();
|
||||
|
||||
const char* GetFileName() const { return m_pszFileName; }
|
||||
void SetFileName( const char *pszFileName ) { m_pszFileName = pszFileName; }
|
||||
|
||||
// VScript functions
|
||||
ALLOW_SCRIPT_ACCESS();
|
||||
private:
|
||||
@ -360,13 +363,16 @@ private:
|
||||
int GetEntityFirstBrush(int idx) { return (idx < num_entities && idx >= 0) ? entities[idx].firstbrush : 0; }
|
||||
int GetEntityNumBrushes(int idx) { return (idx < num_entities && idx >= 0) ? entities[idx].numbrushes : 0; }
|
||||
|
||||
void ScriptGetEntityKeyValues(int idx, HSCRIPT hKeyTable, HSCRIPT hValTable);
|
||||
int FindEntityIndexByName( int i, const char *pszName );
|
||||
int FindEntityIndexByClass( int i, const char *pszClassName );
|
||||
void ScriptGetEntityKeyValues( int idx, HSCRIPT hTable );
|
||||
|
||||
int ScriptAddSimpleEntityKV(HSCRIPT hKV/*, const Vector& vecOrigin, int iFirstBrush, int iNumBrushes*/);
|
||||
int ScriptAddInstance(const char *pszVMF, const Vector& vecOrigin, const QAngle& angAngles);
|
||||
|
||||
int GetNumEntities() { return num_entities; }
|
||||
|
||||
const char *m_pszFileName;
|
||||
HSCRIPT m_hScriptInstance;
|
||||
#endif
|
||||
};
|
||||
|
@ -357,3 +357,77 @@ void VScriptVBSPTerm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
CUtlVector<CScriptScope> g_ScriptScopes;
|
||||
|
||||
#define MAX_SCRIPT_ENT_PARAM_GROUPS 16
|
||||
|
||||
ChunkFileResult_t HandleBSPScriptEnt( entity_t *pMapEnt )
|
||||
{
|
||||
// Get the list of the sides.
|
||||
char *pszScripts = ValueForKey( pMapEnt, "vscripts_bsp" );
|
||||
|
||||
if (pszScripts == NULL)
|
||||
{
|
||||
Warning( "logic_script_bsp with no scripts\n" );
|
||||
return (ChunkFile_Fail);
|
||||
}
|
||||
|
||||
if (g_pScriptVM == NULL)
|
||||
{
|
||||
Warning( "logic_script_bsp (%s) with no script VM\n", pszScripts );
|
||||
return (ChunkFile_Fail);
|
||||
}
|
||||
|
||||
int i = g_ScriptScopes.AddToTail();
|
||||
|
||||
// Get params
|
||||
// TODO: CreateArray?
|
||||
//g_ScriptScopes[i].Run( "ParamGroup <- []" );
|
||||
//
|
||||
//HSCRIPT hArray = NULL;
|
||||
ScriptVariant_t varArray;
|
||||
//if (g_ScriptScopes[i].GetValue( "ParamGroup", &var ))
|
||||
// hArray = var.m_hScript;
|
||||
|
||||
g_pScriptVM->CreateArray( varArray );
|
||||
g_pScriptVM->SetValue( g_ScriptScopes[i], "ParamGroup", varArray );
|
||||
|
||||
if (varArray.m_hScript)
|
||||
{
|
||||
//for (epair_t *ep = pMapEnt->epairs; ep; ep = ep->next)
|
||||
//{
|
||||
// // TODO: Does this need manual sorting?
|
||||
// if (!Q_strnicmp( ep->key, "Group", 5 ))
|
||||
// g_pScriptVM->ArrayAppend( varArray.m_hScript, ep->value );
|
||||
//}
|
||||
|
||||
for (int i = 0; i < MAX_SCRIPT_ENT_PARAM_GROUPS; i++)
|
||||
{
|
||||
CFmtStrN<8> groupKey( "Group%s%i", (i < 10 ? "0" : ""), i );
|
||||
const char *pszValue = ValueForKey( pMapEnt, groupKey.Access() );
|
||||
g_pScriptVM->ArrayAppend( varArray.m_hScript, pszValue );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning("ERROR: ParamGroup not found\n");
|
||||
}
|
||||
|
||||
CUtlStringList szScripts;
|
||||
V_SplitString( pszScripts, " ", szScripts );
|
||||
|
||||
for (int i = 0; i < szScripts.Count(); i++)
|
||||
{
|
||||
Msg( "logic_script_bsp executing script: %s\n", szScripts[i] );
|
||||
VScriptRunScript( szScripts[i], g_ScriptScopes[i], true );
|
||||
}
|
||||
|
||||
// Clear out this entity.
|
||||
pMapEnt->epairs = NULL;
|
||||
g_pScriptVM->ClearValue( "ParamGroup" );
|
||||
g_pScriptVM->ReleaseValue( varArray );
|
||||
return ( ChunkFile_Ok );
|
||||
}
|
||||
|
@ -24,4 +24,8 @@ inline bool VScriptRunScript( const char *pszScriptName, bool bWarnMissing = fal
|
||||
bool VScriptVBSPInit();
|
||||
void VScriptVBSPTerm();
|
||||
|
||||
#endif // VSCRIPT_SERVER_H
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChunkFileResult_t HandleBSPScriptEnt( entity_t *pMapEnt );
|
||||
|
||||
#endif // VSCRIPT_VBSP_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user