Exemplo n.º 1
0
void CItemCommCrystal::OnHear(LPCTSTR pszCmd, CChar *pSrc)
{
	ADDTOCALLSTACK("CItemCommCrystal::OnHear");
	// IT_COMM_CRYSTAL
	// STATF_COMM_CRYSTAL = if i am on a person.
	TALKMODE_TYPE mode = TALKMODE_SAY;
	for ( size_t i = 0; i < m_Speech.GetCount(); i++ )
	{
		CResourceLink *pLink = m_Speech[i];
		ASSERT(pLink);
		CResourceLock s;
		if ( !pLink->ResourceLock(s) )
			continue;
		TRIGRET_TYPE iRet = OnHearTrigger(s, pszCmd, pSrc, mode);
		if ( iRet == TRIGRET_ENDIF || iRet == TRIGRET_RET_FALSE )
			continue;
		break;
	}

	// That's prevent @ -1 crash speech :P
	if ( *pszCmd == '@' )
		return;

	if ( m_uidLink.IsValidUID() )
	{
		// I am linked to something ?
		// Transfer the sound.
		CItem *pItem = m_uidLink.ItemFind();
		if ( pItem && pItem->IsType(IT_COMM_CRYSTAL) )
			pItem->Speak(pszCmd);
	}
	else if ( m_Speech.GetCount() <= 0 )
		Speak(pszCmd);
}
Exemplo n.º 2
0
bool CResourceBase::ResourceLock( CResourceLock & s, RESOURCE_ID_BASE rid )
{
	ADDTOCALLSTACK("CResourceBase::ResourceLock");
	// Lock a referenced resource object.
	if ( ! rid.IsValidUID())
		return( false );
	CResourceLink * pResourceLink = dynamic_cast <CResourceLink *>( ResourceGetDef( rid ));
	if ( pResourceLink )
	{
		return( pResourceLink->ResourceLock(s));
	}
	return( false );
}
Exemplo n.º 3
0
const CRandGroupDef * CRegionWorld::FindNaturalResource(int type) const
{
	ADDTOCALLSTACK("CRegionWorld::FindNaturalResource");
	// Find the natural resources assinged to this region.
	// ARGS: type = IT_TYPE

	for ( size_t i = 0; i < m_Events.GetCount(); i++ )
	{
		CResourceLink * pLink = m_Events[i];
		if ( !pLink || ( pLink->GetResType() != RES_REGIONTYPE ))
			continue;

		if ( pLink->GetResPage() == type )
			return (dynamic_cast <const CRandGroupDef *>(pLink));
	}
	return NULL;
}
Exemplo n.º 4
0
void CItemMulti::OnHearRegion( LPCTSTR pszCmd, CChar * pSrc )
{
	// IT_SHIP or IT_MULTI

	const CItemBaseMulti * pMultiDef = Multi_GetDef();
	if ( pMultiDef == NULL )
		return;
	TALKMODE_TYPE		mode	= TALKMODE_SAY;

	for ( int i=0; i<pMultiDef->m_Speech.GetCount(); i++ )
	{
		CResourceLink * pLink = pMultiDef->m_Speech[i];
		ASSERT(pLink);
		CResourceLock s;
		if ( ! pLink->ResourceLock( s ))
			continue;
		DEBUG_CHECK( pLink->HasTrigger(XTRIG_UNKNOWN));
		TRIGRET_TYPE iRet = OnHearTrigger( s, pszCmd, pSrc, mode );
		if ( iRet == TRIGRET_ENDIF || iRet == TRIGRET_RET_FALSE )
			continue;
		break;
	}
}
Exemplo n.º 5
0
TRIGRET_TYPE CRegionBase::OnRegionTrigger( CTextConsole * pSrc, RTRIG_TYPE iAction )
{
	ADDTOCALLSTACK("CRegionBase::OnRegionTrigger");
	// RETURN: true = halt prodcessing (don't allow in this region

	TRIGRET_TYPE iRet;

	for ( size_t i = 0; i < m_Events.GetCount(); ++i )
	{
		CResourceLink * pLink = m_Events[i];
		if ( !pLink || ( pLink->GetResType() != RES_REGIONTYPE ) || !pLink->HasTrigger(iAction) )
			continue;
		CResourceLock s;
		if ( pLink->ResourceLock(s) )
		{
			iRet = CScriptObj::OnTriggerScript(s, sm_szTrigName[iAction], pSrc);
			if ( iRet == TRIGRET_RET_TRUE )
				return iRet;
		}
	}

	//	EVENTSREGION triggers (constant events of regions set from sphere.ini)
	for ( size_t i = 0; i < g_Cfg.m_pEventsRegionLink.GetCount(); ++i )
	{
		CResourceLink * pLink = g_Cfg.m_pEventsRegionLink[i];
		if ( !pLink || ( pLink->GetResType() != RES_REGIONTYPE ) || !pLink->HasTrigger(iAction) )
			continue;
		CResourceLock s;
		if ( !pLink->ResourceLock(s) )
			continue;
		iRet = CScriptObj::OnTriggerScript(s, sm_szTrigName[iAction], pSrc);
		if ( iRet != TRIGRET_RET_FALSE && iRet != TRIGRET_RET_DEFAULT )
			return iRet;
	}

	return TRIGRET_RET_DEFAULT;
}
Exemplo n.º 6
0
// @Create trigger, NPC version
void CChar::NPC_CreateTrigger()
{
	ADDTOCALLSTACK("CChar::NPC_CreateTrigger");
	if (!m_pNPC)
		return;

	CCharBase *pCharDef = Char_GetDef();
	TRIGRET_TYPE iRet = TRIGRET_RET_DEFAULT;
	lpctstr pszTrigName = "@Create";
	CTRIG_TYPE iAction = (CTRIG_TYPE)FindTableSorted(pszTrigName, sm_szTrigName, CountOf(sm_szTrigName) - 1);

	// 2) TEVENTS
	for (size_t i = 0; i < pCharDef->m_TEvents.GetCount(); ++i)
	{
		CResourceLink * pLink = pCharDef->m_TEvents[i];
		if (!pLink || !pLink->HasTrigger(iAction))
			continue;
		CResourceLock s;
		if (!pLink->ResourceLock(s))
			continue;
		iRet = CScriptObj::OnTriggerScript(s, pszTrigName, this, 0);
		if (iRet != TRIGRET_RET_FALSE && iRet != TRIGRET_RET_DEFAULT)
			return;
	}

	// 4) EVENTSPET triggers
	for (size_t i = 0; i < g_Cfg.m_pEventsPetLink.GetCount(); ++i)
	{
		CResourceLink * pLink = g_Cfg.m_pEventsPetLink[i];
		if (!pLink || !pLink->HasTrigger(iAction))
			continue;
		CResourceLock s;
		if (!pLink->ResourceLock(s))
			continue;
		iRet = CScriptObj::OnTriggerScript(s, pszTrigName, this, 0);
		if (iRet != TRIGRET_RET_FALSE && iRet != TRIGRET_RET_DEFAULT)
			return;
	}
}
Exemplo n.º 7
0
bool CResourceRefArray::r_LoadVal( CScript & s, RES_TYPE restype )
{
	ADDTOCALLSTACK("CResourceRefArray::r_LoadVal");
	EXC_TRY("LoadVal");
	bool fRet = false;
	// A bunch of CResourceLink (CResourceDef) pointers.
	// Add or remove from the list.
	// RETURN: false = it failed.

	// ? "TOWN" and "REGION" are special !

	TCHAR * pszCmd = s.GetArgStr();

	TCHAR * ppBlocks[128];	// max is arbitrary
	size_t iArgCount = Str_ParseCmds( pszCmd, ppBlocks, COUNTOF(ppBlocks));

	for ( size_t i = 0; i < iArgCount; i++ )
	{
		pszCmd = ppBlocks[i];

		if ( pszCmd[0] == '-' )
		{
			// remove a frag or all frags.
			pszCmd ++;
			if ( pszCmd[0] == '0' || pszCmd[0] == '*' )
			{
				RemoveAll();
				fRet = true;
				continue;
			}

			CResourceLink * pResourceLink = dynamic_cast<CResourceLink *>( g_Cfg.ResourceGetDefByName( restype, pszCmd ));
			if ( pResourceLink == NULL )
			{
				fRet = false;
				continue;
			}

			int iIndex = RemovePtr(pResourceLink);
			fRet = ( iIndex >= 0 );
		}
		else
		{
			// Add a single knowledge fragment or appropriate group item.

			if ( pszCmd[0] == '+' ) pszCmd ++;

			CResourceLink * pResourceLink = dynamic_cast<CResourceLink *>( g_Cfg.ResourceGetDefByName( restype, pszCmd ));
			if ( pResourceLink == NULL )
			{
				fRet = false;
				DEBUG_ERR(( "Unknown '%s' Resource '%s'\n", CResourceBase::GetResourceBlockName(restype), pszCmd ));
				continue;
			}

			// Is it already in the list ?
			fRet = true;
			if ( ContainsPtr(pResourceLink) )
			{
				continue;
			}
			if ( g_Cfg.m_pEventsPetLink.ContainsPtr(pResourceLink) )
			{
				DEBUG_ERR(("'%s' already defined in sphere.ini - skipping\n", pResourceLink->GetName()));
				continue;
			}
			else if ( g_Cfg.m_pEventsPlayerLink.ContainsPtr(pResourceLink) )
			{
				DEBUG_ERR(("'%s' already defined in sphere.ini - skipping\n", pResourceLink->GetName()));
				continue;
			}
			else if ( restype == RES_REGIONTYPE && g_Cfg.m_pEventsRegionLink.ContainsPtr(pResourceLink) )
			{
				DEBUG_ERR(("'%s' already defined in sphere.ini - skipping\n", pResourceLink->GetName()));
				continue;
			}
			else if ( g_Cfg.m_iEventsItemLink.ContainsPtr(pResourceLink) )
			{
				DEBUG_ERR(("'%s' already defined in sphere.ini - skipping\n", pResourceLink->GetName()));
				continue;
			}

			Add( pResourceLink );
		}
	}
	return fRet;
	EXC_CATCH;

	EXC_DEBUG_START;
	EXC_ADD_SCRIPT;
	EXC_DEBUG_END;
	return false;
}