Update grunt repel

This commit is contained in:
Roman Chistokhodov 2019-08-01 06:46:44 +03:00
parent 865ea98475
commit f4e71b6143
5 changed files with 89 additions and 6 deletions

View File

@ -747,6 +747,14 @@ int CBaseEntity::DamageDecal( int bitsDamageType )
// NOTE: szName must be a pointer to constant memory, e.g. "monster_class" because the entity
// will keep a pointer to it after this call.
CBaseEntity *CBaseEntity::Create( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner )
{
CBaseEntity *pEntity = CreateNoSpawn(szName, vecOrigin, vecAngles, pentOwner);
if (pEntity)
DispatchSpawn( pEntity->edict() );
return pEntity;
}
CBaseEntity *CBaseEntity::CreateNoSpawn( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner )
{
edict_t *pent;
CBaseEntity *pEntity;
@ -761,6 +769,5 @@ CBaseEntity *CBaseEntity::Create( const char *szName, const Vector &vecOrigin, c
pEntity->pev->owner = pentOwner;
pEntity->pev->origin = vecOrigin;
pEntity->pev->angles = vecAngles;
DispatchSpawn( pEntity->edict() );
return pEntity;
}

View File

@ -349,6 +349,7 @@ public:
virtual void UpdateOwner( void ) { return; };
static CBaseEntity *Create( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner = NULL );
static CBaseEntity *CreateNoSpawn( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner = NULL );
virtual BOOL FBecomeProne( void ) {return FALSE;};
edict_t *edict() { return ENT( pev ); };

View File

@ -2909,13 +2909,64 @@ void CHFGrunt::DeclineFollowing( void )
// repelling down a line.
//=========================================================
class CHFGruntRepel : public CHGruntRepel
class CTalkMonsterRepel : public CHGruntRepel
{
public:
void KeyValue(KeyValueData* pkvd);
void PrepareBeforeSpawn(CBaseEntity* pEntity);
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
string_t m_iszUse;
string_t m_iszUnUse;
};
TYPEDESCRIPTION CTalkMonsterRepel::m_SaveData[] =
{
DEFINE_FIELD( CTalkMonsterRepel, m_iszUse, FIELD_STRING ),
DEFINE_FIELD( CTalkMonsterRepel, m_iszUnUse, FIELD_STRING ),
};
IMPLEMENT_SAVERESTORE( CTalkMonsterRepel, CHGruntRepel )
void CTalkMonsterRepel::KeyValue(KeyValueData *pkvd)
{
if( FStrEq( pkvd->szKeyName, "UseSentence" ) )
{
m_iszUse = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if( FStrEq( pkvd->szKeyName, "UnUseSentence" ) )
{
m_iszUnUse = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
CHGruntRepel::KeyValue( pkvd );
}
void CTalkMonsterRepel::PrepareBeforeSpawn(CBaseEntity *pEntity)
{
if (FBitSet(pev->spawnflags, SF_MONSTER_PREDISASTER))
{
SetBits(pEntity->pev->spawnflags, SF_MONSTER_PREDISASTER);
}
CTalkMonster* monster = (CTalkMonster*)pEntity;
monster->m_iszUse = m_iszUse;
monster->m_iszUnUse = m_iszUnUse;
}
class CHFGruntRepel : public CTalkMonsterRepel
{
public:
void KeyValue(KeyValueData* pkvd);
const char* TrooperName() {
return "monster_human_grunt_ally";
}
void PrepareBeforeSpawn(CBaseEntity* pEntity);
int Save( CSave &save );
int Restore( CRestore &restore );
@ -2931,7 +2982,7 @@ TYPEDESCRIPTION CHFGruntRepel::m_SaveData[] =
DEFINE_FIELD( CHFGruntRepel, m_iGruntHead, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CHFGruntRepel, CHGruntRepel )
IMPLEMENT_SAVERESTORE( CHFGruntRepel, CTalkMonsterRepel )
void CHFGruntRepel::KeyValue(KeyValueData *pkvd)
{
@ -2941,7 +2992,14 @@ void CHFGruntRepel::KeyValue(KeyValueData *pkvd)
pkvd->fHandled = TRUE;
}
else
CHGruntRepel::KeyValue( pkvd );
CTalkMonsterRepel::KeyValue( pkvd );
}
void CHFGruntRepel::PrepareBeforeSpawn(CBaseEntity *pEntity)
{
CHFGrunt* grunt = (CHFGrunt*)pEntity;
grunt->m_iHead = m_iGruntHead;
CTalkMonsterRepel::PrepareBeforeSpawn(pEntity);
}
class CMedicRepel : public CHFGruntRepel
@ -2954,7 +3012,7 @@ public:
LINK_ENTITY_TO_CLASS( monster_medic_ally_repel, CMedicRepel )
class CTorchRepel : public CHGruntRepel
class CTorchRepel : public CTalkMonsterRepel
{
public:
const char* TrooperName() {

View File

@ -2300,6 +2300,11 @@ const char* CHGruntRepel::TrooperName()
return "monster_human_grunt";
}
void CHGruntRepel::PrepareBeforeSpawn(CBaseEntity *pEntity)
{
}
void CHGruntRepel::Precache( void )
{
UTIL_PrecacheOther( TrooperName() );
@ -2315,7 +2320,7 @@ void CHGruntRepel::RepelUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_
return NULL;
*/
CBaseEntity *pEntity = Create( TrooperName(), pev->origin, pev->angles );
CBaseEntity *pEntity = CreateNoSpawn( TrooperName(), pev->origin, pev->angles );
if (!pEntity) {
UTIL_Remove( this );
return;
@ -2325,6 +2330,17 @@ void CHGruntRepel::RepelUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_
UTIL_Remove( this );
return;
}
const int knownFlags =
SF_MONSTER_GAG | SF_MONSTER_HITMONSTERCLIP |
SF_MONSTER_PRISONER | SF_SQUADMONSTER_LEADER;
const int flagsToSet = knownFlags & pev->spawnflags;
SetBits(pEntity->pev->spawnflags, flagsToSet);
pEntity->pev->netname = pev->netname;
pEntity->pev->weapons = pev->weapons;
PrepareBeforeSpawn(pEntity);
DispatchSpawn(pEntity->edict());
pGrunt->pev->movetype = MOVETYPE_FLY;
pGrunt->pev->velocity = Vector( 0, 0, RANDOM_FLOAT( -196, -128 ) );
pGrunt->SetActivity( ACT_GLIDE );

View File

@ -103,6 +103,7 @@ public:
void EXPORT RepelUse ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
int m_iSpriteTexture; // Don't save, precache
virtual const char* TrooperName();
virtual void PrepareBeforeSpawn(CBaseEntity* pEntity);
};
#endif // HGRUNT_H