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

📄 script.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    m_nObjectIndex = atoi(m_scriptCmdList[m_nCurrLine]->data);
    
    // Arg1 = TargetID
    // TargetID
    m_nCurrLine++;
    nTargetID = atoi(m_scriptCmdList[m_nCurrLine]->data);
    _mbscpy((unsigned char*)pTargetName, (const unsigned char*)ScriptObject[nTargetID].m_szObjectName);
    
    // Arg2 = BurnTime
    m_nCurrLine++;
    fBurnTime = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
	if (pTargetName && pTargetName[0] != '\0')
    {
    	ObjectList*	pList = g_pServerDE->FindNamedObjects(pTargetName);
    	if (pList)
        {
	        ObjectLink* pLink = pList->m_pFirstLink;
        	while(pLink)
	        {
		        if (pLink)
    		    {
                    hTargetObject = pLink->m_hObject;
	    	    }
            
	    	    pLink = pLink->m_pNext;
        	}
	    
	        g_pServerDE->RelinquishList(pList);
        }
        
    }

    _mbscpy((unsigned char*)pClassName, (const unsigned char*)"FireFX");
    
    // Found object, now add Fire
    if (hTargetObject)
    {
    	theStruct.m_ObjectType = OT_NORMAL; 

        // 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);

    	DVector vPos;
        g_pServerDE->GetObjectPos(m_hObject, &vPos);

        ROT_COPY(theStruct.m_Rotation, rRot);
	    VEC_COPY(theStruct.m_Pos, vPos);
    
    	theStruct.m_NextUpdate = 0.01f;
    
	    HCLASS pClass = g_pServerDE->GetClass(pClassName);
    
        // Check to make sure this is a valid class.
        if (pClass)
        {    
        	FireFX* pObject = (FireFX*)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);
            
                pObject->Setup(hTargetObject, fBurnTime);
                return DTRUE;
            }
        }
    }
    
    g_pServerDE->BPrint("ObjectCreateFire");
    g_pServerDE->BPrint("Error creating");
    g_pServerDE->BPrint(pClassName);
    return DFALSE;
} 



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CreateObject Exposion
//
//	PURPOSE:	Creates a Exposion object
//
// ----------------------------------------------------------------------- //
DBOOL Script::ObjectCreateExplosionAt()
{
    char pName[MAXDATA_LEN];
    char pClassName[MAXDATA_LEN];
    DFLOAT fDuration = 0.0f;
    DFLOAT fSoundRadius = 1000.0f;
    DFLOAT fDamageRadius = 1000.0f;
    DFLOAT fScaleMin = 0.1f;
	DFLOAT fScaleMax = 1.0f;
    
	if (!g_pServerDE || !m_hObject) return DFALSE;

    // Arg0 = X
    // Arg1 = Y
    // Arg2 = Z
    // Arg3 = Duration
    // Arg4 = Sound Radius
    // Arg5 = Damage Radius
    // Arg6 = Min Scale
    // Arg7 = Max Scale
    
    ObjectCreateStruct theStruct;
	INIT_OBJECTCREATESTRUCT(theStruct);

    sprintf(pName,"ScriptObjExp");
    _mbscpy((unsigned char*)theStruct.m_Name, (const unsigned char*)pName);
    
    _mbscpy((unsigned char*)pClassName, (const unsigned char*)"Explosion");

    DRotation rRot;
    ROT_INIT(rRot);
    ROT_COPY(theStruct.m_Rotation, rRot);

	DVector vPos;
    // Arg0 = X Position
    m_nCurrLine++;
    vPos.x = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    // Arg1 = Y
    m_nCurrLine++;
    vPos.y = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    // Arg2 = Z
    m_nCurrLine++;
    vPos.z = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    // Arg3 = Duration
    m_nCurrLine++;
    fDuration = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    // Arg4 = Sound Radius
    m_nCurrLine++;
    fSoundRadius = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    // Arg5 = Damage Radius
    m_nCurrLine++;
    fDamageRadius = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    // Arg6 = Min Scale
    m_nCurrLine++;
    fScaleMin = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    // Arg7 = Max Scale
    m_nCurrLine++;
    fScaleMax = (float)atof(m_scriptCmdList[m_nCurrLine]->data);


	VEC_COPY(theStruct.m_Pos, vPos);
    
    theStruct.m_NextUpdate = 0.01f;
    
	HCLASS pClass = g_pServerDE->GetClass(pClassName);
    
    // Check to make sure this is a valid class.
    if (pClass)
    {    
    	Explosion* pExplosion = (Explosion *)g_pServerDE->CreateObject(pClass, &theStruct);
        
        if (pExplosion)
        {
//            HOBJECT hObject = g_pServerDE->ObjectToHandle(pExplosion);
        
            DFLOAT fDamage = 50.0f;
            DBOOL bCreateMark = DTRUE;
            DBOOL bAddSparks  = DFALSE;
            DBOOL bCreateSmoke = DTRUE;
            
            DVector vLightColor;
	        VEC_SET(vLightColor, 1, 1, 1);
            
    		pExplosion->Setup("Sounds\\exp_tnt.wav", fSoundRadius, fDuration,
						  NULL, fDamageRadius, fDamage, fScaleMin,
						  fScaleMax, bCreateMark, bAddSparks, bCreateSmoke);


		    pExplosion->SetupLight(DTRUE, vLightColor, fScaleMin*10, fScaleMax*10);

            // Boom!
        	pExplosion->Explode();

            return DTRUE;
        }
    }
    
    g_pServerDE->BPrint("ObjectCreateExposionAt");
    g_pServerDE->BPrint("Error creating");
    g_pServerDE->BPrint(pClassName);
    return DFALSE;
} 
                    


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CreateObject Exposion Near a Object
//
//	PURPOSE:	Creates a Exposion object
//
// ----------------------------------------------------------------------- //
DBOOL Script::ObjectCreateExplosionNear()
{
    char pName[MAXDATA_LEN];
    char pClassName[MAXDATA_LEN];
    DFLOAT fDuration = 0.0f;
    DFLOAT fSoundRadius = 1000.0f;
    DFLOAT fDamageRadius = 1000.0f;
    DFLOAT fScaleMin = 0.1f;
    DFLOAT fScaleMax = 1.0f;
    int nTargetID;
    
	if (!g_pServerDE || !m_hObject) return DFALSE;

    // Arg0 = TargetID
    // Arg1 = Duration
    // Arg2 = Sound Radius
    // Arg3 = Damage Radius
    // Arg4 = Min Scale
    // Arg5 = Max Scale
    
    ObjectCreateStruct theStruct;
	INIT_OBJECTCREATESTRUCT(theStruct);

    sprintf(pName,"ScriptObjExp");
    _mbscpy((unsigned char*)theStruct.m_Name, (const unsigned char*)pName);
    
    // Arg0 = Object ID
    m_nCurrLine++;
    nTargetID = atoi(m_scriptCmdList[m_nCurrLine]->data);
    
    _mbscpy((unsigned char*)pClassName, (const unsigned char*)"Explosion");

//    DRotation rRot;
//    ROT_INIT(rRot);
//    ROT_COPY(theStruct.m_Rotation, rRot);

    HOBJECT hLinkObject = ScriptObject[nTargetID].m_hObject;
    
    if (hLinkObject)
    {
        // Random explosion position (from the FireFX code)
            DRotation rRot;
            DVector m_vUp, m_vRight, m_vForward;
            DVector vPos, vTemp, vDir, vDims;

            VEC_INIT(m_vUp);
            VEC_INIT(m_vRight);
            VEC_INIT(m_vForward);

            g_pServerDE->GetObjectRotation(hLinkObject, &rRot);
            g_pServerDE->GetRotationVectors(&rRot, &m_vUp, &m_vRight, &m_vForward);    

            g_pServerDE->GetObjectDims(hLinkObject, &vDims);
            g_pServerDE->GetObjectPos(hLinkObject, &vPos);
            
            // Need to use the Dims of the Object to set these!!!
//			VEC_MULSCALAR(vDims, vDims, 0.8f);
            DFLOAT m_fForwardOffset = g_pServerDE->Random(-vDims.x, vDims.x);
            DFLOAT m_fUpOffset = g_pServerDE->Random(-vDims.y, vDims.y/2.0f);
            DFLOAT m_fRightOffset = g_pServerDE->Random(-vDims.z, vDims.z);
    
    	    VEC_MULSCALAR(vTemp, m_vForward, m_fForwardOffset);
        	VEC_ADD(vPos, vPos, vTemp);
    
            // vPos is a point in front of you.
            // vDir is a point in front of you, but down
        	VEC_COPY(vDir, vPos);
            vDir.y = vDir.y - m_fUpOffset;
            vDir.x = vDir.x - m_fRightOffset;
			vDir.z = vDir.z - m_fForwardOffset;
            
            VEC_COPY(vPos, vDir);
    

        // Arg1 = Duration
        m_nCurrLine++;
        fDuration = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

        // Arg2 = Sound Radius
        m_nCurrLine++;
        fSoundRadius = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

        // Arg3 = Damage Radius
        m_nCurrLine++;
        fDamageRadius = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
        
        // Arg4 = Min Scale
        m_nCurrLine++;
        fScaleMin = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

        // Arg5 = Max Scale
        m_nCurrLine++;
        fScaleMax = (float)atof(m_scriptCmdList[m_nCurrLine]->data);

    	VEC_COPY(theStruct.m_Pos, vPos);
    
        theStruct.m_NextUpdate = 0.01f;
    
    	HCLASS pClass = g_pServerDE->GetClass(pClassName);
    
        // Check to make sure this is a valid class.
        if (pClass)
        {    
    	    Explosion* pExplosion = (Explosion *)g_pServerDE->CreateObject(pClass, &theStruct);
        
            if (pExplosion)
            {
//            HOBJECT hObject = g_pServerDE->ObjectToHandle(pExplosion);
        
                DFLOAT fDamage = 50.0f;
                DBOOL bCreateMark = DTRUE;
                DBOOL bAddSparks  = DFALSE;
                DBOOL bCreateSmoke = DTRUE;
            
                DVector vLightColor;
	            VEC_SET(vLightColor, 1, 1, 1);
            
    		    pExplosion->Setup("Sounds\\exp_tnt.wav", fSoundRadius, fDuration,
						  NULL, fDamageRadius, fDamage, fScaleMin,
						  fScaleMax, bCreateMark, bAddSparks, bCreateSmoke);


    		    pExplosion->SetupLight(DTRUE, vLightColor, fScaleMin*10, fScaleMax*10);

                // Boom!
            	pExplosion->Explode();

                return DTRUE;
            }
        }
    }
    
    g_pServerDE->BPrint("ObjectCreateExposionNear");
    g_pServerDE->BPrint("Error creating");
    g_pServerDE->BPrint(pClassName);
    return DFALSE;
} 
 


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	
//
//	PURPOSE:	Move the Object
//
// ----------------------------------------------------------------------- //
DBOOL Script::ObjectMove()
{
	DVector Pos;
    int nObjectID;
    
	if (!g_pServerDE) return DFALSE;
    
//    g_pServerDE->BPrint( "ObjectMove" );
    // Arg0 = object number (m_nObjectIndex)
    // Arg1 = x
    // Arg2 = y
    // Arg3 = z
    m_nCurrLine++;
    nObjectID = atoi(m_scriptCmdList[m_nCurrLine]->data);
    
    m_nCurrLine++;
    Pos.x = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    m_nCurrLine++;
    Pos.y = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    m_nCurrLine++;
    Pos.z = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    // If any of the points are zero, then we are going to Offset from current Point
    
    if (ScriptObject[nObjectID].m_hObject)
    {
//        if (Pos.x == 0 || Pos.y == 0 || Pos.z == 0)
//        {

        // Always Move from current position
            DVector vCurPos;
            g_pServerDE->GetObjectPos(ScriptObject[nObjectID].m_hObject, &vCurPos);
            
    	    VEC_ADD(Pos, Pos, vCurPos);
//        }    
        
//    	g_pServerDE->SetVelocity(ScriptObject[nObjectID].m_hObject, &Pos);
    	g_pServerDE->MoveObject(ScriptObject[nObjectID].m_hObject, &Pos);
        return DTRUE;
    }            
    
    g_pServerDE->BPrint( "ObjectMove" );
    g_pServerDE->BPrint( "Error Moving" );
    return DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	
//
//	PURPOSE:	Teleport the Object
//
// ----------------------------------------------------------------------- //
DBOOL Script::ObjectTeleport()
{
	DVector vPos;
    int nObjectID;

	if (!g_pServerDE) return DFALSE;
    
    // Arg0 = object number (m_nObjectIndex)
    // Arg1 = x
    // Arg2 = y
    // Arg3 = z

    m_nCurrLine++;
    nObjectID = atoi(m_scriptCmdList[m_nCurrLine]->data);
    m_nCurrLine++;
    vPos.x = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    m_nCurrLine++;
    vPos.y = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    m_nCurrLine++;
    vPos.z = (float)atof(m_scriptCmdList[m_nCurrLine]->data);
    
    if (ScriptObject[nObjectID].m_hObject)
    {
        // If any of the points are zero, then we are going to Offset from current Point
//        if (vPos.x == 0 || vPos.y == 0 || vPos.z == 0)
//        {
// Always Move from current position
            DVector vCurP

⌨️ 快捷键说明

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