2003-10-24 21:43:32 +00:00
|
|
|
#include "common.qh"
|
|
|
|
#include "protocol.qh"
|
|
|
|
#include "misc.qh"
|
2003-10-27 22:27:29 +00:00
|
|
|
#include "server.qh"
|
2003-10-24 21:43:32 +00:00
|
|
|
#include "teleport.qh"
|
2003-10-27 22:27:29 +00:00
|
|
|
#include "weapon.qh"
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2003-10-28 21:20:34 +00:00
|
|
|
.float tl_notsolid;
|
|
|
|
|
2003-10-24 21:43:32 +00:00
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity (string clname)
|
|
|
|
spawn =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity e;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
e = BUILTIN_spawn ();
|
2003-10-24 21:43:32 +00:00
|
|
|
e.classname = clname;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
SUB_remove =
|
|
|
|
{
|
|
|
|
remove (self);
|
|
|
|
};
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity e)
|
|
|
|
safe_remove =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
e.takedamage = DAMAGE_NO;
|
|
|
|
e.solid = SOLID_NOT;
|
2011-03-20 08:27:47 +00:00
|
|
|
e.model = nil;
|
2003-10-24 21:43:32 +00:00
|
|
|
e.modelindex = 0;
|
|
|
|
|
|
|
|
e.think = SUB_remove;
|
|
|
|
e.nextthink = time;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
SUB_makestatic =
|
|
|
|
{
|
|
|
|
makestatic (self);
|
|
|
|
};
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity e)
|
|
|
|
safe_makestatic =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
if (sv_spawning) {
|
2004-02-08 07:34:17 +00:00
|
|
|
makestatic (self);
|
2003-10-24 21:43:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.takedamage = DAMAGE_NO;
|
|
|
|
e.solid = SOLID_NOT;
|
|
|
|
|
|
|
|
e.think = SUB_makestatic;
|
|
|
|
e.nextthink = time;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
_sound_vector_think =
|
|
|
|
{
|
|
|
|
sound (self, CHAN_VOICE, self.noise1, self.volume, self.attenuation);
|
|
|
|
remove (self);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
2004-02-08 07:34:17 +00:00
|
|
|
|
|
|
|
void (vector org, string samp, float vol, float atten)
|
|
|
|
sound_vector =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity e;
|
|
|
|
|
|
|
|
e = spawn("SOUND");
|
|
|
|
e.origin = org;
|
|
|
|
e.noise1 = samp;
|
|
|
|
e.volume = vol;
|
|
|
|
e.attenuation = atten;
|
|
|
|
|
|
|
|
e.think = _sound_vector_think;
|
|
|
|
e.nextthink = time;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
float (vector org)
|
|
|
|
_missile_th_teleport =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
self.owner = world;
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity mis) missile_check_teleport;
|
|
|
|
|
|
|
|
void ()
|
|
|
|
_missile_always_trigger =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
self.think = SUB_remove;
|
|
|
|
self.nextthink = self.attack_finished;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
if ((self.movetype != MOVETYPE_FLYMISSILE)
|
|
|
|
&& (self.movetype != MOVETYPE_FLY))
|
2003-10-24 21:43:32 +00:00
|
|
|
return;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
tl_proj_begin ();
|
2003-10-24 21:43:32 +00:00
|
|
|
/* Make sure we're still going to hit the thing */
|
2004-02-08 07:34:17 +00:00
|
|
|
traceline (self.origin, self.origin + self.velocity * sv_maxtic * 2, FALSE,
|
|
|
|
self);
|
|
|
|
if (trace_ent == self.enemy)
|
|
|
|
tl_touch (trace_ent, self);
|
|
|
|
else
|
|
|
|
self.enemy = world;
|
|
|
|
tl_proj_end ();
|
|
|
|
|
|
|
|
missile_check_teleport (self);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity mis)
|
|
|
|
missile_check_teleport =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local float duration;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
tl_proj_begin ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
trace_ent = mis;
|
|
|
|
trace_endpos = mis.origin;
|
|
|
|
duration = mis.attack_finished - time;
|
|
|
|
|
|
|
|
while (duration > sv_maxtic) {
|
2004-02-08 07:34:17 +00:00
|
|
|
traceline (trace_endpos, trace_endpos + mis.velocity * duration,
|
|
|
|
FALSE, trace_ent);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (!trace_ent || trace_ent.solid == SOLID_BSP) {
|
|
|
|
/* Don't bother tracing through BSP, it won't happen. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
if (tl_issolid (trace_ent) || mis.enemy == trace_ent
|
|
|
|
|| (duration * trace_fraction) <= sv_maxtic) {
|
2003-10-24 21:43:32 +00:00
|
|
|
/* We hit a triggered trigger,
|
|
|
|
a solid ent, or something we _just_ hit */
|
|
|
|
if (trace_fraction == 0) {
|
|
|
|
/* We're not going anywhere. Fudge it. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Trace on past it. */
|
2004-02-08 07:34:17 +00:00
|
|
|
duration -= duration * trace_fraction;
|
2003-10-24 21:43:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reached a [new] trigger */
|
|
|
|
mis.enemy = trace_ent;
|
|
|
|
mis.think = _missile_always_trigger;
|
2004-02-08 07:34:17 +00:00
|
|
|
mis.nextthink = time + duration * trace_fraction - sv_maxtic;
|
2003-10-24 21:43:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
tl_proj_end ();
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity (string clname, string mod, vector org, vector dir, float spd)
|
|
|
|
spawn_missile =
|
|
|
|
{
|
|
|
|
newmis = spawn (clname);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
newmis.owner = self;
|
|
|
|
newmis.goalentity = self;
|
|
|
|
|
|
|
|
newmis.movetype = MOVETYPE_FLYMISSILE;
|
|
|
|
newmis.solid = SOLID_BBOX;
|
|
|
|
newmis.deadflag = DEAD_NONLIVING;
|
|
|
|
|
|
|
|
newmis.th_teleport = _missile_th_teleport;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
setmodel (newmis, mod);
|
|
|
|
setsize (newmis, '0 0 0', '0 0 0');
|
|
|
|
setorigin (newmis, org);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
newmis.angles = vectoangles (dir);
|
2003-10-24 21:43:32 +00:00
|
|
|
newmis.speed = spd;
|
|
|
|
newmis.velocity = dir * spd;
|
|
|
|
|
|
|
|
newmis.attack_finished = time + (6000 / spd);
|
|
|
|
|
|
|
|
newmis.think = SUB_remove;
|
|
|
|
newmis.nextthink = newmis.attack_finished;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
missile_check_teleport (newmis);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
return newmis;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
|
|
|
entity tl_first;
|
|
|
|
.entity tl_next;
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
tl_proj_begin =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity walk;
|
|
|
|
|
|
|
|
tl_first = world;
|
2004-02-08 07:34:17 +00:00
|
|
|
for (walk = nextent (world); walk; walk = nextent (walk)) {
|
2003-10-24 21:43:32 +00:00
|
|
|
if (walk.solid != SOLID_TRIGGER)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
walk.tl_next = tl_first;
|
|
|
|
tl_first = walk;
|
|
|
|
|
|
|
|
walk.solid = SOLID_BBOX;
|
|
|
|
walk.tl_notsolid = TRUE;
|
2004-02-08 07:34:17 +00:00
|
|
|
setorigin (walk, walk.origin); // relink
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
tl_proj_end =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity walk;
|
|
|
|
|
|
|
|
for (walk = tl_first; walk; walk = walk.tl_next) {
|
|
|
|
walk.solid = SOLID_TRIGGER;
|
|
|
|
walk.tl_notsolid = FALSE;
|
2004-02-08 07:34:17 +00:00
|
|
|
setorigin (walk, walk.origin); // relink
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity trigger, entity fake_proj)
|
|
|
|
tl_touch =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity oldself, oldother;
|
|
|
|
|
|
|
|
if (!trigger.touch)
|
|
|
|
return;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
tl_proj_end ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
oldself = self;
|
|
|
|
oldother = other;
|
|
|
|
|
|
|
|
self = trigger;
|
|
|
|
other = fake_proj;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
self.touch ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
self = oldself;
|
|
|
|
other = oldother;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
tl_proj_begin ();
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
string (entity e)
|
|
|
|
name =
|
|
|
|
{
|
|
|
|
if (e.netname)
|
|
|
|
return e.netname;
|
|
|
|
if (e.classname)
|
|
|
|
return e.classname;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (e.velocity)
|
|
|
|
return "an unidentified flying object";
|
|
|
|
return "an unidentified stationary object";
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (.string fld, string match, void (entity e) func)
|
|
|
|
foreach =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity ent;
|
|
|
|
|
|
|
|
ent = world;
|
2004-02-08 07:34:17 +00:00
|
|
|
while ((ent = find (ent, fld, match))) {
|
2003-10-24 21:43:32 +00:00
|
|
|
if (!func) {
|
2004-02-08 07:34:17 +00:00
|
|
|
dprint ("NULL function in foreach, classname: ", ent.classname,
|
|
|
|
"\n");
|
2003-10-24 21:43:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
func (ent);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (.string fld, string match, .void () func)
|
|
|
|
foreach_field =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity oldself;
|
|
|
|
|
|
|
|
oldself = self;
|
|
|
|
|
|
|
|
self = world;
|
2004-02-08 07:34:17 +00:00
|
|
|
while ((self = find (self, fld, match))) {
|
2003-10-24 21:43:32 +00:00
|
|
|
if (!self.func) {
|
2004-02-08 07:34:17 +00:00
|
|
|
dprint ("NULL function in foreach_field, classname: ",
|
|
|
|
self.classname, "\n");
|
2003-10-24 21:43:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
self.func ();
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self = oldself;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
float (entity newself, entity newother, float () func)
|
|
|
|
switcheroo = {
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity oldself, oldother;
|
|
|
|
local float ret;
|
|
|
|
|
|
|
|
oldself = self;
|
|
|
|
oldother = other;
|
|
|
|
|
|
|
|
self = newself;
|
|
|
|
other = newother;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
ret = func ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
self = oldself;
|
|
|
|
other = oldother;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
float (float current, float increment, float max)
|
|
|
|
increase_bound =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local float diff;
|
|
|
|
|
|
|
|
diff = max - current;
|
2004-02-08 07:34:17 +00:00
|
|
|
if (diff <= 0)
|
|
|
|
return current;
|
|
|
|
if (diff > increment)
|
|
|
|
diff = increment;
|
2003-10-24 21:43:32 +00:00
|
|
|
return current + diff;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
float (.float fld, float increment, float max)
|
|
|
|
increase_field =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local float new;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
new = increase_bound (self.fld, increment, max);
|
2003-10-24 21:43:32 +00:00
|
|
|
if (new == self.fld)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
self.fld = new;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
|
|
|
/* Not to be confused with maxspeed */
|
2004-02-08 07:34:17 +00:00
|
|
|
float (entity e)
|
|
|
|
calc_max_speed =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local float spd;
|
|
|
|
|
|
|
|
spd = e.maxspeed;
|
|
|
|
|
|
|
|
if (self.waterlevel >= 2)
|
|
|
|
spd = spd * 0.7; // Bah. Hard coded in engine.
|
|
|
|
else if (!self.waterlevel && !(self.flags & FL_ONGROUND)) {
|
|
|
|
if (spd > 30)
|
|
|
|
spd = 30; // Also hard coded.
|
|
|
|
}
|
|
|
|
|
|
|
|
return spd;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
|
|
|
entity _xprint_client;
|
|
|
|
float _xprint_level;
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity client, float level)
|
|
|
|
xprint_start =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
_xprint_client = client;
|
|
|
|
_xprint_level = level;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (string str)
|
|
|
|
xprint_str =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
msg_entity = _xprint_client;
|
2004-02-09 04:25:00 +00:00
|
|
|
WriteBytes (MSG_ONE, SVC_PRINT, _xprint_level);
|
2004-02-08 07:34:17 +00:00
|
|
|
WriteString (MSG_ONE, str);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity (.string fld, string str)
|
|
|
|
find_random =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local float r, numents;
|
|
|
|
local entity ent;
|
|
|
|
|
|
|
|
numents = 0;
|
2004-02-08 07:34:17 +00:00
|
|
|
r = floor (random () * 512);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
while (1) {
|
2004-02-08 07:34:17 +00:00
|
|
|
ent = find (world, fld, str);
|
|
|
|
if (!ent)
|
|
|
|
return world;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
while (ent) {
|
|
|
|
numents++;
|
|
|
|
|
|
|
|
r--;
|
2004-02-08 07:34:17 +00:00
|
|
|
if (r <= 0)
|
|
|
|
return ent;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
ent = find (ent, fld, str);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
r -= numents * floor (r / numents);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return world;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity (entity ech)
|
|
|
|
random_enemy_chain =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity walk;
|
|
|
|
local float tot, r;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
r = floor (random () * 64) + 1;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
tot = 1;
|
|
|
|
for (walk = ech.enemy; walk != ech; walk = walk.enemy) {
|
|
|
|
r--;
|
|
|
|
if (r <= 0)
|
|
|
|
return walk;
|
|
|
|
|
|
|
|
tot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tot)
|
|
|
|
return ech;
|
|
|
|
|
|
|
|
/* Ok, only look at half the remaining ones */
|
2004-02-08 07:34:17 +00:00
|
|
|
tot = floor (tot * 0.5);
|
2003-10-24 21:43:32 +00:00
|
|
|
if (!tot)
|
|
|
|
return ech.enemy;
|
|
|
|
|
|
|
|
r -= tot * floor(r / tot);
|
|
|
|
|
|
|
|
for (walk = ech.enemy; walk; walk = walk.enemy) {
|
|
|
|
if (r <= 0)
|
|
|
|
return walk;
|
|
|
|
|
|
|
|
r--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return world;
|
|
|
|
};
|