2003-10-27 22:27:29 +00:00
|
|
|
#include "act.qh"
|
|
|
|
|
2003-10-24 21:43:32 +00:00
|
|
|
#include "common.qh"
|
|
|
|
|
|
|
|
#include "items.qh"
|
|
|
|
#include "damage.qh"
|
2003-10-27 22:27:29 +00:00
|
|
|
#include "misc.qh"
|
2003-10-24 21:43:32 +00:00
|
|
|
#include "teleport.qh"
|
|
|
|
|
|
|
|
#include "override.qh"
|
|
|
|
|
|
|
|
.entity overrider, overrider_self;
|
|
|
|
.float overrider_priority;
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
|
|
|
/* Let's make my life simpler when I add new ones, mmmkay? */
|
|
|
|
#define all_funcs() \
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(float (), f_v, th_takeitem, (), return, FALSE); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(void (entity missile), v_e, th_attack, (missile), , ); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(float (float dmg), f_f, th_takedamage, (dmg), return, FALSE); \
|
|
|
|
one_func(float (float dmg), f_f, th_dealdamage, (dmg), return, dmg); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(void (), v_v, th_die, (), , ); \
|
|
|
|
one_func(void (), v_v, th_kill, (), , ); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(void (), v_v, prethink, (), , ); \
|
|
|
|
one_func(void (), v_v, actthink, (), , ); \
|
|
|
|
one_func(void (), v_v, postthink, (), , ); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(float (vector org), f_c, th_teleport, (org), return, TRUE); \
|
2003-10-24 21:43:32 +00:00
|
|
|
\
|
2004-02-08 07:34:17 +00:00
|
|
|
one_func(float (entity missile), f_e, th_projectile, (missile), return, TRUE)
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define all_types() \
|
2004-02-08 07:34:17 +00:00
|
|
|
one_type (void (), v_v); \
|
|
|
|
one_type (float (), f_v); \
|
|
|
|
one_type (void (entity ent), v_e); \
|
|
|
|
one_type (float (float flt), f_f); \
|
|
|
|
one_type (float (vector vec), f_c); \
|
|
|
|
one_type (float (entity ent), f_e)
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
|
|
|
/* default passthru functions */
|
|
|
|
#define one_func(type1,type2,func,args,return,val) \
|
|
|
|
type1 _passthru_##func = { \
|
|
|
|
local entity ovr; \
|
2004-02-08 07:34:17 +00:00
|
|
|
ovr = override_findself (); \
|
2003-10-24 21:43:32 +00:00
|
|
|
if (ovr.func) \
|
2003-10-25 06:05:14 +00:00
|
|
|
return ovr.func args; \
|
2003-10-24 21:43:32 +00:00
|
|
|
return val; \
|
|
|
|
}
|
|
|
|
|
|
|
|
all_funcs();
|
|
|
|
|
|
|
|
#undef one_func
|
|
|
|
|
|
|
|
/* for the override_set_FUNCTION macros in override.qh */
|
|
|
|
#define one_type(type1,type2) \
|
2004-02-08 07:34:17 +00:00
|
|
|
void(entity e, .type1 fld, type1 func) override_set_##type2 = { \
|
2003-10-24 21:43:32 +00:00
|
|
|
if (e.overrider) \
|
|
|
|
e.overrider.fld = func; \
|
|
|
|
else \
|
|
|
|
e.fld = func; \
|
2004-02-08 07:34:17 +00:00
|
|
|
}
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
all_types ();
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
#undef one_type
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity e1, entity e2)
|
|
|
|
_override_swap =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
#define one_type(type1,type2) local type1 t_##type2
|
|
|
|
all_types();
|
|
|
|
#undef one_type
|
|
|
|
|
|
|
|
/* Swap all the functions */
|
|
|
|
#define one_func(type1,type2,func,args,return,val) \
|
2004-02-08 07:34:17 +00:00
|
|
|
t_##type2 = e1.func; \
|
|
|
|
e1.func = e2.func; \
|
|
|
|
e2.func = t_##type2
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
all_funcs();
|
|
|
|
#undef one_func
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===================================================================== //
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity (entity e, string override_class, float priority)
|
|
|
|
override_create =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity ovr, ovr2;
|
|
|
|
|
|
|
|
for (ovr = e.overrider; ovr; ovr = ovr.overrider) {
|
|
|
|
if (ovr.classname == override_class) {
|
|
|
|
ovr2 = ovr.overrider;
|
2004-02-08 07:34:17 +00:00
|
|
|
if (!ovr2)
|
|
|
|
ovr2 = e;
|
|
|
|
_override_swap (ovr, ovr2);
|
2003-10-24 21:43:32 +00:00
|
|
|
return ovr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the tail.. */
|
|
|
|
for (ovr = e; ovr.overrider; ovr = ovr.overrider) {
|
|
|
|
if (ovr.overrider.overrider_priority > priority)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ovr2 = ovr.overrider;
|
|
|
|
ovr.overrider = spawn(override_class);
|
|
|
|
ovr.overrider.owner = ovr;
|
|
|
|
ovr.overrider.overrider = ovr2;
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
if (ovr2)
|
|
|
|
ovr2.owner = ovr.overrider;
|
|
|
|
if (!ovr2)
|
|
|
|
ovr2 = e;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
ovr = ovr.overrider;
|
|
|
|
ovr.overrider_priority = priority;
|
|
|
|
ovr.goalentity = ovr2;
|
|
|
|
|
|
|
|
/* Set default passthru funcs for ovr */
|
|
|
|
#define one_func(type1,type2,func,args,return,val) \
|
2004-02-08 07:34:17 +00:00
|
|
|
ovr.func = _passthru_##func
|
2003-10-24 21:43:32 +00:00
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
all_funcs ();
|
2003-10-24 21:43:32 +00:00
|
|
|
#undef one_func
|
|
|
|
|
|
|
|
return ovr;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity ovr)
|
|
|
|
override_finalize =
|
|
|
|
{
|
|
|
|
_override_swap (ovr, ovr.goalentity);
|
2003-10-24 21:43:32 +00:00
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
entity ()
|
|
|
|
override_findself =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity ovrself;
|
|
|
|
|
|
|
|
ovrself = self.overrider_self;
|
|
|
|
if (!ovrself) {
|
|
|
|
/* Move to the end of the list */
|
2004-02-08 07:34:17 +00:00
|
|
|
for (ovrself = self.overrider; ovrself.overrider;
|
|
|
|
ovrself = ovrself.overrider);
|
2003-10-24 21:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.overrider_self = ovrself.owner;
|
|
|
|
if (self.overrider_self == self)
|
|
|
|
self.overrider_self = world;
|
|
|
|
|
|
|
|
return ovrself;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void ()
|
|
|
|
override_halt =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
self.overrider_self = world;
|
|
|
|
};
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
void (entity e, entity ovr)
|
|
|
|
override_destroy =
|
|
|
|
{
|
2003-10-24 21:43:32 +00:00
|
|
|
local entity ovr2;
|
|
|
|
|
|
|
|
ovr2 = ovr.overrider;
|
2004-02-08 07:34:17 +00:00
|
|
|
if (!ovr2)
|
|
|
|
ovr2 = e;
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
/* Copy the funcs from ovr to ovr2 */
|
|
|
|
#define one_func(type1,type2,func,args,return,val) \
|
2004-02-08 07:34:17 +00:00
|
|
|
ovr2.func = ovr.func
|
2003-10-24 21:43:32 +00:00
|
|
|
|
|
|
|
all_funcs();
|
|
|
|
#undef one_func
|
|
|
|
|
2004-02-08 07:34:17 +00:00
|
|
|
if (ovr.overrider)
|
|
|
|
ovr.overrider.owner = ovr.owner;
|
2003-10-24 21:43:32 +00:00
|
|
|
ovr.owner.overrider = ovr.overrider;
|
|
|
|
|
|
|
|
ovr.think = SUB_remove;
|
|
|
|
ovr.nextthink = time;
|
|
|
|
};
|