2003-10-22 09:24:50 +00:00
|
|
|
#include "config.rh"
|
|
|
|
|
|
|
|
#include "paroxysm.rh"
|
|
|
|
|
|
|
|
void() SUB_Null = {};
|
2003-10-22 21:54:29 +00:00
|
|
|
void() SUB_Remove = {remove(@self);};
|
2003-10-22 09:24:50 +00:00
|
|
|
/*
|
|
|
|
QuakeEd only writes a single float for angles (bad idea), so up and down are
|
|
|
|
just constant angles.
|
|
|
|
*/
|
|
|
|
vector() SetMovedir =
|
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.angles == '0 -1 0')
|
|
|
|
@self.movedir = '0 0 1';
|
|
|
|
else if (@self.angles == '0 -2 0')
|
|
|
|
@self.movedir = '0 0 -1';
|
2003-10-22 09:24:50 +00:00
|
|
|
else
|
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
makevectors (@self.angles);
|
|
|
|
@self.movedir = v_forward;
|
2003-10-22 09:24:50 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.angles = '0 0 0';
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
InitTrigger
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void() InitTrigger =
|
|
|
|
{
|
|
|
|
// trigger angles are used for one-way touches. An angle of 0 is assumed
|
|
|
|
// to mean no restrictions, so use a yaw of 360 instead.
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.angles != '0 0 0')
|
2003-10-22 09:24:50 +00:00
|
|
|
SetMovedir ();
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.solid = SOLID_TRIGGER;
|
|
|
|
setmodel (@self, @self.model); // set size and link into world
|
|
|
|
@self.movetype = MOVETYPE_NONE;
|
|
|
|
@self.modelindex = 0;
|
|
|
|
@self.model = "";
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
SUB_CalcMove
|
2003-10-22 21:54:29 +00:00
|
|
|
calculate @self.velocity and @self.nextthink to reach dest from
|
|
|
|
@self.origin traveling at speed
|
2003-10-22 09:24:50 +00:00
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void(entity ent, vector tdest, float tspeed, void() func) SUB_CalcMoveEnt =
|
|
|
|
{
|
|
|
|
local entity stemp;
|
2003-10-22 21:54:29 +00:00
|
|
|
stemp = @self;
|
|
|
|
@self = ent;
|
2003-10-22 09:24:50 +00:00
|
|
|
SUB_CalcMove (tdest, tspeed, func);
|
2003-10-22 21:54:29 +00:00
|
|
|
@self = stemp;
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void(vector tdest, float tspeed, void() func) SUB_CalcMove =
|
|
|
|
{
|
|
|
|
local vector vdestdelta;
|
|
|
|
local float len, traveltime;
|
|
|
|
if (!tspeed)
|
|
|
|
objerror("No speed is defined!");
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.think1 = func;
|
|
|
|
@self.finaldest = tdest;
|
|
|
|
@self.think = SUB_CalcMoveDone;
|
|
|
|
if (tdest == @self.origin)
|
2003-10-22 09:24:50 +00:00
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.velocity = '0 0 0';
|
|
|
|
@self.nextthink = @self.ltime + 0.1;
|
2003-10-22 09:24:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set destdelta to the vector needed to move
|
2003-10-22 21:54:29 +00:00
|
|
|
vdestdelta = tdest - @self.origin;
|
2003-10-22 09:24:50 +00:00
|
|
|
|
|
|
|
// calculate length of vector
|
|
|
|
len = vlen (vdestdelta);
|
|
|
|
|
|
|
|
// divide by speed to get time to reach dest
|
|
|
|
traveltime = len / tspeed;
|
|
|
|
if (traveltime < 0.03)
|
|
|
|
traveltime = 0.03;
|
|
|
|
|
|
|
|
// set nextthink to trigger a think when dest is reached
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.nextthink = @self.ltime + traveltime;
|
2003-10-22 09:24:50 +00:00
|
|
|
// scale the destdelta vector by the time spent traveling to get velocity
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.velocity = vdestdelta * (1/traveltime); // qcc won't take vec/float
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
After moving, set origin to exact final destination
|
|
|
|
*/
|
|
|
|
void() SUB_CalcMoveDone =
|
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
setorigin (@self, @self.finaldest);
|
|
|
|
@self.velocity = '0 0 0';
|
|
|
|
@self.nextthink = -1;
|
|
|
|
if (@self.think1)
|
|
|
|
@self.think1 ();
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
SUB_CalcAngleMove
|
2003-10-22 21:54:29 +00:00
|
|
|
calculate @self.avelocity and @self.nextthink to reach destangle from
|
|
|
|
@self.angles rotating
|
|
|
|
The calling function should make sure @self.think is valid
|
2003-10-22 09:24:50 +00:00
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void(entity ent, vector destangle, float tspeed, void() func) SUB_CalcAngleMoveEnt =
|
|
|
|
{
|
|
|
|
local entity stemp;
|
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
stemp = @self;
|
|
|
|
@self = ent;
|
2003-10-22 09:24:50 +00:00
|
|
|
SUB_CalcAngleMove (destangle, tspeed, func);
|
2003-10-22 21:54:29 +00:00
|
|
|
@self = stemp;
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void (vector destangle, float tspeed, void() func) SUB_CalcAngleMove =
|
|
|
|
{
|
|
|
|
local vector destdelta;
|
|
|
|
local float len, traveltime;
|
|
|
|
|
|
|
|
if (!tspeed)
|
|
|
|
objerror ("No speed is defined!");
|
|
|
|
|
|
|
|
// set destdelta to the vector needed to move
|
2003-10-22 21:54:29 +00:00
|
|
|
destdelta = destangle - @self.angles;
|
2003-10-22 09:24:50 +00:00
|
|
|
|
|
|
|
// calculate length of vector
|
|
|
|
len = vlen (destdelta);
|
|
|
|
|
|
|
|
// divide by speed to get time to reach dest
|
|
|
|
traveltime = len / tspeed;
|
|
|
|
|
|
|
|
// set nextthink to trigger a think when dest is reached
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.nextthink = @self.ltime + traveltime;
|
2003-10-22 09:24:50 +00:00
|
|
|
|
|
|
|
// scale the destdelta vector by the time spent traveling to get velocity
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.avelocity = destdelta * (1 / traveltime);
|
2003-10-22 09:24:50 +00:00
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.think1 = func;
|
|
|
|
@self.finalangle = destangle;
|
|
|
|
@self.think = SUB_CalcAngleMoveDone;
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
After rotating, set angle to exact final angle
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void() SUB_CalcAngleMoveDone =
|
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
@self.angles = @self.finalangle;
|
|
|
|
@self.avelocity = '0 0 0';
|
|
|
|
@self.nextthink = -1;
|
|
|
|
if (@self.think1)
|
|
|
|
@self.think1();
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
//=============================================================================
|
|
|
|
void() DelayThink =
|
|
|
|
{
|
2003-10-22 21:54:29 +00:00
|
|
|
activator = @self.enemy;
|
2003-10-22 09:24:50 +00:00
|
|
|
SUB_UseTargets ();
|
2003-10-22 21:54:29 +00:00
|
|
|
remove(@self);
|
2003-10-22 09:24:50 +00:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
==============================
|
|
|
|
SUB_UseTargets
|
|
|
|
the global "activator" should be set to the entity that initiated the firing.
|
2003-10-22 21:54:29 +00:00
|
|
|
If @self.delay is set, a DelayedUse entity will be created that will actually
|
2003-10-22 09:24:50 +00:00
|
|
|
do the SUB_UseTargets after that many seconds have passed.
|
2003-10-22 21:54:29 +00:00
|
|
|
Centerprints any @self.message to the activator.
|
|
|
|
Removes all entities with a targetname that match @self.killtarget,
|
2003-10-22 09:24:50 +00:00
|
|
|
and removes them, so some events can remove other triggers.
|
|
|
|
Search for (string)targetname in all entities that
|
2003-10-22 21:54:29 +00:00
|
|
|
match (string)@self.target and call their .use function
|
2003-10-22 09:24:50 +00:00
|
|
|
==============================
|
|
|
|
*/
|
|
|
|
void() SUB_UseTargets =
|
|
|
|
{
|
|
|
|
local entity t, stemp, otemp, act;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
check for a delay
|
|
|
|
*/
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.delay) { // create a temp object to fire at a later time
|
2003-10-22 09:24:50 +00:00
|
|
|
t = spawn();
|
|
|
|
t.classname = "DelayedUse";
|
2003-10-22 21:54:29 +00:00
|
|
|
t.nextthink = time + @self.delay;
|
2003-10-22 09:24:50 +00:00
|
|
|
t.think = DelayThink;
|
|
|
|
t.enemy = activator;
|
2003-10-22 21:54:29 +00:00
|
|
|
t.message = @self.message;
|
|
|
|
t.killtarget = @self.killtarget;
|
|
|
|
t.target = @self.target;
|
2003-10-22 09:24:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print the message
|
2003-10-22 21:54:29 +00:00
|
|
|
if ((activator.classname == "player") && (@self.message != "")) {
|
|
|
|
@self.target_id_finished = time + 4; // don't let TargetID override centerprints
|
2003-10-22 09:24:50 +00:00
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
centerprint (activator, @self.message);
|
|
|
|
if (!@self.noise)
|
2003-10-22 09:24:50 +00:00
|
|
|
sound (activator, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
// kill the killtagets
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.killtarget) {
|
2003-10-22 09:24:50 +00:00
|
|
|
t = world;
|
|
|
|
do {
|
2003-10-22 21:54:29 +00:00
|
|
|
if (!(t = find (t, targetname, @self.killtarget)))
|
2003-10-22 09:24:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
remove (t);
|
|
|
|
} while ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire targets
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.target) {
|
2003-10-22 09:24:50 +00:00
|
|
|
act = activator;
|
|
|
|
t = world;
|
|
|
|
|
|
|
|
do {
|
2003-10-22 21:54:29 +00:00
|
|
|
if (!(t = find (t, targetname, @self.target)))
|
2003-10-22 09:24:50 +00:00
|
|
|
return;
|
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
stemp = @self;
|
2003-10-22 09:24:50 +00:00
|
|
|
otemp = other;
|
2003-10-22 21:54:29 +00:00
|
|
|
@self = t;
|
2003-10-22 09:24:50 +00:00
|
|
|
other = stemp;
|
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
if (@self.use != SUB_Null) {
|
|
|
|
if (@self.use)
|
|
|
|
@self.use ();
|
2003-10-22 09:24:50 +00:00
|
|
|
}
|
|
|
|
|
2003-10-22 21:54:29 +00:00
|
|
|
@self = stemp;
|
2003-10-22 09:24:50 +00:00
|
|
|
other = otemp;
|
|
|
|
activator = act;
|
|
|
|
} while ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|