コード例 #1
0
ファイル: g_as_gametypes.cpp プロジェクト: DenMSC/qfusion
//"Entity @GT_SelectSpawnPoint( Entity @ent )"
edict_t *GT_asCallSelectSpawnPoint( edict_t *ent )
{
	int error;
	asIScriptContext *ctx;
	edict_t *spot;

	if( !level.gametype.selectSpawnPointFunc )
		return SelectDeathmatchSpawnPoint( ent ); // should have a hardcoded backup

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.selectSpawnPointFunc) );
	if( error < 0 ) 
		return SelectDeathmatchSpawnPoint( ent );

	// Now we need to pass the parameters to the script function.
	ctx->SetArgObject( 0, ent );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		GT_asShutdownScript();

	spot = ( edict_t * )ctx->GetReturnObject();
	if( !spot )
		spot = SelectDeathmatchSpawnPoint( ent );

	return spot;
}
コード例 #2
0
ファイル: g_as_gametypes.cpp プロジェクト: DenMSC/qfusion
//"bool GT_MatchStateFinished( int incomingMatchState )"
bool GT_asCallMatchStateFinished( int incomingMatchState )
{
	int error;
	asIScriptContext *ctx;
	bool result;

	if( !level.gametype.matchStateFinishedFunc )
		return true;

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.matchStateFinishedFunc) );
	if( error < 0 ) 
		return true;

	// Now we need to pass the parameters to the script function.
	ctx->SetArgDWord( 0, incomingMatchState );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		GT_asShutdownScript();

	// Retrieve the return from the context
	result = ctx->GetReturnByte() == 0 ? false : true;

	return result;
}
コード例 #3
0
ファイル: g_as_gametypes.cpp プロジェクト: DenMSC/qfusion
//"String @GT_ScoreboardMessage( uint maxlen )"
// The result is stored in scoreboardString.
void GT_asCallScoreboardMessage( unsigned int maxlen )
{
	asstring_t *string;
	int error;
	asIScriptContext *ctx;

	scoreboardString[0] = 0;

	if( !level.gametype.scoreboardMessageFunc )
		return;

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.scoreboardMessageFunc) );
	if( error < 0 ) 
		return;

	// Now we need to pass the parameters to the script function.
	ctx->SetArgDWord( 0, maxlen );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		GT_asShutdownScript();

	string = ( asstring_t * )ctx->GetReturnObject( );
	if( !string || !string->len || !string->buffer )
		return;

	Q_strncpyz( scoreboardString, string->buffer, sizeof( scoreboardString ) );
}
コード例 #4
0
ファイル: g_as_maps.cpp プロジェクト: Clever-Boy/qfusion
/*
* G_asCallMapGametype
*/
const char *G_asCallMapGametype( void )
{
	asstring_t *string;
	int error;
	asIScriptContext *ctx;
	static char gametypeName[MAX_CONFIGSTRING_CHARS];
	asstring_t *s;

	if( !level.mapscript.gametypeFunc )
		return "";

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.mapscript.gametypeFunc) );
	if( error < 0 ) 
		return "";

	s = angelExport->asStringFactoryBuffer( g_gametype->string, strlen( g_gametype->string ) );

	ctx->SetArgObject( 0, s );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		GT_asShutdownScript();

	string = ( asstring_t * )ctx->GetReturnObject( );
	if( !string || !string->len || !string->buffer )
		return "";

	Q_strncpyz( gametypeName, string->buffer, sizeof( gametypeName ) );

	return gametypeName;
}
コード例 #5
0
ファイル: g_as_gametypes.cpp プロジェクト: Picmip/qfusion
//"void GT_playerRespawn( Entity @ent, int old_team, int new_team )"
void GT_asCallPlayerRespawn( edict_t *ent, int old_team, int new_team ) {
	int error;
	asIScriptContext *ctx;

	if( !level.gametype.playerRespawnFunc ) {
		return;
	}

	ctx = game.asExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>( level.gametype.playerRespawnFunc ) );
	if( error < 0 ) {
		return;
	}

	// Now we need to pass the parameters to the script function.
	ctx->SetArgObject( 0, ent );
	ctx->SetArgDWord( 1, old_team );
	ctx->SetArgDWord( 2, new_team );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) ) {
		GT_asShutdownScript();
	}
}
コード例 #6
0
ファイル: g_as_gametypes.cpp プロジェクト: DenMSC/qfusion
//"void GT_MatchStateStarted()"
void GT_asCallMatchStateStarted( void )
{
	int error;
	asIScriptContext *ctx;

	if( !level.gametype.matchStateStartedFunc )
		return;

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.matchStateStartedFunc) );
	if( error < 0 ) 
		return;

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		GT_asShutdownScript();
}
コード例 #7
0
ファイル: g_as_maps.cpp プロジェクト: codetwister/qfusion
/*
* G_asCallMapFunction
*/
static void G_asCallMapFunction( void *func )
{
	int error;
	asIScriptContext *ctx;

	if( !func || !angelExport )
		return;

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(func) );
	if( error < 0 ) 
		return;

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		G_asShutdownMapScript();
}
コード例 #8
0
ファイル: g_as_gametypes.cpp プロジェクト: Picmip/qfusion
//"bool GT_Command( Client @client, String &cmdString, String &argsString, int argc )"
bool GT_asCallGameCommand( gclient_t *client, const char *cmd, const char *args, int argc ) {
	int error;
	asIScriptContext *ctx;
	asstring_t *s1, *s2;

	if( !level.gametype.clientCommandFunc ) {
		return false; // should have a hardcoded backup

	}

	// check for having any command to parse
	if( !cmd || !cmd[0] ) {
		return false;
	}

	ctx = game.asExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>( level.gametype.clientCommandFunc ) );
	if( error < 0 ) {
		return false;
	}

	// Now we need to pass the parameters to the script function.
	s1 = game.asExport->asStringFactoryBuffer( cmd, strlen( cmd ) );
	s2 = game.asExport->asStringFactoryBuffer( args, strlen( args ) );

	ctx->SetArgObject( 0, client );
	ctx->SetArgObject( 1, s1 );
	ctx->SetArgObject( 2, s2 );
	ctx->SetArgDWord( 3, argc );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) ) {
		GT_asShutdownScript();
	}

	game.asExport->asStringRelease( s1 );
	game.asExport->asStringRelease( s2 );

	// Retrieve the return from the context
	return ctx->GetReturnByte() == 0 ? false : true;
}
コード例 #9
0
ファイル: g_as_gametypes.cpp プロジェクト: Picmip/qfusion
//"void GT_SpawnGametype()"
void GT_asCallSpawn( void ) {
	int error;
	asIScriptContext *ctx;

	if( !level.gametype.spawnFunc ) {
		return;
	}

	ctx = game.asExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>( level.gametype.spawnFunc ) );
	if( error < 0 ) {
		return;
	}

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) ) {
		GT_asShutdownScript();
	}
}
コード例 #10
0
ファイル: g_as_gametypes.cpp プロジェクト: Picmip/qfusion
//"void GT_scoreEvent( Client @client, String &score_event, String &args )"
void GT_asCallScoreEvent( gclient_t *client, const char *score_event, const char *args ) {
	int error;
	asIScriptContext *ctx;
	asstring_t *s1, *s2;

	if( !level.gametype.scoreEventFunc ) {
		return;
	}

	if( !score_event || !score_event[0] ) {
		return;
	}

	if( !args ) {
		args = "";
	}

	ctx = game.asExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>( level.gametype.scoreEventFunc ) );
	if( error < 0 ) {
		return;
	}

	// Now we need to pass the parameters to the script function.
	s1 = game.asExport->asStringFactoryBuffer( score_event, strlen( score_event ) );
	s2 = game.asExport->asStringFactoryBuffer( args, strlen( args ) );

	ctx->SetArgObject( 0, client );
	ctx->SetArgObject( 1, s1 );
	ctx->SetArgObject( 2, s2 );

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) ) {
		GT_asShutdownScript();
	}

	game.asExport->asStringRelease( s1 );
	game.asExport->asStringRelease( s2 );
}
コード例 #11
0
ファイル: g_as_gametypes.cpp プロジェクト: Picmip/qfusion
void GT_asShutdownScript( void ) {
	int i;
	edict_t *e;

	if( game.asEngine == NULL ) {
		return;
	}

	// release the callback and any other objects obtained from the script engine before releasing the engine
	for( i = 0; i < game.numentities; i++ ) {
		e = &game.edicts[i];

		if( e->scriptSpawned && e->asScriptModule &&
			!strcmp( ( static_cast<asIScriptModule*>( e->asScriptModule ) )->GetName(), GAMETYPE_SCRIPTS_MODULE_NAME ) ) {
			G_asReleaseEntityBehaviors( e );
			e->asScriptModule = NULL;
		}
	}

	GT_ResetScriptData();

	GAME_AS_ENGINE()->DiscardModule( GAMETYPE_SCRIPTS_MODULE_NAME );
}
コード例 #12
0
ファイル: g_as_gametypes.cpp プロジェクト: DenMSC/qfusion
static bool G_asInitializeGametypeScript( asIScriptModule *asModule )
{
	int error;
	asIScriptContext *ctx;
	int funcCount;
	const char *fdeclstr;

	// grab script function calls
	funcCount = 0;

	fdeclstr = "void GT_InitGametype()";
	level.gametype.initFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.initFunc )
	{
		G_Printf( "* The function '%s' was not found. Can not continue.\n", fdeclstr );
		return false;
	}
	else
		funcCount++;

	fdeclstr = "void GT_SpawnGametype()";
	level.gametype.spawnFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.spawnFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "void GT_MatchStateStarted()";
	level.gametype.matchStateStartedFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.matchStateStartedFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "bool GT_MatchStateFinished( int incomingMatchState )";
	level.gametype.matchStateFinishedFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.matchStateFinishedFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "void GT_ThinkRules()";
	level.gametype.thinkRulesFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.thinkRulesFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "void GT_PlayerRespawn( Entity @ent, int old_team, int new_team )";
	level.gametype.playerRespawnFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.playerRespawnFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "void GT_ScoreEvent( Client @client, const String &score_event, const String &args )";
	level.gametype.scoreEventFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.scoreEventFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "String @GT_ScoreboardMessage( uint maxlen )";
	level.gametype.scoreboardMessageFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.scoreboardMessageFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "Entity @GT_SelectSpawnPoint( Entity @ent )";
	level.gametype.selectSpawnPointFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.selectSpawnPointFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "bool GT_Command( Client @client, const String &cmdString, const String &argsString, int argc )";
	level.gametype.clientCommandFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.clientCommandFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	fdeclstr = "void GT_Shutdown()";
	level.gametype.shutdownFunc = asModule->GetFunctionByDecl( fdeclstr );
	if( !level.gametype.shutdownFunc )
	{
		if( developer->integer || sv_cheats->integer )
			G_Printf( "* The function '%s' was not present in the script.\n", fdeclstr );
	}
	else
		funcCount++;

	//
	// Initialize AI gametype exports
	//
	AI_InitGametypeScript(asModule);

	//
	// execute the GT_InitGametype function
	//

	ctx = angelExport->asAcquireContext( GAME_AS_ENGINE() );

	error = ctx->Prepare( static_cast<asIScriptFunction *>(level.gametype.initFunc) );
	if( error < 0 ) 
		return false;

	error = ctx->Execute();
	if( G_ExecutionErrorReport( error ) )
		return false;

	return true;
}