⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scriptmaster.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            for ( i = 1; i <= waitingNumObjects; i++ )
               {
               tent = tlist->list.ObjectAt( i );
               // add the object to the update list to make sure we tell it to do a move
               if ( !updateList.ObjectInList( tent->entnum ) )
                  {
                  updateList.AddObject( tent->entnum );
                  }
               }
            }
         }

      // add the object to the update list to make sure we tell it to do a move
      if ( !updateList.ObjectInList( ent->entnum ) )
         {
         updateList.AddObject( ent->entnum );
         }
      }

   DoMove();
   }

void ScriptThread::EventWaitForThread
	(
	Event *ev
	)

	{
	doneProcessing = true;

	ClearWaitFor();
	waitingForThread = Director.GetThread( ev->GetInteger( 1 ) );
	if ( !waitingForThread )
		{
		ev->Error( "EventWaitForThread", "Thread %d not running", ev->GetInteger( 1 ) );
		return;
		}

	DoMove();
	}

void ScriptThread::EventWaitForDeath
	(
	Event *ev
	)

	{
   doneProcessing = true;

	ClearWaitFor();
	waitingForDeath = ev->GetString(1);
	if ( !waitingForDeath.length() )
		{
		ev->Error( "EventWaitForDeath", "Null name" );
		return;
		}

	DoMove();
	}

void ScriptThread::EventWaitForConsole
	(
	Event *ev
	)

	{
   doneProcessing = true;

	ClearWaitFor();
	waitingForConsole = ev->GetString(1);
	
   if ( !waitingForConsole.length() )
		{
		ev->Error( "EventWaitForConsole", "Null console" );
		return;
		}

	DoMove();
	}

void ScriptThread::EventWaitForVariable
	(
	Event *ev
	)

	{
   doneProcessing = true;

	ClearWaitFor();
	waitingForVariable = ev->GetString(1);

	if ( !waitingForVariable.length() )
		{
		ev->Error( "EventWaitForVariable", "Null variable" );
		return;
		}

	DoMove();
	}

void ScriptThread::EventWaitForSound
	(
	Event *ev
	)

	{
   str sound;
   float delay;

	ClearWaitFor();

	DoMove();

   delay = 0;
	sound = ev->GetString( 1 );
   if ( ev->NumArgs() > 1 )
      delay = ev->GetFloat( 2 );

   delay += gi.SoundLength( sound.c_str() );

   Start( delay );
	doneProcessing = true;
	}

void ScriptThread::EventWaitForPlayer
	(
	Event *ev
	)

	{
   if ( !Director.PlayerReady() )
      {
      doneProcessing = true;

	   ClearWaitFor();
	   waitingForPlayer = true;

	   DoMove();
      }
	}

void ScriptThread::EventEnd
	(
	Event *ev
	)

	{
	ScriptVariable *var;
	const char *text;
	Entity *ent;

	ClearWaitFor();

	// If we're a model script, we have to tell our owning entity that we're done.
	if ( ( ev->GetSource() == EV_FROM_SCRIPT ) && ( type == MODEL_SCRIPT ) )
		{
		doneProcessing = true;
		var = Vars()->GetVariable( "self" );
		if ( !var )
			{
			ev->Error( "Model script ending without local.self set" );
			}
		else
			{
			text = var->stringValue();
			if ( ( text[ 0 ] == '*' ) && IsNumeric( &text[ 1 ] ) )
				{
				ent = G_GetEntity( atoi( &text[ 1 ] ) );

				// pass the event on to entity pointed to by self
				if ( ent )
					{
					ent->ProcessEvent( ev );
					return;
					}
				}
			else
				{
				ev->Error( "Model script ending.  Invalid value in local.self '%s'", text );
				}
			}
		}

	Director.NotifyOtherThreads( threadNum );
	PostEvent( EV_Remove, 0 );
	doneProcessing = true;
	threadDying = true;
	}

void ScriptThread::Print
	(
	Event *ev
	)

	{
	gi.dprintf( "%s", ev->GetString( 1 ) );
	}

void ScriptThread::PrintInt
	(
	Event *ev
	)

	{
	gi.dprintf( "%d", ev->GetInteger( 1 ) );
	}

void ScriptThread::PrintFloat
	(
	Event *ev
	)

	{
	gi.dprintf( "%.2f", ev->GetFloat( 1 ) );
	}

void ScriptThread::PrintVector
	(
	Event *ev
	)

	{
   Vector vec;

   vec = ev->GetVector( 1 );
	gi.dprintf( "(%.2f %.2f %.2f)", vec.x, vec.y, vec.z );
	}

void ScriptThread::NewLine
	(
	Event *ev
	)

	{
	gi.dprintf( "\n" );
	}


void ScriptThread::UserPrint
	(
	Event *ev
	)

	{
	gi.bprintf( PRINT_HIGH, "%s", ev->GetString( 1 ) );
	}

void ScriptThread::UserPrintInt
	(
	Event *ev
	)

	{
	gi.bprintf( PRINT_HIGH, "%d", ev->GetInteger( 1 ) );
	}

void ScriptThread::UserPrintFloat
	(
	Event *ev
	)

	{
	gi.bprintf( PRINT_HIGH, "%.2f", ev->GetFloat( 1 ) );
	}

void ScriptThread::UserPrintVector
	(
	Event *ev
	)

	{
   Vector vec;

   vec = ev->GetVector( 1 );
	gi.bprintf( PRINT_HIGH, "(%.2f %.2f %.2f)", vec.x, vec.y, vec.z );
	}

void ScriptThread::UserNewLine
	(
	Event *ev
	)

	{
	gi.bprintf( PRINT_HIGH, "\n" );
	}

void ScriptThread::Assert
	(
	Event *ev
	)

	{
	assert( ev->GetFloat( 1 ) );
	}

void ScriptThread::Break
	(
	Event *ev
	)

	{
	// Break into the debugger
	assert( 0 );
	}

void ScriptThread::Clear
	(
	Event *ev
	)

	{
	ScriptVariableList *vars;

	vars = Director.GetVarGroup( ev->GetToken( 1 ) );
	if ( vars )
		{
		vars->ClearList();
		}
	}

EXPORT_FROM_DLL void ScriptThread::ScriptCallback
	(
	Event *ev
	)

	{
	char		name[ MAXTOKEN ];
	Entity	*other;
	Entity	*slave;

	if ( threadDying )
		{
		return;
		}

	slave = ev->GetEntity( 1 );
	strcpy( name, ev->GetString( 2 ) );
	other = ev->GetEntity( 3 );

	if ( !Goto( name ) )
		{
		ev->Error( "Label '%s' not found", name );
		}
	else
		{
		// kill any execute events (in case our last command was "wait")
		ClearWaitFor();
      // start right away
      Start( -1 );
		}
	}

EXPORT_FROM_DLL void ScriptThread::ThreadCallback
	(
	Event *ev
	)

	{
	ScriptThread *thread;

	if ( threadDying )
		{
		return;
		}

	thread = ev->GetThread();

	// should never happen, so catch it during development
	//assert( thread && ( thread == waitingForThread ) );

	if ( thread && ( thread == waitingForThread ) )
		{
		ClearWaitFor();
      // start right away
      Start( -1 );
		}
	}

EXPORT_FROM_DLL void ScriptThread::ConsoleCallback
	(
	Event *ev
	)

	{
	if ( threadDying )
		{
		return;
		}

	ClearWaitFor();
   // start right away
   Start( -1 );
   }

EXPORT_FROM_DLL void ScriptThread::VariableCallback
	(
	Event *ev
	)

	{
	ClearWaitFor();
   // start right away
   Start( -1 );
   }

EXPORT_FROM_DLL void ScriptThread::DeathCallback
	(
	Event *ev
	)

	{
	if ( threadDying )
		{
		return;
		}

	ClearWaitFor();
   // start right away
   Start( -1 );
   }


EXPORT_FROM_DLL void ScriptThread::DoMove
   (
   void
   )

   {
   int      entnum;
   Entity   *ent;
   Event    *event;
   int      count;
   int      i;

   count = updateList.NumObjects();

   for( i = 1; i <= count; i++ )
      {
      entnum = ( int )updateList.ObjectAt( i );
      ent = G_GetEntity( entnum );
      if ( ent )
         {
         if ( ent->ValidEvent( EV_ProcessCommands ) )
            {
            event = new Event( EV_ProcessCommands );
            event->SetThread( this );
            ent->PostEvent( event, 0 );
            }
         else
            {
            // try to remove this from the update list
            if ( waitingNumObjects > 0 )
               {
               waitingNumObjects--;
               }
            }
         }
      }

   updateList.ClearObjectList();
   }

void ScriptThread::TriggerEvent
	(
	Event *ev
	)

	{
	const char	*name;
	Event		   *event;
	Entity	   *ent;
   TargetList  *tlist;
   int         i;
   int         num;

	name = ev->GetString( 1 );

	// Check for object commands
	if ( name && name[ 0 ] == '$' )
		{
      tlist = GetTargetList( str( name + 1 ) );
      num = tlist->list.NumObjects();
      for ( i = 1; i <= num; i++ )
         {
         ent = tlist->list.ObjectAt( i );

		   assert( ent );

         event = new Event( EV_Activate );
			event->SetSource( EV_FROM_SCRIPT );
			event->SetThread( this );
			event->SetLineNumber( linenumber );
         event->AddEntity( world );
		   ent->ProcessEvent( event );
         }
      }
	else if ( name[ 0 ] == '*' )   // Check for entnum commands
      {
		if ( !IsNumeric( &name[ 1 ] ) )
			{
			ScriptError( "Expecting numeric value for * command, but found '%s'\n", &name[ 1 ] );
			}
		else
         {
         ent = G_GetEntity( atoi( &name[ 1 ] ) );
         if ( ent )
            {
            event = new Event( EV_Activate );
				event->SetSource( EV_FROM_SCRIPT );
				event->SetThread( this );
				event->SetLineNumber( linenumber );
            event->AddEntity( world );
            ent->ProcessEvent( event );
            }
         else
            {
            ScriptError( "Entity not found for * command\n" );
            }
         }
      return;   
      }
	else
		{
		ScriptError( "Invalid entity reference '%s'.\n", name );
		}
	}

void ScriptThread::ServerEvent
	(
	Event *ev
	)

	{
   int i, argc;
	const char *argv[ MAX_COMMANDS ];

	argc = 0;
   for ( i = 1; i <= ev->NumArgs(); i++ )
      argv[argc++] = ev->GetString( i );

   if (argc)
	   ProcessCommand( argc, argv );
	}

void ScriptThread::ClientEvent
	(
	Event *ev
	)

	{
   //
   // do nothing
   //
   }

void Scr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -