2016-06-04 15:24:23 +02:00
|
|
|
/***
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Use, distribution, and modification of this source code and/or resulting
|
|
|
|
* object code is restricted to non-commercial enhancements to products from
|
|
|
|
* Valve LLC. All other use, distribution, or modification is prohibited
|
|
|
|
* without written permission from Valve LLC.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
|
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "monsters.h"
|
|
|
|
#include "soundent.h"
|
|
|
|
#include "nodes.h"
|
|
|
|
#include "talkmonster.h"
|
|
|
|
|
|
|
|
float CTalkMonster::g_talkWaitTime = 0; // time delay until it's ok to speak: used so that two NPCs don't talk at once
|
|
|
|
|
|
|
|
/*********************************************************/
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CGraph WorldGraph;
|
|
|
|
void CGraph::InitGraph( void ) { }
|
|
|
|
int CGraph::FLoadGraph( char *szMapName ) { return FALSE; }
|
|
|
|
int CGraph::AllocNodes( void ) { return FALSE; }
|
|
|
|
int CGraph::CheckNODFile( char *szMapName ) { return FALSE; }
|
|
|
|
int CGraph::FSetGraphPointers( void ) { return 0; }
|
|
|
|
void CGraph::ShowNodeConnections( int iNode ) { }
|
|
|
|
int CGraph::FindNearestNode( const Vector &vecOrigin, int afNodeTypes ) { return 0; }
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
/*********************************************************/
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseMonster::ReportAIState( void ) { }
|
|
|
|
float CBaseMonster::ChangeYaw( int speed ) { return 0; }
|
|
|
|
void CBaseMonster::MakeIdealYaw( Vector vecTarget ) { }
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
void CBaseMonster::CorpseFallThink( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->flags & FL_ONGROUND )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetThink( NULL );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
SetSequenceBox();
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_SetOrigin( pev, pev->origin );// link into world.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Call after animation/pose is set up
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseMonster::MonsterInitDead( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
InitBoneControllers();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->solid = SOLID_BBOX;
|
|
|
|
pev->movetype = MOVETYPE_TOSS;// so he'll fall to ground
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->frame = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
ResetSequenceInfo();
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->framerate = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// Copy health
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->max_health = pev->health;
|
|
|
|
pev->deadflag = DEAD_DEAD;
|
|
|
|
|
|
|
|
UTIL_SetSize( pev, g_vecZero, g_vecZero );
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_SetOrigin( pev, pev->origin );
|
|
|
|
|
|
|
|
// Setup health counters, etc.
|
|
|
|
BecomeDead();
|
2017-02-01 15:55:40 +01:00
|
|
|
SetThink( &CBaseMonster::CorpseFallThink );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.5;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
BOOL CBaseMonster::ShouldFadeOnDeath( void )
|
|
|
|
{
|
|
|
|
return FALSE;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
BOOL CBaseMonster::FCheckAITrigger( void )
|
|
|
|
{
|
|
|
|
return FALSE;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseMonster::KeyValue( KeyValueData *pkvd )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseToggle::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseMonster::IRelationship( CBaseEntity *pTarget )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
static int iEnemy[14][14] =
|
|
|
|
{ // NONE MACH PLYR HPASS HMIL AMIL APASS AMONST APREY APRED INSECT PLRALY PBWPN ABWPN
|
|
|
|
/*NONE*/ { R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO ,R_NO, R_NO, R_NO },
|
|
|
|
/*MACHINE*/ { R_NO ,R_NO ,R_DL ,R_DL ,R_NO ,R_DL ,R_DL ,R_DL ,R_DL ,R_DL ,R_NO ,R_DL, R_DL, R_DL },
|
|
|
|
/*PLAYER*/ { R_NO ,R_DL ,R_NO ,R_NO ,R_DL ,R_DL ,R_DL ,R_DL ,R_DL ,R_DL ,R_NO ,R_NO, R_DL, R_DL },
|
|
|
|
/*HUMANPASSIVE*/{ R_NO ,R_NO ,R_AL ,R_AL ,R_HT ,R_FR ,R_NO ,R_HT ,R_DL ,R_FR ,R_NO ,R_AL, R_NO, R_NO },
|
|
|
|
/*HUMANMILITAR*/{ R_NO ,R_NO ,R_HT ,R_DL ,R_NO ,R_HT ,R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|
return iEnemy[Classify()][pTarget->Classify()];
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// Look - Base class monster function to find enemies or
|
|
|
|
// food by sight. iDistance is distance ( in units ) that the
|
|
|
|
// monster can see.
|
|
|
|
//
|
|
|
|
// Sets the sight bits of the m_afConditions mask to indicate
|
|
|
|
// which types of entities were sighted.
|
|
|
|
// Function also sets the Looker's m_pLink
|
|
|
|
// to the head of a link list that contains all visible ents.
|
|
|
|
// (linked via each ent's m_pLink field)
|
|
|
|
//
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseMonster::Look( int iDistance )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
int iSighted = 0;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// DON'T let visibility information from last frame sit around!
|
2016-07-31 15:48:50 +02:00
|
|
|
ClearConditions( bits_COND_SEE_HATE | bits_COND_SEE_DISLIKE | bits_COND_SEE_ENEMY | bits_COND_SEE_FEAR | bits_COND_SEE_NEMESIS | bits_COND_SEE_CLIENT );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pLink = NULL;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pSightEnt = NULL;// the current visible entity that we're dealing with
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
CBaseEntity *pList[100];
|
|
|
|
|
|
|
|
Vector delta = Vector( iDistance, iDistance, iDistance );
|
|
|
|
|
|
|
|
// Find only monsters/clients in box, NOT limited to PVS
|
2016-07-31 15:48:50 +02:00
|
|
|
int count = UTIL_EntitiesInBox( pList, 100, pev->origin - delta, pev->origin + delta, FL_CLIENT | FL_MONSTER );
|
|
|
|
for( int i = 0; i < count; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pSightEnt = pList[i];
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pSightEnt != this && pSightEnt->pev->health > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// the looker will want to consider this entity
|
|
|
|
// don't check anything else about an entity that can't be seen, or an entity that you don't care about.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IRelationship( pSightEnt ) != R_NO && FInViewCone( pSightEnt ) && !FBitSet( pSightEnt->pev->flags, FL_NOTARGET ) && FVisible( pSightEnt ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pSightEnt->IsPlayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// if we see a client, remember that (mostly for scripted AI)
|
|
|
|
iSighted |= bits_COND_SEE_CLIENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSightEnt->m_pLink = m_pLink;
|
|
|
|
m_pLink = pSightEnt;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pSightEnt == m_hEnemy )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// we know this ent is visible, so if it also happens to be our enemy, store that now.
|
|
|
|
iSighted |= bits_COND_SEE_ENEMY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't add the Enemy's relationship to the conditions. We only want to worry about conditions when
|
|
|
|
// we see monsters other than the Enemy.
|
2016-07-31 15:48:50 +02:00
|
|
|
switch( IRelationship( pSightEnt ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
case R_NM:
|
2016-06-04 15:24:23 +02:00
|
|
|
iSighted |= bits_COND_SEE_NEMESIS;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case R_HT:
|
2016-06-04 15:24:23 +02:00
|
|
|
iSighted |= bits_COND_SEE_HATE;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case R_DL:
|
2016-06-04 15:24:23 +02:00
|
|
|
iSighted |= bits_COND_SEE_DISLIKE;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case R_FR:
|
2016-06-04 15:24:23 +02:00
|
|
|
iSighted |= bits_COND_SEE_FEAR;
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case R_AL:
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_aiconsole, "%s can't assess %s\n", STRING( pev->classname ), STRING(pSightEnt->pev->classname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
SetConditions( iSighted );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// BestVisibleEnemy - this functions searches the link
|
|
|
|
// list whose head is the caller's m_pLink field, and returns
|
|
|
|
// a pointer to the enemy entity in that list that is nearest the
|
|
|
|
// caller.
|
|
|
|
//
|
|
|
|
// !!!UNDONE - currently, this only returns the closest enemy.
|
|
|
|
// we'll want to consider distance, relationship, attack types, back turned, etc.
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *CBaseMonster::BestVisibleEnemy( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseEntity *pReturn;
|
|
|
|
CBaseEntity *pNextEnt;
|
2016-07-31 15:48:50 +02:00
|
|
|
int iNearest;
|
|
|
|
int iDist;
|
|
|
|
int iBestRelationship;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
iNearest = 8192;// so first visible entity will become the closest.
|
|
|
|
pNextEnt = m_pLink;
|
|
|
|
pReturn = NULL;
|
|
|
|
iBestRelationship = R_NO;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
while( pNextEnt != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pNextEnt->IsAlive() )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( IRelationship( pNextEnt ) > iBestRelationship )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// this entity is disliked MORE than the entity that we
|
|
|
|
// currently think is the best visible enemy. No need to do
|
|
|
|
// a distance check, just get mad at this one for now.
|
2016-07-31 15:48:50 +02:00
|
|
|
iBestRelationship = IRelationship( pNextEnt );
|
2017-06-29 15:56:03 +02:00
|
|
|
(int)iNearest = ( pNextEnt->pev->origin - pev->origin ).Length();
|
2016-06-04 15:24:23 +02:00
|
|
|
pReturn = pNextEnt;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( IRelationship( pNextEnt ) == iBestRelationship )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// this entity is disliked just as much as the entity that
|
|
|
|
// we currently think is the best visible enemy, so we only
|
|
|
|
// get mad at it if it is closer.
|
2017-06-29 15:56:03 +02:00
|
|
|
(int)iDist = ( pNextEnt->pev->origin - pev->origin ).Length();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( iDist <= iNearest )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
iNearest = iDist;
|
2016-07-31 15:48:50 +02:00
|
|
|
iBestRelationship = IRelationship( pNextEnt );
|
2016-06-04 15:24:23 +02:00
|
|
|
pReturn = pNextEnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pNextEnt = pNextEnt->m_pLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pReturn;
|
|
|
|
}
|