316 lines
5.9 KiB
C++
316 lines
5.9 KiB
C++
|
|
|
|
void() sub_null = {};
|
|
|
|
void() sub_remove = {remove(self);};
|
|
|
|
|
|
/*
|
|
quakeed only writes a single float for angles (bad idea), so up and down are
|
|
just constant angles.
|
|
*/
|
|
vector() setmovedir =
|
|
{
|
|
if (self.angles == '0 -1 0')
|
|
self.movedir = '0 0 1';
|
|
else if (self.angles == '0 -2 0')
|
|
self.movedir = '0 0 -1';
|
|
else
|
|
{
|
|
makevectors (self.angles);
|
|
self.movedir = v_forward;
|
|
}
|
|
|
|
self.angles = '0 0 0';
|
|
};
|
|
|
|
/*
|
|
================
|
|
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.
|
|
if (self.angles != '0 0 0')
|
|
setmovedir ();
|
|
self.solid = solid_trigger;
|
|
setmodel (self, self.model); // set size and link into world
|
|
self.movetype = movetype_none;
|
|
self.modelindex = 0;
|
|
self.model = "";
|
|
};
|
|
|
|
/*
|
|
=============
|
|
sub_calcmove
|
|
|
|
calculate self.velocity and self.nextthink to reach dest from
|
|
self.origin traveling at speed
|
|
===============
|
|
*/
|
|
void(entity ent, vector tdest, float tspeed, void() func) sub_calcmoveent =
|
|
{
|
|
local entity stemp;
|
|
stemp = self;
|
|
self = ent;
|
|
|
|
sub_calcmove (tdest, tspeed, func);
|
|
self = stemp;
|
|
};
|
|
|
|
void(vector tdest, float tspeed, void() func) sub_calcmove =
|
|
{
|
|
local vector vdestdelta;
|
|
local float len, traveltime;
|
|
|
|
if (!tspeed)
|
|
objerror("no speed is defined!");
|
|
|
|
self.think1 = func;
|
|
self.finaldest = tdest;
|
|
self.think = sub_calcmovedone;
|
|
|
|
if (tdest == self.origin)
|
|
{
|
|
self.velocity = '0 0 0';
|
|
self.nextthink = self.ltime + 0.1;
|
|
return;
|
|
}
|
|
|
|
// set destdelta to the vector needed to move
|
|
vdestdelta = tdest - self.origin;
|
|
|
|
// calculate length of vector
|
|
len = vlen (vdestdelta);
|
|
|
|
// divide by speed to get time to reach dest
|
|
traveltime = len / tspeed;
|
|
|
|
if (traveltime < 0.1)
|
|
{
|
|
self.velocity = '0 0 0';
|
|
self.nextthink = self.ltime + 0.1;
|
|
return;
|
|
}
|
|
|
|
// set nextthink to trigger a think when dest is reached
|
|
self.nextthink = self.ltime + traveltime;
|
|
|
|
// scale the destdelta vector by the time spent traveling to get velocity
|
|
self.velocity = vdestdelta * (1/traveltime); // qcc won't take vec/float
|
|
};
|
|
|
|
/*
|
|
============
|
|
after moving, set origin to exact final destination
|
|
============
|
|
*/
|
|
void() sub_calcmovedone =
|
|
{
|
|
setorigin(self, self.finaldest);
|
|
self.velocity = '0 0 0';
|
|
self.nextthink = -1;
|
|
if (self.think1)
|
|
self.think1();
|
|
};
|
|
|
|
|
|
/*
|
|
=============
|
|
sub_calcanglemove
|
|
|
|
calculate self.avelocity and self.nextthink to reach destangle from
|
|
self.angles rotating
|
|
|
|
the calling function should make sure self.think is valid
|
|
===============
|
|
*/
|
|
void(entity ent, vector destangle, float tspeed, void() func) sub_calcanglemoveent =
|
|
{
|
|
local entity stemp;
|
|
stemp = self;
|
|
self = ent;
|
|
sub_calcanglemove (destangle, tspeed, func);
|
|
self = stemp;
|
|
};
|
|
|
|
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
|
|
destdelta = destangle - self.angles;
|
|
|
|
// 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
|
|
self.nextthink = self.ltime + traveltime;
|
|
|
|
// scale the destdelta vector by the time spent traveling to get velocity
|
|
self.avelocity = destdelta * (1 / traveltime);
|
|
|
|
self.think1 = func;
|
|
self.finalangle = destangle;
|
|
self.think = sub_calcanglemovedone;
|
|
};
|
|
|
|
/*
|
|
============
|
|
after rotating, set angle to exact final angle
|
|
============
|
|
*/
|
|
void() sub_calcanglemovedone =
|
|
{
|
|
self.angles = self.finalangle;
|
|
self.avelocity = '0 0 0';
|
|
self.nextthink = -1;
|
|
if (self.think1)
|
|
self.think1();
|
|
};
|
|
|
|
|
|
//=============================================================================
|
|
|
|
void() delaythink =
|
|
{
|
|
activator = self.enemy;
|
|
sub_usetargets ();
|
|
remove(self);
|
|
};
|
|
|
|
/*
|
|
==============================
|
|
sub_usetargets
|
|
|
|
the global "activator" should be set to the entity that initiated the firing.
|
|
|
|
if self.delay is set, a delayeduse entity will be created that will actually
|
|
do the sub_usetargets after that many seconds have passed.
|
|
|
|
centerprints any self.message to the activator.
|
|
|
|
removes all entities with a targetname that match self.killtarget,
|
|
and removes them, so some events can remove other triggers.
|
|
|
|
search for (string)targetname in all entities that
|
|
match (string)self.target and call their .use function
|
|
|
|
==============================
|
|
*/
|
|
void() sub_usetargets =
|
|
{
|
|
local entity t, stemp, otemp, act;
|
|
|
|
//
|
|
// check for a delay
|
|
//
|
|
if (self.delay)
|
|
{
|
|
// create a temp object to fire at a later time
|
|
t = spawn();
|
|
t.classname = "delayeduse";
|
|
t.nextthink = time + self.delay;
|
|
t.think = delaythink;
|
|
t.enemy = activator;
|
|
t.message = self.message;
|
|
t.killtarget = self.killtarget;
|
|
t.target = self.target;
|
|
return;
|
|
}
|
|
|
|
|
|
//
|
|
// print the message
|
|
//
|
|
if (activator.classname == "player" && self.message != "")
|
|
{
|
|
centerprint (activator, self.message);
|
|
if (!self.noise)
|
|
sound (activator, chan_voice, "misc/talk.wav", 1, attn_norm);
|
|
}
|
|
|
|
//
|
|
// kill the killtagets
|
|
//
|
|
if (self.killtarget)
|
|
{
|
|
t = world;
|
|
do
|
|
{
|
|
t = find (t, targetname, self.killtarget);
|
|
if (!t)
|
|
return;
|
|
remove (t);
|
|
} while ( 1 );
|
|
}
|
|
|
|
//
|
|
// fire targets
|
|
//
|
|
if (self.target)
|
|
{
|
|
act = activator;
|
|
t = world;
|
|
do
|
|
{
|
|
t = find (t, targetname, self.target);
|
|
if (!t)
|
|
{
|
|
return;
|
|
}
|
|
stemp = self;
|
|
otemp = other;
|
|
self = t;
|
|
other = stemp;
|
|
if (self.use != sub_null)
|
|
{
|
|
if (self.use)
|
|
self.use ();
|
|
}
|
|
self = stemp;
|
|
other = otemp;
|
|
activator = act;
|
|
} while ( 1 );
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
|
in nightmare mode, all attack_finished times become 0
|
|
some monsters refire twice automatically
|
|
|
|
*/
|
|
|
|
void(float normal) sub_attackfinished =
|
|
{
|
|
self.cnt = 0; // refire count for nightmare
|
|
if (skill != 3)
|
|
self.attack_finished = time + normal;
|
|
};
|
|
|
|
float (entity targ) visible;
|
|
|
|
void (void() thinkst) sub_checkrefire =
|
|
{
|
|
if (skill != 3)
|
|
return;
|
|
if (self.cnt == 1)
|
|
return;
|
|
if (!visible (self.enemy))
|
|
return;
|
|
self.cnt = 1;
|
|
self.think = thinkst;
|
|
};
|