From 4ce3de298e6bc8a307fa34a4f9c27020b3379332 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 27 Sep 2015 15:55:31 +1000 Subject: [PATCH] Migrate turrets to the registry system --- qcsrc/common/turrets/{all.qh => all.inc} | 0 qcsrc/common/turrets/cl_turrets.qc | 10 +-- qcsrc/common/turrets/config.qc | 9 ++- qcsrc/common/turrets/turrets.qc | 50 ++------------- qcsrc/common/turrets/turrets.qh | 71 ++++++++++++++++------ qcsrc/common/turrets/unit/ewheel.qc | 4 +- qcsrc/common/turrets/unit/flac.qc | 4 +- qcsrc/common/turrets/unit/fusionreactor.qc | 4 +- qcsrc/common/turrets/unit/hellion.qc | 4 +- qcsrc/common/turrets/unit/hk.qc | 4 +- qcsrc/common/turrets/unit/machinegun.qc | 4 +- qcsrc/common/turrets/unit/mlrs.qc | 4 +- qcsrc/common/turrets/unit/phaser.qc | 4 +- qcsrc/common/turrets/unit/plasma.qc | 4 +- qcsrc/common/turrets/unit/plasma_dual.qc | 4 +- qcsrc/common/turrets/unit/tesla.qc | 4 +- qcsrc/common/turrets/unit/walker.qc | 4 +- 17 files changed, 89 insertions(+), 99 deletions(-) rename qcsrc/common/turrets/{all.qh => all.inc} (100%) diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.inc similarity index 100% rename from qcsrc/common/turrets/all.qh rename to qcsrc/common/turrets/all.inc diff --git a/qcsrc/common/turrets/cl_turrets.qc b/qcsrc/common/turrets/cl_turrets.qc index e25b0b41a..1418a8f39 100644 --- a/qcsrc/common/turrets/cl_turrets.qc +++ b/qcsrc/common/turrets/cl_turrets.qc @@ -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 { diff --git a/qcsrc/common/turrets/config.qc b/qcsrc/common/turrets/config.qc index f35448e9c..1a8c2cbe7 100644 --- a/qcsrc/common/turrets/config.qc +++ b/qcsrc/common/turrets/config.qc @@ -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)); } diff --git a/qcsrc/common/turrets/turrets.qc b/qcsrc/common/turrets/turrets.qc index a75a80619..1b43468ca 100644 --- a/qcsrc/common/turrets/turrets.qc +++ b/qcsrc/common/turrets/turrets.qc @@ -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 diff --git a/qcsrc/common/turrets/turrets.qh b/qcsrc/common/turrets/turrets.qh index e1bf48c1b..7318a5875 100644 --- a/qcsrc/common/turrets/turrets.qh +++ b/qcsrc/common/turrets/turrets.qh @@ -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 diff --git a/qcsrc/common/turrets/unit/ewheel.qc b/qcsrc/common/turrets/unit/ewheel.qc index 23942ce24..cd111b258 100644 --- a/qcsrc/common/turrets/unit/ewheel.qc +++ b/qcsrc/common/turrets/unit/ewheel.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/flac.qc b/qcsrc/common/turrets/unit/flac.qc index 975f9045e..e19116067 100644 --- a/qcsrc/common/turrets/unit/flac.qc +++ b/qcsrc/common/turrets/unit/flac.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/fusionreactor.qc b/qcsrc/common/turrets/unit/fusionreactor.qc index 3ba1ff074..5a8df2aad 100644 --- a/qcsrc/common/turrets/unit/fusionreactor.qc +++ b/qcsrc/common/turrets/unit/fusionreactor.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/hellion.qc b/qcsrc/common/turrets/unit/hellion.qc index 596b95fa0..56f5da90a 100644 --- a/qcsrc/common/turrets/unit/hellion.qc +++ b/qcsrc/common/turrets/unit/hellion.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/hk.qc b/qcsrc/common/turrets/unit/hk.qc index dc3a89b23..106c982ae 100644 --- a/qcsrc/common/turrets/unit/hk.qc +++ b/qcsrc/common/turrets/unit/hk.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/machinegun.qc b/qcsrc/common/turrets/unit/machinegun.qc index de6030def..35f1921ed 100644 --- a/qcsrc/common/turrets/unit/machinegun.qc +++ b/qcsrc/common/turrets/unit/machinegun.qc @@ -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); diff --git a/qcsrc/common/turrets/unit/mlrs.qc b/qcsrc/common/turrets/unit/mlrs.qc index 37fde41c8..21e0a435d 100644 --- a/qcsrc/common/turrets/unit/mlrs.qc +++ b/qcsrc/common/turrets/unit/mlrs.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/phaser.qc b/qcsrc/common/turrets/unit/phaser.qc index a1f766f01..04e226448 100644 --- a/qcsrc/common/turrets/unit/phaser.qc +++ b/qcsrc/common/turrets/unit/phaser.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/plasma.qc b/qcsrc/common/turrets/unit/plasma.qc index ed8cf6d19..baafa51c6 100644 --- a/qcsrc/common/turrets/unit/plasma.qc +++ b/qcsrc/common/turrets/unit/plasma.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/plasma_dual.qc b/qcsrc/common/turrets/unit/plasma_dual.qc index fed077ba2..bf3362ab8 100644 --- a/qcsrc/common/turrets/unit/plasma_dual.qc +++ b/qcsrc/common/turrets/unit/plasma_dual.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/tesla.qc b/qcsrc/common/turrets/unit/tesla.qc index 50e37182c..d3c894b96 100644 --- a/qcsrc/common/turrets/unit/tesla.qc +++ b/qcsrc/common/turrets/unit/tesla.qc @@ -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(); diff --git a/qcsrc/common/turrets/unit/walker.qc b/qcsrc/common/turrets/unit/walker.qc index b68c8acf6..792e7a338 100644 --- a/qcsrc/common/turrets/unit/walker.qc +++ b/qcsrc/common/turrets/unit/walker.qc @@ -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(); -- 2.39.2