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

📄 firefx.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//----------------------------------------------------------
//
// MODULE  : FireFX.CPP
//
// PURPOSE : defines classes for Fire on Objects
//
// CREATED : 2/23/98
//
//----------------------------------------------------------

// Includes....
#include <stdio.h>
#include <string.h>
#include "serverobj_de.h"
#include "FireFX.h"
#include "cpp_server_de.h"
#include "BaseCharacter.h"
#include "ClientSmokeTrail.h"


BEGIN_CLASS(FireFX)
	ADD_STRINGPROP(PlaceFireOn, "MyName")	    //  Object to place the fire on
//	ADD_REALPROP(BurnTime, 0.0f)	            //  Burn time
//	ADD_STRINGPROP(FireType, "small")	        //  Small/Medium/Large
END_CLASS_DEFAULT(FireFX, B2BaseClass, NULL, NULL)

void BPrint(char*);

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::FireFX
//
//	PURPOSE:	Initialize
//
// ----------------------------------------------------------------------- //

FireFX::FireFX() : B2BaseClass(OT_NORMAL)
{
	m_bPlaySound	= DTRUE;
	m_bFirstUpdate	= DTRUE;

	VEC_SET(m_vScale, 0.2f, 0.2f, 0.0f);

	m_fSoundVol		= 200;

	m_hstrAttachTo	= DNULL;
    
    m_hLinkObject   = DNULL;
    m_hLight        = DNULL;
    
    m_fLastTime     = 0.0f;
    m_bDead         = DFALSE;

	m_fBurnTime		= 0.0f;
    
    // Setup default values
    for (int x=0; x<MAXFIRES; x++)
    {
        m_hSmokeTrail[x] = DNULL;
		m_hSprite[x] = DNULL;
		m_fDuration[x] = 0.0f;
    	m_fStartTime[x]	= 0.0f;
    }            

    m_nFireIndex = 0;    
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::~FireFX
//
//	PURPOSE:	Destructor
//
// ----------------------------------------------------------------------- //

FireFX::~FireFX()
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	if (m_hstrAttachTo)
	{
		pServerDE->FreeString(m_hstrAttachTo);
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::EngineMessageFn
//
//	PURPOSE:	Handle engine messages
//
// ----------------------------------------------------------------------- //

DDWORD FireFX::EngineMessageFn(DDWORD messageID, void *pData, DFLOAT fData)
{
	switch(messageID)
	{
		case MID_UPDATE:
		{
			if (!Update((DVector *)pData))
			{
				CServerDE* pServerDE = BaseClass::GetServerDE();
				if (!pServerDE) return 0;

				pServerDE->RemoveObject(m_hObject);
			}
			break;
		}

		case MID_PRECREATE:
		{
			if (fData == 1.0f)
			{
				ReadProp((ObjectCreateStruct*)pData);
			}
			break;
		}

		case MID_INITIALUPDATE:
		{
			InitialUpdate((DVector *)pData);
			break;
		}

		// If we created a link to the target, this will tell us that it no longer exists
		case MID_LINKBROKEN:
		{
			HOBJECT hObj = (HOBJECT)pData;
            if (m_hLinkObject == hObj)
            {
	    		m_hLinkObject = DNULL;
		    }
		}
		break;
		
		default : break;
	}

	return B2BaseClass::EngineMessageFn(messageID, pData, fData);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::Setup
//
//	PURPOSE:	Set up a impact with the information needed
//
// ----------------------------------------------------------------------- //

void FireFX::Setup(HOBJECT hLinkObject, DFLOAT fBurnTime)
{
	m_hLinkObject = hLinkObject;
	m_fBurnTime = fBurnTime;
    
	FirstUpdate();
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::ReadProp
//
//	PURPOSE:	Set property values
//
// ----------------------------------------------------------------------- //

DBOOL FireFX::ReadProp(ObjectCreateStruct *pStruct)
{
	CServerDE* pServerDE = GetServerDE();
	if (!pServerDE || !pStruct) return DFALSE;
	char buf[MAX_CS_FILENAME_LEN];


	buf[0] = '\0';
	pServerDE->GetPropString("PlaceFireOn", buf, MAX_CS_FILENAME_LEN);
	if (buf[0]) m_hstrAttachTo = pServerDE->CreateString(buf);

	pServerDE->GetPropReal("BurnTime", &m_fBurnTime);

	return DTRUE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::InitialUpdate
//
//	PURPOSE:	Do initial updating
//
// ----------------------------------------------------------------------- //

DBOOL FireFX::InitialUpdate(DVector*)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE || !m_hObject) return DFALSE;

	pServerDE->SetNextUpdate(m_hObject, (DFLOAT)0.1);

    return DTRUE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	FireFX::FirstUpdate
//
//	PURPOSE:	Do First updating
//
// ----------------------------------------------------------------------- //

void FireFX::FirstUpdate()
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
	if (!pServerDE) return;

	// Can Create Up to 5 Fire Object at a Time....
    // Create Random durations for each Flame
    for (int x=0; x<MAXFIRES; x++)
    {
        m_fDuration[x] = pServerDE->Random(0.25f, 0.50f);
        m_fStartTime[x] = pServerDE->GetTime();
    }            

    // If FireFx was created from something else then They would set the LinkObject    
    
    if (m_hLinkObject == DNULL)
    {
    	DVector vPos;
    	pServerDE->GetObjectPos(m_hObject, &vPos);

        //
        // Need to get this name from the Props...
        //
        
    	ObjectList* pTargets = pServerDE->FindNamedObjects(pServerDE->GetStringData(m_hstrAttachTo));
        
        
	    if (!pTargets || pTargets->m_nInList <= 0) return;

        // Found all the Objects
    	ObjectLink *pLink = pTargets->m_pFirstLink;
        
    	while(pLink && pLink->m_hObject)
	    {
		    HCLASS hType = pServerDE->GetObjectClass(pLink->m_hObject);

            HCLASS hObjectTest = pServerDE->GetClass("CBaseCharacter");

		    if( (pServerDE->IsKindOf(hType, hObjectTest)) )
    		{
                m_hLinkObject = pLink->m_hObject;
				break;
    		}

            // Next object
		    pLink = pLink->m_pNext;
    	}

        // clean up	
	    pServerDE->RelinquishList(pTargets);

    }

    if (m_hLinkObject)
    {
        m_bFirstUpdate = DFALSE;

        // Create a Link to the Object on Fire
	   	pServerDE->CreateInterObjectLink(m_hObject, m_hLinkObject);

	    if (m_hLight == DNULL)
        {
            // Add Light
            ObjectCreateStruct theStruct;
        	INIT_OBJECTCREATESTRUCT(theStruct);

        	theStruct.m_Flags = FLAG_VISIBLE;
        	theStruct.m_ObjectType = OT_LIGHT; 
           //	VEC_COPY(theStruct.m_Pos, *pvPos);
            pServerDE->GetObjectPos(m_hObject, &theStruct.m_Pos);

        	HCLASS hClass = pServerDE->GetClass("BaseClass");
        
            if (hClass)
            {
                LPBASECLASS	pLight = pServerDE->CreateObject(hClass, &theStruct);

⌨️ 快捷键说明

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