Example #1
0
// Periodic check of hostage count in case we lost some
void CCSBot::UpdateHostageEscortCount()
{
	const float updateInterval = 1.0f;
	if (m_hostageEscortCount == 0 || gpGlobals->time - m_hostageEscortCountTimestamp < updateInterval)
		return;

	m_hostageEscortCountTimestamp = gpGlobals->time;

	// recount the hostages in case we lost some
	m_hostageEscortCount = 0;

	CHostage *pHostage = nullptr;
	while ((pHostage = UTIL_FindEntityByClassname(pHostage, "hostage_entity")))
	{
		if (FNullEnt(pHostage->edict()))
			break;

		// skip dead or rescued hostages
		if (!pHostage->IsAlive())
			continue;

		// check if hostage has targeted us, and is following
		if (pHostage->IsFollowing(this))
			m_hostageEscortCount++;
	}
}
Example #2
0
void CCSBot::UpdateHostageEscortCount()
{
	const float updateInterval = 1.0f;
	if (m_hostageEscortCount == 0 || gpGlobals->time - m_hostageEscortCountTimestamp < updateInterval)
		return;

	m_hostageEscortCountTimestamp = gpGlobals->time;

	// recount the hostages in case we lost some
	m_hostageEscortCount = 0;

	CHostage *hostage = NULL;
	while ((hostage = static_cast<CHostage *>(UTIL_FindEntityByClassname(hostage, "hostage_entity"))) != NULL)
	{
		if (FNullEnt(hostage->edict()))
			break;

		// skip dead or rescued hostages
		if (!hostage->IsValid())
			continue;

		// check if hostage has targeted us, and is following
		if (hostage->IsFollowing(this))
			++m_hostageEscortCount;
	}
}
Example #3
0
/* <1efc6c> ../cstrike/dlls/career_tasks.cpp:268 */
void CCareerTask::OnWeaponKill(int weaponId, int weaponClassId, bool headshot, bool killerHasShield, CBasePlayer *pAttacker, CBasePlayer *pVictim)
{
	if (m_isComplete || m_event != EVENT_KILL && (m_event != EVENT_HEADSHOT || !headshot))
	{
		return;
	}

	if (!pVictim || (m_defuser && !pVictim->m_bIsDefusing) || (m_vip && !pVictim->m_bIsVIP))
	{
		return;
	}

	if (m_rescuer)
	{
		int hostages_ = 0;
		CBaseEntity *hostageEntity = NULL;

		while ((hostageEntity = UTIL_FindEntityByClassname(hostageEntity, "hostage_entity")) != NULL)
		{
			CHostage *hostage = (CHostage *)hostageEntity;

			if (!hostage || hostage->pev->takedamage != DAMAGE_YES)
				continue;

			if (hostage->m_improv)
			{
				if (!hostage->IsFollowingSomeone())
					continue;
			}
			else if (!hostage->m_hTargetEnt || hostage->m_State != CHostage::FOLLOW)
				continue;

			if (hostage->IsValid() && hostage->m_target == pAttacker)
				++hostages_;
		}

		if (!hostages_)
			return;	
	}

	if (m_weaponId == WEAPON_SHIELDGUN)
	{
		if (!killerHasShield)
			return;
	}
	else if (m_weaponId)
	{
		if (m_weaponId != weaponId)
			return;
	}
	else if (m_weaponClassId)
	{
		if (m_weaponClassId != weaponClassId)
			return;
	}

	++m_eventsSeen;
	SendPartialNotification();
}
void CLocalNav::Think(void)
{
	EHANDLE hostage;
	static cvar_t *sv_stepsize = NULL;

	if (flNextCvarCheck <= gpGlobals->time)
	{
		if (sv_stepsize)
		{
			flNextCvarCheck = gpGlobals->time + 1;
			s_flStepSize = sv_stepsize->value;
		}
		else
		{
			sv_stepsize = CVAR_GET_POINTER("sv_stepsize");
			flNextCvarCheck = gpGlobals->time + 1;
			s_flStepSize = s_flStepSize ? sv_stepsize->value : 18;
		}
	}

	HostagePrethink();
	nodeval -= (gpGlobals->time - flLastThinkTime) * 250;
	flLastThinkTime = gpGlobals->time;

	if (nodeval < 0)
		nodeval = 0;
	else if (nodeval > 17)
		return;

	if (tot_inqueue)
	{
		hostage = NULL;
		hostage = queue[qptr];

		if (hostage == NULL)
		{
			while (tot_inqueue > 0)
			{
				if (++qptr == MAX_HOSTAGES)
					qptr = 0;

				tot_inqueue--;

				if (!tot_inqueue)
				{
					hostage = NULL;
					break;
				}

				hostage = queue[qptr];

				if (hostage)
					break;
			}
		}

		if (hostage)
		{
			CHostage *pHostage = GetClassPtr((CHostage *)hostage->pev);

			if (++qptr == MAX_HOSTAGES)
				qptr = 0;

			tot_inqueue--;
			pHostage->NavReady();
		}
	}
}
Example #5
0
/* <1ef79d> ../cstrike/dlls/career_tasks.cpp:385 */
void CCareerTask::__MAKE_VHOOK(OnEvent)(GameEventType event, CBasePlayer *pVictim, CBasePlayer *pAttacker)
{
	if (m_isComplete)
		return;

	if (event == m_event)
	{
		if ((m_defuser && !pAttacker->m_bIsDefusing) || (m_vip && !pAttacker->m_bIsVIP))
			return;

		if (m_rescuer)
		{
			int hostages_ = 0;
			CBaseEntity *hostageEntity = NULL;

			while ((hostageEntity = UTIL_FindEntityByClassname(hostageEntity, "hostage_entity")) != NULL)
			{
				if (hostageEntity->pev->takedamage != DAMAGE_YES)
					continue;

				CHostage *hostage = static_cast<CHostage *>(hostageEntity);

				if (!hostage->IsFollowingSomeone())
					continue;

				if (hostage->IsValid() && hostage->m_target == pAttacker)
					++hostages_;
			}

			if (!hostages_)
			{
				return;
			}
		}

		if (m_event != EVENT_KILL || (!m_weaponId && !m_weaponClassId)
			&& m_event != EVENT_HEADSHOT || (!m_weaponId && !m_weaponClassId)
			&& m_event != EVENT_PLAYER_TOOK_DAMAGE || (!m_weaponId && !m_weaponClassId))
		{
			if (m_event == EVENT_ROUND_WIN)
			{
				if (!Q_strcmp(m_name, "defendhostages"))
				{
					int hostages_ = 0;
					CBaseEntity *hostageEntity = NULL;

					while ((hostageEntity = UTIL_FindEntityByClassname(hostageEntity, "hostage_entity")) != NULL)
					{
						if (hostageEntity->pev->takedamage != 1.0f && hostageEntity->pev->deadflag != DEAD_DEAD)
							++hostages_;
					}

					if (!hostages_)
					{
						++m_eventsSeen;
						SendPartialNotification();
					}
				}
				else if (!Q_strcmp(m_name, "hostagessurvive"))
				{
					int hostages_ = 0;
					CBaseEntity *hostageEntity = NULL;

					while ((hostageEntity = UTIL_FindEntityByClassname(hostageEntity, "hostage_entity")) != NULL)
					{
						CHostage *hostage = (CHostage *)hostageEntity;

						if (hostage && hostage->IsDead())
							++hostages_;
					}

					if (!hostages_)
					{
						++m_eventsSeen;
						SendPartialNotification();
					}
				}
				else if (!Q_strcmp(m_name, "winfast"))
				{
					if (m_eventsNeeded >= TheCareerTasks->GetRoundElapsedTime())
					{
						m_eventsSeen = m_eventsNeeded;
						SendPartialNotification();
					}
				}
				else if (IsTaskCompletableThisRound())
				{
					++m_eventsSeen;
					SendPartialNotification();
				}
			}
			else
			{
				++m_eventsSeen;
				SendPartialNotification();
			}
		}
	}

	if (event == m_event && !m_mustLive && m_eventsSeen >= m_eventsNeeded && IsTaskCompletableThisRound())
	{
		CBasePlayer *player = UTIL_GetLocalPlayer();
		EMIT_SOUND(ENT(player->pev), CHAN_VOICE, "events/task_complete.wav", VOL_NORM, ATTN_NORM);

		m_isComplete = true;
		MESSAGE_BEGIN(MSG_ALL, gmsgCZCareer);
			WRITE_STRING("TASKDONE");
			WRITE_BYTE(m_id);
		MESSAGE_END();

		if (TheTutor != NULL)
		{
			TheTutor->OnEvent(EVENT_CAREER_TASK_DONE);
		}

		UTIL_LogPrintf("Career Task Done %d\n", m_id);

		if (m_event == EVENT_ROUND_WIN && !Q_strcmp(m_name, "winfast"))
		{
			TheCareerTasks->SetFinishedTaskTime((int)TheCareerTasks->GetRoundElapsedTime());
			UTIL_GetLocalPlayer()->SyncRoundTimer();
		}
	}
	else if (event >= EVENT_ROUND_DRAW)
	{
		if (event > EVENT_ROUND_LOSS)
		{
			if (event == EVENT_DIE && (m_mustLive || m_crossRounds))
			{
				m_eventsSeen = 0;
				SendPartialNotification();
				m_diedThisRound = true;
			}
		}
		else if (m_mustLive)
		{
			if (m_eventsSeen >= m_eventsNeeded && !m_diedThisRound && IsTaskCompletableThisRound())
			{
				CBasePlayer *player = UTIL_GetLocalPlayer();
				EMIT_SOUND(ENT(player->pev), CHAN_VOICE, "events/task_complete.wav", VOL_NORM, ATTN_NORM);

				m_isComplete = true;
				MESSAGE_BEGIN(MSG_ALL, gmsgCZCareer);
					WRITE_STRING("TASKDONE");
					WRITE_BYTE(m_id);
				MESSAGE_END();

				UTIL_LogPrintf("Career Task Done %d\n", m_id);

				if (m_event == EVENT_ROUND_WIN && !Q_strcmp(m_name, "winfast"))
				{
					TheCareerTasks->SetFinishedTaskTime((int)TheCareerTasks->GetRoundElapsedTime());
					UTIL_GetLocalPlayer()->SyncRoundTimer();
				}

				if (TheTutor != NULL)
				{
					TheTutor->OnEvent(EVENT_CAREER_TASK_DONE);
				}
			}

			m_diedThisRound = false;

			if (m_mustLive)
			{
				m_eventsSeen = 0;
				SendPartialNotification();
			}
		}
	}
}
void CLocalNav::Think()
{
	EHANDLE hCallback;
	static cvar_t *sv_stepsize = NULL;

	if (gpGlobals->time >= flNextCvarCheck)
	{
		if (sv_stepsize != NULL)
			s_flStepSize = sv_stepsize->value;
		else
		{
			sv_stepsize = CVAR_GET_POINTER("sv_stepsize");
			s_flStepSize = s_flStepSize ? sv_stepsize->value : HOSTAGE_STEPSIZE_DEFAULT;
		}

		flNextCvarCheck = gpGlobals->time + 1.0f;
	}

	HostagePrethink();

	float flElapsedTime = gpGlobals->time - flLastThinkTime;
	nodeval -= flElapsedTime * 250;
	flLastThinkTime = gpGlobals->time;

	if (nodeval < 0)
		nodeval = 0;

	else if (nodeval > 17)
		return;

	if (tot_inqueue)
	{
		hCallback = _queue[qptr];

		if (!hCallback)
		{
			while (tot_inqueue > 0)
			{
				if (++qptr == MAX_HOSTAGES_NAV)
					qptr = 0;

				tot_inqueue--;
				if (!tot_inqueue)
				{
					hCallback = NULL;
					break;
				}

				hCallback = _queue[qptr];

				if (hCallback)
					break;
			}
		}

		if (hCallback)
		{
			CHostage *pHostage = GetClassPtr((CHostage *)hCallback->pev);

			if (++qptr == MAX_HOSTAGES_NAV)
				qptr = 0;

			tot_inqueue--;
			pHostage->NavReady();
		}
	}
}