Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1415 lines
35 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "talkmonster.h"
#include "defaultai.h"
#include "scripted.h"
#include "soundent.h"
#include "animation.h"
//=========================================================
// Talking monster base class
// Used for scientists and barneys
//=========================================================
8 years ago
float CTalkMonster::g_talkWaitTime = 0; // time delay until it's ok to speak: used so that two NPCs don't talk at once
9 years ago
// NOTE: m_voicePitch & m_szGrp should be fixed up by precache each save/restore
TYPEDESCRIPTION CTalkMonster::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CTalkMonster, m_bitsSaid, FIELD_INTEGER ),
DEFINE_FIELD( CTalkMonster, m_nSpeak, FIELD_INTEGER ),
// Recalc'ed in Precache()
8 years ago
//DEFINE_FIELD( CTalkMonster, m_voicePitch, FIELD_INTEGER ),
//DEFINE_FIELD( CTalkMonster, m_szGrp, FIELD_??? ),
9 years ago
DEFINE_FIELD( CTalkMonster, m_useTime, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_iszUse, FIELD_STRING ),
DEFINE_FIELD( CTalkMonster, m_iszUnUse, FIELD_STRING ),
DEFINE_FIELD( CTalkMonster, m_flLastSaidSmelled, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_flStopTalkTime, FIELD_TIME ),
DEFINE_FIELD( CTalkMonster, m_hTalkTarget, FIELD_EHANDLE ),
};
IMPLEMENT_SAVERESTORE( CTalkMonster, CBaseMonster )
9 years ago
// array of friend names
const char *CTalkMonster::m_szFriends[TLK_CFRIENDS] =
9 years ago
{
"monster_barney",
"monster_scientist",
"monster_sitting_scientist",
"monster_otis",
"monster_cleansuit_scientist",
"monster_human_grunt_ally"
9 years ago
};
//=========================================================
// AI Schedules Specific to talking monsters
//=========================================================
8 years ago
Task_t tlIdleResponse[] =
9 years ago
{
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE }, // Stop and listen
{ TASK_WAIT, (float)0.5 }, // Wait until sure it's me they are talking to
{ TASK_TLK_EYECONTACT, (float)0 }, // Wait until speaker is done
{ TASK_TLK_RESPOND, (float)0 }, // Wait and then say my response
{ TASK_TLK_IDEALYAW, (float)0 }, // look at who I'm talking to
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, (float)0 }, // Wait until speaker is done
9 years ago
};
8 years ago
Schedule_t slIdleResponse[] =
9 years ago
{
8 years ago
{
9 years ago
tlIdleResponse,
8 years ago
ARRAYSIZE( tlIdleResponse ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"Idle Response"
},
};
8 years ago
Task_t tlIdleSpeak[] =
9 years ago
{
8 years ago
{ TASK_TLK_SPEAK, (float)0 },// question or remark
{ TASK_TLK_IDEALYAW, (float)0 },// look at who I'm talking to
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, (float)0 },
{ TASK_WAIT_RANDOM, (float)0.5 },
9 years ago
};
8 years ago
Schedule_t slIdleSpeak[] =
9 years ago
{
{
9 years ago
tlIdleSpeak,
8 years ago
ARRAYSIZE( tlIdleSpeak ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"Idle Speak"
},
};
Task_t tlIdleSpeakWait[] =
{
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },// Stop and talk
{ TASK_TLK_SPEAK, (float)0 },// question or remark
{ TASK_TLK_EYECONTACT, (float)0 },//
{ TASK_WAIT, (float)2 },// wait - used when sci is in 'use' mode to keep head turned
9 years ago
};
8 years ago
Schedule_t slIdleSpeakWait[] =
9 years ago
{
8 years ago
{
9 years ago
tlIdleSpeakWait,
8 years ago
ARRAYSIZE( tlIdleSpeakWait ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"Idle Speak Wait"
},
};
8 years ago
Task_t tlIdleHello[] =
9 years ago
{
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },// Stop and talk
{ TASK_TLK_HELLO, (float)0 },// Try to say hello to player
{ TASK_TLK_EYECONTACT, (float)0 },
{ TASK_WAIT, (float)0.5 },// wait a bit
{ TASK_TLK_HELLO, (float)0 },// Try to say hello to player
{ TASK_TLK_EYECONTACT, (float)0 },
{ TASK_WAIT, (float)0.5 },// wait a bit
{ TASK_TLK_HELLO, (float)0 },// Try to say hello to player
{ TASK_TLK_EYECONTACT, (float)0 },
{ TASK_WAIT, (float)0.5 },// wait a bit
{ TASK_TLK_HELLO, (float)0 },// Try to say hello to player
{ TASK_TLK_EYECONTACT, (float)0 },
{ TASK_WAIT, (float)0.5 },// wait a bit
9 years ago
};
8 years ago
Schedule_t slIdleHello[] =
9 years ago
{
8 years ago
{
9 years ago
tlIdleHello,
8 years ago
ARRAYSIZE( tlIdleHello ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_HEAR_SOUND |
9 years ago
bits_COND_PROVOKED,
bits_SOUND_COMBAT,
"Idle Hello"
},
};
8 years ago
Task_t tlIdleStopShooting[] =
9 years ago
{
8 years ago
{ TASK_TLK_STOPSHOOTING, (float)0 },// tell player to stop shooting friend
// { TASK_TLK_EYECONTACT, (float)0 },// look at the player
9 years ago
};
8 years ago
Schedule_t slIdleStopShooting[] =
9 years ago
{
8 years ago
{
9 years ago
tlIdleStopShooting,
8 years ago
ARRAYSIZE( tlIdleStopShooting ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
9 years ago
bits_COND_HEAR_SOUND,
0,
"Idle Stop Shooting"
},
};
8 years ago
Task_t tlMoveAway[] =
9 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_MOVE_AWAY_FAIL },
{ TASK_STORE_LASTPOSITION, (float)0 },
{ TASK_MOVE_AWAY_PATH, (float)100 },
{ TASK_WALK_PATH_FOR_UNITS, (float)100 },
{ TASK_STOP_MOVING, (float)0 },
{ TASK_FACE_PLAYER, (float)0.5 },
9 years ago
};
8 years ago
Schedule_t slMoveAway[] =
9 years ago
{
{
tlMoveAway,
8 years ago
ARRAYSIZE( tlMoveAway ),
9 years ago
0,
0,
"MoveAway"
},
};
8 years ago
Task_t tlMoveAwayFail[] =
9 years ago
{
8 years ago
{ TASK_STOP_MOVING, (float)0 },
{ TASK_FACE_PLAYER, (float)0.5 },
9 years ago
};
8 years ago
Schedule_t slMoveAwayFail[] =
9 years ago
{
{
tlMoveAwayFail,
8 years ago
ARRAYSIZE( tlMoveAwayFail ),
9 years ago
0,
0,
"MoveAwayFail"
},
};
8 years ago
Task_t tlMoveAwayFollow[] =
9 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_TARGET_FACE },
{ TASK_STORE_LASTPOSITION, (float)0 },
{ TASK_MOVE_AWAY_PATH, (float)100 },
{ TASK_WALK_PATH_FOR_UNITS, (float)100 },
{ TASK_STOP_MOVING, (float)0 },
{ TASK_SET_SCHEDULE, (float)SCHED_TARGET_FACE },
9 years ago
};
8 years ago
Schedule_t slMoveAwayFollow[] =
9 years ago
{
{
tlMoveAwayFollow,
8 years ago
ARRAYSIZE( tlMoveAwayFollow ),
9 years ago
0,
0,
"MoveAwayFollow"
},
};
8 years ago
Task_t tlTlkIdleWatchClient[] =
9 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_TLK_LOOK_AT_CLIENT, (float)6 },
9 years ago
};
8 years ago
Task_t tlTlkIdleWatchClientStare[] =
9 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_TLK_CLIENT_STARE, (float)6 },
{ TASK_TLK_STARE, (float)0 },
{ TASK_TLK_IDEALYAW, (float)0 },// look at who I'm talking to
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, (float)0 },
9 years ago
};
8 years ago
Schedule_t slTlkIdleWatchClient[] =
9 years ago
{
8 years ago
{
9 years ago
tlTlkIdleWatchClient,
8 years ago
ARRAYSIZE( tlTlkIdleWatchClient ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_HEAR_SOUND |
bits_COND_SMELL |
bits_COND_CLIENT_PUSH |
bits_COND_CLIENT_UNSEEN |
9 years ago
bits_COND_PROVOKED,
8 years ago
bits_SOUND_COMBAT |// sound flags - change these, and you'll break the talking code.
//bits_SOUND_PLAYER |
//bits_SOUND_WORLD |
bits_SOUND_DANGER |
bits_SOUND_MEAT |// scents
bits_SOUND_CARCASS |
9 years ago
bits_SOUND_GARBAGE,
"TlkIdleWatchClient"
},
8 years ago
{
9 years ago
tlTlkIdleWatchClientStare,
8 years ago
ARRAYSIZE( tlTlkIdleWatchClientStare ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_HEAR_SOUND |
bits_COND_SMELL |
bits_COND_CLIENT_PUSH |
bits_COND_CLIENT_UNSEEN |
9 years ago
bits_COND_PROVOKED,
8 years ago
bits_SOUND_COMBAT |// sound flags - change these, and you'll break the talking code.
//bits_SOUND_PLAYER |
//bits_SOUND_WORLD |
bits_SOUND_DANGER |
bits_SOUND_MEAT |// scents
bits_SOUND_CARCASS |
9 years ago
bits_SOUND_GARBAGE,
"TlkIdleWatchClientStare"
},
};
Task_t tlTlkIdleEyecontact[] =
{
8 years ago
{ TASK_TLK_IDEALYAW, (float)0 },// look at who I'm talking to
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, (float)0 },// Wait until speaker is done
9 years ago
};
8 years ago
Schedule_t slTlkIdleEyecontact[] =
9 years ago
{
{
9 years ago
tlTlkIdleEyecontact,
8 years ago
ARRAYSIZE( tlTlkIdleEyecontact ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
9 years ago
bits_COND_HEAVY_DAMAGE,
0,
"TlkIdleEyecontact"
},
};
DEFINE_CUSTOM_SCHEDULES( CTalkMonster )
{
slIdleResponse,
slIdleSpeak,
slIdleHello,
slIdleSpeakWait,
slIdleStopShooting,
slMoveAway,
slMoveAwayFollow,
slMoveAwayFail,
slTlkIdleWatchClient,
8 years ago
&slTlkIdleWatchClient[1],
9 years ago
slTlkIdleEyecontact,
};
IMPLEMENT_CUSTOM_SCHEDULES( CTalkMonster, CBaseMonster )
9 years ago
8 years ago
void CTalkMonster::SetActivity( Activity newActivity )
9 years ago
{
8 years ago
if( newActivity == ACT_IDLE && IsTalking() )
9 years ago
newActivity = ACT_SIGNAL3;
8 years ago
if( newActivity == ACT_SIGNAL3 && ( LookupActivity( ACT_SIGNAL3 ) == ACTIVITY_NOT_AVAILABLE ) )
9 years ago
newActivity = ACT_IDLE;
CBaseMonster::SetActivity( newActivity );
}
8 years ago
void CTalkMonster::StartTask( Task_t *pTask )
9 years ago
{
8 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_TLK_SPEAK:
// ask question or make statement
FIdleSpeak();
TaskComplete();
break;
case TASK_TLK_RESPOND:
// respond to question
IdleRespond();
TaskComplete();
break;
case TASK_TLK_HELLO:
// greet player
FIdleHello();
TaskComplete();
break;
case TASK_TLK_STARE:
// let the player know I know he's staring at me.
FIdleStare();
TaskComplete();
break;
case TASK_FACE_PLAYER:
case TASK_TLK_LOOK_AT_CLIENT:
case TASK_TLK_CLIENT_STARE:
// track head to the client for a while.
m_flWaitFinished = gpGlobals->time + pTask->flData;
break;
case TASK_TLK_EYECONTACT:
break;
case TASK_TLK_IDEALYAW:
if( m_hTalkTarget != 0 )
9 years ago
{
pev->yaw_speed = 60;
8 years ago
float yaw = VecToYaw( m_hTalkTarget->pev->origin - pev->origin ) - pev->angles.y;
9 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
9 years ago
8 years ago
if( yaw < 0 )
9 years ago
{
pev->ideal_yaw = Q_min( yaw + 45, 0 ) + pev->angles.y;
9 years ago
}
else
{
pev->ideal_yaw = Q_max( yaw - 45, 0 ) + pev->angles.y;
9 years ago
}
}
TaskComplete();
break;
case TASK_TLK_HEADRESET:
// reset head position after looking at something
m_hTalkTarget = NULL;
TaskComplete();
break;
case TASK_TLK_STOPSHOOTING:
// tell player to stop shooting
8 years ago
PlaySentence( m_szGrp[TLK_NOSHOOT], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_NORM );
9 years ago
TaskComplete();
break;
case TASK_CANT_FOLLOW:
StopFollowing( FALSE );
8 years ago
PlaySentence( m_szGrp[TLK_STOP], RANDOM_FLOAT( 2, 2.5 ), VOL_NORM, ATTN_NORM );
9 years ago
TaskComplete();
break;
case TASK_WALK_PATH_FOR_UNITS:
m_movementActivity = ACT_WALK;
break;
case TASK_MOVE_AWAY_PATH:
{
Vector dir = pev->angles;
dir.y = pev->ideal_yaw + 180;
Vector move;
UTIL_MakeVectorsPrivate( dir, move, NULL, NULL );
dir = pev->origin + move * pTask->flData;
8 years ago
if( MoveToLocation( ACT_WALK, 2, dir ) )
9 years ago
{
TaskComplete();
}
8 years ago
else if( FindCover( pev->origin, pev->view_ofs, 0, CoverRadius() ) )
9 years ago
{
// then try for plain ole cover
m_flMoveWaitFinished = gpGlobals->time + 2;
TaskComplete();
}
else
{
// nowhere to go?
TaskFail();
}
}
break;
case TASK_PLAY_SCRIPT:
m_hTalkTarget = NULL;
CBaseMonster::StartTask( pTask );
break;
default:
CBaseMonster::StartTask( pTask );
}
}
8 years ago
void CTalkMonster::RunTask( Task_t *pTask )
9 years ago
{
8 years ago
edict_t *pPlayer;
9 years ago
switch( pTask->iTask )
{
case TASK_TLK_CLIENT_STARE:
case TASK_TLK_LOOK_AT_CLIENT:
// track head to the client for a while.
8 years ago
if( m_MonsterState == MONSTERSTATE_IDLE &&
!IsMoving() &&
!IsTalking() )
9 years ago
{
// Get edict for one player
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
8 years ago
if( pPlayer )
9 years ago
{
IdleHeadTurn( pPlayer->v.origin );
}
}
else
{
// started moving or talking
TaskFail();
return;
}
8 years ago
if( pTask->iTask == TASK_TLK_CLIENT_STARE )
9 years ago
{
// fail out if the player looks away or moves away.
8 years ago
if( ( pPlayer->v.origin - pev->origin ).Length2D() > TLK_STARE_DIST )
9 years ago
{
// player moved away.
TaskFail();
}
UTIL_MakeVectors( pPlayer->v.angles );
8 years ago
if( UTIL_DotPoints( pPlayer->v.origin, pev->origin, gpGlobals->v_forward ) < m_flFieldOfView )
9 years ago
{
// player looked away
TaskFail();
}
}
8 years ago
if( gpGlobals->time > m_flWaitFinished )
9 years ago
{
TaskComplete();
}
break;
case TASK_FACE_PLAYER:
{
// Get edict for one player
8 years ago
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
9 years ago
8 years ago
if( pPlayer )
9 years ago
{
8 years ago
MakeIdealYaw( pPlayer->v.origin );
ChangeYaw( pev->yaw_speed );
9 years ago
IdleHeadTurn( pPlayer->v.origin );
8 years ago
if( gpGlobals->time > m_flWaitFinished && FlYawDiff() < 10 )
9 years ago
{
TaskComplete();
}
}
else
{
TaskFail();
}
}
break;
case TASK_TLK_EYECONTACT:
if( !IsMoving() && IsTalking() && m_hTalkTarget != 0 )
9 years ago
{
// ALERT( at_console, "waiting %f\n", m_flStopTalkTime - gpGlobals->time );
IdleHeadTurn( m_hTalkTarget->pev->origin );
}
else
{
TaskComplete();
}
break;
case TASK_WALK_PATH_FOR_UNITS:
{
float distance;
8 years ago
distance = ( m_vecLastPosition - pev->origin ).Length2D();
9 years ago
// Walk path until far enough away
8 years ago
if( distance > pTask->flData || MovementIsComplete() )
9 years ago
{
TaskComplete();
RouteClear(); // Stop moving
}
}
break;
case TASK_WAIT_FOR_MOVEMENT:
if( IsTalking() && m_hTalkTarget != 0 )
9 years ago
{
8 years ago
// ALERT( at_console, "walking, talking\n" );
9 years ago
IdleHeadTurn( m_hTalkTarget->pev->origin );
}
else
{
IdleHeadTurn( pev->origin );
// override so that during walk, a scientist may talk and greet player
FIdleHello();
8 years ago
if( RANDOM_LONG( 0, m_nSpeak * 20 ) == 0)
9 years ago
{
FIdleSpeak();
}
}
CBaseMonster::RunTask( pTask );
8 years ago
if( TaskIsComplete() )
9 years ago
IdleHeadTurn( pev->origin );
break;
default:
if( IsTalking() && m_hTalkTarget != 0 )
9 years ago
{
IdleHeadTurn( m_hTalkTarget->pev->origin );
}
else
{
SetBoneController( 0, 0 );
}
CBaseMonster::RunTask( pTask );
}
}
8 years ago
void CTalkMonster::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
// If a client killed me (unless I was already Barnacle'd), make everyone else mad/afraid of him
8 years ago
if( ( pevAttacker->flags & FL_CLIENT) && m_MonsterState != MONSTERSTATE_PRONE )
9 years ago
{
AlertFriends();
8 years ago
LimitFollowers( CBaseEntity::Instance( pevAttacker ), 0 );
9 years ago
}
m_hTargetEnt = 0;
9 years ago
// Don't finish that sentence
StopTalking();
SetUse( NULL );
CBaseMonster::Killed( pevAttacker, iGib );
}
8 years ago
CBaseEntity *CTalkMonster::EnumFriends( CBaseEntity *pPrevious, int listNumber, BOOL bTrace )
9 years ago
{
CBaseEntity *pFriend = pPrevious;
const char *pszFriend;
9 years ago
TraceResult tr;
Vector vecCheck;
8 years ago
pszFriend = m_szFriends[FriendNumber( listNumber )];
while( ( pFriend = UTIL_FindEntityByClassname( pFriend, pszFriend ) ) )
9 years ago
{
8 years ago
if( pFriend == this || !pFriend->IsAlive() )
9 years ago
// don't talk to self or dead people
continue;
8 years ago
if( bTrace )
9 years ago
{
vecCheck = pFriend->pev->origin;
vecCheck.z = pFriend->pev->absmax.z;
8 years ago
UTIL_TraceLine( pev->origin, vecCheck, ignore_monsters, ENT( pev ), &tr );
9 years ago
}
else
tr.flFraction = 1.0;
8 years ago
if( tr.flFraction == 1.0 )
9 years ago
{
return pFriend;
}
}
return NULL;
}
void CTalkMonster::AlertFriends( void )
{
CBaseEntity *pFriend = NULL;
int i;
// for each friend in this bsp...
8 years ago
for( i = 0; i < TLK_CFRIENDS; i++ )
9 years ago
{
8 years ago
while( ( pFriend = EnumFriends( pFriend, i, TRUE ) ) )
9 years ago
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster->IsAlive() )
9 years ago
{
// don't provoke a friend that's playing a death animation. They're a goner
pMonster->m_afMemory |= bits_MEMORY_PROVOKED;
}
}
}
}
void CTalkMonster::ShutUpFriends( void )
{
CBaseEntity *pFriend = NULL;
int i;
// for each friend in this bsp...
8 years ago
for( i = 0; i < TLK_CFRIENDS; i++ )
9 years ago
{
8 years ago
while( ( pFriend = EnumFriends( pFriend, i, TRUE ) ) )
9 years ago
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster )
9 years ago
{
pMonster->SentenceStop();
}
}
}
}
// UNDONE: Keep a follow time in each follower, make a list of followers in this function and do LRU
// UNDONE: Check this in Restore to keep restored monsters from joining a full list of followers
void CTalkMonster::LimitFollowers( CBaseEntity *pPlayer, int maxFollowers )
{
CBaseEntity *pFriend = NULL;
int i, count;
count = 0;
9 years ago
// for each friend in this bsp...
8 years ago
for( i = 0; i < TLK_CFRIENDS; i++ )
9 years ago
{
8 years ago
while( ( pFriend = EnumFriends( pFriend, i, FALSE ) ) )
9 years ago
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster )
9 years ago
{
8 years ago
if( pMonster->m_hTargetEnt == pPlayer )
9 years ago
{
count++;
8 years ago
if( count > maxFollowers )
9 years ago
pMonster->StopFollowing( TRUE );
}
}
}
}
}
float CTalkMonster::TargetDistance( void )
{
// If we lose the player, or he dies, return a really large distance
if( m_hTargetEnt == 0 || !m_hTargetEnt->IsAlive() )
9 years ago
return 1e6;
8 years ago
return ( m_hTargetEnt->pev->origin - pev->origin ).Length();
9 years ago
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
8 years ago
void CTalkMonster::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
8 years ago
{
9 years ago
case SCRIPT_EVENT_SENTENCE_RND1: // Play a named sentence group 25% of the time
8 years ago
if( RANDOM_LONG( 0, 99 ) < 75 )
9 years ago
break;
// fall through...
case SCRIPT_EVENT_SENTENCE: // Play a named sentence group
ShutUpFriends();
8 years ago
PlaySentence( pEvent->options, RANDOM_FLOAT( 2.8, 3.4 ), VOL_NORM, ATTN_IDLE );
//ALERT( at_console, "script event speak\n" );
9 years ago
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
// monsters derived from ctalkmonster should call this in precache()
8 years ago
void CTalkMonster::TalkInit( void )
9 years ago
{
// every new talking monster must reset this global, otherwise
// when a level is loaded, nobody will talk (time is reset to 0)
CTalkMonster::g_talkWaitTime = 0;
m_voicePitch = 100;
}
//=========================================================
// FindNearestFriend
// Scan for nearest, visible friend. If fPlayer is true, look for
// nearest player
//=========================================================
8 years ago
CBaseEntity *CTalkMonster::FindNearestFriend( BOOL fPlayer )
9 years ago
{
CBaseEntity *pFriend = NULL;
CBaseEntity *pNearest = NULL;
float range = 10000000.0;
TraceResult tr;
Vector vecStart = pev->origin;
Vector vecCheck;
int i;
const char *pszFriend;
9 years ago
int cfriends;
vecStart.z = pev->absmax.z;
8 years ago
if( fPlayer )
9 years ago
cfriends = 1;
else
cfriends = TLK_CFRIENDS;
// for each type of friend...
8 years ago
for( i = cfriends-1; i > -1; i-- )
9 years ago
{
8 years ago
if( fPlayer )
9 years ago
pszFriend = "player";
else
8 years ago
pszFriend = m_szFriends[FriendNumber( i )];
9 years ago
8 years ago
if( !pszFriend )
9 years ago
continue;
// for each friend in this bsp...
8 years ago
while( ( pFriend = UTIL_FindEntityByClassname( pFriend, pszFriend ) ) )
9 years ago
{
8 years ago
if( pFriend == this || !pFriend->IsAlive() )
9 years ago
// don't talk to self or dead people
continue;
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
// If not a monster for some reason, or in a script, or prone
8 years ago
if( !pMonster || pMonster->m_MonsterState == MONSTERSTATE_SCRIPT || pMonster->m_MonsterState == MONSTERSTATE_PRONE )
9 years ago
continue;
vecCheck = pFriend->pev->origin;
vecCheck.z = pFriend->pev->absmax.z;
// if closer than previous friend, and in range, see if he's visible
8 years ago
if( range > ( vecStart - vecCheck ).Length())
9 years ago
{
8 years ago
UTIL_TraceLine( vecStart, vecCheck, ignore_monsters, ENT( pev ), &tr );
9 years ago
8 years ago
if( tr.flFraction == 1.0 )
9 years ago
{
// visible and in range, this is the new nearest scientist
8 years ago
if( ( vecStart - vecCheck ).Length() < TALKRANGE_MIN )
9 years ago
{
pNearest = pFriend;
8 years ago
range = ( vecStart - vecCheck ).Length();
9 years ago
}
}
}
}
}
return pNearest;
}
8 years ago
int CTalkMonster::GetVoicePitch( void )
9 years ago
{
8 years ago
return m_voicePitch + RANDOM_LONG( 0, 3 );
9 years ago
}
8 years ago
void CTalkMonster::Touch( CBaseEntity *pOther )
9 years ago
{
// Did the player touch me?
8 years ago
if( pOther->IsPlayer() )
9 years ago
{
// Ignore if pissed at player
8 years ago
if( m_afMemory & bits_MEMORY_PROVOKED )
9 years ago
return;
// Stay put during speech
8 years ago
if( IsTalking() )
9 years ago
return;
// Heuristic for determining if the player is pushing me away
8 years ago
float speed = fabs( pOther->pev->velocity.x ) + fabs( pOther->pev->velocity.y );
if( speed > 50 )
9 years ago
{
SetConditions( bits_COND_CLIENT_PUSH );
MakeIdealYaw( pOther->pev->origin );
}
}
}
//=========================================================
// IdleRespond
// Respond to a previous question
//=========================================================
8 years ago
void CTalkMonster::IdleRespond( void )
9 years ago
{
//int pitch = GetVoicePitch();
9 years ago
// play response
8 years ago
PlaySentence( m_szGrp[TLK_ANSWER], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
9 years ago
}
8 years ago
int CTalkMonster::FOkToSpeak( void )
9 years ago
{
// if in the grip of a barnacle, don't speak
8 years ago
if( m_MonsterState == MONSTERSTATE_PRONE || m_IdealMonsterState == MONSTERSTATE_PRONE )
9 years ago
{
return FALSE;
}
// if not alive, certainly don't speak
8 years ago
if( pev->deadflag != DEAD_NO )
9 years ago
{
return FALSE;
}
// if someone else is talking, don't speak
8 years ago
if( gpGlobals->time <= CTalkMonster::g_talkWaitTime )
9 years ago
return FALSE;
8 years ago
if( pev->spawnflags & SF_MONSTER_GAG )
9 years ago
return FALSE;
8 years ago
if( m_MonsterState == MONSTERSTATE_PRONE )
9 years ago
return FALSE;
// if player is not in pvs, don't speak
8 years ago
if( !IsAlive() || FNullEnt(FIND_CLIENT_IN_PVS( edict() ) ) )
9 years ago
return FALSE;
// don't talk if you're in combat
if( m_hEnemy != 0 && FVisible( m_hEnemy ) )
9 years ago
return FALSE;
return TRUE;
}
int CTalkMonster::CanPlaySentence( BOOL fDisregardState )
{
8 years ago
if( fDisregardState )
9 years ago
return CBaseMonster::CanPlaySentence( fDisregardState );
return FOkToSpeak();
}
//=========================================================
// FIdleStare
//=========================================================
8 years ago
int CTalkMonster::FIdleStare( void )
9 years ago
{
8 years ago
if( !FOkToSpeak() )
9 years ago
return FALSE;
PlaySentence( m_szGrp[TLK_STARE], RANDOM_FLOAT(5, 7.5), VOL_NORM, ATTN_IDLE );
m_hTalkTarget = FindNearestFriend( TRUE );
return TRUE;
}
//=========================================================
// IdleHello
// Try to greet player first time he's seen
//=========================================================
8 years ago
int CTalkMonster::FIdleHello( void )
9 years ago
{
8 years ago
if( !FOkToSpeak() )
9 years ago
return FALSE;
// if this is first time scientist has seen player, greet him
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidHelloPlayer ) )
9 years ago
{
// get a player
8 years ago
CBaseEntity *pPlayer = FindNearestFriend( TRUE );
9 years ago
8 years ago
if( pPlayer )
9 years ago
{
8 years ago
if( FInViewCone( pPlayer ) && FVisible( pPlayer ) )
9 years ago
{
m_hTalkTarget = pPlayer;
8 years ago
if( FBitSet(pev->spawnflags, SF_MONSTER_PREDISASTER ) )
PlaySentence( m_szGrp[TLK_PHELLO], RANDOM_FLOAT( 3, 3.5 ), VOL_NORM, ATTN_IDLE );
9 years ago
else
8 years ago
PlaySentence( m_szGrp[TLK_HELLO], RANDOM_FLOAT( 3, 3.5 ), VOL_NORM, ATTN_IDLE );
SetBits( m_bitsSaid, bit_saidHelloPlayer );
9 years ago
return TRUE;
}
}
}
return FALSE;
}
// turn head towards supplied origin
8 years ago
void CTalkMonster::IdleHeadTurn( Vector &vecFriend )
9 years ago
{
// turn head in desired direction only if ent has a turnable head
8 years ago
if( m_afCapability & bits_CAP_TURN_HEAD )
9 years ago
{
8 years ago
float yaw = VecToYaw( vecFriend - pev->origin ) - pev->angles.y;
9 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
9 years ago
// turn towards vector
SetBoneController( 0, yaw );
}
}
//=========================================================
// FIdleSpeak
// ask question of nearby friend, or make statement
//=========================================================
8 years ago
int CTalkMonster::FIdleSpeak( void )
9 years ago
{
// try to start a conversation, or make statement
//int pitch;
9 years ago
const char *szIdleGroup;
const char *szQuestionGroup;
float duration;
8 years ago
if( !FOkToSpeak() )
9 years ago
return FALSE;
// set idle groups based on pre/post disaster
8 years ago
if( FBitSet( pev->spawnflags, SF_MONSTER_PREDISASTER ) )
9 years ago
{
szIdleGroup = m_szGrp[TLK_PIDLE];
szQuestionGroup = m_szGrp[TLK_PQUESTION];
// set global min delay for next conversation
8 years ago
duration = RANDOM_FLOAT( 4.8, 5.2 );
9 years ago
}
else
{
szIdleGroup = m_szGrp[TLK_IDLE];
szQuestionGroup = m_szGrp[TLK_QUESTION];
// set global min delay for next conversation
8 years ago
duration = RANDOM_FLOAT( 2.8, 3.2 );
9 years ago
}
//pitch = GetVoicePitch();
9 years ago
// player using this entity is alive and wounded?
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget != NULL )
9 years ago
{
8 years ago
if( pTarget->IsPlayer() )
9 years ago
{
8 years ago
if( pTarget->IsAlive() )
9 years ago
{
m_hTalkTarget = m_hTargetEnt;
8 years ago
if( !FBitSet(m_bitsSaid, bit_saidDamageHeavy ) &&
( m_hTargetEnt->pev->health <= m_hTargetEnt->pev->max_health / 8 ) )
9 years ago
{
8 years ago
//EMIT_SOUND_DYN(ENT( pev ), CHAN_VOICE, m_szGrp[TLK_PLHURT3], 1.0, ATTN_IDLE, 0, pitch );
9 years ago
PlaySentence( m_szGrp[TLK_PLHURT3], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageHeavy );
9 years ago
return TRUE;
}
8 years ago
else if( !FBitSet( m_bitsSaid, bit_saidDamageMedium ) &&
( m_hTargetEnt->pev->health <= m_hTargetEnt->pev->max_health / 4 ) )
9 years ago
{
8 years ago
//EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, m_szGrp[TLK_PLHURT2], 1.0, ATTN_IDLE, 0, pitch );
9 years ago
PlaySentence( m_szGrp[TLK_PLHURT2], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageMedium );
9 years ago
return TRUE;
}
8 years ago
else if( !FBitSet( m_bitsSaid, bit_saidDamageLight) &&
( m_hTargetEnt->pev->health <= m_hTargetEnt->pev->max_health / 2 ) )
9 years ago
{
8 years ago
//EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, m_szGrp[TLK_PLHURT1], 1.0, ATTN_IDLE, 0, pitch );
9 years ago
PlaySentence( m_szGrp[TLK_PLHURT1], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageLight );
9 years ago
return TRUE;
}
}
else
{
//!!!KELLY - here's a cool spot to have the talkmonster talk about the dead player if we want.
// "Oh dear, Gordon Freeman is dead!" -Scientist
// "Damn, I can't do this without you." -Barney
}
}
}
// if there is a friend nearby to speak to, play sentence, set friend's response time, return
8 years ago
CBaseEntity *pFriend = FindNearestFriend( FALSE );
9 years ago
8 years ago
if( pFriend && !( pFriend->IsMoving() ) && ( RANDOM_LONG( 0, 99 ) < 75 ) )
9 years ago
{
PlaySentence( szQuestionGroup, duration, VOL_NORM, ATTN_IDLE );
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), szQuestionGroup, 1.0, ATTN_IDLE, 0, pitch );
9 years ago
// force friend to answer
CTalkMonster *pTalkMonster = (CTalkMonster *)pFriend;
m_hTalkTarget = pFriend;
pTalkMonster->SetAnswerQuestion( this ); // UNDONE: This is EVIL!!!
pTalkMonster->m_flStopTalkTime = m_flStopTalkTime;
m_nSpeak++;
return TRUE;
}
// otherwise, play an idle statement, try to face client when making a statement.
8 years ago
if( RANDOM_LONG( 0, 1 ) )
9 years ago
{
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), szIdleGroup, 1.0, ATTN_IDLE, 0, pitch );
pFriend = FindNearestFriend( TRUE );
9 years ago
8 years ago
if( pFriend )
9 years ago
{
m_hTalkTarget = pFriend;
PlaySentence( szIdleGroup, duration, VOL_NORM, ATTN_IDLE );
m_nSpeak++;
return TRUE;
}
}
// didn't speak
Talk( 0 );
CTalkMonster::g_talkWaitTime = 0;
return FALSE;
}
void CTalkMonster::PlayScriptedSentence( const char *pszSentence, float duration, float volume, float attenuation, BOOL bConcurrent, CBaseEntity *pListener )
{
8 years ago
if( !bConcurrent )
9 years ago
ShutUpFriends();
ClearConditions( bits_COND_CLIENT_PUSH ); // Forget about moving! I've got something to say!
m_useTime = gpGlobals->time + duration;
PlaySentence( pszSentence, duration, volume, attenuation );
m_hTalkTarget = pListener;
}
void CTalkMonster::PlaySentence( const char *pszSentence, float duration, float volume, float attenuation )
{
8 years ago
if( !pszSentence )
9 years ago
return;
8 years ago
Talk( duration );
9 years ago
CTalkMonster::g_talkWaitTime = gpGlobals->time + duration + 2.0;
8 years ago
if( pszSentence[0] == '!' )
EMIT_SOUND_DYN( edict(), CHAN_VOICE, pszSentence, volume, attenuation, 0, GetVoicePitch() );
9 years ago
else
SENTENCEG_PlayRndSz( edict(), pszSentence, volume, attenuation, 0, GetVoicePitch() );
// If you say anything, don't greet the player - you may have already spoken to them
8 years ago
SetBits( m_bitsSaid, bit_saidHelloPlayer );
9 years ago
}
//=========================================================
// Talk - set a timer that tells us when the monster is done
// talking.
//=========================================================
8 years ago
void CTalkMonster::Talk( float flDuration )
9 years ago
{
8 years ago
if( flDuration <= 0 )
9 years ago
{
// no duration :(
m_flStopTalkTime = gpGlobals->time + 3;
}
else
{
m_flStopTalkTime = gpGlobals->time + flDuration;
}
}
// Prepare this talking monster to answer question
8 years ago
void CTalkMonster::SetAnswerQuestion( CTalkMonster *pSpeaker )
9 years ago
{
8 years ago
if( !m_pCine )
9 years ago
ChangeSchedule( slIdleResponse );
m_hTalkTarget = (CBaseMonster *)pSpeaker;
}
8 years ago
int CTalkMonster::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
8 years ago
if( IsAlive() )
9 years ago
{
// if player damaged this entity, have other friends talk about it
8 years ago
if( pevAttacker && m_MonsterState != MONSTERSTATE_PRONE && FBitSet( pevAttacker->flags, FL_CLIENT ) )
9 years ago
{
8 years ago
CBaseEntity *pFriend = FindNearestFriend( FALSE );
9 years ago
8 years ago
if( pFriend && pFriend->IsAlive() )
9 years ago
{
// only if not dead or dying!
CTalkMonster *pTalkMonster = (CTalkMonster *)pFriend;
pTalkMonster->ChangeSchedule( slIdleStopShooting );
}
}
}
8 years ago
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
9 years ago
}
8 years ago
Schedule_t *CTalkMonster::GetScheduleOfType( int Type )
9 years ago
{
switch( Type )
{
case SCHED_MOVE_AWAY:
return slMoveAway;
case SCHED_MOVE_AWAY_FOLLOW:
return slMoveAwayFollow;
case SCHED_MOVE_AWAY_FAIL:
return slMoveAwayFail;
case SCHED_TARGET_FACE:
// speak during 'use'
8 years ago
if( RANDOM_LONG( 0, 99 ) < 2 )
//ALERT( at_console, "target chase speak\n" );
9 years ago
return slIdleSpeakWait;
else
return slIdleStand;
case SCHED_IDLE_STAND:
{
// if never seen player, try to greet him
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidHelloPlayer ) )
9 years ago
{
return slIdleHello;
}
// sustained light wounds?
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidWoundLight ) && ( pev->health <= ( pev->max_health * 0.75 ) ) )
9 years ago
{
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), m_szGrp[TLK_WOUND], 1.0, ATTN_IDLE, 0, GetVoicePitch() );
//CTalkMonster::g_talkWaitTime = gpGlobals->time + RANDOM_FLOAT( 2.8, 3.2 );
PlaySentence( m_szGrp[TLK_WOUND], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
SetBits( m_bitsSaid, bit_saidWoundLight );
9 years ago
return slIdleStand;
}
// sustained heavy wounds?
8 years ago
else if( !FBitSet( m_bitsSaid, bit_saidWoundHeavy ) && ( pev->health <= ( pev->max_health * 0.5 ) ) )
9 years ago
{
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), m_szGrp[TLK_MORTAL], 1.0, ATTN_IDLE, 0, GetVoicePitch() );
//CTalkMonster::g_talkWaitTime = gpGlobals->time + RANDOM_FLOAT( 2.8, 3.2 );
PlaySentence( m_szGrp[TLK_MORTAL], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
SetBits( m_bitsSaid, bit_saidWoundHeavy );
9 years ago
return slIdleStand;
}
// talk about world
8 years ago
if( FOkToSpeak() && RANDOM_LONG( 0, m_nSpeak * 2 ) == 0 )
9 years ago
{
//ALERT ( at_console, "standing idle speak\n" );
return slIdleSpeak;
}
8 years ago
if( !IsTalking() && HasConditions( bits_COND_SEE_CLIENT ) && RANDOM_LONG( 0, 6 ) == 0 )
9 years ago
{
edict_t *pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
8 years ago
if( pPlayer )
9 years ago
{
// watch the client.
8 years ago
UTIL_MakeVectors( pPlayer->v.angles );
if( ( pPlayer->v.origin - pev->origin ).Length2D() < TLK_STARE_DIST &&
UTIL_DotPoints( pPlayer->v.origin, pev->origin, gpGlobals->v_forward ) >= m_flFieldOfView )
9 years ago
{
// go into the special STARE schedule if the player is close, and looking at me too.
8 years ago
return &slTlkIdleWatchClient[1];
9 years ago
}
return slTlkIdleWatchClient;
}
}
else
{
8 years ago
if( IsTalking() )
9 years ago
// look at who we're talking to
return slTlkIdleEyecontact;
else
// regular standing idle
return slIdleStand;
}
// NOTE - caller must first CTalkMonster::GetScheduleOfType,
// then check result and decide what to return ie: if sci gets back
// slIdleStand, return slIdleSciStand
}
break;
}
return CBaseMonster::GetScheduleOfType( Type );
}
//=========================================================
// IsTalking - am I saying a sentence right now?
//=========================================================
8 years ago
BOOL CTalkMonster::IsTalking( void )
9 years ago
{
8 years ago
if( m_flStopTalkTime > gpGlobals->time )
9 years ago
{
return TRUE;
}
return FALSE;
}
//=========================================================
// If there's a player around, watch him.
//=========================================================
8 years ago
void CTalkMonster::PrescheduleThink( void )
9 years ago
{
8 years ago
if( !HasConditions( bits_COND_SEE_CLIENT ) )
9 years ago
{
8 years ago
SetConditions( bits_COND_CLIENT_UNSEEN );
9 years ago
}
}
// try to smell something
8 years ago
void CTalkMonster::TrySmellTalk( void )
9 years ago
{
8 years ago
if( !FOkToSpeak() )
9 years ago
return;
// clear smell bits periodically
8 years ago
if( gpGlobals->time > m_flLastSaidSmelled )
9 years ago
{
8 years ago
//ALERT( at_aiconsole, "Clear smell bits\n" );
ClearBits( m_bitsSaid, bit_saidSmelled );
9 years ago
}
9 years ago
// smelled something?
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidSmelled ) && HasConditions( bits_COND_SMELL ) )
9 years ago
{
8 years ago
PlaySentence( m_szGrp[TLK_SMELL], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
9 years ago
m_flLastSaidSmelled = gpGlobals->time + 60;// don't talk about the stinky for a while.
8 years ago
SetBits( m_bitsSaid, bit_saidSmelled );
9 years ago
}
}
int CTalkMonster::IRelationship( CBaseEntity *pTarget )
{
8 years ago
if( pTarget->IsPlayer() )
if( m_afMemory & bits_MEMORY_PROVOKED )
9 years ago
return R_HT;
return CBaseMonster::IRelationship( pTarget );
}
void CTalkMonster::StopFollowing( BOOL clearSchedule )
{
8 years ago
if( IsFollowing() )
9 years ago
{
8 years ago
if( !( m_afMemory & bits_MEMORY_PROVOKED ) )
9 years ago
{
8 years ago
PlaySentence( m_szGrp[TLK_UNUSE], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
9 years ago
m_hTalkTarget = m_hTargetEnt;
}
8 years ago
if( m_movementGoal == MOVEGOAL_TARGETENT )
9 years ago
RouteClear(); // Stop him from walking toward the player
m_hTargetEnt = 0;
8 years ago
if( clearSchedule )
9 years ago
ClearSchedule();
if( m_hEnemy != 0 )
9 years ago
m_IdealMonsterState = MONSTERSTATE_COMBAT;
}
}
void CTalkMonster::StartFollowing( CBaseEntity *pLeader )
{
8 years ago
if( m_pCine )
9 years ago
m_pCine->CancelScript();
if( m_hEnemy != 0 )
9 years ago
m_IdealMonsterState = MONSTERSTATE_ALERT;
m_hTargetEnt = pLeader;
8 years ago
PlaySentence( m_szGrp[TLK_USE], RANDOM_FLOAT( 2.8, 3.2 ), VOL_NORM, ATTN_IDLE );
9 years ago
m_hTalkTarget = m_hTargetEnt;
ClearConditions( bits_COND_CLIENT_PUSH );
ClearSchedule();
}
BOOL CTalkMonster::CanFollow( void )
{
8 years ago
if( m_MonsterState == MONSTERSTATE_SCRIPT )
9 years ago
{
if( !m_pCine )
return FALSE;
8 years ago
if( !m_pCine->CanInterrupt() )
9 years ago
return FALSE;
}
8 years ago
if( !IsAlive() )
9 years ago
return FALSE;
return !IsFollowing();
}
8 years ago
void CTalkMonster::FollowerUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
9 years ago
{
// Don't allow use during a scripted_sentence
8 years ago
if( m_useTime > gpGlobals->time )
9 years ago
return;
8 years ago
if( pCaller != NULL && pCaller->IsPlayer() )
9 years ago
{
// Pre-disaster followers can't be used
8 years ago
if( pev->spawnflags & SF_MONSTER_PREDISASTER )
9 years ago
{
DeclineFollowing();
}
8 years ago
else if( CanFollow() )
9 years ago
{
8 years ago
LimitFollowers( pCaller, 1 );
9 years ago
8 years ago
if( m_afMemory & bits_MEMORY_PROVOKED )
9 years ago
ALERT( at_console, "I'm not following you, you evil person!\n" );
else
{
StartFollowing( pCaller );
8 years ago
SetBits( m_bitsSaid, bit_saidHelloPlayer ); // Don't say hi after you've started following
9 years ago
}
}
else
{
StopFollowing( TRUE );
}
}
}
void CTalkMonster::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "UseSentence" ) )
9 years ago
{
8 years ago
m_iszUse = ALLOC_STRING( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "UnUseSentence" ) )
9 years ago
{
8 years ago
m_iszUnUse = ALLOC_STRING( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
else
CBaseMonster::KeyValue( pkvd );
}
void CTalkMonster::Precache( void )
{
8 years ago
if( m_iszUse )
9 years ago
m_szGrp[TLK_USE] = STRING( m_iszUse );
8 years ago
if( m_iszUnUse )
9 years ago
m_szGrp[TLK_UNUSE] = STRING( m_iszUnUse );
}