Migrate turrets to the registry system
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Sep 2015 05:55:31 +0000 (15:55 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 27 Sep 2015 05:55:31 +0000 (15:55 +1000)
18 files changed:
qcsrc/common/turrets/all.inc [new file with mode: 0644]
qcsrc/common/turrets/all.qh [deleted file]
qcsrc/common/turrets/cl_turrets.qc
qcsrc/common/turrets/config.qc
qcsrc/common/turrets/turrets.qc
qcsrc/common/turrets/turrets.qh
qcsrc/common/turrets/unit/ewheel.qc
qcsrc/common/turrets/unit/flac.qc
qcsrc/common/turrets/unit/fusionreactor.qc
qcsrc/common/turrets/unit/hellion.qc
qcsrc/common/turrets/unit/hk.qc
qcsrc/common/turrets/unit/machinegun.qc
qcsrc/common/turrets/unit/mlrs.qc
qcsrc/common/turrets/unit/phaser.qc
qcsrc/common/turrets/unit/plasma.qc
qcsrc/common/turrets/unit/plasma_dual.qc
qcsrc/common/turrets/unit/tesla.qc
qcsrc/common/turrets/unit/walker.qc

diff --git a/qcsrc/common/turrets/all.inc b/qcsrc/common/turrets/all.inc
new file mode 100644 (file)
index 0000000..04bb10f
--- /dev/null
@@ -0,0 +1,12 @@
+#include "unit/ewheel.qc"
+#include "unit/flac.qc"
+#include "unit/fusionreactor.qc"
+#include "unit/hellion.qc"
+#include "unit/hk.qc"
+#include "unit/machinegun.qc"
+#include "unit/mlrs.qc"
+#include "unit/phaser.qc"
+#include "unit/plasma.qc"
+#include "unit/plasma_dual.qc"
+#include "unit/tesla.qc"
+#include "unit/walker.qc"
diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh
deleted file mode 100644 (file)
index 04bb10f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "unit/ewheel.qc"
-#include "unit/flac.qc"
-#include "unit/fusionreactor.qc"
-#include "unit/hellion.qc"
-#include "unit/hk.qc"
-#include "unit/machinegun.qc"
-#include "unit/mlrs.qc"
-#include "unit/phaser.qc"
-#include "unit/plasma.qc"
-#include "unit/plasma_dual.qc"
-#include "unit/tesla.qc"
-#include "unit/walker.qc"
index e25b0b4..1418a8f 100644 (file)
@@ -1,3 +1,5 @@
+#include "turrets.qh"
+
 void turret_remove()
 {SELFPARAM();
        remove(self.tur_head);
@@ -216,7 +218,7 @@ void turret_construct()
        setsize(self, tur.mins, tur.maxs);
        setsize(self.tur_head, '0 0 0', '0 0 0');
 
-       if(self.turretid == TUR_EWHEEL)
+       if(self.turretid == TUR_EWHEEL.m_id)
                setattachment(self.tur_head, self, "");
        else
                setattachment(self.tur_head, self, "tag_head");
@@ -323,11 +325,11 @@ void turret_die()
        if (!autocvar_cl_nogibs)
        {
                // Base
-               if(self.turretid == TUR_EWHEEL)
+               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)
+               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)
+               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);
                else
                {
index f35448e..1a8c2cb 100644 (file)
@@ -27,9 +27,8 @@ float T_Config_Queue_Compare(float root, float child, entity pass)
 
 void Dump_Turret_Settings(void)
 {
-       float i, x, totalsettings = 0;
-       for(i = TUR_FIRST; i <= TUR_LAST; ++i)
-       {
+       float x, totalsettings = 0;
+       FOREACH(turret_info, it != TUR_Null, LAMBDA({
                // step 1: clear the queue
                TUR_CONFIG_COUNT = 0;
                for(x = 0; x <= MAX_TUR_CONFIG; ++x)
@@ -50,7 +49,7 @@ void Dump_Turret_Settings(void)
                // step 5: debug info
                LOG_INFO(sprintf("#%d: %s: %d settings...\n", i, TUR_NAME(i), TUR_CONFIG_COUNT));
                totalsettings += TUR_CONFIG_COUNT;
-       }
+       }));
 
        // clear queue now that we're finished
        TUR_CONFIG_COUNT = 0;
@@ -58,5 +57,5 @@ void Dump_Turret_Settings(void)
                { tur_config_queue[x] = string_null; }
 
        // extra information
-       LOG_INFO(sprintf("Totals: %d turrets, %d settings\n", (i - 1), totalsettings));
+       LOG_INFO(sprintf("Totals: %d turrets, %d settings\n", (TUR_COUNT - 1), totalsettings));
 }
index a75a806..1b43468 100644 (file)
@@ -1,47 +1,5 @@
-#include "all.qh"
+#include "turrets.qh"
 
-// TURRET PLUGIN SYSTEM
-entity turret_info[TUR_MAXCOUNT];
-entity dummy_turret_info;
-
-void register_turret(float id, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname)
-{
-       entity e;
-       turret_info[id - 1] = e = spawn();
-       e.classname = "turret_info";
-       e.turretid = 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.model = strzone(strcat("models/turrets/", modelname));
-       e.head_model = strzone(strcat("models/turrets/", headmodelname));
-}
-float t_null(float dummy) { return 0; }
-void register_turrets_done()
-{
-       dummy_turret_info = spawn();
-       dummy_turret_info.classname = "turret_info";
-       dummy_turret_info.turretid = 0; // you can recognize dummies by this
-       dummy_turret_info.netname = "";
-       dummy_turret_info.turret_name = "Turret";
-       dummy_turret_info.turret_func = t_null;
-       dummy_turret_info.mdl = "";
-       dummy_turret_info.mins = '-0 -0 -0';
-       dummy_turret_info.maxs = '0 0 0';
-       dummy_turret_info.model = "";
-}
-entity get_turretinfo(float id)
-{
-       entity m;
-       if(id < TUR_FIRST || id > TUR_LAST)
-               return dummy_turret_info;
-       m = turret_info[id - 1];
-       if(m)
-               return m;
-       return dummy_turret_info;
-}
+#define IMPLEMENTATION
+#include "all.inc"
+#undef IMPLEMENTATION
index e1bf48c..7318a58 100644 (file)
@@ -154,35 +154,66 @@ const int TNSF_FULL_UPDATE  = 16777215;
 // =====================
 
 float t_null(float dummy);
-void register_turret(float id, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname);
-void register_turrets_done();
+void register_turret(entity e, float(float) func, float turretflags, vector min_s, vector max_s, string modelname, string headmodelname, string shortname, string mname);
 
-const float TUR_MAXCOUNT = 24;
-const int TUR_FIRST = 1;
+const int TUR_MAXCOUNT = 24;
+entity turret_info[TUR_MAXCOUNT], turret_info_first, turret_info_last;
 float TUR_COUNT;
-float TUR_LAST;
 
-#define REGISTER_TURRET_2(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
-       float id; \
+#define _REGISTER_TURRET(id, func, turretflags, min_s, max_s, modelname, headmodelname, shortname, mname) \
        float func(float); \
-       void RegisterTurrets_##id() \
-       { \
-               TUR_LAST = (id = TUR_FIRST + TUR_COUNT); \
-               ++TUR_COUNT; \
-               register_turret(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname); \
-       } \
-       ACCUMULATE_FUNCTION(RegisterTurrets, RegisterTurrets_##id)
+       REGISTER(RegisterTurrets, TUR, turret_info, TUR_COUNT, id, m_id, spawn()) { \
+               register_turret(this, func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname); \
+       }
+
 #ifdef MENUQC
 #define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
-       REGISTER_TURRET_2(TUR_##id,t_null,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
+       _REGISTER_TURRET(id,t_null,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname)
 #else
 #define REGISTER_TURRET(id,func,turretflags,min_s,max_s,modelname,headmodelname,shortname,mname) \
-       REGISTER_TURRET_2(TUR_##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
 
-#include "all.qh"
-
-#undef REGISTER_TURRET
-ACCUMULATE_FUNCTION(RegisterTurrets, register_turrets_done)
+void register_turret(entity e, float(float) 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.model = strzone(strcat("models/turrets/", modelname));
+       e.head_model = strzone(strcat("models/turrets/", headmodelname));
+}
+float t_null(float dummy) { return 0; }
+
+
+REGISTER_TURRET(Null,
+       t_null,
+       0,
+       '-0 -0 -0',
+       '0 0 0',
+       "",
+       "",
+       "",
+       "Turret"
+);
+
+entity get_turretinfo(float id)
+{
+       entity m;
+       if(id < 1 || id > TUR_COUNT - 1)
+               return TUR_Null;
+       m = turret_info[id];
+       if(m)
+               return m;
+       return TUR_Null;
+}
+
+#include "all.inc"
 
 #endif
index 23942ce..cd111b2 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ EWHEEL,
 /* function   */ t_ewheel,
@@ -121,7 +121,7 @@ void ewheel_move_idle()
         movelib_beak_simple((autocvar_g_turrets_unit_ewheel_speed_stop));
 }
 
-void spawnfunc_turret_ewheel() { SELFPARAM(); if(!turret_initialize(TUR_EWHEEL)) remove(self); }
+void spawnfunc_turret_ewheel() { SELFPARAM(); if(!turret_initialize(TUR_EWHEEL.m_id)) remove(self); }
 
 float t_ewheel(float req)
 {SELFPARAM();
index 975f904..e191160 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ FLAC,
 /* function   */ t_flac,
@@ -28,7 +28,7 @@ void turret_flac_projectile_think_explode()
     remove(self);
 }
 
-void spawnfunc_turret_flac() { SELFPARAM(); if(!turret_initialize(TUR_FLAC)) remove(self); }
+void spawnfunc_turret_flac() { SELFPARAM(); if(!turret_initialize(TUR_FLAC.m_id)) remove(self); }
 
 float t_flac(float req)
 {SELFPARAM();
index 3ba1ff0..5a8df2a 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ FUSIONREACTOR,
 /* function   */ t_fusionreactor,
@@ -40,7 +40,7 @@ bool turret_fusionreactor_firecheck()
     return true;
 }
 
-void spawnfunc_turret_fusionreactor() { SELFPARAM(); if(!turret_initialize(TUR_FUSIONREACTOR)) remove(self); }
+void spawnfunc_turret_fusionreactor() { SELFPARAM(); if(!turret_initialize(TUR_FUSIONREACTOR.m_id)) remove(self); }
 
 float t_fusionreactor(float req)
 {SELFPARAM();
index 596b95f..56f5da9 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ HELLION,
 /* function   */ t_hellion,
@@ -76,7 +76,7 @@ void turret_hellion_missile_think()
     UpdateCSQCProjectile(self);
 }
 
-void spawnfunc_turret_hellion() { SELFPARAM(); if(!turret_initialize(TUR_HELLION)) remove(self); }
+void spawnfunc_turret_hellion() { SELFPARAM(); if(!turret_initialize(TUR_HELLION.m_id)) remove(self); }
 
 float t_hellion(float req)
 {SELFPARAM();
index dc3a89b..106c982 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ HK,
 /* function   */ t_hk,
@@ -273,7 +273,7 @@ float turret_hk_addtarget(entity e_target,entity e_sender)
     return 0;
 }
 
-void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK)) remove(self); }
+void spawnfunc_turret_hk() { SELFPARAM(); if(!turret_initialize(TUR_HK.m_id)) remove(self); }
 
 float t_hk(float req)
 {SELFPARAM();
index de6030d..35f1921 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ MACHINEGUN,
 /* function   */ t_machinegun,
@@ -11,7 +11,7 @@ REGISTER_TURRET(
 );
 #else
 #ifdef SVQC
-void spawnfunc_turret_machinegun() { SELFPARAM(); if(!turret_initialize(TUR_MACHINEGUN)) remove(self); }
+void spawnfunc_turret_machinegun() { SELFPARAM(); if(!turret_initialize(TUR_MACHINEGUN.m_id)) remove(self); }
 
 void W_MachineGun_MuzzleFlash(void);
 
index 37fde41..21e0a43 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ MLRS,
 /* function   */ t_mlrs,
@@ -11,7 +11,7 @@ REGISTER_TURRET(
 );
 #else
 #ifdef SVQC
-void spawnfunc_turret_mlrs() { SELFPARAM(); if(!turret_initialize(TUR_MLRS)) remove(self); }
+void spawnfunc_turret_mlrs() { SELFPARAM(); if(!turret_initialize(TUR_MLRS.m_id)) remove(self); }
 
 float t_mlrs(float req)
 {SELFPARAM();
index a1f766f..04e2264 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ PHASER,
 /* function   */ t_phaser,
@@ -57,7 +57,7 @@ void beam_think()
 
 }
 
-void spawnfunc_turret_phaser() { SELFPARAM(); if(!turret_initialize(TUR_PHASER)) remove(self); }
+void spawnfunc_turret_phaser() { SELFPARAM(); if(!turret_initialize(TUR_PHASER.m_id)) remove(self); }
 
 float t_phaser(float req)
 {SELFPARAM();
index ed8cf6d..baafa51 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ PLASMA,
 /* function   */ t_plasma,
@@ -11,7 +11,7 @@ REGISTER_TURRET(
 );
 #else
 #ifdef SVQC
-void spawnfunc_turret_plasma() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA)) remove(self); }
+void spawnfunc_turret_plasma() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA.m_id)) remove(self); }
 
 float t_plasma(float req)
 {SELFPARAM();
index fed077b..bf3362a 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ PLASMA_DUAL,
 /* function   */ t_plasma_dual,
@@ -11,7 +11,7 @@ REGISTER_TURRET(
 );
 #else
 #ifdef SVQC
-void spawnfunc_turret_plasma_dual() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA_DUAL)) remove(self); }
+void spawnfunc_turret_plasma_dual() { SELFPARAM(); if(!turret_initialize(TUR_PLASMA_DUAL.m_id)) remove(self); }
 
 float t_plasma_dual(float req)
 {SELFPARAM();
index 50e3718..d3c894b 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ TESLA,
 /* function   */ t_tesla,
@@ -89,7 +89,7 @@ float turret_tesla_firecheck()
     return 0;
 }
 
-void spawnfunc_turret_tesla() { SELFPARAM(); if(!turret_initialize(TUR_TESLA)) remove(self); }
+void spawnfunc_turret_tesla() { SELFPARAM(); if(!turret_initialize(TUR_TESLA.m_id)) remove(self); }
 
 float t_tesla(float req)
 {SELFPARAM();
index b68c8ac..792e7a3 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef REGISTER_TURRET
+#ifndef IMPLEMENTATION
 REGISTER_TURRET(
 /* TUR_##id   */ WALKER,
 /* function   */ t_walker,
@@ -334,7 +334,7 @@ void walker_move_path()
 #endif
 }
 
-void spawnfunc_turret_walker() { SELFPARAM(); if(!turret_initialize(TUR_WALKER)) remove(self); }
+void spawnfunc_turret_walker() { SELFPARAM(); if(!turret_initialize(TUR_WALKER.m_id)) remove(self); }
 
 float t_walker(float req)
 {SELFPARAM();