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

📄 door.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//----------------------------------------------------------
//
// MODULE  : DOOR.CPP
//
// PURPOSE : a Door object
//
// CREATED : 8/5/97 5:07:00 PM
//
//----------------------------------------------------------

// Includes...

#include "generic_msg_de.h"
#include "door.h"
#include "Trigger.h"
#include "ClientServerShared.h"
#include "ObjectUtilities.h"
#include "SharedDefs.h"
#include <mbstring.h>
#include "SoundTypes.h"



#define	DOOR_DEFAULT_BLOCKING_PRIORITY	100
#define	DOOR_DEFAULT_DEACTIVATION_TIME	30.0f


// Static global variables..
static char *g_szTrigger		= "TRIGGER"; 
static char *g_szTriggerClose	= "TRIGGERCLOSE";
static char *g_szLock			= "LOCK"; 
static char *g_szUnLock			= "UNLOCK";


BEGIN_CLASS(Door)
	ADD_VISIBLE_FLAG(1, 0)
	ADD_SOLID_FLAG(1, 0)
	ADD_REALPROP(Speed, 0.0f)			//  movement speed
	ADD_REALPROP(MoveDist, 0.0f)		//  distance to open
	ADD_VECTORPROP(MoveDir)				//  direction to open
	ADD_STRINGPROP(OpenBusySound, "")	//  sound to play while opening
	ADD_STRINGPROP(OpenStopSound, "")	//  sound to play when done opening
	ADD_STRINGPROP(CloseBusySound, "")	//  sound to play while closing
	ADD_STRINGPROP(CloseStopSound, "")	//  sound to play when done closing
	ADD_REALPROP_FLAG(SoundRadius, 1000.0f, PF_RADIUS) //  radius of all sounds
	ADD_REALPROP(WaitTime, 0.0f)		//  length of time to stay open
	ADD_REALPROP(OpenDelay, 0.0f)		// Length of time to wait before opening
	ADD_VECTORPROP_FLAG(TriggerDims, PF_DIMS)	//  Dimensions for trigger box
	ADD_REALPROP(ClosingSpeed, 0.0f)	//  movement speed while closing
	ADD_STRINGPROP(PortalName, "")		// A Portal brush name
	ADD_LONGINTPROP(Waveform, DOORWAVE_LINEAR)
	ADD_BOOLPROP(BoxPhysics, DTRUE)		// Door uses "box physics"
	ADD_BOOLPROP(TriggerClosed, DFALSE)	// Door must be triggered to close
	ADD_BOOLPROP(StartOpen, DFALSE)		// Door starts in open position
	ADD_BOOLPROP(RemainsOpen, DFALSE)	// One-time door, remains open after opening

	ADD_BOOLPROP(SelfTrigger, DFALSE)	// Door creates it's own trigger
	ADD_BOOLPROP(FireThrough, DFALSE)	// Can shoot through the door.
	PROP_DEFINEGROUP(SelfTriggerOpts, PF_GROUP1) 
		ADD_BOOLPROP_FLAG(TouchActivate, DFALSE, PF_GROUP1)
		ADD_BOOLPROP_FLAG(PlayerActivate, DTRUE, PF_GROUP1)
		ADD_BOOLPROP_FLAG(AIActivate, DTRUE, PF_GROUP1)
		ADD_BOOLPROP_FLAG(ObjectActivate, DFALSE, PF_GROUP1)
		ADD_BOOLPROP_FLAG(TriggerRelayActivate, DTRUE, PF_GROUP1)
		ADD_BOOLPROP_FLAG(NamedObjectActivate, DFALSE, PF_GROUP1)
		ADD_STRINGPROP_FLAG(ActivationObjectName, "", PF_GROUP1)
		ADD_BOOLPROP_FLAG(Locked, DFALSE, PF_GROUP1)
		ADD_STRINGPROP_FLAG(LockedSound, "", PF_GROUP1)
		ADD_STRINGPROP_FLAG(UnlockedSound, "", PF_GROUP1)
		ADD_STRINGPROP_FLAG(UnlockKeyName, "Key", PF_GROUP1)

END_CLASS_DEFAULT(Door, B2BaseClass, NULL, NULL)


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Door::Door()
//
//	PURPOSE:	Initialize object
//
// ----------------------------------------------------------------------- //

Door::Door() : B2BaseClass(OT_WORLDMODEL)
{
	m_hstrOpenBusySound  = DNULL;
	m_hstrOpenStopSound  = DNULL;
	m_hstrCloseBusySound = DNULL;
	m_hstrCloseStopSound = DNULL;
	m_hstrPortal		 = DNULL;
	m_sndLastSound		 = DNULL;
	m_fSoundRadius		 = 1000.0f;

	m_dwWaveform		 = DOORWAVE_LINEAR;
	m_dwTriggerFlags	 = 0;
	m_bBoxPhysics		 = 0;

	m_hTriggerObj		 = DNULL;
	m_fOpenDelay		 = 0.0f;

	m_bTrigTouchActivate	= DFALSE;		// Trigger can be activated with TouchNotify
	m_bTrigPlayerActivate	= DTRUE;		// Can be triggered by player
	m_bTrigAIActivate		= DTRUE;		// Can be triggered by AI
	m_bTrigObjectActivate	= DFALSE;		// Can be triggered by another object
	m_bTrigTriggerRelayActivate	= DTRUE;	// Can be triggered by another trigger
	m_bTrigNamedObjectActivate	= DFALSE;	// Can it only be triggered by a specific object?
	m_hstrTrigActivationObjectName = DNULL;
	m_bTrigLocked				= DFALSE;		// Trigger is locked.
	m_hstrTrigLockedSound		= DNULL;		// Message to display when trigger is locked.
	m_hstrTrigUnlockedSound		= DNULL;		// Message to display when trigger is locked.
	m_hstrTrigKeyName			= DNULL;		// Name of key item needed to open the trigger.
	m_bFireThrough			= DFALSE;

	m_bDoorBlocked			= DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	Door::~Door()
//
//	PURPOSE:	Deallocate object
//
// ----------------------------------------------------------------------- //

Door::~Door()
{
	CServerDE* pServerDE = GetServerDE();

	if (m_hstrOpenBusySound)
	{
		pServerDE->FreeString(m_hstrOpenBusySound);
		m_hstrOpenBusySound = NULL;
	}
	if (m_hstrOpenStopSound)
	{
		pServerDE->FreeString(m_hstrOpenStopSound);
		m_hstrOpenStopSound = NULL;
	}
	if (m_hstrCloseBusySound)
	{
		pServerDE->FreeString(m_hstrCloseBusySound);
		m_hstrCloseBusySound = NULL;
	}
	if (m_hstrCloseStopSound)
	{
		pServerDE->FreeString(m_hstrCloseStopSound);
		m_hstrCloseStopSound = NULL;
	}
	if (m_hstrPortal)
	{
		pServerDE->FreeString(m_hstrPortal);
		m_hstrPortal = NULL;
	}
	if (m_hstrTrigActivationObjectName)
	{
		pServerDE->FreeString(m_hstrTrigActivationObjectName);
		m_hstrTrigActivationObjectName = NULL;
	}
	if (m_hstrTrigLockedSound)
	{
		pServerDE->FreeString(m_hstrTrigLockedSound);
		m_hstrTrigLockedSound = NULL;
	}
	if (m_hstrTrigUnlockedSound)
	{
		pServerDE->FreeString(m_hstrTrigUnlockedSound);
		m_hstrTrigUnlockedSound = NULL;
	}
	if (m_hstrTrigKeyName)
	{
		pServerDE->FreeString(m_hstrTrigKeyName);
		m_hstrTrigKeyName = NULL;
	}
	if (m_sndLastSound)
	{
		pServerDE->KillSound(m_sndLastSound);
	}
}


// --------------------------------------------------------------------------- //
//
//	ROUTINE:	Door::ReadProp()
//
//	PURPOSE:	Reads door properties
//
// --------------------------------------------------------------------------- //

DBOOL Door::ReadProp(ObjectCreateStruct *)
{
	CServerDE* pServerDE = GetServerDE();

	GenericProp genProp;

	if (pServerDE->GetPropGeneric("Speed", &genProp) == DE_OK)
		m_fSpeed = genProp.m_Float;

	if (pServerDE->GetPropGeneric("ClosingSpeed", &genProp) == DE_OK)
		m_fClosingSpeed = genProp.m_Float;

	if (pServerDE->GetPropGeneric("MoveDist", &genProp) == DE_OK)
		m_fMoveDist = genProp.m_Float;

	if (pServerDE->GetPropGeneric("MoveDir", &genProp) == DE_OK)
		VEC_COPY(m_vMoveDir, genProp.m_Vec);

	if (pServerDE->GetPropGeneric("OpenBusySound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			m_hstrOpenBusySound = pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("OpenStopSound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			m_hstrOpenStopSound = pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("CloseBusySound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			m_hstrCloseBusySound = pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("CloseStopSound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			m_hstrCloseStopSound = pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("PortalName", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			m_hstrPortal = pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("WaitTime", &genProp) == DE_OK)
		m_fWaitTime = genProp.m_Float;

	if (pServerDE->GetPropGeneric("OpenDelay", &genProp) == DE_OK)
	{
		m_fOpenDelay = genProp.m_Float;
	}

	if (pServerDE->GetPropGeneric("SoundRadius", &genProp) == DE_OK)
		m_fSoundRadius = genProp.m_Float;

	if (pServerDE->GetPropGeneric("TriggerDims", &genProp) == DE_OK)
		VEC_COPY(m_vTriggerDims, genProp.m_Vec);

	if (pServerDE->GetPropGeneric("Waveform", &genProp) == DE_OK)
		m_dwWaveform = genProp.m_Long;

	if (pServerDE->GetPropGeneric("BoxPhysics", &genProp) == DE_OK)
	{
		m_bBoxPhysics = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("SelfTrigger", &genProp) == DE_OK)
	{
		m_dwTriggerFlags |= genProp.m_Bool ? DTF_SELFTRIGGER : 0;
	}

	if (pServerDE->GetPropGeneric("TriggerClosed", &genProp) == DE_OK)
	{
		m_dwTriggerFlags |= genProp.m_Bool ? DTF_TRIGGERCLOSED : 0;
	}

	if (pServerDE->GetPropGeneric("StartOpen", &genProp) == DE_OK)
	{
		m_dwTriggerFlags |= genProp.m_Bool ? DTF_STARTOPEN : 0;
	}

	if (pServerDE->GetPropGeneric("RemainsOpen", &genProp) == DE_OK)
	{
		m_dwTriggerFlags |= genProp.m_Bool ? DTF_REMAINSOPEN : 0;
	}

	// Self-create trigger options
	if (pServerDE->GetPropGeneric("TouchActivate", &genProp) == DE_OK)
	{
		m_bTrigTouchActivate = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("PlayerActivate", &genProp) == DE_OK)
	{
		m_bTrigPlayerActivate = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("AIActivate", &genProp) == DE_OK)
	{
		m_bTrigAIActivate = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("TriggerRelayActivate", &genProp) == DE_OK)
	{
		m_bTrigTriggerRelayActivate = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("ObjectActivate", &genProp) == DE_OK)
	{
		m_bTrigObjectActivate = genProp.m_Bool;
	}

	if (pServerDE->GetPropGeneric("NamedObjectActivate", &genProp) == DE_OK)
	{
		m_bTrigNamedObjectActivate = genProp.m_Bool;
	}

	if (g_pServerDE->GetPropGeneric("ActivationObjectName", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			 m_hstrTrigActivationObjectName = g_pServerDE->CreateString(genProp.m_String);
	}

	if (g_pServerDE->GetPropGeneric("Locked", &genProp) == DE_OK)
		m_bTrigLocked = genProp.m_Bool;

	if (g_pServerDE->GetPropGeneric("LockedSound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			 m_hstrTrigLockedSound = g_pServerDE->CreateString(genProp.m_String);
	}

	if (g_pServerDE->GetPropGeneric("UnlockedSound", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			 m_hstrTrigUnlockedSound = g_pServerDE->CreateString(genProp.m_String);
	}

	if (g_pServerDE->GetPropGeneric("UnlockKeyName", &genProp) == DE_OK)
	{
		if (genProp.m_String[0])
			 m_hstrTrigKeyName = g_pServerDE->CreateString(genProp.m_String);
	}

	if (pServerDE->GetPropGeneric("FireThrough", &genProp) == DE_OK)
	{
		m_bFireThrough = genProp.m_Bool;
	}

	return DTRUE;
}


// --------------------------------------------------------------------------- //
//
//	ROUTINE:	Door::PostPropRead()
//
//	PURPOSE:	Initializes door data
//
// --------------------------------------------------------------------------- //

void Door::PostPropRead(ObjectCreateStruct *pStruct)
{
	_mbscpy((unsigned char*)pStruct->m_Filename, (const unsigned char*)pStruct->m_Name);
	pStruct->m_SkinName[0] = '\0';
	pStruct->m_Flags |= FLAG_GOTHRUWORLD | FLAG_FULLPOSITIONRES | FLAG_MODELGOURAUDSHADE;
	pStruct->m_Flags |= FLAG_FULLPOSITIONRES | FLAG_GOTHRUWORLD | FLAG_DONTFOLLOWSTANDING | (m_bBoxPhysics ? FLAG_BOXPHYSICS : 0);
	pStruct->m_fDeactivationTime = DOOR_DEFAULT_DEACTIVATION_TIME;

	if (m_fClosingSpeed == 0.0f)
		m_fClosingSpeed = m_fSpeed;

	// Set the move delay to a minimal value.
	if (m_fOpenDelay == 0.0f)
		m_fOpenDelay = 0.01f;
}


// --------------------------------------------------------------------------- //
//
//	ROUTINE:	Door::TriggerHandler()
//
//	PURPOSE:	Trigger function to open and close a door
//
// --------------------------------------------------------------------------- //

void Door::TriggerHandler()
{
	if (m_dwDoorState == DOORSTATE_CLOSED || m_dwDoorState == DOORSTATE_CLOSING)
	{
		SetOpening();
	}
	else if (m_dwDoorState == DOORSTATE_OPEN)
	{
		if (m_dwTriggerFlags & DTF_TRIGGERCLOSED)
			SetClosing();
		else
			SetOpen(DFALSE);		// Call SetOpen again to reset the door times
	}
}

// --------------------------------------------------------------------------- //
//
//	ROUTINE:	Door::TriggerClose()
//

⌨️ 快捷键说明

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