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.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
//=========================================================
|
|
|
|
// 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
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// MonsterMaker - this ent creates monsters during the game.
|
|
|
|
//=========================================================
|
|
|
|
class CMonsterMaker : public CBaseMonster
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData* pkvd);
|
2016-07-31 15:48:50 +02:00
|
|
|
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.
|
2016-06-04 15:24:23 +02:00
|
|
|
void MakeMonster( void );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
string_t m_iszMonsterClassname;// classname of the monster(s) that will be created.
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int m_cNumMonsters;// max number of monsters this ent can create
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
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.
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
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?
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( monstermaker, CMonsterMaker )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
TYPEDESCRIPTION CMonsterMaker::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CMonsterMaker, CBaseMonster )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::KeyValue( KeyValueData *pkvd )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "monstercount" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_cNumMonsters = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_imaxlivechildren" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iMaxLiveChildren = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "monstertype" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_iszMonsterClassname = ALLOC_STRING( pkvd->szValue );
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CBaseMonster::KeyValue( pkvd );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::Spawn()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
|
|
|
|
m_cLiveChildren = 0;
|
|
|
|
Precache();
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( pev->targetname ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_MONSTERMAKER_CYCLIC )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SetUse( &CMonsterMaker::CyclicUse );// drop one monster each time we fire
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetUse( &CMonsterMaker::ToggleUse );// so can be turned on/off
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FBitSet( pev->spawnflags, SF_MONSTERMAKER_START_ON ) )
|
2016-06-25 18:33:39 +02:00
|
|
|
{
|
|
|
|
// start making monsters as soon as monstermaker spawns
|
2016-06-04 15:24:23 +02:00
|
|
|
m_fActive = TRUE;
|
|
|
|
SetThink( &CMonsterMaker::MakerThink );
|
|
|
|
}
|
|
|
|
else
|
2016-06-25 18:33:39 +02:00
|
|
|
{
|
|
|
|
// wait to be activated.
|
2016-06-04 15:24:23 +02:00
|
|
|
m_fActive = FALSE;
|
|
|
|
SetThink( &CBaseEntity::SUB_DoNothing );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-06-25 18:33:39 +02:00
|
|
|
{
|
|
|
|
// no targetname, just start.
|
|
|
|
pev->nextthink = gpGlobals->time + m_flDelay;
|
|
|
|
m_fActive = TRUE;
|
|
|
|
SetThink( &CMonsterMaker::MakerThink );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_cNumMonsters == 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_fFadeChildren = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fFadeChildren = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flGround = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseMonster::Precache();
|
|
|
|
|
|
|
|
UTIL_PrecacheOther( STRING( m_iszMonsterClassname ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// MakeMonster- this is the code that drops the monster
|
|
|
|
//=========================================================
|
|
|
|
void CMonsterMaker::MakeMonster( void )
|
|
|
|
{
|
|
|
|
edict_t *pent;
|
2016-07-31 15:48:50 +02:00
|
|
|
entvars_t *pevCreate;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_iMaxLiveChildren > 0 && m_cLiveChildren >= m_iMaxLiveChildren )
|
2016-06-25 18:33:39 +02:00
|
|
|
{
|
|
|
|
// not allowed to make a new one yet. Too many live ones out right now.
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !m_flGround )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// set altitude. Now that I'm activated, any breakables, etc should be out from under me.
|
|
|
|
TraceResult tr;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( pev->origin, pev->origin - Vector( 0, 0, 2048 ), ignore_monsters, ENT( pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
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];
|
2016-07-31 15:48:50 +02:00
|
|
|
int count = UTIL_EntitiesInBox( pList, 2, mins, maxs, FL_CLIENT | FL_MONSTER );
|
|
|
|
if( count )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// don't build a stack of monsters!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pent = CREATE_NAMED_ENTITY( m_iszMonsterClassname );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FNullEnt( pent ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
ALERT ( at_console, "NULL Ent in MonsterMaker!\n" );
|
|
|
|
return;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// If I have a target, fire!
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( pev->target ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// delay already overloaded for this entity, so can't call SUB_UseTargets()
|
2016-07-31 15:48:50 +02:00
|
|
|
FireTargets( STRING( pev->target ), this, this, USE_TOGGLE, 0 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pevCreate = VARS( pent );
|
|
|
|
pevCreate->origin = pev->origin;
|
|
|
|
pevCreate->angles = pev->angles;
|
|
|
|
SetBits( pevCreate->spawnflags, SF_MONSTER_FALL_TO_GROUND );
|
|
|
|
|
|
|
|
// Children hit monsterclip brushes
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & SF_MONSTERMAKER_MONSTERCLIP )
|
2016-06-04 15:24:23 +02:00
|
|
|
SetBits( pevCreate->spawnflags, SF_MONSTER_HITMONSTERCLIP );
|
|
|
|
|
|
|
|
DispatchSpawn( ENT( pevCreate ) );
|
|
|
|
pevCreate->owner = edict();
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( pev->netname ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// if I have a netname (overloaded), give the child monster that name as a targetname
|
|
|
|
pevCreate->targetname = pev->netname;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cLiveChildren++;// count this monster
|
|
|
|
m_cNumMonsters--;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_cNumMonsters == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::CyclicUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
MakeMonster();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// ToggleUse - activates/deactivates the monster maker
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !ShouldToggle( useType, m_fActive ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_fActive )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_fActive = FALSE;
|
|
|
|
SetThink( NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fActive = TRUE;
|
|
|
|
SetThink( &CMonsterMaker::MakerThink );
|
|
|
|
}
|
|
|
|
|
|
|
|
pev->nextthink = gpGlobals->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// MakerThink - creates a new monster every so often
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::MakerThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->nextthink = gpGlobals->time + m_flDelay;
|
|
|
|
|
|
|
|
MakeMonster();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
//=========================================================
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMonsterMaker::DeathNotice( entvars_t *pevChild )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// ok, we've gotten the deathnotice from our child, now clear out its owner if we don't want it to fade.
|
|
|
|
m_cLiveChildren--;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !m_fFadeChildren )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pevChild->owner = NULL;
|
|
|
|
}
|
|
|
|
}
|