Пример #1
0
int CHostage::TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType)
{
	CBasePlayer *pAttacker = NULL;
	flDamage = GetModifiedDamage(flDamage);

	if (flDamage > pev->health)
		flDamage = pev->health;

	pev->health -= flDamage;

	if (m_improv)
	{
	}

	PlayPainSound();

	if (pevAttacker)
	{
		CBaseEntity *pEntity = GetClassPtr((CBaseEntity *)pevAttacker);

		if (pEntity->Classify() == CLASS_VEHICLE)
		{
			CBaseEntity *pDriver = ((CFuncVehicle *)pEntity)->m_pDriver;

			if (pDriver)
				pevAttacker = pDriver->pev;
		}

		if (pEntity->IsPlayer())
			pAttacker = GetClassPtr((CBasePlayer *)pevAttacker);
	}

	if (pev->health <= 0)
	{
		pev->health = 0;
		pev->movetype = MOVETYPE_TOSS;
		ClearBits(pev->flags, FL_ONGROUND);
		SetDeathActivity();

		if (pAttacker)
		{
			pAttacker->AddAccount((-25 - flDamage) * 20);
			AnnounceDeath(pAttacker);
			ApplyHostagePenalty(pAttacker);
		}

		pev->takedamage = DAMAGE_NO;
		pev->deadflag = DEAD_DEAD;
		pev->solid = SOLID_NOT;

		if (m_improv)
		{
		}

		g_pGameRules->CheckWinConditions();

		if (!g_pGameRules->m_fTeamCount)
			SendHostageEventMsg();

		pev->nextthink = gpGlobals->time + 3;
		SetThink(&CHostage::Remove);
		return 0;
	}

	m_flFlinchTime = gpGlobals->time + 0.75;

	if (m_improv)
	{
	}
	else
	{
		SetFlinchActivity();

		if (pAttacker)
		{
			pAttacker->AddAccount((int)flDamage * -20);
			ClientPrint(pAttacker->pev, HUD_PRINTCENTER, "#Injured_Hostage");

			if (!(pAttacker->m_flDisplayHistory & DHF_HOSTAGE_INJURED))
			{
				pAttacker->HintMessage("#Hint_careful_around_hostages");
				pAttacker->m_flDisplayHistory |= DHF_HOSTAGE_INJURED;
			}

			return 1;
		}
	}

	return 0;
}
Пример #2
0
void CHostage::IdleThink(void)
{
	pev->nextthink = gpGlobals->time + (1.0 / 30);
	DispatchAnimEvents(StudioFrameAdvance());

	if (gpGlobals->time >= m_flNextFullThink)
	{
		m_flNextFullThink = gpGlobals->time + 0.1;

		if (pev->deadflag == DEAD_DEAD)
		{
			UTIL_SetSize(pev, Vector(0, 0, 0), Vector(0, 0, 0));
			return;
		}

		if (m_hTargetEnt != NULL)
		{
			if ((m_bStuck != FALSE && gpGlobals->time - m_flStuckTime > 5) || m_hTargetEnt->pev->deadflag != DEAD_NO)
			{
				m_State = STAND;
				m_hTargetEnt = NULL;
				m_bStuck = FALSE;
			}
		}

		if (m_hTargetEnt != 0 || m_improv)
		{
			CBasePlayer *pPlayer;

			if (m_improv)
			{
			}
			else
				pPlayer = GetClassPtr((CBasePlayer *)m_hTargetEnt->pev);

			if (!pPlayer || pPlayer->m_iTeam == TEAM_CT)
			{
				if (!g_pGameRules->m_bMapHasRescueZone)
				{
					BOOL hasRescueZone = FALSE;

					if (UTIL_FindEntityByClassname(NULL, "info_hostage_rescue"))
						hasRescueZone = TRUE;

					CBaseEntity *pEntity = NULL;

					while ((pEntity = UTIL_FindEntityByClassname(pEntity, "info_hostage_rescue")) != NULL)
					{
						if ((pEntity->pev->origin - pev->origin).Length() < 256)
						{
							m_bRescueMe = TRUE;
							break;
						}
					}

					if (!hasRescueZone)
					{
						pEntity = NULL;

						while ((pEntity = UTIL_FindEntityByClassname(pEntity, "info_player_start")) != NULL)
						{
							if ((pEntity->pev->origin - pev->origin).Length() < 256)
							{
								m_bRescueMe = TRUE;
								break;
							}
						}
					}
				}

				if (m_bRescueMe)
				{
					if (g_pGameRules->IsCareer() && pPlayer && !pPlayer->IsBot())
					{
					}

					if (pPlayer)
					{
						pev->deadflag = DEAD_RESPAWNABLE;
						pPlayer->AddAccount(1000);
						UTIL_LogPrintf("\"%s<%i><%s><CT>\" triggered \"Rescued_A_Hostage\"\n", STRING(pPlayer->pev->netname), GETPLAYERUSERID(pPlayer->edict()), GETPLAYERAUTHID(pPlayer->edict()));
					}

					SendHostageEventMsg();

					MESSAGE_BEGIN(MSG_SPEC, SVC_DIRECTOR);
					WRITE_BYTE(9);
					WRITE_BYTE(DRC_CMD_EVENT);
					WRITE_SHORT(pPlayer ? ENTINDEX(pPlayer->edict()) : 0);
					WRITE_SHORT(ENTINDEX(edict()));
					WRITE_LONG(15);
					MESSAGE_END();

					pev->effects |= EF_NODRAW;
					Remove();

					g_pGameRules->m_iHostagesRescued++;
					g_pGameRules->CheckWinConditions();

					if (pPlayer)
						Broadcast("rescued");
					else
						Broadcast("escaped");
				}
			}
		}

		DoFollow();

		if (pev->deadflag != DEAD_DEAD && !(pev->effects & EF_NODRAW))
		{
			if (m_flNextRadarTime <= gpGlobals->time)
			{
				if ((m_vOldPos - pev->origin).Length() > 1)
				{
					m_vOldPos = pev->origin;

					if (!g_pGameRules->m_fTeamCount)
						SendHostagePositionMsg();
				}

				m_flNextRadarTime = gpGlobals->time + 1;
			}
		}

		if (m_flFlinchTime <= gpGlobals->time)
		{
			if (pev->velocity.Length() > 160)
				SetActivity(ACT_RUN);
			else if (pev->velocity.Length() > 15)
				SetActivity(ACT_WALK);
			else
				SetActivity(ACT_IDLE);
		}
	}
}