📄 scriptmaster.cpp
字号:
}
EXPORT_FROM_DLL int ScriptMaster::GetUniqueThreadNumber
(
void
)
{
do
{
threadIndex++;
if ( threadIndex == 0 )
{
threadIndex = 1;
}
}
while( GetThread( threadIndex ) );
return threadIndex;
}
EXPORT_FROM_DLL qboolean ScriptMaster::labelExists
(
GameScript * scr,
const char *name
)
{
return scr->labelExists( name );
}
EXPORT_FROM_DLL qboolean ScriptMaster::Goto
(
GameScript * scr,
const char *name
)
{
return scr->Goto( name );
}
EXPORT_FROM_DLL ScriptVariableList *ScriptMaster::GetVarGroup
(
const char *name
)
{
ScriptVariableList *vars;
const char *v;
char vargroup[ 20 ];
int len;
v = strchr( name, '.' );
if ( !v )
{
return NULL;
}
len = v - name;
if ( len > sizeof( vargroup ) - 1 )
{
len = sizeof( vargroup ) - 1;
}
memset( vargroup, 0, sizeof( vargroup ) );
strncpy( vargroup, name, len );
vars = NULL;
if ( !strcmp( vargroup, "game" ) )
{
vars = &gameVars;
}
else if ( !strcmp( vargroup, "level" ) )
{
vars = &levelVars;
}
else if ( !strcmp( vargroup, "local" ) && currentThread )
{
vars = currentThread->Vars();
}
else if ( !strcmp( vargroup, "parm" ) )
{
vars = &parmVars;
}
else if ( !strcmp( vargroup, "console" ) )
{
vars = &consoleVars;
}
return vars;
}
EXPORT_FROM_DLL ScriptVariable *ScriptMaster::GetExistingVariable
(
const char *name
)
{
ScriptVariableList *vars;
const char *v;
vars = GetVarGroup( name );
if ( !vars )
{
return NULL;
}
v = strchr( name, '.' );
if ( !v )
{
return NULL;
}
return vars->GetVariable( v + 1 );
}
EXPORT_FROM_DLL ScriptVariable *ScriptMaster::GetVariable
(
const char *name
)
{
ScriptVariable *var;
ScriptVariableList *vars;
const char *v;
var = GetExistingVariable( name );
if ( !var )
{
vars = GetVarGroup( name );
if ( !vars )
{
return NULL;
}
v = strchr( name, '.' );
assert( v );
var = vars->CreateVariable( v + 1, "" );
}
return var;
}
CLASS_DECLARATION( Listener, ScriptThread, NULL );
ResponseDef ScriptThread::Responses[] =
{
{ &EV_ScriptThread_Execute, ( Response )ScriptThread::Execute },
{ &EV_MoveDone, ( Response )ScriptThread::ObjectMoveDone },
{ &EV_ScriptThread_Callback, ( Response )ScriptThread::ScriptCallback },
{ &EV_ScriptThread_ThreadCallback, ( Response )ScriptThread::ThreadCallback },
{ &EV_ScriptThread_ConsoleCallback, ( Response )ScriptThread::ConsoleCallback },
{ &EV_ScriptThread_VariableCallback,( Response )ScriptThread::VariableCallback },
{ &EV_ScriptThread_DeathCallback, ( Response )ScriptThread::DeathCallback },
{ &EV_ScriptThread_CreateThread, ( Response )ScriptThread::CreateThread },
{ &EV_ScriptThread_TerminateThread, ( Response )ScriptThread::TerminateThread },
{ &EV_ScriptThread_ControlObject, ( Response )ScriptThread::ControlObject },
{ &EV_ScriptThread_Goto, ( Response )ScriptThread::EventGoto },
{ &EV_ScriptThread_Pause, ( Response )ScriptThread::EventPause },
{ &EV_ScriptThread_Wait, ( Response )ScriptThread::EventWait },
{ &EV_ScriptThread_WaitFor, ( Response )ScriptThread::EventWaitFor },
{ &EV_ScriptThread_WaitForThread, ( Response )ScriptThread::EventWaitForThread },
{ &EV_ScriptThread_WaitForConsole, ( Response )ScriptThread::EventWaitForConsole },
{ &EV_ScriptThread_WaitForVariable, ( Response )ScriptThread::EventWaitForVariable },
{ &EV_ScriptThread_WaitForDeath, ( Response )ScriptThread::EventWaitForDeath },
{ &EV_ScriptThread_WaitForSound, ( Response )ScriptThread::EventWaitForSound },
{ &EV_ScriptThread_WaitForPlayer, ( Response )ScriptThread::EventWaitForPlayer },
{ &EV_ScriptThread_End, ( Response )ScriptThread::EventEnd },
{ &EV_ScriptThread_Print, ( Response )ScriptThread::Print },
{ &EV_ScriptThread_PrintInt, ( Response )ScriptThread::PrintInt },
{ &EV_ScriptThread_PrintFloat, ( Response )ScriptThread::PrintFloat },
{ &EV_ScriptThread_PrintVector, ( Response )ScriptThread::PrintVector },
{ &EV_ScriptThread_NewLine, ( Response )ScriptThread::NewLine },
{ &EV_ScriptThread_UserPrint, ( Response )ScriptThread::UserPrint },
{ &EV_ScriptThread_UserPrintInt, ( Response )ScriptThread::UserPrintInt },
{ &EV_ScriptThread_UserPrintFloat, ( Response )ScriptThread::UserPrintFloat },
{ &EV_ScriptThread_UserPrintVector, ( Response )ScriptThread::UserPrintVector },
{ &EV_ScriptThread_UserNewLine, ( Response )ScriptThread::UserNewLine },
{ &EV_ScriptThread_Assert, ( Response )ScriptThread::Assert },
{ &EV_ScriptThread_Break, ( Response )ScriptThread::Break },
{ &EV_ScriptThread_Clear, ( Response )ScriptThread::Clear },
{ &EV_ScriptThread_Trigger, ( Response )ScriptThread::TriggerEvent },
{ &EV_ScriptThread_ServerOnly, ( Response )ScriptThread::ServerEvent },
{ &EV_ScriptThread_ClientOnly, ( Response )ScriptThread::ClientEvent },
{ &EV_ScriptThread_StuffCommand, ( Response )ScriptThread::StuffCommand },
{ &EV_ScriptThread_Training, ( Response )ScriptThread::Training },
{ &EV_ScriptThread_ClearSaveGames, ( Response )ScriptThread::ClearSaveGames },
{ &EV_ScriptThread_Spawn, ( Response )ScriptThread::Spawn },
{ &EV_ScriptThread_SetLightStyle, ( Response )ScriptThread::EventSetLightStyle },
{ &EV_ScriptThread_Precache_Model, ( Response )ScriptThread::CacheModel },
{ &EV_ScriptThread_Precache_PlayerModel, ( Response )ScriptThread::CachePlayerModel },
{ &EV_ScriptThread_Precache_Sound, ( Response )ScriptThread::CacheSound },
{ &EV_ScriptThread_RegisterAlias, ( Response )ScriptThread::RegisterAlias },
{ &EV_ScriptThread_RegisterAliasAndCache, ( Response )ScriptThread::RegisterAliasAndCache },
{ &EV_ScriptThread_Map, ( Response )ScriptThread::MapEvent },
{ &EV_ScriptThread_SetCvar, ( Response )ScriptThread::SetCvarEvent },
{ &EV_ScriptThread_CueCamera, ( Response )ScriptThread::CueCamera },
{ &EV_ScriptThread_CuePlayer, ( Response )ScriptThread::CuePlayer },
{ &EV_ScriptThread_FreezePlayer, ( Response )ScriptThread::FreezePlayer },
{ &EV_ScriptThread_ReleasePlayer, ( Response )ScriptThread::ReleasePlayer },
{ &EV_DialogEvent, ( Response )ScriptThread::DialogEvent },
{ &EV_ScriptThread_SetDialogScript, ( Response )ScriptThread::SetDialogScript },
{ &EV_ScriptThread_FadeIn, ( Response )ScriptThread::FadeIn },
{ &EV_ScriptThread_FadeOut, ( Response )ScriptThread::FadeOut },
{ &EV_ScriptThread_Hud, ( Response )ScriptThread::Hud },
{ &EV_ScriptThread_Menu, ( Response )ScriptThread::MenuEvent },
{ &EV_ScriptThread_MusicEvent, ( Response )ScriptThread::MusicEvent },
{ &EV_ScriptThread_ForceMusicEvent, ( Response )ScriptThread::ForceMusicEvent },
{ &EV_ScriptThread_SoundtrackEvent, ( Response )ScriptThread::SoundtrackEvent },
{ &EV_ScriptThread_LoadOverlay, ( Response )ScriptThread::LoadOverlay },
{ &EV_ScriptThread_LoadIntermission,( Response )ScriptThread::LoadIntermission },
{ &EV_ScriptThread_IntermissionLayout, ( Response )ScriptThread::IntermissionLayout },
{ &EV_ScriptThread_Overlay, ( Response )ScriptThread::Overlay },
{ &EV_ScriptThread_ScreenPrint, ( Response )ScriptThread::ScreenPrint },
{ &EV_ScriptThread_ScreenPrintFile, ( Response )ScriptThread::ScreenPrintFile },
{ &EV_ScriptThread_MapName, ( Response )ScriptThread::MapName },
{ &EV_ScriptThread_EndGame, ( Response )ScriptThread::EndGame },
{ &EV_ScriptThread_ClearScreenPrintFile, ( Response )ScriptThread::ClearScreenPrintFile },
{ &EV_ScriptThread_SetCinematic, ( Response )ScriptThread::SetCinematic },
{ &EV_ScriptThread_SetNonCinematic, ( Response )ScriptThread::SetNonCinematic },
{ &EV_ScriptThread_SetSkipThread, ( Response )ScriptThread::SetSkipThread },
{ &EV_ScriptThread_AirClamp, ( Response )ScriptThread::AirClamp },
{ &EV_ScriptThread_JC_Hearable, ( Response )ScriptThread::JC_Hearable },
{ &EV_ScriptThread_JC_Not_Hearable, ( Response )ScriptThread::JC_Not_Hearable },
{ &EV_ScriptThread_MissionFailed, ( Response )ScriptThread::MissionFailed },
{ &EV_ScriptThread_KillEnt, ( Response )ScriptThread::KillEnt },
{ &EV_ScriptThread_RemoveEnt, ( Response )ScriptThread::RemoveEnt },
{ &EV_ScriptThread_KillClass, ( Response )ScriptThread::KillClass },
{ &EV_ScriptThread_RemoveClass, ( Response )ScriptThread::RemoveClass },
{ &EV_ScriptThread_CrucialDialog, ( Response )ScriptThread::CrucialDialogEvent },
{ &EV_ScriptThread_DialogSound, ( Response )ScriptThread::DialogSoundEvent },
{ &EV_AI_RecalcPaths, ( Response )ScriptThread::PassToPathmanager },
{ &EV_AI_CalcPath, ( Response )ScriptThread::PassToPathmanager },
{ &EV_AI_DisconnectPath, ( Response )ScriptThread::PassToPathmanager },
{ NULL, NULL }
};
ScriptThread::ScriptThread()
{
threadNum = 0;
ClearWaitFor();
threadDying = false;
doneProcessing = true;
type = LEVEL_SCRIPT;
}
ScriptThread::~ScriptThread()
{
Director.NotifyOtherThreads( threadNum );
Director.RemoveThread( threadNum );
}
EXPORT_FROM_DLL void ScriptThread::ClearWaitFor
(
void
)
{
waitUntil = 0;
waitingFor = "";
waitingNumObjects = 0;
waitingForThread = NULL;
waitingForConsole = "";
waitingForVariable = "";
waitingForDeath = "";
waitingForPlayer = false;
}
EXPORT_FROM_DLL void ScriptThread::SetType
(
scripttype_t newtype
)
{
type = newtype;
}
EXPORT_FROM_DLL scripttype_t ScriptThread::GetType
(
void
)
{
return type;
}
EXPORT_FROM_DLL int ScriptThread::ThreadNum
(
void
)
{
return threadNum;
}
EXPORT_FROM_DLL const char *ScriptThread::ThreadName
(
void
)
{
return threadName.c_str();
}
EXPORT_FROM_DLL int ScriptThread::CurrentLine
(
void
)
{
return linenumber;
}
EXPORT_FROM_DLL const char *ScriptThread::Filename
(
void
)
{
return script.Filename();
}
EXPORT_FROM_DLL ScriptThread *ScriptThread::WaitingOnThread
(
void
)
{
return waitingForThread;
}
EXPORT_FROM_DLL const char *ScriptThread::WaitingOnConsole
(
void
)
{
return waitingForConsole.c_str();
}
EXPORT_FROM_DLL const char *ScriptThread::WaitingOnVariable
(
void
)
{
return waitingForVariable.c_str();
}
EXPORT_FROM_DLL const char *ScriptThread::WaitingOnDeath
(
void
)
{
return waitingForDeath.c_str();
}
EXPORT_FROM_DLL qboolean ScriptThread::WaitingOnPlayer
(
void
)
{
return waitingForPlayer;
}
EXPORT_FROM_DLL ScriptVariableList *ScriptThread::Vars
(
void
)
{
return &localVars;
}
EXPORT_FROM_DLL qboolean ScriptThread::Setup
(
int num,
GameScript *scr,
const char *label
)
{
threadNum = num;
ClearWaitFor();
script.SetSourceScript( scr );
if ( label && !Goto( label ) )
{
ScriptError( "Can't create thread. Label '%s' not found", label );
return false;
}
if ( label )
{
threadName = label;
}
else
{
threadName = script.Filename();
}
return true;
}
EXPORT_FROM_DLL qboolean ScriptThread::SetScript
(
const char *name
)
{
GameScript *scr;
scr = ScriptLib.GetScript( name );
if ( scr )
{
Setup( threadNum, scr, NULL );
return true;
}
return false;
}
EXPORT_FROM_DLL qboolean ScriptThread::Goto
(
const char *name
)
{
qboolean result;
result = ScriptLib.Goto( &script, name );
if ( result )
{
// Cancel pending execute events when waitUntil is set
if ( waitUntil )
{
CancelEventsOfType( EV_ScriptThread_Execute );
}
ClearWaitFor();
}
return result;
}
EXPORT_FROM_DLL qboolean ScriptThread::labelExists
(
const char *name
)
{
return ScriptLib.labelExists( &script, name );
}
EXPORT_FROM_DLL void ScriptThread::Mark
(
ThreadMarker *mark
)
{
assert( mark );
mark->linenumber = linenumber;
mark->doneProcessing = doneProcessing;
mark->waitingFor = waitingFor;
mark->waitingForThread = waitingForThread;
mark->waitingForConsole = waitingForConsole;
mark->waitingForVariable = waitingForVariable;
mark->waitingForDeath = waitingForDeath;
mark->waitingForPlayer = waitingForPlayer;
mark->waitingNumObjects = waitingNumObjects;
if ( waitUntil )
{
// add one so that 0 is always reserved for no wait
mark->waitUntil = waitUntil - level.time + 1;
}
else
{
mark->waitUntil = 0;
}
script.Mark( &mark->scriptmarker );
}
EXPORT_FROM_DLL void ScriptThread::Restore
(
ThreadMarker *mark
)
{
assert( mark );
linenumber = mark->linenumber;
doneProcessing = mark->doneProcessing;
waitingFor = mark->waitingFor;
waitingForThread = mark->waitingForThread;
waitingForConsole = mark->waitingForConsole;
waitingForVariable = mark->waitingForVariable;
waitingForDeath = mark->waitingForDeath;
waitingForPlayer = mark->waitingForPlayer;
waitingNumObjects = mark->waitingNumObjects;
script.Restore( &mark->scriptmarker );
if ( mark->waitUntil )
{
// subtract one since we added one when we stored it.
// this way, 0 is always reserved for no wait
// Cheezy, yeah, but since I'm commenting it, it's "ok". :)
waitUntil = mark->waitUntil + level.time - 1;
Start( waitUntil - level.time );
}
}
EXPORT_FROM_DLL TargetList *ScriptThread::GetTargetList
(
str &targetname
)
{
TargetList *tlist;
int num;
int i;
num = targets.NumObjects();
for( i = 1; i <= num; i++ )
{
tlist = targets.ObjectAt( i );
if ( targetname == tlist->targetname )
{
return tlist;
}
}
tlist = world->GetTargetList( targetname );
targets.AddObject( tlist );
return tlist;
}
EXPORT_FROM_DLL void ScriptThread::SendCommandToSlaves
(
const char *name,
Event *ev
)
{
Event *sendevent;
Entity *ent;
TargetList *tlist;
int i;
int num;
if ( name && name[ 0 ] )
{
tlist = GetTargetList( str(name+1) );
num = tlist->list.NumObjects();
for ( i = 1; i <= num; i++ )
{
ent = tlist->list.ObjectAt( i );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -