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

📄 script.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

	char seps[] = " ,\t\n";

	char *tokenname;            // Script Command
	char *temparg;

	nEOF = 0;

	// Get a line, check for End of File
	if (fgets(line, 256, infile) == NULL)
	{
		nEOF = 1;
		return DTRUE;
	}

	// GET THE FIRST TOKEN
	/////////////////////////////////////////////////////////////////
	tokenname = NextToken(line, seps);

	// See if its a comment
	if ( !tokenname || tokenname[0] == ';' || _mbsncmp((const unsigned char*)tokenname, (const unsigned char*)"//", 2) == 0) return DTRUE;

	// Check for DEFINES
	if ( m_nDefineCnt < MAX_DEFINES && _mbsncmp((const unsigned char*)tokenname, (const unsigned char*)"define", 6) == 0)
	{
		if ( (temparg = NextToken(NULL, " =\t\n")) )
		{
			// Copy the Define data to structure
			memset(sDefineObject[m_nDefineCnt].m_szDefineName, 0, MAXDATA_LEN);
			_mbsncpy((unsigned char*)sDefineObject[m_nDefineCnt].m_szDefineName, (const unsigned char*)temparg, MAXDATA_LEN);

			if ( (temparg = NextToken(NULL, " =\t\n")) )
			{
				// Copy the Define data to structure
				memset(sDefineObject[m_nDefineCnt].m_szDefineValue, 0, MAXDATA_LEN);
				_mbsncpy((unsigned char*)sDefineObject[m_nDefineCnt].m_szDefineValue, (const unsigned char*)temparg, MAXDATA_LEN);
			}
			else
			{
				// Error
				g_pServerDE->BPrint("ERROR...define missing value");
				return DFALSE;
			}
		}
		else
		{
			// Error
			g_pServerDE->BPrint("ERROR...define missing name");
			return DFALSE;
		}

		// Increate the Array counter    
		m_nDefineCnt++;

		// next line
		return DTRUE;
	}


	// GET THE NEXT TOKEN
	/////////////////////////////////////////////////////////////////
//	tokenname = NextToken(NULL, seps);
	// If no command then skip
//	if (!(tokenname) ) return DTRUE;

	// make sure the command is always uppercase
	_strupr(tokenname);

	SCRIPTCMD* pCmd = new SCRIPTCMD;
	if (!pCmd)
	{
		g_pServerDE->BPrint( "ERROR...Could not create Temp Script" );
		return DFALSE;
	}

	int nArgs;
	int nCheckObjID;

	// Store the command in Temp cmd
	pCmd->command = StringToScriptCutCmdType(tokenname, nArgs, nCheckObjID);

	// Make sure the command is Valid!
	if (pCmd->command == 0)
	{    
		g_pServerDE->BPrint("ERROR...Unknown command %s", tokenname);
		return DFALSE;
	}                 

	// Store the number of args in data
	sprintf(pCmd->data, "%d", nArgs);

	// set the start time
//	pCmd->fStartTime = m_fScriptTime;
	pCmd->m_bExecuted = DFALSE;

	m_scriptCmdList.Add(pCmd);

	if (nArgs > 0)
	{
		for (int i=0; i < nArgs; i++)
		{
			// Get Next Arg (based on the number of args for this command)
			/////////////////////////////////////////////////////////////////
			if ( (temparg = NextToken(NULL, " ,\t\n")) )
			{
				// Add Arg Script
				if (AddArgScript(temparg) == DFALSE)   return DFALSE;


				// NEED TO GET THE DEFINED ARG OBJECT TO CHECK FOR THIS...
				//            
				//                // Check the ObjectID
				//                if ((nCheckObjID > 0) && (i+1 == nCheckObjID) )
				//                {
				//                    if (atoi(temparg) > MAXSCRIPTOBJ)
				//                    {
				//                        g_pServerDE->BPrint( "ERROR...ObjectID Greater than MAX" );
				//                  	return DFALSE;
				//                    }
				//                }

				//
				// Do some pre processing checking!
				//
				if ( ((pCmd->command == SCRIPT_SCMD_OBJECT_CREATE_NEAR)||(pCmd->command == SCRIPT_SCMD_OBJECT_CREATE_AT)) && (i==1)  )
				{
					// Check to make sure the class is Valid!
					HCLASS pClass = g_pServerDE->GetClass(temparg);
					if (!pClass)
					{    
						g_pServerDE->BPrint("ERROR...Invalid ObjectCLASS: %s",temparg);
						return DFALSE;
					}                 
				}
			}
			else
			{
				g_pServerDE->BPrint( "ERROR...Invalid Args for script command %s", tokenname );
				return DFALSE;
			}
		}
	}    

	return DTRUE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	AddArgScript
//
//	PURPOSE:	Add a Arg to the Script list
//
// ----------------------------------------------------------------------- //
DBOOL Script::AddArgScript(char *temparg)
{
    char szCopyArg[256];
    
    memset(szCopyArg,0,256);
    _mbsncpy((unsigned char*)szCopyArg,(const unsigned char*)temparg,MAXDATA_LEN);

    // Do the Define replacements
    // Only check the args that have a (
    if (m_nDefineCnt > 0 && szCopyArg[0] == '#')
    {
		char *pToken = &szCopyArg[1];
        for (int i=0; i < m_nDefineCnt; i++)
        {
            if ( _mbsncmp((const unsigned char*)pToken, (const unsigned char*)sDefineObject[i].m_szDefineName, _mbstrlen(sDefineObject[i].m_szDefineName) ) == 0)
            {
                memset(szCopyArg,0,256);
                _mbsncpy((unsigned char*)szCopyArg, (const unsigned char*)sDefineObject[i].m_szDefineValue, MAXDATA_LEN);
            
                break;
            }
        }
        
    }        

    //
    // Create a Temp Arg Scriptbuffer
    //
    SCRIPTCMD* pArg = new SCRIPTCMD;
    if (!pArg)
    {
        g_pServerDE->BPrint( "ERROR...Could not create Temp Script" );
        return DFALSE;
    }

    // Store the Arg command
    pArg->command = SCRIPT_SCMD_ARG;

    char* pData = szCopyArg;
    if (pData) 
    {
        _mbsncpy((unsigned char*)pArg->data, (const unsigned char*)pData, MAXDATA_LEN);
	    m_scriptCmdList.Add(pArg);
    }
    else
    {
        g_pServerDE->BPrint( "ERROR...Arg not found" );
        return DFALSE;
    }

    return DTRUE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Start
//
//	PURPOSE:	Init the script
//
// ----------------------------------------------------------------------- //
DBOOL Script::StartScript()
{
	if (!g_pServerDE) return DFALSE;

// If Script is already running, return

    if (m_bScriptStarted == DFALSE)
    {
        m_bScriptStarted = DTRUE;
    
    }

// Init the Execute commands to DFALSE

    return DTRUE;
}    

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Start
//
//	PURPOSE:	Init the script
//
// ----------------------------------------------------------------------- //
DBOOL Script::SetCutScene()
{
	if (!g_pServerDE) return DFALSE;

//    g_pServerDE->BPrint( "SetCutScene" );

    int nCutMode;
    
    // Arg0 = On or Off (1 or 0)
    m_nCurrLine++;
    nCutMode = atoi(m_scriptCmdList[m_nCurrLine]->data);
    
    if (nCutMode == 1)
    {    
//        g_pServerDE->BPrint( "CutSceneStart" );

	    HMESSAGEWRITE hMsg = g_pServerDE->StartMessage(NULL, SMSG_CUTSCENE_START);
    	g_pServerDE->EndMessage(hMsg);
    }
    else
    {
  //      g_pServerDE->BPrint( "CutSceneEnd" );

	    HMESSAGEWRITE hMsg = g_pServerDE->StartMessage(NULL, SMSG_CUTSCENE_END);
    	g_pServerDE->EndMessage(hMsg);

		// Deactivate all cameras
		for (int i=0; i<MAXSCRIPTOBJ; i++)
		{
			if (ScriptCamera[i].m_hObject)
			{
    			CameraObj* pCamera = (CameraObj*)g_pServerDE->HandleToObject(ScriptCamera[i].m_hObject);
				pCamera->SetActive(DFALSE);
			}
		}
    
    }
    return DTRUE;
}
    
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	End
//
//	PURPOSE:	End the script
//
// ----------------------------------------------------------------------- //
DBOOL Script::EndScript()
{
	if (!g_pServerDE) return DFALSE;

//    g_pServerDE->BPrint("Script DONE!");
    g_pServerDE->SetNextUpdate(m_hObject, 0.0f);
    //return DFALSE;
    
    return DTRUE;
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Display Title
//
//	PURPOSE:	
//
// ----------------------------------------------------------------------- //
DBOOL Script::SubTitleDisplay()
{
	if (!g_pServerDE) return DFALSE;

//    g_pServerDE->BPrint( "DisplayTitle" );

    char szTitle[128];
    
	// Arg0 = Length of time to display subtitle
    // Arg1 = Text to display

    m_nCurrLine++;
    DFLOAT fTime = (DFLOAT)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    m_nCurrLine++;
    _mbscpy((unsigned char*)szTitle, (const unsigned char*)m_scriptCmdList[m_nCurrLine]->data);
    
	HMESSAGEWRITE hMsg = g_pServerDE->StartMessage(NULL, SMSG_DISPLAYTEXT);
	g_pServerDE->WriteToMessageFloat(hMsg, fTime);
	g_pServerDE->WriteToMessageString(hMsg, szTitle);
	g_pServerDE->EndMessage(hMsg);

    return DTRUE;
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Fade
//
//	PURPOSE:	
//
// ----------------------------------------------------------------------- //
DBOOL Script::SubTitleFade()
{
	if (!g_pServerDE) return DFALSE;
    
//    g_pServerDE->BPrint( "FadeSubTitle" );
    
    int nFadeMode;
    
    // Arg0 = Class
    m_nCurrLine++;
    nFadeMode = atoi(m_scriptCmdList[m_nCurrLine]->data);
    
	HMESSAGEWRITE hMsg = g_pServerDE->StartMessage(NULL, SMSG_SCREENFADE);
	g_pServerDE->WriteToMessageByte(hMsg, (DBYTE)nFadeMode);
	g_pServerDE->EndMessage(hMsg);

    
    return DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CreateObjectAt
//
//	PURPOSE:	Creates a object
//
// ----------------------------------------------------------------------- //
DBOOL Script::ObjectCreateAt()
{
    char pName[MAXDATA_LEN];
    char pClassName[MAXDATA_LEN];
    
	if (!g_pServerDE || !m_hObject) return DFALSE;

    // Arg0 = Object number
    // Arg1 = Class
    // Arg2 = X
    // Arg3 = Y
    // Arg4 = Z
    
    ObjectCreateStruct theStruct;
	INIT_OBJECTCREATESTRUCT(theStruct);

    // Arg0 = Object Number
    m_nCurrLine++;
    sprintf(pName,"ScriptObj%d", atoi(m_scriptCmdList[m_nCurrLine]->data) );
    _mbscpy((unsigned char*)theStruct.m_Name, (const unsigned char*)pName);
    
    // Set the Object Index  NEED TO CHECK FOR OBJECT ALREADY USING THIS...
    m_nObjectIndex = atoi(m_scriptCmdList[m_nCurrLine]->data);

    // Arg1 = Class
    m_nCurrLine++;
    _mbscpy((unsigned char*)pClassName, (const unsigned char*)m_scriptCmdList[m_nCurrLine]->data);
    
	DVector vPos;
    // Arg2 = X Position
    m_nCurrLine++;
    vPos.x = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    // Arg3 = Y
    m_nCurrLine++;
    vPos.y = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    // Arg4 = Z
    m_nCurrLine++;
    vPos.z = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

	VEC_COPY(theStruct.m_Pos, vPos);
    
    // Store the names into the Object Array    
    _mbsncpy((unsigned char*)ScriptObject[m_nObjectIndex].m_szObjectName, (const unsigned char*)pName, MAXDATA_LEN);
    _mbsncpy((unsigned char*)ScriptObject[m_nObjectIndex].m_szClassName, (const unsigned char*)pClassName, MAXDATA_LEN);
    
	DRotation rRot;
    ROT_INIT(rRot);
    ROT_COPY(theStruct.m_Rotation, rRot);
    
	theStruct.m_NextUpdate = 0.1f;
    
	HCLASS pClass = g_pServerDE->GetClass(pClassName);
    
    // Check to make sure this is a valid class.
    if (pClass)
    {    
    	LPBASECLASS pObject = g_pServerDE->CreateObject(pClass, &theStruct);
        
        if (pObject)
        {
            ScriptObject[m_nObjectIndex].m_hObject = g_pServerDE->ObjectToHandle(pObject);
			// Link to the target so we are notified if it's destroyed
			g_pServerDE->CreateInterObjectLink(m_hObject, ScriptObject[m_nObjectIndex].m_hObject);
            
            return DTRUE;
        }
    }        
    
    g_pServerDE->BPrint("ObjectCreateAt");
    g_pServerDE->BPrint("Error creating");

⌨️ 快捷键说明

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