Skip to content

Commit

Permalink
server: restructurized source code from scripted.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Mar 10, 2024
1 parent 0a36908 commit 7833cb8
Show file tree
Hide file tree
Showing 15 changed files with 1,242 additions and 1,160 deletions.
2 changes: 1 addition & 1 deletion server/defaultai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "defaultai.h"
#include "soundent.h"
#include "nodes.h"
#include "scripted.h"
#include "scripted_sequence.h"

//=========================================================
// Fail
Expand Down
182 changes: 182 additions & 0 deletions server/entities/aiscripted_sequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/***
*
* 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 "aiscripted_sequence.h"

// when a monster finishes an AI scripted sequence, we can choose
// a schedule to place them in. These defines are the aliases to
// resolve worldcraft input to real schedules (sjb)
#define SCRIPT_FINISHSCHED_DEFAULT 0
#define SCRIPT_FINISHSCHED_AMBUSH 1

LINK_ENTITY_TO_CLASS( aiscripted_sequence, CCineAI );

//=========================================================
// FCanOverrideState - returns true because scripted AI can
// possess entities regardless of their state.
//=========================================================
BOOL CCineAI :: FCanOverrideState( void )
{
return TRUE;
}

// make the entity carry out the scripted sequence instructions, but without
// destroying the monster's state.
void CCineAI :: PossessEntity( void )
{
Schedule_t *pNewSchedule;

CBaseEntity *pEntity = m_hTargetEnt;
CBaseMonster *pTarget = NULL;
if ( pEntity )
pTarget = pEntity->MyMonsterPointer();

if ( pTarget )
{
if ( !pTarget->CanPlaySequence( FCanOverrideState(), SS_INTERRUPT_AI ) )
{
ALERT( at_aiconsole, "(AI)Can't possess entity %s\n", STRING(pTarget->pev->classname) );
return;
}

pTarget->m_pGoalEnt = this;
pTarget->m_pCine = this;
pTarget->m_hTargetEnt = this;

m_saved_movetype = pTarget->pev->movetype;
m_saved_solid = pTarget->pev->solid;
m_saved_effects = pTarget->pev->effects;
pTarget->pev->effects |= pev->effects;
Vector vecTargetAngles;

switch (m_fMoveTo)
{
case 0:
case 5:
pTarget->m_scriptState = SCRIPT_WAIT;
break;

case 1:
pTarget->m_scriptState = SCRIPT_WALK_TO_MARK;
break;

case 2:
pTarget->m_scriptState = SCRIPT_RUN_TO_MARK;
break;

case 4:
// zap the monster instantly to the site of the script entity.
UTIL_SetOrigin( pTarget, GetAbsOrigin() );
pTarget->pev->ideal_yaw = GetAbsAngles().y;
pTarget->SetLocalAvelocity( g_vecZero );
pTarget->SetLocalVelocity( g_vecZero );
pTarget->pev->effects |= EF_NOINTERP;
vecTargetAngles = pTarget->GetLocalAngles();
vecTargetAngles.y = GetAbsAngles().y;
pTarget->SetLocalAngles( vecTargetAngles );
pTarget->m_scriptState = SCRIPT_WAIT;
m_startTime = gpGlobals->time + 1E6;
// UNDONE: Add a flag to do this so people can fixup physics after teleporting monsters
pTarget->pev->flags &= ~FL_ONGROUND;
break;
default:
ALERT ( at_aiconsole, "aiscript: invalid Move To Position value!" );
break;
}

ALERT( at_aiconsole, "\"%s\" found and used\n", STRING( pTarget->pev->targetname ) );

pTarget->m_IdealMonsterState = MONSTERSTATE_SCRIPT;

/*
if (m_iszIdle)
{
StartSequence( pTarget, m_iszIdle, FALSE );
if (FStrEq( STRING(m_iszIdle), STRING(m_iszPlay)))
{
pTarget->pev->framerate = 0;
}
}
*/
// Already in a scripted state?
if ( pTarget->m_MonsterState == MONSTERSTATE_SCRIPT )
{
pNewSchedule = pTarget->GetScheduleOfType( SCHED_AISCRIPT );
pTarget->ChangeSchedule( pNewSchedule );
}
}
}



// lookup a sequence name and setup the target monster to play it
// overridden for CCineAI because it's ok for them to not have an animation sequence
// for the monster to play. For a regular Scripted Sequence, that situation is an error.
BOOL CCineAI :: StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty )
{
if ( iszSeq == 0 && completeOnEmpty )
{
// no sequence was provided. Just let the monster proceed, however, we still have to fire any Sequence target
// and remove any non-repeatable CineAI entities here ( because there is code elsewhere that handles those tasks, but
// not until the animation sequence is finished. We have to manually take care of these things where there is no sequence.

SequenceDone ( pTarget );

return TRUE;
}

pTarget->pev->sequence = pTarget->LookupSequence( STRING( iszSeq ) );

if (pTarget->pev->sequence == -1)
{
ALERT( at_error, "%s: unknown aiscripted sequence \"%s\"\n", STRING( pTarget->pev->targetname ), STRING( iszSeq) );
pTarget->pev->sequence = 0;
// return FALSE;
}

pTarget->pev->frame = 0;
pTarget->ResetSequenceInfo( );
return TRUE;
}

//=========================================================
// When a monster finishes a scripted sequence, we have to
// fix up its state and schedule for it to return to a
// normal AI monster.
//
// AI Scripted sequences will, depending on what the level
// designer selects:
//
// -Dirty the monster's schedule and drop out of the
// sequence in their current state.
//
// -Select a specific AMBUSH schedule, regardless of state.
//=========================================================
void CCineAI :: FixScriptMonsterSchedule( CBaseMonster *pMonster )
{
switch ( m_iFinishSchedule )
{
case SCRIPT_FINISHSCHED_DEFAULT:
pMonster->ClearSchedule();
break;
case SCRIPT_FINISHSCHED_AMBUSH:
pMonster->ChangeSchedule( pMonster->GetScheduleOfType( SCHED_AMBUSH ) );
break;
default:
ALERT ( at_aiconsole, "FixScriptMonsterSchedule - no case!\n" );
pMonster->ClearSchedule();
break;
}
}
30 changes: 30 additions & 0 deletions server/entities/aiscripted_sequence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***
*
* 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.
*
***/

#pragma once
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "scripted_sequence.h"

class CCineAI : public CCineMonster
{
DECLARE_CLASS( CCineAI, CCineMonster );
public:
BOOL StartSequence( CBaseMonster *pTarget, int iszSeq, BOOL completeOnEmpty );
void PossessEntity( void );
BOOL FCanOverrideState ( void );
virtual void FixScriptMonsterSchedule( CBaseMonster *pMonster );
};
57 changes: 57 additions & 0 deletions server/entities/monster_furniture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/***
*
* 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 "monster_furniture.h"

LINK_ENTITY_TO_CLASS( monster_furniture, CFurniture );

//=========================================================
// Furniture is killed
//=========================================================
void CFurniture :: Die ( void )
{
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time;
}

//=========================================================
// This used to have something to do with bees flying, but
// now it only initializes moving furniture in scripted sequences
//=========================================================
void CFurniture :: Spawn( )
{
PRECACHE_MODEL((char *)STRING(pev->model));
SET_MODEL(ENT(pev), STRING(pev->model));

pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_BBOX;
pev->health = 80000;
pev->takedamage = DAMAGE_AIM;
pev->yaw_speed = 0;
pev->sequence = 0;
pev->frame = 0;

ResetSequenceInfo( );
pev->frame = 0;
MonsterInit();
}

//=========================================================
// ID's Furniture as neutral (noone will attack it)
//=========================================================
int CFurniture::Classify ( void )
{
return m_iClass ? m_iClass : CLASS_NONE;
}
32 changes: 32 additions & 0 deletions server/entities/monster_furniture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/***
*
* 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.
*
***/

#pragma once
#include "extdll.h"
#include "util.h"
#include "cbase.h"

//=========================================================
// Furniture - this is the cool comment I cut-and-pasted
//=========================================================
class CFurniture : public CBaseMonster
{
DECLARE_CLASS( CFurniture, CBaseMonster );
public:
void Spawn ( void );
void Die( void );
int Classify ( void );
virtual int ObjectCaps( void ) { return (BaseClass :: ObjectCaps() & ~FCAP_ACROSS_TRANSITION); }
};
Loading

0 comments on commit 7833cb8

Please sign in to comment.