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.

413 lines
11 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.
*
* 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.
*
****/
//=========================================================
// Monster Maker - this is an entity that creates monsters
// in the game.
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "saverestore.h"
// Monstermaker spawnflags
#define SF_MONSTERMAKER_START_ON 1 // start active ( if has targetname )
#define SF_MONSTERMAKER_CYCLIC 4 // drop one monster every time fired.
#define SF_MONSTERMAKER_MONSTERCLIP 8 // Children are blocked by monsterclip
//=============modif de Julien
#define SF_MONSTERMAKER_GAG 32
#define SF_MONSTERMAKER_PRISONER 64
#define SF_MONSTERMAKER_SQUADLEADER 128
#define SF_MONSTERMAKER_PREDISASTER 256
#define SF_MONSTERMAKER_WAITFORSCRIPT 512
#define SF_MONSTERMAKER_SENTRY 1024
#define SF_MONSTERMAKER_L3M3 2048
#define SF_MONSTERMAKER_FLASHLIGHT 16
//=========
9 years ago
//=========================================================
// MonsterMaker - this ent creates monsters during the game.
//=========================================================
class CMonsterMaker : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void KeyValue( KeyValueData* pkvd);
8 years ago
void EXPORT ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT CyclicUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT MakerThink( void );
void DeathNotice( entvars_t *pevChild );// monster maker children use this to tell the monster maker that they have died.
9 years ago
void MakeMonster( void );
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
9 years ago
8 years ago
static TYPEDESCRIPTION m_SaveData[];
9 years ago
string_t m_iszMonsterClassname;// classname of the monster(s) that will be created.
8 years ago
int m_cNumMonsters;// max number of monsters this ent can create
9 years ago
8 years ago
int m_cLiveChildren;// how many monsters made by this monster maker that are currently alive
int m_iMaxLiveChildren;// max number of monsters that this maker may have out at one time.
9 years ago
float m_flGround; // z coord of the ground under me, used to make sure no monsters are under the maker when it drops a new child
BOOL m_fActive;
BOOL m_fFadeChildren;// should we make the children fadeout?
//======== modifs de Julien
int m_iMBody; // permet de choisir la t
int m_iMWeapon; // et l'arme du grunt
int m_iTriggerCondition;
string_t m_iszTriggerTarget;// name of target that should be fired.
//=================
9 years ago
};
LINK_ENTITY_TO_CLASS( monstermaker, CMonsterMaker )
9 years ago
TYPEDESCRIPTION CMonsterMaker::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CMonsterMaker, m_iszMonsterClassname, FIELD_STRING ),
DEFINE_FIELD( CMonsterMaker, m_cNumMonsters, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_cLiveChildren, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_flGround, FIELD_FLOAT ),
DEFINE_FIELD( CMonsterMaker, m_iMaxLiveChildren, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_fActive, FIELD_BOOLEAN ),
DEFINE_FIELD( CMonsterMaker, m_fFadeChildren, FIELD_BOOLEAN ),
// modifs de Julien
DEFINE_FIELD( CMonsterMaker, m_iMBody, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_iMWeapon, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_iTriggerCondition, FIELD_INTEGER ),
DEFINE_FIELD( CMonsterMaker, m_iszTriggerTarget, FIELD_STRING ),
//=============
9 years ago
};
IMPLEMENT_SAVERESTORE( CMonsterMaker, CBaseMonster )
9 years ago
8 years ago
void CMonsterMaker::KeyValue( KeyValueData *pkvd )
9 years ago
{
8 years ago
if( FStrEq( pkvd->szKeyName, "monstercount" ) )
9 years ago
{
8 years ago
m_cNumMonsters = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "m_imaxlivechildren" ) )
9 years ago
{
8 years ago
m_iMaxLiveChildren = atoi( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "monstertype" ) )
9 years ago
{
m_iszMonsterClassname = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
//===========modifs de Julien
else if ( FStrEq(pkvd->szKeyName, "m_imbody") )
{
m_iMBody = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "m_imweapon") )
{
m_iMWeapon = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "TriggerTarget"))
{
m_iszTriggerTarget = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "TriggerCondition") )
{
m_iTriggerCondition = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
//==============
9 years ago
else
CBaseMonster::KeyValue( pkvd );
}
8 years ago
void CMonsterMaker::Spawn()
9 years ago
{
pev->solid = SOLID_NOT;
m_cLiveChildren = 0;
Precache();
8 years ago
if( !FStringNull( pev->targetname ) )
9 years ago
{
8 years ago
if( pev->spawnflags & SF_MONSTERMAKER_CYCLIC )
9 years ago
{
SetUse( &CMonsterMaker::CyclicUse );// drop one monster each time we fire
}
else
{
SetUse( &CMonsterMaker::ToggleUse );// so can be turned on/off
}
8 years ago
if( FBitSet( pev->spawnflags, SF_MONSTERMAKER_START_ON ) )
{
// start making monsters as soon as monstermaker spawns
9 years ago
m_fActive = TRUE;
SetThink( &CMonsterMaker::MakerThink );
}
else
{
// wait to be activated.
9 years ago
m_fActive = FALSE;
SetThink( &CBaseEntity::SUB_DoNothing );
}
}
else
{
// no targetname, just start.
pev->nextthink = gpGlobals->time + m_flDelay;
m_fActive = TRUE;
SetThink( &CMonsterMaker::MakerThink );
9 years ago
}
8 years ago
if( m_cNumMonsters == 1 )
9 years ago
{
m_fFadeChildren = FALSE;
}
else
{
m_fFadeChildren = TRUE;
}
m_flGround = 0;
}
8 years ago
void CMonsterMaker::Precache( void )
9 years ago
{
CBaseMonster::Precache();
UTIL_PrecacheOther( STRING( m_iszMonsterClassname ) );
}
//=========================================================
// MakeMonster- this is the code that drops the monster
//=========================================================
void CMonsterMaker::MakeMonster( void )
{
edict_t *pent;
8 years ago
entvars_t *pevCreate;
9 years ago
8 years ago
if( m_iMaxLiveChildren > 0 && m_cLiveChildren >= m_iMaxLiveChildren )
{
// not allowed to make a new one yet. Too many live ones out right now.
9 years ago
return;
}
8 years ago
if( !m_flGround )
9 years ago
{
// set altitude. Now that I'm activated, any breakables, etc should be out from under me.
TraceResult tr;
8 years ago
UTIL_TraceLine( pev->origin, pev->origin - Vector( 0, 0, 2048 ), ignore_monsters, ENT( pev ), &tr );
9 years ago
m_flGround = tr.vecEndPos.z;
}
Vector mins = pev->origin - Vector( 34, 34, 0 );
Vector maxs = pev->origin + Vector( 34, 34, 0 );
maxs.z = pev->origin.z;
mins.z = m_flGround;
CBaseEntity *pList[2];
8 years ago
int count = UTIL_EntitiesInBox( pList, 2, mins, maxs, FL_CLIENT | FL_MONSTER );
if( count )
9 years ago
{
// don't build a stack of monsters!
return;
}
pent = CREATE_NAMED_ENTITY( m_iszMonsterClassname );
8 years ago
if( FNullEnt( pent ) )
9 years ago
{
ALERT ( at_console, "NULL Ent in MonsterMaker!\n" );
return;
}
8 years ago
9 years ago
// If I have a target, fire!
8 years ago
if( !FStringNull( pev->target ) )
9 years ago
{
// delay already overloaded for this entity, so can't call SUB_UseTargets()
8 years ago
FireTargets( STRING( pev->target ), this, this, USE_TOGGLE, 0 );
9 years ago
}
pevCreate = VARS( pent );
pevCreate->origin = pev->origin;
pevCreate->angles = pev->angles;
SetBits( pevCreate->spawnflags, SF_MONSTER_FALL_TO_GROUND );
// Children hit monsterclip brushes
8 years ago
if( pev->spawnflags & SF_MONSTERMAKER_MONSTERCLIP )
9 years ago
SetBits( pevCreate->spawnflags, SF_MONSTER_HITMONSTERCLIP );
//============
/* modifs de Julien */
//============
if ( m_iMBody != -2 ) // s
{
pevCreate->body = m_iMBody;
}
if ( m_iMWeapon != 0 ) // s
{
pevCreate->weapons = m_iMWeapon;
}
if ( FClassnameIs( pevCreate, STRING(m_iszMonsterClassname) ) && m_iMWeapon == 0 )
{
pevCreate->weapons = 1;
}
CBaseMonster* pCreate = ( CBaseMonster* ) CBaseEntity::Instance( pevCreate );
pCreate->m_iTriggerCondition = m_iTriggerCondition;
pCreate->m_iszTriggerTarget = m_iszTriggerTarget;
if ( pev->spawnflags & SF_MONSTERMAKER_GAG )
SetBits( pevCreate->spawnflags, SF_MONSTER_GAG );
if ( pev->spawnflags & SF_MONSTERMAKER_PRISONER )
SetBits( pevCreate->spawnflags, SF_MONSTER_PRISONER );
if ( pev->spawnflags & SF_MONSTERMAKER_SQUADLEADER )
SetBits( pevCreate->spawnflags, 32 ); // 32 == SF_SQUADMONSTER_LEADER, inconnu ici
if ( pev->spawnflags & SF_MONSTERMAKER_PREDISASTER )
SetBits( pevCreate->spawnflags, SF_MONSTER_PREDISASTER );
if ( pev->spawnflags & SF_MONSTERMAKER_WAITFORSCRIPT )
SetBits( pevCreate->spawnflags, SF_MONSTER_WAIT_FOR_SCRIPT );
//=============
//=============
9 years ago
DispatchSpawn( ENT( pevCreate ) );
pevCreate->owner = edict();
8 years ago
if( !FStringNull( pev->netname ) )
9 years ago
{
// if I have a netname (overloaded), give the child monster that name as a targetname
pevCreate->targetname = pev->netname;
}
//modif de Julien
if ( pev->spawnflags & SF_MONSTERMAKER_L3M3 )
{
CBaseMonster *pMonster = NULL;
pMonster = (CBaseMonster*)(CBaseEntity::Instance( pevCreate ));
pMonster->m_hEnemy = CBaseEntity :: Instance ( FIND_ENTITY_BY_CLASSNAME( NULL, "player" ) );
pMonster->SetState ( MONSTERSTATE_COMBAT );
}
// modif de Julien
if ( pev->spawnflags & SF_MONSTERMAKER_SENTRY && FClassnameIs ( pevCreate, "monster_sentry" ) )
{
pevCreate->spawnflags |= 1024; // SF_MONSTER_TURRET_INVINCIBLE = 1024
}
if ( pev->spawnflags & SF_MONSTERMAKER_SENTRY && FClassnameIs ( pevCreate, "monster_human_grunt" ) )
{
pevCreate->spawnflags |= 256; // SF_GRUNT_INVINCIBLE = 256
}
if ( pev->spawnflags & SF_MONSTERMAKER_FLASHLIGHT && FClassnameIs ( pevCreate, "monster_human_grunt" ) )
{
pevCreate->spawnflags |= 64; // SF_GRUNT_FLASHLIGHT = 64
}
9 years ago
m_cLiveChildren++;// count this monster
m_cNumMonsters--;
8 years ago
if( m_cNumMonsters == 0 )
9 years ago
{
// Disable this forever. Don't kill it because it still gets death notices
SetThink( NULL );
SetUse( NULL );
}
}
//=========================================================
// CyclicUse - drops one monster from the monstermaker
// each time we call this.
//=========================================================
8 years ago
void CMonsterMaker::CyclicUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
9 years ago
{
MakeMonster();
}
//=========================================================
// ToggleUse - activates/deactivates the monster maker
//=========================================================
8 years ago
void CMonsterMaker::ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
9 years ago
{
8 years ago
if( !ShouldToggle( useType, m_fActive ) )
9 years ago
return;
8 years ago
if( m_fActive )
9 years ago
{
m_fActive = FALSE;
SetThink( NULL );
}
else
{
m_fActive = TRUE;
SetThink( &CMonsterMaker::MakerThink );
}
pev->nextthink = gpGlobals->time;
}
//=========================================================
// MakerThink - creates a new monster every so often
//=========================================================
8 years ago
void CMonsterMaker::MakerThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + m_flDelay;
MakeMonster();
}
//=========================================================
//=========================================================
8 years ago
void CMonsterMaker::DeathNotice( entvars_t *pevChild )
9 years ago
{
// ok, we've gotten the deathnotice from our child, now clear out its owner if we don't want it to fade.
m_cLiveChildren--;
8 years ago
if( !m_fFadeChildren )
9 years ago
{
pevChild->owner = NULL;
}
}