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.

1498 lines
38 KiB

7 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.
*
****/
7 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
7 years ago
// NOTE: m_voicePitch & m_szGrp should be fixed up by precache each save/restore
TYPEDESCRIPTION CTalkMonster::m_SaveData[] =
7 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_??? ),
7 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 )
7 years ago
// array of friend names
const char *CTalkMonster::m_szFriends[TLK_CFRIENDS] =
7 years ago
{
"monster_barney",
"monster_scientist",
"monster_sitting_scientist",
};
//=========================================================
// AI Schedules Specific to talking monsters
//=========================================================
8 years ago
Task_t tlIdleResponse[] =
7 years ago
{
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_IDLE }, // Stop and listen
{ TASK_WAIT, 0.5f }, // Wait until sure it's me they are talking to
{ TASK_TLK_EYECONTACT, 0.0f }, // Wait until speaker is done
{ TASK_TLK_RESPOND, 0.0f }, // Wait and then say my response
{ TASK_TLK_IDEALYAW, 0.0f }, // look at who I'm talking to
{ TASK_FACE_IDEAL, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, 0.0f }, // Wait until speaker is done
7 years ago
};
8 years ago
Schedule_t slIdleResponse[] =
7 years ago
{
8 years ago
{
7 years ago
tlIdleResponse,
8 years ago
ARRAYSIZE( tlIdleResponse ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
7 years ago
bits_COND_HEAVY_DAMAGE,
0,
"Idle Response"
},
};
8 years ago
Task_t tlIdleSpeak[] =
7 years ago
{
{ TASK_TLK_SPEAK, 0.0f },// question or remark
{ TASK_TLK_IDEALYAW, 0.0f },// look at who I'm talking to
{ TASK_FACE_IDEAL, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, 0.0f },
{ TASK_WAIT_RANDOM, 0.5f },
7 years ago
};
8 years ago
Schedule_t slIdleSpeak[] =
7 years ago
{
{
7 years ago
tlIdleSpeak,
8 years ago
ARRAYSIZE( tlIdleSpeak ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
7 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, 0.0f },// question or remark
{ TASK_TLK_EYECONTACT, 0.0f },//
{ TASK_WAIT, 2.0f },// wait - used when sci is in 'use' mode to keep head turned
7 years ago
};
8 years ago
Schedule_t slIdleSpeakWait[] =
7 years ago
{
8 years ago
{
7 years ago
tlIdleSpeakWait,
8 years ago
ARRAYSIZE( tlIdleSpeakWait ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
7 years ago
bits_COND_HEAVY_DAMAGE,
0,
"Idle Speak Wait"
},
};
8 years ago
Task_t tlIdleHello[] =
7 years ago
{
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },// Stop and talk
{ TASK_TLK_HELLO, 0.0f },// Try to say hello to player
{ TASK_TLK_EYECONTACT, 0.0f },
{ TASK_WAIT, 0.5f },// wait a bit
{ TASK_TLK_HELLO, 0.0f },// Try to say hello to player
{ TASK_TLK_EYECONTACT, 0.0f },
{ TASK_WAIT, 0.5f },// wait a bit
{ TASK_TLK_HELLO, 0.0f },// Try to say hello to player
{ TASK_TLK_EYECONTACT, 0.0f },
{ TASK_WAIT, 0.5f },// wait a bit
{ TASK_TLK_HELLO, 0.0f },// Try to say hello to player
{ TASK_TLK_EYECONTACT, 0.0f },
{ TASK_WAIT, 0.5f },// wait a bit
7 years ago
};
8 years ago
Schedule_t slIdleHello[] =
7 years ago
{
8 years ago
{
7 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 |
7 years ago
bits_COND_PROVOKED,
bits_SOUND_COMBAT,
"Idle Hello"
},
};
8 years ago
Task_t tlIdleStopShooting[] =
7 years ago
{
{ TASK_TLK_STOPSHOOTING, 0.0f },// tell player to stop shooting friend
// { TASK_TLK_EYECONTACT, 0.0f },// look at the player
7 years ago
};
8 years ago
Schedule_t slIdleStopShooting[] =
7 years ago
{
8 years ago
{
7 years ago
tlIdleStopShooting,
8 years ago
ARRAYSIZE( tlIdleStopShooting ),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
7 years ago
bits_COND_HEAR_SOUND,
0,
"Idle Stop Shooting"
},
};
8 years ago
Task_t tlMoveAway[] =
7 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_MOVE_AWAY_FAIL },
{ TASK_STORE_LASTPOSITION, 0.0f },
{ TASK_MOVE_AWAY_PATH, 100.0f },
{ TASK_WALK_PATH_FOR_UNITS, 100.0f },
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_PLAYER, 0.5f },
7 years ago
};
8 years ago
Schedule_t slMoveAway[] =
7 years ago
{
{
tlMoveAway,
8 years ago
ARRAYSIZE( tlMoveAway ),
7 years ago
0,
0,
"MoveAway"
},
};
8 years ago
Task_t tlMoveAwayFail[] =
7 years ago
{
{ TASK_STOP_MOVING, 0.0f },
{ TASK_FACE_PLAYER, 0.5f },
7 years ago
};
8 years ago
Schedule_t slMoveAwayFail[] =
7 years ago
{
{
tlMoveAwayFail,
8 years ago
ARRAYSIZE( tlMoveAwayFail ),
7 years ago
0,
0,
"MoveAwayFail"
},
};
8 years ago
Task_t tlMoveAwayFollow[] =
7 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 },
7 years ago
};
8 years ago
Schedule_t slMoveAwayFollow[] =
7 years ago
{
{
tlMoveAwayFollow,
8 years ago
ARRAYSIZE( tlMoveAwayFollow ),
7 years ago
0,
0,
"MoveAwayFollow"
},
};
8 years ago
Task_t tlTlkIdleWatchClient[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_TLK_LOOK_AT_CLIENT, 6.0f },
7 years ago
};
8 years ago
Task_t tlTlkIdleWatchClientStare[] =
7 years ago
{
8 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_TLK_CLIENT_STARE, 6.0f },
{ TASK_TLK_STARE, 0.0f },
{ TASK_TLK_IDEALYAW, 0.0f },// look at who I'm talking to
{ TASK_FACE_IDEAL, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, 0.0f },
7 years ago
};
8 years ago
Schedule_t slTlkIdleWatchClient[] =
7 years ago
{
8 years ago
{
7 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 |
7 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 |
7 years ago
bits_SOUND_GARBAGE,
"TlkIdleWatchClient"
},
8 years ago
{
7 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 |
7 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 |
7 years ago
bits_SOUND_GARBAGE,
"TlkIdleWatchClientStare"
},
};
Task_t tlTlkIdleEyecontact[] =
{
{ TASK_TLK_IDEALYAW, 0.0f },// look at who I'm talking to
{ TASK_FACE_IDEAL, 0.0f },
8 years ago
{ TASK_SET_ACTIVITY, (float)ACT_SIGNAL3 },
{ TASK_TLK_EYECONTACT, 0.0f },// Wait until speaker is done
7 years ago
};
8 years ago
Schedule_t slTlkIdleEyecontact[] =
7 years ago
{
{
7 years ago
tlTlkIdleEyecontact,
8 years ago
ARRAYSIZE( tlTlkIdleEyecontact ),
bits_COND_NEW_ENEMY |
bits_COND_CLIENT_PUSH |
bits_COND_LIGHT_DAMAGE |
7 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],
7 years ago
slTlkIdleEyecontact,
};
IMPLEMENT_CUSTOM_SCHEDULES( CTalkMonster, CBaseMonster )
7 years ago
8 years ago
void CTalkMonster::SetActivity( Activity newActivity )
7 years ago
{
8 years ago
if( newActivity == ACT_IDLE && IsTalking() )
7 years ago
newActivity = ACT_SIGNAL3;
8 years ago
if( newActivity == ACT_SIGNAL3 && ( LookupActivity( ACT_SIGNAL3 ) == ACTIVITY_NOT_AVAILABLE ) )
7 years ago
newActivity = ACT_IDLE;
CBaseMonster::SetActivity( newActivity );
}
8 years ago
void CTalkMonster::StartTask( Task_t *pTask )
7 years ago
{
8 years ago
switch( pTask->iTask )
7 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 )
7 years ago
{
pev->yaw_speed = 60;
8 years ago
float yaw = VecToYaw( m_hTalkTarget->pev->origin - pev->origin ) - pev->angles.y;
7 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
7 years ago
8 years ago
if( yaw < 0 )
7 years ago
{
pev->ideal_yaw = Q_min( yaw + 45, 0 ) + pev->angles.y;
7 years ago
}
else
{
pev->ideal_yaw = Q_max( yaw - 45, 0 ) + pev->angles.y;
7 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 );
7 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 );
7 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 ) )
7 years ago
{
TaskComplete();
}
8 years ago
else if( FindCover( pev->origin, pev->view_ofs, 0, CoverRadius() ) )
7 years ago
{
// then try for plain ole cover
m_flMoveWaitFinished = gpGlobals->time + 2.0f;
7 years ago
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 )
7 years ago
{
edict_t *pPlayer;
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() )
7 years ago
{
// Get edict for one player
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
8 years ago
if( pPlayer )
7 years ago
{
IdleHeadTurn( pPlayer->v.origin );
}
}
else
{
// started moving or talking
TaskFail();
return;
}
8 years ago
if( pTask->iTask == TASK_TLK_CLIENT_STARE )
7 years ago
{
if( pPlayer )
7 years ago
{
// fail out if the player looks away or moves away.
if( ( pPlayer->v.origin - pev->origin ).Length2D() > TLK_STARE_DIST )
{
// player moved away.
TaskFail();
}
7 years ago
UTIL_MakeVectors( pPlayer->v.angles );
if( UTIL_DotPoints( pPlayer->v.origin, pev->origin, gpGlobals->v_forward ) < m_flFieldOfView )
{
// player looked away
TaskFail();
}
7 years ago
}
}
8 years ago
if( gpGlobals->time > m_flWaitFinished )
7 years ago
{
TaskComplete();
}
break;
case TASK_FACE_PLAYER:
{
// Get edict for one player
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
8 years ago
if( pPlayer )
7 years ago
{
8 years ago
MakeIdealYaw( pPlayer->v.origin );
ChangeYaw( pev->yaw_speed );
7 years ago
IdleHeadTurn( pPlayer->v.origin );
8 years ago
if( gpGlobals->time > m_flWaitFinished && FlYawDiff() < 10 )
7 years ago
{
TaskComplete();
}
}
else
{
TaskFail();
}
}
break;
case TASK_TLK_EYECONTACT:
if( !IsMoving() && IsTalking() && m_hTalkTarget != 0 )
7 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();
7 years ago
// Walk path until far enough away
8 years ago
if( distance > pTask->flData || MovementIsComplete() )
7 years ago
{
TaskComplete();
RouteClear(); // Stop moving
}
}
break;
case TASK_WAIT_FOR_MOVEMENT:
if( IsTalking() && m_hTalkTarget != 0 )
7 years ago
{
8 years ago
// ALERT( at_console, "walking, talking\n" );
7 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)
7 years ago
{
FIdleSpeak();
}
}
CBaseMonster::RunTask( pTask );
8 years ago
if( TaskIsComplete() )
7 years ago
IdleHeadTurn( pev->origin );
break;
default:
if( IsTalking() && m_hTalkTarget != 0 )
7 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 )
7 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 )
7 years ago
{
AlertFriends();
8 years ago
LimitFollowers( CBaseEntity::Instance( pevAttacker ), 0 );
7 years ago
}
m_hTargetEnt = 0;
7 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 )
7 years ago
{
CBaseEntity *pFriend = pPrevious;
const char *pszFriend;
7 years ago
TraceResult tr;
Vector vecCheck;
8 years ago
pszFriend = m_szFriends[FriendNumber( listNumber )];
7 years ago
while( ( pFriend = UTIL_FindEntityByClassname( pFriend, pszFriend ) ) )
{
8 years ago
if( pFriend == this || !pFriend->IsAlive() )
7 years ago
// don't talk to self or dead people
continue;
8 years ago
if( bTrace )
7 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 );
7 years ago
}
else
tr.flFraction = 1.0f;
7 years ago
if( tr.flFraction == 1.0f )
7 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++ )
7 years ago
{
while( ( pFriend = EnumFriends( pFriend, i, TRUE ) ) )
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster->IsAlive() )
7 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++ )
7 years ago
{
while( ( pFriend = EnumFriends( pFriend, i, TRUE ) ) )
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster )
7 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;
7 years ago
// for each friend in this bsp...
8 years ago
for( i = 0; i < TLK_CFRIENDS; i++ )
7 years ago
{
while( ( pFriend = EnumFriends( pFriend, i, FALSE ) ) )
{
CBaseMonster *pMonster = pFriend->MyMonsterPointer();
8 years ago
if( pMonster )
7 years ago
{
8 years ago
if( pMonster->m_hTargetEnt == pPlayer )
7 years ago
{
count++;
8 years ago
if( count > maxFollowers )
7 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() )
7 years ago
return 1e6;
8 years ago
return ( m_hTargetEnt->pev->origin - pev->origin ).Length();
7 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 )
7 years ago
{
switch( pEvent->event )
8 years ago
{
7 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 )
7 years ago
break;
// fall through...
case SCRIPT_EVENT_SENTENCE: // Play a named sentence group
ShutUpFriends();
PlaySentence( pEvent->options, RANDOM_FLOAT( 2.8f, 3.4f ), VOL_NORM, ATTN_IDLE );
8 years ago
//ALERT( at_console, "script event speak\n" );
7 years ago
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
// monsters derived from ctalkmonster should call this in precache()
8 years ago
void CTalkMonster::TalkInit( void )
7 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;
if (m_iszSpeakAs) //LRC: changing voice groups for monsters
{
char szBuf[64];
strcpy(szBuf,STRING(m_iszSpeakAs));
strcat(szBuf,"_");
char *szAssign = &(szBuf[strlen(szBuf)]);
//LRC - this is pretty dodgy; test with save/restore.
strcpy(szAssign,"ANSWER");
m_szGrp[TLK_ANSWER] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"QUESTION");
m_szGrp[TLK_QUESTION] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"IDLE");
m_szGrp[TLK_IDLE] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"STARE");
m_szGrp[TLK_STARE] = STRING(ALLOC_STRING(szBuf));
if (pev->spawnflags & SF_MONSTER_PREDISASTER) //LRC
strcpy(szAssign,"PFOLLOW");
else
strcpy(szAssign,"OK");
m_szGrp[TLK_USE] = STRING(ALLOC_STRING(szBuf));
if (pev->spawnflags & SF_MONSTER_PREDISASTER) //LRC
strcpy(szAssign,"PWAIT");
else
strcpy(szAssign,"WAIT");
m_szGrp[TLK_UNUSE] = STRING(ALLOC_STRING(szBuf));
if (pev->spawnflags & SF_MONSTER_PREDISASTER) //LRC
strcpy(szAssign,"POK");
else
strcpy(szAssign,"NOTOK");
m_szGrp[TLK_DECLINE] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"STOP");
m_szGrp[TLK_STOP] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"NOSHOOT");
m_szGrp[TLK_NOSHOOT] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"HELLO");
m_szGrp[TLK_HELLO] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PLHURT1");
m_szGrp[TLK_PLHURT1] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PLHURT2");
m_szGrp[TLK_PLHURT2] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PLHURT3");
m_szGrp[TLK_PLHURT3] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PHELLO");
m_szGrp[TLK_PHELLO] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PIDLE");
m_szGrp[TLK_PIDLE] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"PQUESTION");
m_szGrp[TLK_PQUESTION] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"SMELL");
m_szGrp[TLK_SMELL] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"WOUND");
m_szGrp[TLK_WOUND] = STRING(ALLOC_STRING(szBuf));
strcpy(szAssign,"MORTAL");
m_szGrp[TLK_MORTAL] = STRING(ALLOC_STRING(szBuf));
}
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 )
7 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;
7 years ago
int cfriends;
vecStart.z = pev->absmax.z;
8 years ago
if( fPlayer )
7 years ago
cfriends = 1;
else
cfriends = TLK_CFRIENDS;
// for each type of friend...
8 years ago
for( i = cfriends-1; i > -1; i-- )
7 years ago
{
8 years ago
if( fPlayer )
7 years ago
pszFriend = "player";
else
8 years ago
pszFriend = m_szFriends[FriendNumber( i )];
7 years ago
8 years ago
if( !pszFriend )
7 years ago
continue;
// for each friend in this bsp...
while( ( pFriend = UTIL_FindEntityByClassname( pFriend, pszFriend ) ) )
{
8 years ago
if( pFriend == this || !pFriend->IsAlive() )
7 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 )
7 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())
7 years ago
{
8 years ago
UTIL_TraceLine( vecStart, vecCheck, ignore_monsters, ENT( pev ), &tr );
7 years ago
if( tr.flFraction == 1.0f )
7 years ago
{
// visible and in range, this is the new nearest scientist
8 years ago
if( ( vecStart - vecCheck ).Length() < TALKRANGE_MIN )
7 years ago
{
pNearest = pFriend;
8 years ago
range = ( vecStart - vecCheck ).Length();
7 years ago
}
}
}
}
}
return pNearest;
}
8 years ago
int CTalkMonster::GetVoicePitch( void )
7 years ago
{
8 years ago
return m_voicePitch + RANDOM_LONG( 0, 3 );
7 years ago
}
8 years ago
void CTalkMonster::Touch( CBaseEntity *pOther )
7 years ago
{
// Did the player touch me?
8 years ago
if( pOther->IsPlayer() )
7 years ago
{
// Ignore if pissed at player
8 years ago
if( m_afMemory & bits_MEMORY_PROVOKED )
7 years ago
return;
// Stay put during speech
8 years ago
if( IsTalking() )
7 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.0f )
7 years ago
{
SetConditions( bits_COND_CLIENT_PUSH );
if ( m_MonsterState != MONSTERSTATE_SCRIPT )
MakeIdealYaw( pOther->pev->origin );
7 years ago
}
}
}
//=========================================================
// IdleRespond
// Respond to a previous question
//=========================================================
8 years ago
void CTalkMonster::IdleRespond( void )
7 years ago
{
//int pitch = GetVoicePitch();
7 years ago
// play response
PlaySentence( m_szGrp[TLK_ANSWER], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
7 years ago
}
8 years ago
int CTalkMonster::FOkToSpeak( void )
7 years ago
{
// if in the grip of a barnacle, don't speak
8 years ago
if( m_MonsterState == MONSTERSTATE_PRONE || m_IdealMonsterState == MONSTERSTATE_PRONE )
7 years ago
{
return FALSE;
}
// if not alive, certainly don't speak
8 years ago
if( pev->deadflag != DEAD_NO )
7 years ago
{
return FALSE;
}
// if someone else is talking, don't speak
8 years ago
if( gpGlobals->time <= CTalkMonster::g_talkWaitTime )
7 years ago
return FALSE;
8 years ago
if( pev->spawnflags & SF_MONSTER_GAG )
7 years ago
return FALSE;
8 years ago
if( m_MonsterState == MONSTERSTATE_PRONE )
7 years ago
return FALSE;
// if player is not in pvs, don't speak
8 years ago
if( !IsAlive() || FNullEnt(FIND_CLIENT_IN_PVS( edict() ) ) )
7 years ago
return FALSE;
// don't talk if you're in combat
if( m_hEnemy != 0 && FVisible( m_hEnemy ) )
7 years ago
return FALSE;
return TRUE;
}
int CTalkMonster::CanPlaySentence( BOOL fDisregardState )
{
8 years ago
if( fDisregardState )
7 years ago
return CBaseMonster::CanPlaySentence( fDisregardState );
return FOkToSpeak();
}
//=========================================================
// FIdleStare
//=========================================================
8 years ago
int CTalkMonster::FIdleStare( void )
7 years ago
{
8 years ago
if( !FOkToSpeak() )
7 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 )
7 years ago
{
8 years ago
if( !FOkToSpeak() )
7 years ago
return FALSE;
// if this is first time scientist has seen player, greet him
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidHelloPlayer ) )
7 years ago
{
// get a player
8 years ago
CBaseEntity *pPlayer = FindNearestFriend( TRUE );
7 years ago
8 years ago
if( pPlayer )
7 years ago
{
8 years ago
if( FInViewCone( pPlayer ) && FVisible( pPlayer ) )
7 years ago
{
m_hTalkTarget = pPlayer;
8 years ago
if( FBitSet(pev->spawnflags, SF_MONSTER_PREDISASTER ) )
PlaySentence( m_szGrp[TLK_PHELLO], RANDOM_FLOAT( 3.0f, 3.5f ), VOL_NORM, ATTN_IDLE );
7 years ago
else
PlaySentence( m_szGrp[TLK_HELLO], RANDOM_FLOAT( 3.0f, 3.5f ), VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidHelloPlayer );
7 years ago
return TRUE;
}
}
}
return FALSE;
}
// turn head towards supplied origin
8 years ago
void CTalkMonster::IdleHeadTurn( Vector &vecFriend )
7 years ago
{
// turn head in desired direction only if ent has a turnable head
8 years ago
if( m_afCapability & bits_CAP_TURN_HEAD )
7 years ago
{
8 years ago
float yaw = VecToYaw( vecFriend - pev->origin ) - pev->angles.y;
7 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
7 years ago
// turn towards vector
SetBoneController( 0, yaw );
}
}
//=========================================================
// FIdleSpeak
// ask question of nearby friend, or make statement
//=========================================================
8 years ago
int CTalkMonster::FIdleSpeak( void )
7 years ago
{
// try to start a conversation, or make statement
//int pitch;
7 years ago
const char *szIdleGroup;
const char *szQuestionGroup;
float duration;
8 years ago
if( !FOkToSpeak() )
7 years ago
return FALSE;
// set idle groups based on pre/post disaster
8 years ago
if( FBitSet( pev->spawnflags, SF_MONSTER_PREDISASTER ) )
7 years ago
{
szIdleGroup = m_szGrp[TLK_PIDLE];
szQuestionGroup = m_szGrp[TLK_PQUESTION];
// set global min delay for next conversation
duration = RANDOM_FLOAT( 4.8f, 5.2f );
7 years ago
}
else
{
szIdleGroup = m_szGrp[TLK_IDLE];
szQuestionGroup = m_szGrp[TLK_QUESTION];
// set global min delay for next conversation
duration = RANDOM_FLOAT( 2.8f, 3.2f );
7 years ago
}
//pitch = GetVoicePitch();
7 years ago
// player using this entity is alive and wounded?
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget != NULL )
7 years ago
{
8 years ago
if( pTarget->IsPlayer() )
7 years ago
{
8 years ago
if( pTarget->IsAlive() )
7 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 ) )
7 years ago
{
8 years ago
//EMIT_SOUND_DYN(ENT( pev ), CHAN_VOICE, m_szGrp[TLK_PLHURT3], 1.0, ATTN_IDLE, 0, pitch );
7 years ago
PlaySentence( m_szGrp[TLK_PLHURT3], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageHeavy );
7 years ago
return TRUE;
}
8 years ago
else if( !FBitSet( m_bitsSaid, bit_saidDamageMedium ) &&
( m_hTargetEnt->pev->health <= m_hTargetEnt->pev->max_health / 4 ) )
7 years ago
{
8 years ago
//EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, m_szGrp[TLK_PLHURT2], 1.0, ATTN_IDLE, 0, pitch );
7 years ago
PlaySentence( m_szGrp[TLK_PLHURT2], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageMedium );
7 years ago
return TRUE;
}
8 years ago
else if( !FBitSet( m_bitsSaid, bit_saidDamageLight) &&
( m_hTargetEnt->pev->health <= m_hTargetEnt->pev->max_health / 2 ) )
7 years ago
{
8 years ago
//EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, m_szGrp[TLK_PLHURT1], 1.0, ATTN_IDLE, 0, pitch );
7 years ago
PlaySentence( m_szGrp[TLK_PLHURT1], duration, VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidDamageLight );
7 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 );
7 years ago
8 years ago
if( pFriend && !( pFriend->IsMoving() ) && ( RANDOM_LONG( 0, 99 ) < 75 ) )
7 years ago
{
PlaySentence( szQuestionGroup, duration, VOL_NORM, ATTN_IDLE );
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), szQuestionGroup, 1.0, ATTN_IDLE, 0, pitch );
7 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 ) )
7 years ago
{
8 years ago
//SENTENCEG_PlayRndSz( ENT( pev ), szIdleGroup, 1.0, ATTN_IDLE, 0, pitch );
pFriend = FindNearestFriend( TRUE );
7 years ago
8 years ago
if( pFriend )
7 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 )
7 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 )
7 years ago
return;
8 years ago
Talk( duration );
7 years ago
CTalkMonster::g_talkWaitTime = gpGlobals->time + duration + 2.0f;
8 years ago
if( pszSentence[0] == '!' )
EMIT_SOUND_DYN( edict(), CHAN_VOICE, pszSentence, volume, attenuation, 0, GetVoicePitch() );
7 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 );
7 years ago
}
//=========================================================
// Talk - set a timer that tells us when the monster is done
// talking.
//=========================================================
8 years ago
void CTalkMonster::Talk( float flDuration )
7 years ago
{
8 years ago
if( flDuration <= 0 )
7 years ago
{
// no duration :(
m_flStopTalkTime = gpGlobals->time + 3.0f;
7 years ago
}
else
{
m_flStopTalkTime = gpGlobals->time + flDuration;
}
}
// Prepare this talking monster to answer question
8 years ago
void CTalkMonster::SetAnswerQuestion( CTalkMonster *pSpeaker )
7 years ago
{
8 years ago
if( !m_pCine )
7 years ago
ChangeSchedule( slIdleResponse );
m_hTalkTarget = (CBaseMonster *)pSpeaker;
}
8 years ago
int CTalkMonster::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
7 years ago
{
8 years ago
if( IsAlive() )
7 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 ) )
7 years ago
{
8 years ago
CBaseEntity *pFriend = FindNearestFriend( FALSE );
7 years ago
8 years ago
if( pFriend && pFriend->IsAlive() )
7 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 );
7 years ago
}
8 years ago
Schedule_t *CTalkMonster::GetScheduleOfType( int Type )
7 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" );
7 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 ) )
7 years ago
{
return slIdleHello;
}
// sustained light wounds?
if( !FBitSet( m_bitsSaid, bit_saidWoundLight ) && ( pev->health <= ( pev->max_health * 0.75f ) ) )
7 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.8f, 3.2f );
PlaySentence( m_szGrp[TLK_WOUND], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidWoundLight );
7 years ago
return slIdleStand;
}
// sustained heavy wounds?
else if( !FBitSet( m_bitsSaid, bit_saidWoundHeavy ) && ( pev->health <= ( pev->max_health * 0.5f ) ) )
7 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.8f, 3.2f );
PlaySentence( m_szGrp[TLK_MORTAL], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
8 years ago
SetBits( m_bitsSaid, bit_saidWoundHeavy );
7 years ago
return slIdleStand;
}
// talk about world
8 years ago
if( FOkToSpeak() && RANDOM_LONG( 0, m_nSpeak * 2 ) == 0 )
7 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 )
7 years ago
{
edict_t *pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
8 years ago
if( pPlayer )
7 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 )
7 years ago
{
// go into the special STARE schedule if the player is close, and looking at me too.
8 years ago
return &slTlkIdleWatchClient[1];
7 years ago
}
return slTlkIdleWatchClient;
}
}
else
{
8 years ago
if( IsTalking() )
7 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 )
7 years ago
{
8 years ago
if( m_flStopTalkTime > gpGlobals->time )
7 years ago
{
return TRUE;
}
return FALSE;
}
//=========================================================
// If there's a player around, watch him.
//=========================================================
8 years ago
void CTalkMonster::PrescheduleThink( void )
7 years ago
{
8 years ago
if( !HasConditions( bits_COND_SEE_CLIENT ) )
7 years ago
{
8 years ago
SetConditions( bits_COND_CLIENT_UNSEEN );
7 years ago
}
}
// try to smell something
8 years ago
void CTalkMonster::TrySmellTalk( void )
7 years ago
{
8 years ago
if( !FOkToSpeak() )
7 years ago
return;
// clear smell bits periodically
8 years ago
if( gpGlobals->time > m_flLastSaidSmelled )
7 years ago
{
8 years ago
//ALERT( at_aiconsole, "Clear smell bits\n" );
ClearBits( m_bitsSaid, bit_saidSmelled );
7 years ago
}
7 years ago
// smelled something?
8 years ago
if( !FBitSet( m_bitsSaid, bit_saidSmelled ) && HasConditions( bits_COND_SMELL ) )
7 years ago
{
PlaySentence( m_szGrp[TLK_SMELL], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
m_flLastSaidSmelled = gpGlobals->time + 60.0f;// don't talk about the stinky for a while.
8 years ago
SetBits( m_bitsSaid, bit_saidSmelled );
7 years ago
}
}
int CTalkMonster::IRelationship( CBaseEntity *pTarget )
{
8 years ago
if( pTarget->IsPlayer() )
if( m_afMemory & bits_MEMORY_PROVOKED )
7 years ago
return R_HT;
return CBaseMonster::IRelationship( pTarget );
}
void CTalkMonster::StopFollowing( BOOL clearSchedule )
{
8 years ago
if( IsFollowing() )
7 years ago
{
8 years ago
if( !( m_afMemory & bits_MEMORY_PROVOKED ) )
7 years ago
{
PlaySentence( m_szGrp[TLK_UNUSE], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
7 years ago
m_hTalkTarget = m_hTargetEnt;
}
8 years ago
if( m_movementGoal == MOVEGOAL_TARGETENT )
7 years ago
RouteClear(); // Stop him from walking toward the player
m_hTargetEnt = 0;
8 years ago
if( clearSchedule )
7 years ago
ClearSchedule();
if( m_hEnemy != 0 )
7 years ago
m_IdealMonsterState = MONSTERSTATE_COMBAT;
}
}
void CTalkMonster::StartFollowing( CBaseEntity *pLeader )
{
8 years ago
if( m_pCine )
7 years ago
m_pCine->CancelScript();
if( m_hEnemy != 0 )
7 years ago
m_IdealMonsterState = MONSTERSTATE_ALERT;
m_hTargetEnt = pLeader;
PlaySentence( m_szGrp[TLK_USE], RANDOM_FLOAT( 2.8f, 3.2f ), VOL_NORM, ATTN_IDLE );
7 years ago
m_hTalkTarget = m_hTargetEnt;
ClearConditions( bits_COND_CLIENT_PUSH );
ClearSchedule();
}
//LRC- redefined, now returns true if following would be physically possible
BOOL CTalkMonster::CanFollow( void )
{
8 years ago
if( m_MonsterState == MONSTERSTATE_SCRIPT )
7 years ago
{
if( !m_pCine )
return FALSE;
8 years ago
if( !m_pCine->CanInterrupt() )
7 years ago
return FALSE;
}
8 years ago
if( !IsAlive() )
7 years ago
return FALSE;
return TRUE;
}
//LRC- rewritten
8 years ago
void CTalkMonster::FollowerUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
7 years ago
{
// Don't allow use during a scripted_sentence
8 years ago
if( m_useTime > gpGlobals->time )
7 years ago
return;
//ALERT(at_console,"Talkmonster was Used: ");
// CanFollow is now true if the monster could physically follow anyone
if ( pCaller != NULL && pCaller->IsPlayer() && CanFollow() )
{
if ( !IsFollowing() )
9 years ago
{
7 years ago
// Pre-disaster followers can't be used unless they've got a master to override their behaviour...
if (IsLockedByMaster() || (pev->spawnflags & SF_MONSTER_PREDISASTER && !m_sMaster))
9 years ago
{
7 years ago
//ALERT(at_console,"Decline\n");
DeclineFollowing();
}
else
9 years ago
{
8 years ago
LimitFollowers( pCaller, 1 );
9 years ago
8 years ago
if( m_afMemory & bits_MEMORY_PROVOKED )
7 years ago
{
//ALERT(at_console,"Fail\n");
ALERT( at_aiconsole, "I'm not following you, you evil person!\n" );
}
9 years ago
else
{
StartFollowing( pCaller );
8 years ago
SetBits( m_bitsSaid, bit_saidHelloPlayer ); // Don't say hi after you've started following
7 years ago
}
}
}
7 years ago
else
{
StopFollowing( TRUE );
}
}
}
void CTalkMonster::KeyValue( KeyValueData *pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "UseSentence" ) )
7 years ago
{
8 years ago
m_iszUse = ALLOC_STRING( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "UnUseSentence" ) )
7 years ago
{
8 years ago
m_iszUnUse = ALLOC_STRING( pkvd->szValue );
7 years ago
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "RefusalSentence")) //LRC
{
m_iszDecline = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "SpeakAs")) //LRC
{
m_iszSpeakAs = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CBaseMonster::KeyValue( pkvd );
}
void CTalkMonster::Precache( void )
{
8 years ago
if( m_iszUse )
7 years ago
m_szGrp[TLK_USE] = STRING( m_iszUse );
8 years ago
if( m_iszUnUse )
7 years ago
m_szGrp[TLK_UNUSE] = STRING( m_iszUnUse );
if ( m_iszDecline ) //LRC
m_szGrp[TLK_DECLINE] = STRING( m_iszDecline );
}