📄 scriptslave.cpp
字号:
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/scriptslave.cpp $
// $Revision:: 80 $
// $Author:: Markd $
// $Date:: 10/28/98 8:37p $
//
// Copyright (C) 1997 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/scriptslave.cpp $
//
// 80 10/28/98 8:37p Markd
// Added notshootable functionality
//
// 79 10/27/98 9:15p Jimdose
// overrode bind and unbind events
//
// 78 10/25/98 4:22a Markd
// Changed explode command for scriptslaves
//
// 77 10/24/98 2:08p Aldie
// Added func_volumetric
//
// 76 10/24/98 12:42a Markd
// changed origins to worldorigins where appropriate
//
// 75 10/23/98 10:04p Markd
// Added explode event
//
// 74 10/19/98 12:07a Jimdose
// made all code use fast checks for inheritance (no text lookups when
// possible)
// isSubclassOf no longer requires ::_classinfo()
//
// 73 10/14/98 10:18p Jimdose
// made DoMove not return if event's thread was NULL
//
// 72 9/23/98 11:00p Markd
// put in some garbage collection on stuff that wasn't freed up
//
// 71 9/23/98 9:28p Jimdose
// Made thread callback functions clear their labels if the thread is NULL.
// Also removed assertion from callback functions
//
// 70 9/22/98 5:20p Markd
// Put in new consolidated gib function
//
// 69 9/22/98 3:21p Markd
// put in parentmode lockout for blood and gibs
//
// 68 8/22/98 9:33p Markd
// Put in code which would ensure that threads are valid when gotten from the
// event
//
// 67 8/21/98 3:47p Markd
// Added new rotation commands
//
// 66 8/21/98 1:45a Markd
// Added RotateDownTo, RotateUpTo and RotateTo
//
// 65 8/20/98 4:31p Markd
// Added vector support to moveto and jumpto
//
// 64 8/17/98 7:31p Jimdose
// DoMove only sets moveThread if the specified thread is waiting for that
// entity
//
// 63 7/31/98 4:21p Jimdose
// Made events statically created instead of dynamic
//
// 62 7/24/98 7:37p Aldie
// Added feather gibs
//
// 61 7/23/98 6:17p Aldie
// Updated damage system and fixed some damage related bugs. Also put tracers
// back to the way they were, and added gib event to funcscriptmodels
//
// 60 7/22/98 3:48p Jimdose
// Changed damage to an event function. Fixed the slaves not responding to
// damage
//
// 59 7/22/98 12:52p Markd
// tweaked the waitfor on Following Path stuff
//
// 58 7/21/98 10:05p Markd
// Added starttime to followpath
//
// 57 7/21/98 5:32p Jimdose
// DoMove now posts a move done event if no commands are waiting so that any
// waitFor's that are called after a slave has finished it's move won't be
// stuck forever
//
// 56 7/21/98 4:23p Aldie
// Make icons work for locks
//
// 55 7/21/98 1:10p Aldie
// Added meansofdeath to obituaries
//
// 54 7/19/98 4:25p Markd
// Added "other" and "key" support to usethread
//
// 53 7/19/98 3:42p Markd
// Added ondamage variables
//
// 52 7/18/98 3:53p Markd
// Added key support to scriptslave
//
// 51 7/11/98 6:31p Markd
// removed valid orientation, simplified code
//
// 50 7/10/98 1:55p Markd
// when checking for end of spline, had to do a > rather than a >=
//
// 49 7/10/98 1:11p Markd
// Added some more functionality to spline based movement
//
// 48 7/09/98 11:53p Markd
// Added non-orientation support for spline_paths
//
// 47 7/09/98 9:39p Jimdose
// Removed RF_CONSOLE
//
// 46 7/08/98 8:54p Markd
// maybe I didn't need to invert pitch!
//
// 45 7/08/98 12:55p Markd
// forgot to invert pitch on spline based stuff
//
// 44 7/08/98 12:42p Markd
// Added followpath and resumepath and followingpath for spline based movement
//
// 43 6/18/98 8:47p Jimdose
// Added better event error handling
// Added source info to events
//
// 42 6/11/98 11:52a Aldie
// Updated scriptslave damage function to use all the same parms as the
// entity::damage function.
//
// 41 6/10/98 2:10p Aldie
// Updated damage function.
//
// 40 5/24/98 8:46p Jimdose
// Made a lot of functions more str-friendly.
// Got rid of a lot of char * based strings
// Cleaned up get spawn arg functions and sound functions
// sound functions now use consistant syntax
//
// 39 5/24/98 4:48p Jimdose
// Made char *'s const
//
// 38 5/24/98 2:46p Markd
// Made char *'s into const char *'s
//
// 37 5/23/98 4:48p Aldie
// Removed RF_CONSOLE from script object
//
// 36 5/20/98 4:32p Markd
// bullet proofed thread code and made sure that thread variable was non-null
//
// 35 5/19/98 9:52p Markd
// added not_damage flag to objects
//
// 34 5/03/98 4:37p Jimdose
// Changed Vector class
//
// 33 5/01/98 5:08p Jimdose
// TriggerEvent now specifies world as the activator
//
// 32 4/29/98 7:13p Jimdose
// forgot an else. :(
//
// 31 4/29/98 6:34p Jimdose
// Made ScriptSlave use SOLID_NOT when there's a NULL model
//
// 30 4/29/98 6:30p Jimdose
// Added ScriptOrigin
//
// 29 4/25/98 5:09p Markd
// Added up and down support for angles
//
// 28 4/20/98 11:01a Markd
// Fixed client side prediction of non-solid shootables
//
// 27 4/18/98 7:30p Markd
// Made func_scriptmodel not have any dimension
//
// 26 4/18/98 6:10p Aldie
// Added RF_CONSOLE to script objects so users can render consoles on them.
//
// 25 4/09/98 1:40p Markd
// Added in CONTENTS_SHOOTABLE stuff
//
// 24 4/08/98 4:20p Jimdose
// Added NOT_SOLID spawnflag
//
// 23 4/07/98 9:34p Jimdose
// Scriptobjects respond to damage
//
// 22 4/07/98 8:00p Markd
// removed defhandle, changed all SINMDL calls to modelindex calls, removed
// SINMDL prefix
//
// 21 4/06/98 3:55p Jimdose
// Since RF_FRAMELERP is now cleared out every frame, ClearLerp was redundant
//
// 20 4/05/98 1:59a Jimdose
// Made Jumpto prevent lerping of the models position
// Added ScriptModel for amodel-based script objects
//
// 19 3/31/98 2:27p Jimdose
// Cleared out the angles at start
//
// 18 3/30/98 8:09p Jimdose
// Made forward and backward use the start angle
//
// 17 3/24/98 4:58p Jimdose
// Added NewOrders to indicate when the slave should update NewAngles
// Fixed typo related bugs in touch, block, use, damage callback functions
//
// 16 3/23/98 1:31p Jimdose
// Revamped event and command system
//
// 15 3/02/98 8:49p Jimdose
// Changed the classid parameter of CLASS_DECLARATION to a quoted string so
// that you could have a NULL classid.
//
// 14 2/21/98 1:11p Jimdose
// Fixed bug where EVENT_SCRIPTSLAVE_MOVEDONE was allowing the event to pass to
// the superclass
//
// 13 2/18/98 8:07p Jimdose
// Changed pointers to scriptMaster to entity numbers
// Changed direct calls to the master into events
//
// 12 2/17/98 8:34p Jimdose
// Fixed NULL pointer problem in the onTouch, etc, functions
//
// 11 2/17/98 7:09p Jimdose
// no longer pass script into interpretCommand
// added error handling for invalid labels
//
// 10 2/16/98 2:15p Jimdose
// Added script commands rotateX, rotateY, and rotateZ for continual arbitrary
// rotation
//
// 9 2/06/98 5:38p Jimdose
// Added check for null jumpto in onTouch, onBlock, onDamage, etc.
//
// 8 2/03/98 10:44a Jimdose
// Updated to work with Quake 2 engine
//
// 6 10/28/97 4:15p Jimdose
// Removed CommandsWaiting.
// Moved "bind" and "unBind" commands into Entity
// Made DoMove be called when "processCommands" message is sent.
//
// 5 10/27/97 3:29p Jimdose
// Removed dependency on quakedef.h
//
// 4 10/22/97 12:25p Jimdose
// Fixed bug where slave wouldn't damage other entities when they blocked it.
//
// 3 9/26/97 5:23p Jimdose
// Added standard Ritual headers
//
// DESCRIPTION:
// Standard scripted objects. Controlled by ScriptThread. These objects
// are bmodel objects created in the editor and controlled by an external
// text based script. Commands are interpretted on by one and executed
// upon a signal from the script master. The base script object can
// perform several different relative and specific rotations and translations
// and can cause other parts of the script to be executed when touched, damaged,
// touched, or used.
//
#include "g_local.h"
#include "class.h"
#include "mover.h"
#include "scriptmaster.h"
#include "scriptslave.h"
#include "sentient.h"
#include "item.h"
#include "gibs.h"
#include "explosion.h"
/*****************************************************************************/
/*SINED func_scriptobject (0 .5 .8) ? NOT_SOLID
/*****************************************************************************/
CLASS_DECLARATION( Mover, ScriptSlave, "func_scriptobject" );
Event EV_ScriptSlave_DoMove( "processCommands" );
Event EV_ScriptSlave_NewOrders( "newOrders" );
Event EV_ScriptSlave_Angles( "angles" );
Event EV_ScriptSlave_Trigger( "trigger" );
Event EV_ScriptSlave_Next( "next" );
Event EV_ScriptSlave_JumpTo( "jumpto" );
Event EV_ScriptSlave_MoveTo( "moveto" );
Event EV_ScriptSlave_Speed( "speed" );
Event EV_ScriptSlave_Time( "time" );
Event EV_ScriptSlave_MoveUp( "moveUp" );
Event EV_ScriptSlave_MoveDown( "moveDown" );
Event EV_ScriptSlave_MoveNorth( "moveNorth" );
Event EV_ScriptSlave_MoveSouth( "moveSouth" );
Event EV_ScriptSlave_MoveEast( "moveEast" );
Event EV_ScriptSlave_MoveWest( "moveWest" );
Event EV_ScriptSlave_MoveForward( "moveForward" );
Event EV_ScriptSlave_MoveBackward( "moveBackward" );
Event EV_ScriptSlave_MoveLeft( "moveLeft" );
Event EV_ScriptSlave_MoveRight( "moveRight" );
Event EV_ScriptSlave_RotateXDownTo( "rotateXdownto" );
Event EV_ScriptSlave_RotateYDownTo( "rotateYdownto" );
Event EV_ScriptSlave_RotateZDownTo( "rotateZdownto" );
Event EV_ScriptSlave_RotateAxisDownTo( "rotateaxisdownto" );
Event EV_ScriptSlave_RotateXUpTo( "rotateXupto" );
Event EV_ScriptSlave_RotateYUpTo( "rotateYupto" );
Event EV_ScriptSlave_RotateZUpTo( "rotateZupto" );
Event EV_ScriptSlave_RotateAxisUpTo( "rotateaxisupto" );
Event EV_ScriptSlave_RotateXDown( "rotateXdown" );
Event EV_ScriptSlave_RotateYDown( "rotateYdown" );
Event EV_ScriptSlave_RotateZDown( "rotateZdown" );
Event EV_ScriptSlave_RotateAxisDown( "rotateaxisdown" );
Event EV_ScriptSlave_RotateXUp( "rotateXup" );
Event EV_ScriptSlave_RotateYUp( "rotateYup" );
Event EV_ScriptSlave_RotateZUp( "rotateZup" );
Event EV_ScriptSlave_RotateAxisUp( "rotateaxisup" );
Event EV_ScriptSlave_RotateX( "rotateX" );
Event EV_ScriptSlave_RotateY( "rotateY" );
Event EV_ScriptSlave_RotateZ( "rotateZ" );
Event EV_ScriptSlave_RotateAxis( "rotateaxis" );
Event EV_ScriptSlave_RotateDownTo( "rotatedownto" );
Event EV_ScriptSlave_RotateUpTo( "rotateupto" );
Event EV_ScriptSlave_RotateTo( "rotateto" );
Event EV_ScriptSlave_OnTouch( "ontouch" );
Event EV_ScriptSlave_NoTouch( "notouch" );
Event EV_ScriptSlave_OnUse( "onuse" );
Event EV_ScriptSlave_NoUse( "nouse" );
Event EV_ScriptSlave_OnBlock( "onblock" );
Event EV_ScriptSlave_NoBlock( "noblock" );
Event EV_ScriptSlave_OnTrigger( "ontrigger" );
Event EV_ScriptSlave_NoTrigger( "notrigger" );
Event EV_ScriptSlave_OnDamage( "ondamage" );
Event EV_ScriptSlave_NoDamage( "nodamage" );
Event EV_ScriptSlave_SetDamage( "setdamage" );
Event EV_ScriptSlave_FollowPath( "followpath" );
Event EV_ScriptSlave_EndPath( "endpath" );
Event EV_ScriptSlave_MoveDone( "scriptslave_movedone" );
Event EV_ScriptSlave_FollowingPath( "scriptslave_followingpath" );
Event EV_ScriptSlave_Explode( "explode" );
Event EV_ScriptSlave_NotShootable( "notshootable" );
ResponseDef ScriptSlave::Responses[] =
{
{ &EV_Bind, ( Response )ScriptSlave::BindEvent },
{ &EV_Unbind, ( Response )ScriptSlave::EventUnbind },
{ &EV_ScriptSlave_DoMove, ( Response )ScriptSlave::DoMove },
{ &EV_ScriptSlave_NewOrders, ( Response )ScriptSlave::NewOrders },
{ &EV_ScriptSlave_Angles, ( Response )ScriptSlave::SetAnglesEvent },
{ &EV_ScriptSlave_Trigger, ( Response )ScriptSlave::TriggerEvent },
{ &EV_ScriptSlave_Next, ( Response )ScriptSlave::GotoNextWaypoint },
{ &EV_ScriptSlave_JumpTo, ( Response )ScriptSlave::JumpTo },
{ &EV_ScriptSlave_MoveTo, ( Response )ScriptSlave::MoveToEvent },
{ &EV_ScriptSlave_Speed, ( Response )ScriptSlave::SetSpeed },
{ &EV_ScriptSlave_Time, ( Response )ScriptSlave::SetTime },
{ &EV_ScriptSlave_MoveUp, ( Response )ScriptSlave::MoveUp },
{ &EV_ScriptSlave_MoveDown, ( Response )ScriptSlave::MoveDown },
{ &EV_ScriptSlave_MoveNorth, ( Response )ScriptSlave::MoveNorth },
{ &EV_ScriptSlave_MoveSouth, ( Response )ScriptSlave::MoveSouth },
{ &EV_ScriptSlave_MoveEast, ( Response )ScriptSlave::MoveEast },
{ &EV_ScriptSlave_MoveWest, ( Response )ScriptSlave::MoveWest },
{ &EV_ScriptSlave_MoveForward, ( Response )ScriptSlave::MoveForward },
{ &EV_ScriptSlave_MoveBackward, ( Response )ScriptSlave::MoveBackward },
{ &EV_ScriptSlave_MoveLeft, ( Response )ScriptSlave::MoveLeft },
{ &EV_ScriptSlave_MoveRight, ( Response )ScriptSlave::MoveRight },
{ &EV_ScriptSlave_RotateXDownTo, ( Response )ScriptSlave::RotateXdownto },
{ &EV_ScriptSlave_RotateYDownTo, ( Response )ScriptSlave::RotateYdownto },
{ &EV_ScriptSlave_RotateZDownTo, ( Response )ScriptSlave::RotateZdownto },
{ &EV_ScriptSlave_RotateXUpTo, ( Response )ScriptSlave::RotateXupto },
{ &EV_ScriptSlave_RotateYUpTo, ( Response )ScriptSlave::RotateYupto },
{ &EV_ScriptSlave_RotateZUpTo, ( Response )ScriptSlave::RotateZupto },
{ &EV_ScriptSlave_RotateXDown, ( Response )ScriptSlave::RotateXdown },
{ &EV_ScriptSlave_RotateYDown, ( Response )ScriptSlave::RotateYdown },
{ &EV_ScriptSlave_RotateZDown, ( Response )ScriptSlave::RotateZdown },
{ &EV_ScriptSlave_RotateXUp, ( Response )ScriptSlave::RotateXup },
{ &EV_ScriptSlave_RotateYUp, ( Response )ScriptSlave::RotateYup },
{ &EV_ScriptSlave_RotateZUp, ( Response )ScriptSlave::RotateZup },
{ &EV_ScriptSlave_RotateX, ( Response )ScriptSlave::RotateX },
{ &EV_ScriptSlave_RotateY, ( Response )ScriptSlave::RotateY },
{ &EV_ScriptSlave_RotateZ, ( Response )ScriptSlave::RotateZ },
{ &EV_ScriptSlave_RotateAxisDownTo, ( Response )ScriptSlave::RotateAxisdownto },
{ &EV_ScriptSlave_RotateAxisUpTo, ( Response )ScriptSlave::RotateAxisupto },
{ &EV_ScriptSlave_RotateAxisDown, ( Response )ScriptSlave::RotateAxisdown },
{ &EV_ScriptSlave_RotateAxisUp, ( Response )ScriptSlave::RotateAxisup },
{ &EV_ScriptSlave_RotateAxis, ( Response )ScriptSlave::RotateZ },
{ &EV_ScriptSlave_OnTouch, ( Response )ScriptSlave::OnTouch },
{ &EV_ScriptSlave_NoTouch, ( Response )ScriptSlave::NoTouch },
{ &EV_ScriptSlave_OnUse, ( Response )ScriptSlave::OnUse },
{ &EV_ScriptSlave_NoUse, ( Response )ScriptSlave::NoUse },
{ &EV_ScriptSlave_OnBlock, ( Response )ScriptSlave::OnBlock },
{ &EV_ScriptSlave_NoBlock, ( Response )ScriptSlave::NoBlock },
{ &EV_ScriptSlave_OnTrigger, ( Response )ScriptSlave::OnTrigger },
{ &EV_ScriptSlave_NoTrigger, ( Response )ScriptSlave::NoTrigger },
{ &EV_ScriptSlave_OnDamage, ( Response )ScriptSlave::OnDamage },
{ &EV_ScriptSlave_NoDamage, ( Response )ScriptSlave::NoDamage },
{ &EV_ScriptSlave_SetDamage, ( Response )ScriptSlave::SetDamage },
{ &EV_ScriptSlave_FollowPath, ( Response )ScriptSlave::FollowPath },
{ &EV_ScriptSlave_EndPath, ( Response )ScriptSlave::EndPath },
{ &EV_ScriptSlave_FollowingPath, ( Response )ScriptSlave::FollowingPath },
{ &EV_Touch, ( Response )ScriptSlave::TouchFunc },
{ &EV_Blocked, ( Response )ScriptSlave::BlockFunc },
{ &EV_Activate, ( Response )ScriptSlave::TriggerFunc },
{ &EV_Use, ( Response )ScriptSlave::UseFunc },
{ &EV_ScriptSlave_MoveDone, ( Response )ScriptSlave::MoveEnd },
{ &EV_Damage, ( Response )ScriptSlave::DamageFunc },
{ &EV_ScriptSlave_RotateDownTo, ( Response )ScriptSlave::Rotatedownto },
{ &EV_ScriptSlave_RotateUpTo, ( Response )ScriptSlave::Rotateupto },
{ &EV_ScriptSlave_RotateTo, ( Response )ScriptSlave::Rotateto },
{ &EV_ScriptSlave_Explode, ( Response )ScriptSlave::Explode },
{ &EV_ScriptSlave_NotShootable, ( Response )ScriptSlave::NotShootable },
{ NULL, NULL }
};
ScriptSlave::ScriptSlave()
{
float angle;
const char *m;
showModel();
speed = G_GetFloatArg( "speed", 100 );
angle = G_GetFloatArg( "angle" );
if ( angle == -1 )
{
ForwardDir = Vector( 0, 0, 90 );
}
else if ( angle == -2 )
{
ForwardDir = Vector( 0, 0, -90 );
}
else
{
ForwardDir = Vector( 0, angle, 0 );
}
setAngles( vec_zero );
takedamage = DAMAGE_YES;
waypoint = NULL;
NewAngles = angles;
NewPos = origin;
traveltime = 0;
commandswaiting = false;
movethread = NULL;
touchthread = NULL;
blockthread = NULL;
damagethread = NULL;
triggerthread = NULL;
usethread = NULL;
splinePath = NULL;
splineangles = false;
dmg = G_GetIntArg( "dmg", 2 );
attack_finished = 0;
setMoveType( MOVETYPE_PUSH );
m = G_GetSpawnArg( "model" );
if ( !edict->s.modelindex )
{
setSolidType( SOLID_NOT );
}
else if ( spawnflags & 1 )
{
// if it isn't solid, lets still make it shootable
edict->svflags |= SVF_SHOOTABLE;
setSolidType( SOLID_BBOX );
setOrigin( origin );
}
else if ( !m || strstr( m, ".def" ) )
{
setSolidType( SOLID_BBOX );
}
else
{
setSolidType( SOLID_BSP );
}
edict->s.effects |= EF_SMOOTHANGLES;
}
ScriptSlave::~ScriptSlave()
{
if ( splinePath )
{
delete splinePath;
splinePath = NULL;
}
}
void ScriptSlave::NewOrders
(
Event *ev
)
{
// make sure position and angles are current
NewAngles = angles;
NewPos = origin;
}
EXPORT_FROM_DLL void ScriptSlave::BindEvent
(
Event *ev
)
{
Entity *ent;
ent = ev->GetEntity( 1 );
if ( ent )
{
bind( ent );
}
// make sure position and angles are current
NewAngles = angles;
NewPos = origin;
}
EXPORT_FROM_DLL void ScriptSlave::EventUnbind
(
Event *ev
)
{
unbind();
// make sure position and angles are current
NewAngles = angles;
NewPos = origin;
}
void ScriptSlave::DoMove
(
Event *ev
)
{
float dist;
ScriptThread *thread;
Event *event;
thread = ev->GetThread();
assert( thread );
if ( thread && thread->WaitingFor( this ) )
{
if ( movethread && ( movethread != thread ) )
{
// warn the user
ev->Error( "Overriding previous move commands for '%s'\n", TargetName() );
// Yeah, we're not REALLY done, but we tell our old thread
// that we are so that it doesn't wait forever
event = new Event( EV_MoveDone );
event->AddEntity( this );
movethread->ProcessEvent( event );
}
movethread = thread;
}
if ( commandswaiting )
{
if ( splinePath )
{
PostEvent( EV_ScriptSlave_FollowingPath, 0 );
}
else
{
if ( traveltime == 0 )
{
dist = Vector( NewPos - origin ).length();
traveltime = dist / speed;
}
LinearInterpolate( NewPos, NewAngles, traveltime, EV_ScriptSlave_MoveDone );
}
commandswaiting = false;
}
else if ( movethread && ( movethread == thread ) )
{
// No commands, so tell the master that we're done
PostEvent( EV_ScriptSlave_MoveDone, 0 );
}
}
void ScriptSlave::MoveEnd
(
Event *ev
)
{
Event *event;
commandswaiting = false;
NewAngles = angles;
NewPos = origin;
if ( movethread )
{
event = new Event( EV_MoveDone );
event->AddEntity( this );
movethread->ProcessEvent( event );
movethread = NULL;
}
}
void ScriptSlave::SetAnglesEvent
(
Event *ev
)
{
commandswaiting = true;
angles = ev->GetVector( 1 );
NewAngles = angles;
}
void ScriptSlave::TriggerEvent
(
Event *ev
)
{
Entity *ent;
Event *e;
ent = ev->GetEntity( 1 );
if ( ent )
{
SetTarget( ent->TargetName() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -