From eaf335444015f42b9bd29135ec3ad0cb23c2ea63 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 22 Aug 2015 14:31:25 +1000 Subject: [PATCH] Remove vehicleid globals --- qcsrc/common/vehicles/all.qc | 49 +++---------------------- qcsrc/common/vehicles/all.qh | 44 +++++++++++++++------- qcsrc/common/vehicles/cl_vehicles.qc | 4 +- qcsrc/common/vehicles/unit/bumblebee.qc | 5 ++- qcsrc/common/vehicles/unit/racer.qc | 3 +- qcsrc/common/vehicles/unit/raptor.qc | 3 +- qcsrc/common/vehicles/unit/spiderbot.qc | 3 +- qcsrc/common/vehicles/vehicle.qh | 2 +- 8 files changed, 48 insertions(+), 65 deletions(-) diff --git a/qcsrc/common/vehicles/all.qc b/qcsrc/common/vehicles/all.qc index 4923c1b01..d90e0696b 100644 --- a/qcsrc/common/vehicles/all.qc +++ b/qcsrc/common/vehicles/all.qc @@ -13,10 +13,8 @@ #include "all.inc" #undef IMPLEMENTATION -// VEHICLE PLUGIN SYSTEM -entity dummy_vehicle_info; - -void vehicles_common_initialize() +#ifndef MENUQC +STATIC_INIT(vehicles_common_initialize) { #ifdef CSQC precache_model("models/vehicles/bomblet.md3"); @@ -46,54 +44,17 @@ void vehicles_common_initialize() addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2); #endif // SVQC } +#endif -void register_vehicle(entity e, float id, float(float) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname) -{ - vehicle_info[id - 1] = e; - e.classname = "vehicle_info"; - e.vehicleid = id; - e.netname = shortname; - e.vehicle_name = vname; - e.vehicle_func = func; - e.mdl = modelname; - e.spawnflags = vehicleflags; - e.mins = min_s; - e.maxs = max_s; - e.model = modelname; - e.head_model = headmodelname; - e.hud_model = hudmodelname; - e.tag_head = headtag; - e.tag_hud = hudtag; - e.tag_view = viewtag; - - #ifndef MENUQC - vehicles_common_initialize(); - #endif -} -void register_vehicles_done() -{ - dummy_vehicle_info = spawn(); - dummy_vehicle_info.classname = "vehicle_info"; - dummy_vehicle_info.vehicleid = 0; // you can recognize dummies by this - dummy_vehicle_info.netname = ""; - dummy_vehicle_info.vehicle_name = "Vehicle"; - dummy_vehicle_info.vehicle_func = v_null; - dummy_vehicle_info.mdl = ""; - dummy_vehicle_info.mins = '-0 -0 -0'; - dummy_vehicle_info.maxs = '0 0 0'; - dummy_vehicle_info.model = ""; - dummy_vehicle_info.head_model = ""; - dummy_vehicle_info.hud_model = ""; -} entity get_vehicleinfo(float id) { entity m; if(id < VEH_FIRST || id > VEH_LAST) - return dummy_vehicle_info; + return VEH_NULL; m = vehicle_info[id - 1]; if(m) return m; - return dummy_vehicle_info; + return VEH_NULL; } #endif diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index dbb7b0e39..08a3020c7 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -72,23 +72,41 @@ int VEH_COUNT; const int VEH_FIRST = 1; #define VEH_LAST (VEH_FIRST + VEH_COUNT - 1) /** If you register a new vehicle, make sure to add it to all.inc */ -#define REGISTER_VEHICLE(id, class) REGISTER(RegisterVehicles, vehicle_info, vehicle_info, VEH_COUNT, id, m_id, NEW(class)) +#define REGISTER_VEHICLE(id, class) REGISTER(RegisterVehicles, VEH, vehicle_info, VEH_COUNT, id, vehicleid, NEW(class)) #include "vehicle.qh" -#define REGISTER_VEHICLE_SIMPLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \ - int VEH_##id; \ - int func(int); \ - REGISTER_VEHICLE(id, Vehicle) { \ - VEH_##id = VEH_LAST; \ - register_vehicle(this,VEH_##id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname); \ - } \ - REGISTER_INIT(vehicle_info, id) +#define REGISTER_VEHICLE_SIMPLE(id, func, vehicleflags, min_s, max_s, modelname, headmodelname, hudmodelname, headtag, hudtag, viewtag, shortname, vname) \ + REGISTER_VEHICLE(id, Vehicle) { \ + this.netname = shortname; \ + this.vehicle_name = vname; \ + this.vehicle_func = func; \ + this.mdl = modelname; \ + this.spawnflags = vehicleflags; \ + this.mins = min_s; \ + this.maxs = max_s; \ + this.model = modelname; \ + this.head_model = headmodelname; \ + this.hud_model = hudmodelname; \ + this.tag_head = headtag; \ + this.tag_hud = hudtag; \ + this.tag_view = viewtag; \ + } \ + REGISTER_INIT(VEH, id) REGISTER_REGISTRY(RegisterVehicles) -void register_vehicle(entity e, int id, int(int) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname); -void register_vehicles_done(); -#include "all.inc" +REGISTER_VEHICLE(NULL, Vehicle) { + this.vehicleid = 0; // you can recognize dummies by this + this.netname = ""; + this.vehicle_name = "Vehicle"; + this.vehicle_func = v_null; + this.mdl = ""; + this.mins = '-0 -0 -0'; + this.maxs = '0 0 0'; + this.model = ""; + this.head_model = ""; + this.hud_model = ""; +} -ACCUMULATE_FUNCTION(RegisterVehicles, register_vehicles_done); +#include "all.inc" #endif diff --git a/qcsrc/common/vehicles/cl_vehicles.qc b/qcsrc/common/vehicles/cl_vehicles.qc index 2511defb4..141f8fc42 100644 --- a/qcsrc/common/vehicles/cl_vehicles.qc +++ b/qcsrc/common/vehicles/cl_vehicles.qc @@ -295,7 +295,7 @@ void Vehicles_drawHUD( } // Bumblebee gunner crosshairs - if(hud == VEH_BUMBLEBEE) + if(hud == VEH_BUMBLEBEE.vehicleid) { tmpSize = '1 1 1' * hud_fontsize; tmpPos.x = hudPos.x + hudSize.x * (520/768); @@ -314,7 +314,7 @@ void Vehicles_drawHUD( } // Raptor bomb crosshair - if(hud == VEH_RAPTOR && weapon2mode != RSM_FLARE) + if(hud == VEH_RAPTOR.vehicleid && weapon2mode != RSM_FLARE) { vector where; diff --git a/qcsrc/common/vehicles/unit/bumblebee.qc b/qcsrc/common/vehicles/unit/bumblebee.qc index 7d338d3e7..b4686d63c 100644 --- a/qcsrc/common/vehicles/unit/bumblebee.qc +++ b/qcsrc/common/vehicles/unit/bumblebee.qc @@ -1,6 +1,7 @@ #ifndef VEHICLE_BUMBLEBEE #define VEHICLE_BUMBLEBEE #include "bumblebee.qh" +int v_bumblebee(int); REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ BUMBLEBEE, /* function */ v_bumblebee, @@ -660,7 +661,7 @@ void bumblebee_land() void bumblebee_exit(float eject) { - if(self.owner.vehicleid == VEH_BUMBLEBEE) + if(self.owner.vehicleid == VEH_BUMBLEBEE.vehicleid) { bumblebee_gunner_exit(eject); return; @@ -764,7 +765,7 @@ float bumble_raygun_send(entity to, float sf) void spawnfunc_vehicle_bumblebee() { if(!autocvar_g_vehicle_bumblebee) { remove(self); return; } - if(!vehicle_initialize(VEH_BUMBLEBEE, false)) { remove(self); return; } + if(!vehicle_initialize(VEH_BUMBLEBEE.vehicleid, false)) { remove(self); return; } } float v_bumblebee(float req) diff --git a/qcsrc/common/vehicles/unit/racer.qc b/qcsrc/common/vehicles/unit/racer.qc index 3549150d5..afcb131e9 100644 --- a/qcsrc/common/vehicles/unit/racer.qc +++ b/qcsrc/common/vehicles/unit/racer.qc @@ -1,5 +1,6 @@ #ifndef VEHICLE_RACER #define VEHICLE_RACER +int v_racer(int); REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RACER, /* function */ v_racer, @@ -663,7 +664,7 @@ void racer_deadtouch() void spawnfunc_vehicle_racer() { if(!autocvar_g_vehicle_racer) { remove(self); return; } - if(!vehicle_initialize(VEH_RACER, false)) { remove(self); return; } + if(!vehicle_initialize(VEH_RACER.vehicleid, false)) { remove(self); return; } } #endif // SVQC diff --git a/qcsrc/common/vehicles/unit/raptor.qc b/qcsrc/common/vehicles/unit/raptor.qc index 8eaa0c93c..12bc40589 100644 --- a/qcsrc/common/vehicles/unit/raptor.qc +++ b/qcsrc/common/vehicles/unit/raptor.qc @@ -1,6 +1,7 @@ #ifndef VEHICLE_RAPTOR #define VEHICLE_RAPTOR #include "raptor.qh" +int v_raptor(int); REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RAPTOR, /* function */ v_raptor, @@ -785,7 +786,7 @@ float raptor_impulse(float _imp) void spawnfunc_vehicle_raptor() { if(!autocvar_g_vehicle_raptor) { remove(self); return; } - if(!vehicle_initialize(VEH_RAPTOR, false)) { remove(self); return; } + if(!vehicle_initialize(VEH_RAPTOR.vehicleid, false)) { remove(self); return; } } float v_raptor(float req) diff --git a/qcsrc/common/vehicles/unit/spiderbot.qc b/qcsrc/common/vehicles/unit/spiderbot.qc index 7c23205ec..de3cdbb7a 100644 --- a/qcsrc/common/vehicles/unit/spiderbot.qc +++ b/qcsrc/common/vehicles/unit/spiderbot.qc @@ -1,5 +1,6 @@ #ifndef VEHICLE_SPIDERBOT #define VEHICLE_SPIDERBOT +int v_spiderbot(int); REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ SPIDERBOT, /* function */ v_spiderbot, @@ -807,7 +808,7 @@ bool spiderbot_impulse(int _imp) void spawnfunc_vehicle_spiderbot() { if(!autocvar_g_vehicle_spiderbot) { remove(self); return; } - if(!vehicle_initialize(VEH_SPIDERBOT, false)) { remove(self); return; } + if(!vehicle_initialize(VEH_SPIDERBOT.vehicleid, false)) { remove(self); return; } } float v_spiderbot(float req) diff --git a/qcsrc/common/vehicles/vehicle.qh b/qcsrc/common/vehicles/vehicle.qh index 65b1397ab..b085a248b 100644 --- a/qcsrc/common/vehicles/vehicle.qh +++ b/qcsrc/common/vehicles/vehicle.qh @@ -4,7 +4,7 @@ int v_null(int) { return 0; } CLASS(Vehicle, Object) - ATTRIB(Vehicle, m_id, int, 0) + ATTRIB(Vehicle, vehicleid, int, 0) ENDCLASS(Vehicle) #endif -- 2.39.2