]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
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 e25b0b41a9c40cf07afc047f9abbf5241b32f1ce..1418a8f392c787187eb07675ab54a02faae8177f 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 f35448e9c2212dd98506391dbced0b0133658e6d..1a8c2cbe7705e4bf9bf3f037eb37aa8d48107b97 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 a75a806195fbf4faef52ee99f0b3757f3712b39c..1b43468ca12b50532cf66ff149409d57762de5f7 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 e1bf48c1b2af08d2d70a6a062b33ea93c0b32823..7318a587585cef1ab6cd85b59876f0755738ffb3 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 23942ce2429545740ed8ab37f43e0b9fa12a8bd9..cd111b258e6851a2d2b5450dd6ed396b7b7d98c8 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 975f9045eb42ba2b8bdcc500154ab5b0cf00ef57..e19116067ee037cb4d12aff94ec2c9f982095fe2 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 3ba1ff07476a9e03e568f395eeb7561b5bfbdc88..5a8df2aad16a20e40e1a0177cf91ca599f26aa26 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 596b95fa08c6bb5d1461bbd1082999d70bfd757c..56f5da90a3d70b72d9e407c2923c72f6f84aa792 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 dc3a89b23b85c4c146f854b6d18445221917a246..106c982ae8cfa8d8b5d2832f9891740cf086241f 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 de6030deff75d6ef79d9e6d07f66b98bb9c1b3d1..35f1921edae621cca8681943bb5d8c80fdd73651 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 37fde41c82d5c2540d70b0c8e97730e3dcb74928..21e0a435d7a951619029d085a63d12fc113196a7 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 a1f766f018875d638da8a70f277e5d89e26e4155..04e226448405b58acfa9786be112c38918887616 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 ed8cf6d194b76df5aa2859cdada074846ffd2918..baafa51c66b5c1a596f68c9d0337121a75a1d073 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 fed077ba2bf9dfedfdf1ca0290bb4200ecfcc4c5..bf3362ab897593149faff730c372e3b6653fff9f 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 50e37182c3a6ce0a143b6fc8975bd2f89a9fce84..d3c894b96edfe548bbbd2f1b9c9ac8c4d8641267 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 b68c8acf69e94e788505910c5d2cda6d2db9b645..792e7a338d0b080a16d4dcb4a1d0a7f69d936f4f 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();