#include "turret.qh"
-void register_turret(entity e, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname);
+void register_turret(Turret e, bool(Turret, int) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname);
const int TUR_MAXCOUNT = 24;
entity turret_info[TUR_MAXCOUNT], turret_info_first, turret_info_last;
float TUR_COUNT;
#define _REGISTER_TURRET(id, func, turretflags, min_s, max_s, modelname, headmodelname, shortname, mname) \
- float func(float); \
+ bool func(Turret, int); \
REGISTER(RegisterTurrets, TUR, turret_info, TUR_COUNT, id, m_id, NEW(Turret)) { \
register_turret(this, func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname); \
}
void RegisterTurrets();
REGISTER_REGISTRY(RegisterTurrets)
+#define REGISTER_TURRET(...) EVAL(OVERLOAD(REGISTER_TURRET, __VA_ARGS__))
+
+#define REGISTER_TURRET_2(id, inst) REGISTER(RegisterTurrets, TUR, turret_info, TUR_COUNT, id, m_id, inst)
+
#ifdef MENUQC
-#define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
- _REGISTER_TURRET(id,t_null,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
+#define REGISTER_TURRET_9(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
+ _REGISTER_TURRET(id,t_new,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
#else
-#define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
+#define REGISTER_TURRET_9(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
_REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
#endif
-void register_turret(Turret e, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname)
+void register_turret(Turret e, bool(Turret, int) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname)
{
e.classname = "turret_info";
- e.turretid = e.m_id;
- e.netname = shortname;
- e.turret_name = mname;
+
e.turret_func = func;
- e.mdl = modelname;
- e.cvar_basename = shortname;
e.spawnflags = turretflags;
e.mins = min_s;
e.maxs = max_s;
+ e.mdl = modelname;
e.model = strzone(strcat("models/turrets/", modelname));
e.head_model = strzone(strcat("models/turrets/", headmodelname));
+ e.netname = shortname;
+ e.turret_name = mname;
}
entity get_turretinfo(int id);
REGISTER_TURRET(Null,
- t_null,
+ t_new,
0,
'-0 -0 -0',
'0 0 0',
o_z = 0;
if(hud != HUD_NORMAL)
{
- if((get_turretinfo(self.turretid)).spawnflags & TUR_FLAG_MOVE)
+ if((get_turretinfo(self.m_id)).spawnflags & TUR_FLAG_MOVE)
txt = "gfx/vehicles/turret_moving.tga";
else
txt = "gfx/vehicles/turret_stationary.tga";
void turret_construct()
{SELFPARAM();
- entity tur = get_turretinfo(self.turretid);
+ entity tur = get_turretinfo(self.m_id);
if(self.tur_head == world)
self.tur_head = spawn();
- self.netname = TUR_NAME(self.turretid);
+ self.netname = TUR_NAME(self.m_id);
setorigin(self, self.origin);
_setmodel(self, tur.model);
setsize(self, tur.mins, tur.maxs);
setsize(self.tur_head, '0 0 0', '0 0 0');
- if(self.turretid == TUR_EWHEEL.m_id)
+ if(self.m_id == TUR_EWHEEL.m_id)
setattachment(self.tur_head, self, "");
else
setattachment(self.tur_head, self, "tag_head");
self.teamradar_color = '1 0 0';
self.alpha = 1;
- TUR_ACTION(self.turretid, TR_SETUP);
+ TUR_ACTION(self.m_id, TR_SETUP);
}
entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode);
if (!autocvar_cl_nogibs)
{
// Base
- if(self.turretid == TUR_EWHEEL.m_id)
- turret_gibtoss((get_turretinfo(self.turretid)).model, self.origin + '0 0 18', self.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', true);
- else if (self.turretid == TUR_WALKER.m_id)
- turret_gibtoss((get_turretinfo(self.turretid)).model, self.origin + '0 0 18', self.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', true);
- else if (self.turretid == TUR_TESLA.m_id)
- turret_gibtoss((get_turretinfo(self.turretid)).model, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
+ if(self.m_id == TUR_EWHEEL.m_id)
+ turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', self.velocity + '0 0 400' + '0.1 0.1 1' * (random() * 400), '-1 -1 -1', true);
+ else if (self.m_id == TUR_WALKER.m_id)
+ turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', self.velocity + '0 0 300' + '0.1 0.1 1' * (random() * 200), '-1 -1 -1', true);
+ else if (self.m_id == TUR_TESLA.m_id)
+ turret_gibtoss((get_turretinfo(self.m_id)).model, self.origin + '0 0 18', '0 0 200', '-1 -1 -1', false);
else
{
if (random() > 0.5)
else
turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 8', '0 0 0', '0 0 0', true);
- entity headgib = turret_gibtoss((get_turretinfo(self.turretid)).head_model, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
+ entity headgib = turret_gibtoss((get_turretinfo(self.m_id)).head_model, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', true);
if(headgib)
{
headgib.angles = headgib.move_angles = self.tur_head.angles;
if(sf & TNSF_SETUP)
{
- self.turretid = ReadByte();
+ self.m_id = ReadByte();
self.origin_x = ReadCoord();
self.origin_y = ReadCoord();
if(self.damage_flags & TFL_DMG_DEATH_NORESPAWN)
{
- TUR_ACTION(self.turretid, TR_DEATH);
+ TUR_ACTION(self.m_id, TR_DEATH);
remove(self.tur_head);
remove(self);
self.nextthink = time + 0.2;
self.think = turret_hide;
- TUR_ACTION(self.turretid, TR_DEATH);
+ TUR_ACTION(self.m_id, TR_DEATH);
}
}
self.SendFlags = TNSF_FULL_UPDATE;
- TUR_ACTION(self.turretid, TR_SETUP);
+ TUR_ACTION(self.m_id, TR_SETUP);
}
WriteByte(MSG_ENTITY, sf);
if(sf & TNSF_SETUP)
{
- WriteByte(MSG_ENTITY, self.turretid);
+ WriteByte(MSG_ENTITY, self.m_id);
WriteCoord(MSG_ENTITY, self.origin_x);
WriteCoord(MSG_ENTITY, self.origin_y);
return true;
}
-void load_unit_settings(entity ent, string unitname, float is_reload)
+void load_unit_settings(entity ent, float is_reload)
{SELFPARAM();
+ string unitname = ent.netname;
string sbase;
if (ent == world)
ent.track_blendrate = cvar(strcat(sbase,"_track_blendrate"));
if(is_reload)
- TUR_ACTION(self.turretid, TR_SETUP);
+ TUR_ACTION(self.m_id, TR_SETUP);
}
void turret_projectile_explode()
if(MUTATOR_CALLHOOK(TurretFire, self))
return;
- TUR_ACTION(self.turretid, TR_ATTACK);
+ TUR_ACTION(self.m_id, TR_ATTACK);
self.attack_finished_single = time + self.shot_refire;
self.ammo -= self.shot_dmg;
if (turret_checkfire())
turret_fire();
- TUR_ACTION(self.turretid, TR_THINK);
+ TUR_ACTION(self.m_id, TR_THINK);
return;
}
if(!(self.track_flags & TFL_TRACK_NO))
turret_track();
- TUR_ACTION(self.turretid, TR_THINK);
+ TUR_ACTION(self.m_id, TR_THINK);
// And bail.
return;
turret_fire();
}
- TUR_ACTION(self.turretid, TR_THINK);
+ TUR_ACTION(self.m_id, TR_THINK);
}
/*
{
if (IS_TURRET(e))
{
- load_unit_settings(e,e.cvar_basename,1);
- TUR_ACTION(self.turretid, TR_THINK);
+ load_unit_settings(e,1);
+ TUR_ACTION(self.m_id, TR_THINK);
}
e = nextent(e);
entity e;
entity tur = get_turretinfo(tur_id);
- if(tur.turretid == 0)
+ if(tur.m_id == 0)
return false; // invalid turret
if(!self.tur_head) { TUR_ACTION(tur_id, TR_PRECACHE); } // if tur_head exists, we can assume this turret re-spawned
if(!(self.spawnflags & TSF_SUSPENDED))
builtin_droptofloor();
- self.cvar_basename = tur.cvar_basename;
- load_unit_settings(self, self.cvar_basename, 0);
+ self.netname = tur.netname;
+ load_unit_settings(self, 0);
if(!self.team || !teamplay) { self.team = MAX_SHOT_DISTANCE; }
if(!self.ticrate) { self.ticrate = ((self.turret_flags & TUR_FLAG_SUPPORT) ? 0.2 : 0.1); }
_setmodel(self, tur.model);
setsize(self, tur.mins, tur.maxs);
- self.turretid = tur_id;
+ self.m_id = tur_id;
self.classname = "turret_main";
self.active = ACTIVE_ACTIVE;
self.effects = EF_NODRAW;
#ifndef TURRET_H
#define TURRET_H
-// turret requests
-const int TR_SETUP = 1; // (BOTH) setup turret data
-const int TR_THINK = 2; // (SERVER) logic to run every frame
-const int TR_DEATH = 3; // (SERVER) called when turret dies
-const int TR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this turret
-const int TR_ATTACK = 5; // (SERVER) called when turret attacks
-const int TR_CONFIG = 6; // (ALL)
-
// functions:
entity get_turretinfo(int id);
// other useful macros
-#define TUR_ACTION(turrettype,mrequest) (get_turretinfo(turrettype)).turret_func(mrequest)
+#define _TUR_ACTION(tur, mrequest) tur.turret_func(tur, mrequest)
+#define TUR_ACTION(tur, mrequest) _TUR_ACTION(get_turretinfo(tur), mrequest)
#define TUR_NAME(turrettype) (get_turretinfo(turrettype)).turret_name
-float t_null(float dummy) { return 0; }
+bool t_new(entity this, int req);
CLASS(Turret, Object)
ATTRIB(Turret, m_id, int, 0)
- ATTRIB(Turret, turretid, int, 0)
/** short name */
ATTRIB(Turret, netname, string, string_null)
/** human readable name */
ATTRIB(Turret, turret_name, string, string_null)
/** t_... */
- ATTRIB(Turret, turret_func, float(float), t_null)
+ ATTRIB(Turret, turret_func, float(Turret, int), t_new)
/** currently a copy of the model */
ATTRIB(Turret, mdl, string, string_null)
/** full name of model */
ATTRIB(Turret, model, string, string_null)
/** full name of tur_head model */
ATTRIB(Turret, head_model, string, string_null)
- /** TODO: deprecate! */
- ATTRIB(Turret, cvar_basename, string, string_null)
ATTRIB(Turret, spawnflags, int, 0)
/** turret hitbox size */
ENDCLASS(Turret)
+// turret requests
+const int TR_SETUP = 1; // (BOTH) setup turret data
+.bool(Turret) tr_setup;
+const int TR_THINK = 2; // (SERVER) logic to run every frame
+.bool(Turret) tr_think;
+const int TR_DEATH = 3; // (SERVER) called when turret dies
+.bool(Turret) tr_death;
+const int TR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this turret
+.bool(Turret) tr_precache;
+const int TR_ATTACK = 5; // (SERVER) called when turret attacks
+.bool(Turret) tr_attack;
+const int TR_CONFIG = 6; // (ALL)
+.bool(Turret) tr_config;
+
+bool t_new(Turret this, int req)
+{
+ if (req == TR_SETUP) return this.tr_setup ? this.tr_setup(this) : false;
+ if (req == TR_THINK) return this.tr_think ? this.tr_think(this) : false;
+ if (req == TR_DEATH) return this.tr_death ? this.tr_death(this) : false;
+ if (req == TR_PRECACHE) return this.tr_precache ? this.tr_precache(this) : false;
+ if (req == TR_ATTACK) return this.tr_attack ? this.tr_attack(this) : false;
+ if (req == TR_CONFIG) return this.tr_config ? this.tr_config(this) : false;
+ return false;
+}
+
#endif
void spawnfunc_turret_ewheel() { SELFPARAM(); if(!turret_initialize(TUR_EWHEEL.m_id)) remove(self); }
-float t_ewheel(float req)
+float t_ewheel(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
}
-float t_ewheel(float req)
+float t_ewheel(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
void spawnfunc_turret_flac() { SELFPARAM(); if(!turret_initialize(TUR_FLAC.m_id)) remove(self); }
-float t_flac(float req)
+float t_flac(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_flac(float req)
+float t_flac(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_fusionreactor() { SELFPARAM(); if(!turret_initialize(TUR_FUSIONREACTOR.m_id)) remove(self); }
-float t_fusionreactor(float req)
+float t_fusionreactor(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_fusionreactor(float req)
+float t_fusionreactor(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_hellion() { SELFPARAM(); if(!turret_initialize(TUR_HELLION.m_id)) remove(self); }
-float t_hellion(float req)
+float t_hellion(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_hellion(float req)
+float t_hellion(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK.m_id)) remove(self); }
-float t_hk(float req)
+float t_hk(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_hk(float req)
+float t_hk(Turret thistur, float req)
{
switch(req)
{
void W_MachineGun_MuzzleFlash(void);
-float t_machinegun(float req)
+float t_machinegun(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_machinegun(float req)
+float t_machinegun(Turret thistur, float req)
{
switch(req)
{
#ifdef SVQC
void spawnfunc_turret_mlrs() { SELFPARAM(); if(!turret_initialize(TUR_MLRS.m_id)) remove(self); }
-float t_mlrs(float req)
+float t_mlrs(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_mlrs(float req)
+float t_mlrs(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_phaser() { SELFPARAM(); if(!turret_initialize(TUR_PHASER.m_id)) remove(self); }
-float t_phaser(float req)
+float t_phaser(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_phaser(float req)
+float t_phaser(Turret thistur, float req)
{
switch(req)
{
#ifdef SVQC
void spawnfunc_turret_plasma() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA.m_id)) remove(self); }
-float t_plasma(float req)
+float t_plasma(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_plasma(float req)
+float t_plasma(Turret thistur, float req)
{
switch(req)
{
#ifdef SVQC
-float t_plasma_dual(float req);
METHOD(PlasmaDualAttack, wr_think, bool(entity thiswep)) {
SELFPARAM();
if (self.BUTTON_ATCK)
self.tur_head = self;
self.shot_speed = max(1, ((!self.shot_speed) ? 2500 : self.shot_speed));
self.shot_spread = bound(0.0001, ((!self.shot_spread) ? 0.0125 : self.shot_spread), 500);
- t_plasma_dual(TR_ATTACK);
+ TUR_ACTION(TUR_PLASMA_DUAL.m_id, TR_ATTACK);
weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
}
return true;
void spawnfunc_turret_plasma_dual() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA_DUAL.m_id)) remove(self); }
-float t_plasma_dual(float req)
+float t_plasma_dual(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_plasma_dual(float req)
+float t_plasma_dual(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_tesla() { SELFPARAM(); if(!turret_initialize(TUR_TESLA.m_id)) remove(self); }
-float t_tesla(float req)
+float t_tesla(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
#endif // SVQC
#ifdef CSQC
-float t_tesla(float req)
+float t_tesla(Turret thistur, float req)
{
switch(req)
{
void spawnfunc_turret_walker() { SELFPARAM(); if(!turret_initialize(TUR_WALKER.m_id)) remove(self); }
-float t_walker(float req)
+float t_walker(Turret thistur, float req)
{SELFPARAM();
switch(req)
{
te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
}
-float t_walker(float req)
+float t_walker(Turret thistur, float req)
{SELFPARAM();
switch(req)
{