void CinematicTrigger::HandleOn()
{
    m_bOn = LTTRUE;

	if (m_bRemoveBadAI)
	{
		RemoveBadAI();
	}

	// Turn on the camera...

	if (m_hCamera)
	{
		SendTriggerMsgToObject(this, m_hCamera, FALSE, "ON");
	}

	// Turn on the keyframer...

	if (m_hKeyFramer)
	{
		SendTriggerMsgToObject(this, m_hKeyFramer, FALSE, "ON");
	}


	// Make sure we're starting fresh...

	m_nCurMessage	= 0;
	m_byDecision	= 0;
	m_byLastReply	= 0;
    m_bDialogueDone = LTFALSE;
    m_fNextDialogueStart = g_pLTServer->GetTime() + m_fDelay[0];

    SetNextUpdate(m_hObject, 0.001f);
}
void CinematicTrigger::RemoveBadAI()
{
    HOBJECT hObj   = g_pLTServer->GetNextObject(LTNULL);
    HCLASS  hClass = g_pLTServer->GetClass("CAI");

	// Remove all the ai objects...

    LTBOOL bRemove = LTFALSE;

    HOBJECT hRemoveObj = LTNULL;
	while (hObj)
	{
        if (g_pLTServer->IsKindOf(g_pLTServer->GetObjectClass(hObj), hClass))
		{
			hRemoveObj = hObj;
		}

        hObj = g_pLTServer->GetNextObject(hObj);

		if (hRemoveObj)
		{
            CCharacter* pChar = (CCharacter*) g_pLTServer->HandleToObject(hRemoveObj);
			if (pChar && pChar->GetCharacterClass() == BAD)
			{
				SendTriggerMsgToObject(this, pChar->m_hObject, LTFALSE, "REMOVE");
			}

            hRemoveObj = LTNULL;
		}
	}


    hObj = g_pLTServer->GetNextInactiveObject(LTNULL);
    hRemoveObj = LTNULL;
	while (hObj)
	{
        if (g_pLTServer->IsKindOf(g_pLTServer->GetObjectClass(hObj), hClass))
		{
			hRemoveObj = hObj;
		}

        hObj = g_pLTServer->GetNextInactiveObject(hObj);

		if (hRemoveObj)
		{
            CCharacter* pChar = (CCharacter*) g_pLTServer->HandleToObject(hRemoveObj);
			if (pChar && pChar->GetCharacterClass() == BAD)
			{
				SendTriggerMsgToObject(this, pChar->m_hObject, LTFALSE, "REMOVE");
			}

            hRemoveObj = LTNULL;
		}
	}
}
LTBOOL Intelligence::Update()
{
	if (m_bFirstUpdate)
	{
		m_bFirstUpdate = LTFALSE;
		if (m_bStartHidden)
		{
			SendTriggerMsgToObject(this, m_hObject, LTFALSE, "Hidden 1");
			return LTTRUE;
		}
	}

	// If we aren't visible it must be time to respawn...

    uint32 dwFlags = g_pLTServer->GetObjectFlags(m_hObject);
	if (!m_bSkipUpdate && !(dwFlags & FLAG_VISIBLE))
	{
		uint32 dwFlags = g_pLTServer->GetObjectFlags(m_hObject);
		dwFlags |= (FLAG_VISIBLE | FLAG_RAYHIT);
		g_pLTServer->SetObjectFlags(m_hObject, dwFlags);

		// Let the world know what happened...

        LTVector vPos;
        g_pLTServer->GetObjectPos(m_hObject, &vPos);
        g_pServerSoundMgr->PlaySoundFromPos(vPos, INTEL_RESPAWN_SOUND,
				600.0f, SOUNDPRIORITY_MISC_HIGH);
	}
	m_bSkipUpdate = LTFALSE;

    return LTTRUE;
}
Example #4
0
void WorldModel::OnObjectCreated( )
{
	uint32	dwFlags;
	uint32	dwUserFlags = 0;

	g_pCommonLT->GetObjectFlags( m_hObject, OFT_Flags, dwFlags );

	// Set movable flag if we can be destroyed

	if( m_bIsKeyframed || (m_DamageModel.GetCanDamage() && !m_DamageModel.GetNeverDestroy()) )
	{
		dwUserFlags |= USRFLG_MOVEABLE;
	}

	if( dwFlags & FLAG_VISIBLE )
	{
		dwUserFlags |= USRFLG_VISIBLE;
	}

	g_pCommonLT->SetObjectFlags( m_hObject, OFT_User, dwUserFlags, USRFLG_MOVEABLE | USRFLG_VISIBLE );

	if( m_bStartHidden )
	{
		SendTriggerMsgToObject( this, m_hObject, LTFALSE, "Hidden 1" );
	}

	// Don't update us yet

	SetNextUpdate( UPDATE_NEVER );
}
Example #5
0
void WorldModel::HandleActivateMsg( HOBJECT hSender, const CParsedMsg &cMsg )
{
	if( !m_hActivateParent )
		return;

	SendTriggerMsgToObject( g_pLTServer->HandleToObject( hSender ), m_hActivateParent, LTTRUE, "ACTIVATE" );
}
LTBOOL SendTriggerMsgToObjects(LPBASECLASS pSender, const char* pName, const char* pMsg)
{
    if (!pMsg) return LTFALSE;

    // Process the message as a command if it is a valid command...

    if (g_pCmdMgr->IsValidCmd(pMsg))
    {
        return g_pCmdMgr->Process(pMsg);
    }

    if (!pName || pName[0] == '\0') return LTFALSE;

    ObjArray <HOBJECT, MAX_OBJECT_ARRAY_SIZE> objArray;
    // ILTServer::FindNameObjects does not destroy pName so this is safe
    g_pLTServer->FindNamedObjects((char*)pName, objArray);

    int numObjects = objArray.NumObjects();
    if (!numObjects) return LTFALSE;

    for (int i = 0; i < numObjects; i++)
    {
        SendTriggerMsgToObject(pSender, objArray.GetObject(i), 0, pMsg);
    }

    return LTTRUE;
}
void SendMixedTriggerMsgToObject(LPBASECLASS pSender, HOBJECT hObj, LTBOOL bBogus, const char* pStr)
{
    uint32 cMsgs = 0;
    char* aszMsgs[256];

    ParseTriggerMsg(pStr, aszMsgs, &cMsgs);

    LTBOOL bReturn = LTTRUE;
    for ( uint32 iMsg = 0 ; iMsg < cMsgs ; iMsg++ )
    {
        SendTriggerMsgToObject(pSender, hObj, LTFALSE, aszMsgs[iMsg]);
    }
}
void SendMixedTriggerMsgToObject(LPBASECLASS pSender, HOBJECT hObj, HSTRING hMsg)
{
    uint32 cMsgs = 0;
    char* aszMsgs[256];

    ParseTriggerMsg(g_pLTServer->GetStringData(hMsg), aszMsgs, &cMsgs);

    LTBOOL bReturn = LTTRUE;
    for ( uint32 iMsg = 0 ; iMsg < cMsgs ; iMsg++ )
    {
        SendTriggerMsgToObject(pSender, hObj, LTFALSE, aszMsgs[iMsg]);
    }
}
Example #9
0
void CAIGoalAbstractSearch::DeactivateGoal()
{
	super::DeactivateGoal();

	// Detach search light attachment from Light socket.
	// (e.g. for ninjas with search lanterns).

	if( m_pAI->GetBrain()->GetAIDataExist( kAIData_DisposeLantern ) )
	{
		char szDetach[128];
		sprintf(szDetach, "%s Light", KEY_DETACH );		
		SendTriggerMsgToObject( m_pAI, m_pAI->m_hObject, LTFALSE, szDetach);
	}
}
Example #10
0
void AI_Helicopter::InitAttachments()
{
	CAIVehicle::InitAttachments();

	for ( int iObject = 0 ; iObject < m_cObjects ; iObject++ )
	{
		BaseClass* pObject = m_apObjects[iObject];

		if (pObject)
		{
			if ( IsKindOf(pObject->m_hObject, "ControlledSearchLight") )
			{
				m_iObjectSearchLight = iObject;

				ControlledSearchLight* pSearchLight = ((ControlledSearchLight*)pObject);
				pSearchLight->SetController(m_hObject);

				HATTACHMENT hAttachment;
				if ( LT_OK == g_pLTServer->FindAttachment(m_hObject, pSearchLight->m_hObject, &hAttachment) )
				{
					LTransform transform;
					g_pLTServer->Common()->GetAttachmentTransform(hAttachment, transform, LTTRUE);
					g_pTransLT->Get(transform, m_vPosSearchlight, m_rRotSearchlight);
				}
			}
			else if ( IsKindOf(pObject->m_hObject, "CAI") )
			{
				Link(pObject->m_hObject);

				m_iObjectGunner = iObject;

				CAI* pGunner = ((CAI*)pObject);

				HATTACHMENT hAttachment;
				if ( LT_OK == g_pLTServer->FindAttachment(m_hObject, pGunner->m_hObject, &hAttachment) )
				{
					LTransform transform;
					g_pLTServer->Common()->GetAttachmentTransform(hAttachment, transform, LTTRUE);
					g_pTransLT->Get(transform, m_vPosGunner, m_rRotGunner);
				}

				char szMessage[128];
				sprintf(szMessage, "HELIATTACK HELI=%s", g_pLTServer->GetObjectName(m_hObject));
				SendTriggerMsgToObject(this, pGunner->GetObject(), LTFALSE, szMessage);
			}
		}
	}
}
Example #11
0
CAIGoalWork::~CAIGoalWork()
{
	// If destructing because the AI died,
	// and no special death was played,
	// and node is only locked by this goal,
	// then turn off the object.

	if( m_pAI->IsDead() && 
		m_hNodeUseObject &&
		m_bLockedNode &&
		!m_bPlayedSpecialDeathAnim )
	{
		AINodeUseObject* pNodeUseObject = (AINodeUseObject*)g_pLTServer->HandleToObject(m_hNodeUseObject);
		AIASSERT( pNodeUseObject && pNodeUseObject->IsLocked(), m_pAI->m_hObject, "CAIGoalAbstractUseObject::DeactivateGoal: Node is NULL or not locked" );
		if( pNodeUseObject && 
			pNodeUseObject->GetHObject() &&
			( pNodeUseObject->GetLockCount() == 1 ) )
		{
			SendTriggerMsgToObject( m_pAI, pNodeUseObject->GetHObject(), LTFALSE, "OFF" );
		}
	}
}
Example #12
0
void CAIGoalTalk::HandleInRadius()
{
	// Flag that AI is in position.

	if( m_bStartedDialog )
	{
		m_bInTalkPosition = LTTRUE;
	}

	// If Retrigger is TRUE, retrigger the dialogue object,
	// now that the AI is in position.

	else if( m_bRetriggerDialogue && m_hDialogue )
	{
		SendTriggerMsgToObject( m_pAI, m_hDialogue, LTFALSE, "On" );
	}

	// Default behavior.  AI can do other things (work) while in radius.

	else {
		m_fCurImportance = m_fMinImportance;
	}
}
void CinematicTrigger::HandleOff()
{
	if (!m_bOn) return;

	for ( uint32 iWho = 0 ; iWho < MAX_CT_MESSAGES; iWho++ )
	{
		if ( m_hstrWhoPlaysDialogue[iWho] )
		{
			HOBJECT hWho;
			if ( LT_OK == FindNamedObject(m_hstrWhoPlaysDialogue[iWho], hWho) )
			{
				if ( IsKindOf(hWho, "CAI") )
				{
					CAI* pAI = (CAI*)g_pLTServer->HandleToObject(hWho);
					pAI->UnlinkCinematicTrigger(m_hObject);
				}
			}
		}
	}

    m_bOn = LTFALSE;

	// If we have a current speaker, make sure he is done talking...

	if (m_hCurSpeaker)
	{
        CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(m_hCurSpeaker);
		if (pChar)
		{
			pChar->StopDialogue();
		}

		// Clear our speaker...

        g_pLTServer->BreakInterObjectLink(m_hObject, m_hCurSpeaker);
        m_hCurSpeaker = LTNULL;
	}

	// Clear out our last speaker

	if (m_hLastSpeaker)
	{
        CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(m_hLastSpeaker);
		if (pChar)
		{
			pChar->StopDialogue(TRUE);
		}
        g_pLTServer->BreakInterObjectLink(m_hObject, m_hLastSpeaker);
        m_hLastSpeaker = LTNULL;
	}


	// Send the clean up trigger message...

	if (m_hstrCleanUpTriggerTarget && m_hstrCleanUpTriggerMsg)
	{
        SendTriggerMsgToObjects(this, g_pLTServer->GetStringData( m_hstrCleanUpTriggerTarget ), g_pLTServer->GetStringData( m_hstrCleanUpTriggerMsg ));
	}

	// Turn off the camera...

	if (m_hCamera && !m_bLeaveCameraOn)
	{
		SendTriggerMsgToObject(this, m_hCamera, FALSE, "OFF");
	}

	// Turn off the keyframer...

	if (m_hKeyFramer)
	{
		SendTriggerMsgToObject(this, m_hKeyFramer, FALSE, "OFF");
	}

    SetNextUpdate(m_hObject, 0.0f);

	if (m_bOneTimeOnly)
	{
		// Can't get rid of object if we're leaving the camera on ;)...

		if (!m_hCamera || !m_bLeaveCameraOn)
		{
			g_pLTServer->RemoveObject(m_hObject);
		}
	}
}
Example #14
0
void Controller::Update()
{
    uint32 i;
	FadeState *pState;
	float curTime, t;

	if(m_bFirstUpdate)
	{
		FirstUpdate();
        m_bFirstUpdate = LTFALSE;
	}

	if(m_State == CState_Fade)
	{
		// Find out if we're even interpolating.
        curTime = g_pLTServer->GetTime();
		if(curTime > (m_fStartTime + m_fDuration))
		{

			for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
			{
				pState = &m_Fades[i];

				if(!pState->m_hTarget)
					continue;

				InterpolateValue(pState, 1.0f);
			}

			return;
		}

		t = (curTime - m_fStartTime) / m_fDuration;
		t = GetWaveFn(m_WaveType)(t); // Apply wave function.

		for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
		{
			pState = &m_Fades[i];

			if(!pState->m_hTarget)
				continue;

			InterpolateValue(pState, t);
		}

		Activate();
	}
	else if(m_State == CState_Flicker)
	{
        if(g_pLTServer->GetTime() > m_fNextFlickerTime)
		{
			// Send the message.
			for(i=0; i < MAX_CONTROLLER_TARGETS; i++)
			{
				pState = &m_Fades[i];

				if(!pState->m_hTarget)
					continue;

                SendTriggerMsgToObject(this, pState->m_hTarget, LTFALSE, m_FlickerMsg);
			}

			// Go again?
			if(m_FlickerCounter != FLICKER_FOREVER)
				--m_FlickerCounter;

			if(m_FlickerCounter == 0)
				HandleOffCommand(CParsedMsg());

            m_fNextFlickerTime = g_pLTServer->GetTime() + GetRandom(m_fIntervalMin, m_fIntervalMax);
		}

		Activate();
	}
	else
	{
		Deactivate();
	}
}
void CinematicTrigger::TriggerMsg(HOBJECT hSender, const char *pMsg)
{
	if (!pMsg) return;

    ILTCommon* pCommon = g_pLTServer->Common();
	if (!pCommon) return;

	// ConParse does not destroy szMsg, so this is safe
	ConParse parse;
	parse.Init((char*)pMsg);

	while (pCommon->Parse(&parse) == LT_OK)
	{
		if (parse.m_nArgs > 0 && parse.m_Args[0])
		{
			if (_stricmp(parse.m_Args[0], "ON") == 0)
			{
				HandleOn();
			}
			else if (_stricmp(parse.m_Args[0], "OFF") == 0)
			{
				HandleOff();
			}
			else if (_stricmp(parse.m_Args[0], "SKIP") == 0)
			{
				if (m_bCanSkip)
				{
					HandleOff();
				}
			}
			else if (_stricmp(parse.m_Args[0], "CAMERA") == 0)
			{
				if (m_hCamera && parse.m_nArgs > 1 && parse.m_Args[1])
				{
					// Copy all arguments to g_tokenspace...

					sprintf(g_tokenSpace, "%s", parse.m_Args[1]);
					for (int i=2; i < parse.m_nArgs && parse.m_Args[i]; i++)
					{
						strcat(g_tokenSpace, " ");
						strcat(g_tokenSpace, parse.m_Args[i]);
					}

					// Send camera the message...

					SendTriggerMsgToObject(this, m_hCamera, FALSE, g_tokenSpace);
				}
			}
			else if (_stricmp(parse.m_Args[0], "KEYFRAMER") == 0)
			{
				if (m_hKeyFramer && parse.m_nArgs > 1 && parse.m_Args[1])
				{
					// Copy all arguments to g_tokenspace...

					sprintf(g_tokenSpace, "%s", parse.m_Args[1]);
					for (int i=2; i < parse.m_nArgs && parse.m_Args[i]; i++)
					{
						strcat(g_tokenSpace, " ");
						strcat(g_tokenSpace, parse.m_Args[i]);
					}

					// Send keyframer the message...

					SendTriggerMsgToObject(this, m_hKeyFramer, FALSE, g_tokenSpace);
				}
			}
		}
	}
}
void CAIGoalMountedFlashlight::RecalcImportance()
{
	if( m_pAI->IsFirstUpdate() )
	{
		return;
	}

	// Create a flashlight model if we have a ranged weapon
	// (because it is mounted on the gun).

	if( !m_bCheckedForRangedWeapon )
	{
		if( HasRangedWeapon() )
		{
			m_bHasRangedWeapon = LTTRUE;
		}

		m_bCheckedForRangedWeapon = LTTRUE;
	}


	// Ignore flashlight if we do not know our current volume,
	// or do not have a flashlight.

	if( !( m_bHasRangedWeapon && 
		   m_pAI->HasCurrentVolume() ) )
	{
		return;
	}

	AIVolume* pVolume = m_pAI->GetCurrentVolume();

	// Volume is lit, so turn off flashlight.
	// Turn off light if affected by special damage (e.g. knocked out).
	// Turn off light if ranged weapon is not currently armed.

	if( m_bLightOn && 
		( pVolume->IsLit() || 
		  m_pAI->GetDamageFlags() ||
		  !m_pAI->HasWeapon( kAIWeap_Ranged ) ) )
	{
		char szDetach[128];
		sprintf( szDetach, "%s Light", KEY_DETACH );		
		SendTriggerMsgToObject( m_pAI, m_pAI->m_hObject, LTFALSE, szDetach );

		AITRACE( AIShowGoals, ( m_pAI->m_hObject, "Flashlight OFF" ) );

		m_pAI->PlaySound( FLASHLIGHT_SOUND );
		m_bLightOn = LTFALSE;
	}

	// Volume is dark, so turn on flashlight.
	// Do not turn on a light if affected by special damage (e.g. knocked out).
	// Do not turn on light if ranged weapon is not currently armed.

	else if( !m_bLightOn && 
		     !pVolume->IsLit() && 
			 !m_pAI->GetDamageFlags() &&
			 m_pAI->HasWeapon( kAIWeap_Ranged ) )
	{
		char szAttachment[128];
		sprintf( szAttachment, "%s Light (%s)", KEY_ATTACH, FLASHLIGHT_ATTACHMENT );		
		SendTriggerMsgToObject( m_pAI, m_pAI->m_hObject, LTFALSE, szAttachment );

		AITRACE( AIShowGoals, ( m_pAI->m_hObject, "Flashlight ON" ) );

		m_pAI->PlaySound( FLASHLIGHT_SOUND );
		m_bLightOn = LTTRUE;
	}
}
Example #17
0
void Trigger::Activate()
{
	CServerDE* pServerDE = GetServerDE();
	if (!pServerDE) return;


	// Make us wait a bit before we can be triggered again...

	if (m_bTimedTrigger)
	{
		pServerDE->SetNextUpdate(m_hObject, UPDATE_DELTA);
		pServerDE->SetDeactivationTime(m_hObject, 0.0f);
	}
	else
	{
		pServerDE->SetNextUpdate(m_hObject, m_fTriggerDelay);
		pServerDE->SetDeactivationTime(m_hObject, 0.0f);
	}
	
	
	// If this is a counter trigger, determine if we can activate or not...

	if (++m_nCurrentActivation < m_nActivationCount)
	{
		return;
	}
	else
	{
		m_nCurrentActivation = 0;
	}


	if (m_hstrActivationSound)
	{
		char* pSound = pServerDE->GetStringData(m_hstrActivationSound);
		if (pSound && pSound[0] != '\0')
		{
			PlaySoundFromObject(m_hObject, pSound, m_fSoundRadius, SOUNDPRIORITY_MISC_HIGH);
		}
	}

	DBOOL bTriggerMsg1 = DTRUE;
	DBOOL bTriggerMsg2 = DTRUE;

	if (m_bWeightedTrigger)
	{
		bTriggerMsg1 = (GetRandom(0.0f, 1.0f) < m_fMessage1Weight ? DTRUE : DFALSE);
		bTriggerMsg2 = !bTriggerMsg1;
	}

	for (int i=0; i < MAX_NUM_MESSAGES; i++)
	{
		DBOOL bOkayToSend = DTRUE;

		if (i == 0 && !bTriggerMsg1) bOkayToSend = DFALSE;
		else if (i == 1 && !bTriggerMsg2) bOkayToSend = DFALSE;

		if (bOkayToSend && m_hstrTargetName[i] && m_hstrMessageName[i])
		{
			SendTriggerMsgToObjects(this, m_hstrTargetName[i], m_hstrMessageName[i]);
		}
	}

	if (m_bTouchNotifyActivation && m_hTouchObject && m_bTriggerTouch && m_hstrMessageTouch)
	{
		SendTriggerMsgToObject(this, m_hTouchObject, m_hstrMessageTouch);
		m_bTouchNotifyActivation = DFALSE;
		m_hTouchObject = DNULL;
	}
}