2003-10-24 21:43:32 +00:00
|
|
|
#include "common.qh"
|
|
|
|
#include "misc.qh"
|
2003-10-27 22:27:29 +00:00
|
|
|
#include "server.qh"
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
#include "mapents_util.qh"
|
|
|
|
|
2003-10-28 21:20:34 +00:00
|
|
|
.void() th_activate;
|
|
|
|
|
2003-10-24 21:43:32 +00:00
|
|
|
void() util_map_entity_init = {
|
|
|
|
self.deadflag = DEAD_NONLIVING;
|
|
|
|
|
|
|
|
if (self.noise && sv_spawning) {
|
2004-02-09 04:41:39 +00:00
|
|
|
if (!self.volume)
|
|
|
|
self.volume = 0.5;
|
|
|
|
if (!self.attenuation)
|
|
|
|
self.attenuation = ATTN_STATIC;
|
|
|
|
|
|
|
|
precache_sound (self.noise);
|
|
|
|
ambientsound (center (self), self.noise, self.volume,
|
|
|
|
self.attenuation);
|
2003-10-24 21:43:32 +00:00
|
|
|
} else {
|
2004-02-09 04:41:39 +00:00
|
|
|
if (!self.volume)
|
|
|
|
self.volume = 1.0;
|
|
|
|
if (!self.attenuation)
|
|
|
|
self.attenuation = ATTN_NORM;
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sv_spawning) {
|
2004-02-09 04:41:39 +00:00
|
|
|
if (self.noise1)
|
|
|
|
precache_sound (self.noise1);
|
|
|
|
if (self.noise2)
|
|
|
|
precache_sound (self.noise2);
|
|
|
|
if (self.noise5)
|
|
|
|
precache_sound (self.noise5);
|
|
|
|
if (self.noise6)
|
|
|
|
precache_sound (self.noise6);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (self.mangle)
|
|
|
|
self.angles = self.mangle;
|
|
|
|
|
|
|
|
if (self.model) {
|
|
|
|
if (sv_spawning)
|
2004-02-09 04:41:39 +00:00
|
|
|
precache_model (self.model);
|
|
|
|
setmodel (self, self.model);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
setsize (self, self.mins, self.maxs);
|
|
|
|
setorigin (self, self.origin); // Links BSP models
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void() util_map_entity_cull = {
|
|
|
|
if (self.solid || self.takedamage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (self.nextthink > time)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!sv_spawning) {
|
|
|
|
if (self.targetname) {
|
2004-02-09 04:41:39 +00:00
|
|
|
if (find (world, target, self.targetname))
|
2003-10-24 21:43:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.target) {
|
|
|
|
local entity oldself;
|
|
|
|
|
|
|
|
oldself = self;
|
|
|
|
|
|
|
|
self = world;
|
2004-01-31 08:24:03 +00:00
|
|
|
while ((self = find(self, targetname, self.target))) {
|
2003-10-24 21:43:32 +00:00
|
|
|
if (self == oldself)
|
|
|
|
continue;
|
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
util_map_entity_cull ();
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self = oldself;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (self.targetname || self.target) {
|
|
|
|
self.think = util_map_entity_cull;
|
|
|
|
self.nextthink = time + sv_mintic;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
if (self.model)
|
|
|
|
safe_makestatic (self);
|
|
|
|
else
|
|
|
|
safe_remove (self);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void() util_map_entity_drop = {
|
|
|
|
self.origin = self.origin + '0 0 2';
|
2004-02-09 04:41:39 +00:00
|
|
|
if (!droptofloor ()) {
|
|
|
|
dprint (self.classname, " fell out of level from ", vtos (self.origin),
|
|
|
|
"\n");
|
|
|
|
remove (self);
|
2003-10-24 21:43:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
float() util_check_targets = {
|
2004-02-09 04:41:39 +00:00
|
|
|
// if (self.spawnflags & (SPAWNFLAGS_CHECK_ITEMS|SPAWNFLAGS_TAKE_ITEMS)) {
|
|
|
|
// }
|
2003-10-24 21:43:32 +00:00
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
float() util_use_targets = {
|
2004-02-09 04:41:39 +00:00
|
|
|
if (!util_check_targets ())
|
2003-10-24 21:43:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (self.noise1)
|
2004-02-09 04:41:39 +00:00
|
|
|
sound (self, CHAN_VOICE, self.noise1, self.volume, self.attenuation);
|
2003-10-24 21:43:32 +00:00
|
|
|
if (self.noise2)
|
2004-02-09 04:41:39 +00:00
|
|
|
sound (other, CHAN_ITEM, self.noise2, self.volume, self.attenuation);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
if (self.message && is_cl (other))
|
|
|
|
centerprint (other, self.message);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (self.th_activate)
|
2004-02-09 04:41:39 +00:00
|
|
|
self.th_activate ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (self.target)
|
2004-02-09 04:41:39 +00:00
|
|
|
foreach_field (targetname, self.target, use);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (self.killtarget)
|
2004-02-09 04:41:39 +00:00
|
|
|
foreach (targetname, self.killtarget, safe_remove);
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
if (self.count > 0) {
|
|
|
|
self.count--;
|
|
|
|
if (!self.count) {
|
2003-10-27 22:27:29 +00:00
|
|
|
self.targetname = NIL;
|
|
|
|
self.target = NIL;
|
|
|
|
self.killtarget = NIL;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
self.use = NOTHING_function;
|
|
|
|
self.touch = NOTHING_function;
|
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
util_map_entity_cull ();
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
float(entity e) is_living = {
|
2004-02-09 06:15:13 +00:00
|
|
|
return (e.deadflag == DEAD_NO) && is_solid (e);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
float(entity e) is_solid = {
|
|
|
|
return (e.solid != SOLID_NOT && e.solid != SOLID_TRIGGER);
|
|
|
|
};
|
|
|
|
|
|
|
|
float(entity e) is_teleportable = {
|
2004-02-09 04:41:39 +00:00
|
|
|
return (e.movetype != MOVETYPE_NONE &&
|
|
|
|
e.movetype != MOVETYPE_PUSH &&
|
|
|
|
e.movetype != MOVETYPE_NOCLIP &&
|
|
|
|
(e.solid == SOLID_BBOX || e.solid == SOLID_SLIDEBOX));
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void() util_set_movedir = {
|
|
|
|
if (self.mangle != '0 0 0')
|
|
|
|
self.angles = self.mangle;
|
|
|
|
|
2004-02-09 04:41:39 +00:00
|
|
|
if (self.angles == '0 -1 0') {
|
2003-10-24 21:43:32 +00:00
|
|
|
self.movedir = '0 0 1';
|
2004-02-09 04:41:39 +00:00
|
|
|
} else if (self.angles == '0 -2 0') {
|
2003-10-24 21:43:32 +00:00
|
|
|
self.movedir = '0 0 -1';
|
2004-02-09 04:41:39 +00:00
|
|
|
} else {
|
2003-10-24 21:43:32 +00:00
|
|
|
makevectors(self.angles);
|
|
|
|
self.movedir = v_forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.angles = '0 0 0';
|
|
|
|
};
|
|
|
|
|
|
|
|
float(entity ent1, entity ent2) util_entities_touch = {
|
|
|
|
if (ent1.mins_x > ent2.maxs_x)
|
|
|
|
return FALSE;
|
|
|
|
if (ent1.mins_y > ent2.maxs_y)
|
|
|
|
return FALSE;
|
|
|
|
if (ent1.mins_z > ent2.maxs_z)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (ent2.mins_x > ent1.maxs_x)
|
|
|
|
return FALSE;
|
|
|
|
if (ent2.mins_y > ent1.maxs_y)
|
|
|
|
return FALSE;
|
|
|
|
if (ent2.mins_z > ent1.maxs_z)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
};
|