]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Remove vehicleid globals
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 22 Aug 2015 04:31:25 +0000 (14:31 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 22 Aug 2015 04:31:25 +0000 (14:31 +1000)
qcsrc/common/vehicles/all.qc
qcsrc/common/vehicles/all.qh
qcsrc/common/vehicles/cl_vehicles.qc
qcsrc/common/vehicles/unit/bumblebee.qc
qcsrc/common/vehicles/unit/racer.qc
qcsrc/common/vehicles/unit/raptor.qc
qcsrc/common/vehicles/unit/spiderbot.qc
qcsrc/common/vehicles/vehicle.qh

index 4923c1b0100db12c15ba38c9c5b14afd0d6f0fe3..d90e0696be77010bcc862af5b56f0c1b2373cc6e 100644 (file)
 #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
index dbb7b0e39178a60e750393d439c6643763c54d52..08a3020c753a2b6f3c5e33475f437c4e52e381e6 100644 (file)
@@ -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
index 2511defb43860a8baa577b13aed7884329d601cf..141f8fc42d59b5362e4e8bfad7712cc27c8c22fb 100644 (file)
@@ -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;
 
index 7d338d3e7c0346573fe192b4fbcfd693d1750d97..b4686d63c311196f680679a04fe590d84d2f553a 100644 (file)
@@ -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)
index 3549150d536b4ffb83415ca97d660bc6898c43e6..afcb131e9e8427500310bd341a969176dd9477e6 100644 (file)
@@ -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
index 8eaa0c93c0849acca091209c5f4507f4d08347fe..12bc40589b34e749019576107af9ce9154d2b53b 100644 (file)
@@ -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)
index 7c23205ece8c59851ba656d796b772a7d5ce7c75..de3cdbb7afa1b0b6931f236b70d9dc7a538c20c8 100644 (file)
@@ -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)
index 65b1397ab4257b046827d5733117621d1a9d9675..b085a248bdfd690e253f6f600488ddb78d7a6eb9 100644 (file)
@@ -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