Load vehicles in the menu with the registry system
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 22 Aug 2015 04:02:49 +0000 (14:02 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 22 Aug 2015 04:02:49 +0000 (14:02 +1000)
12 files changed:
qcsrc/client/main.qc
qcsrc/client/progs.src
qcsrc/common/vehicles/all.qc
qcsrc/common/vehicles/all.qh
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 [new file with mode: 0644]
qcsrc/menu/progs.src
qcsrc/server/g_world.qc
qcsrc/server/progs.src

index 84358c4..752b518 100644 (file)
@@ -147,7 +147,6 @@ void CSQC_Init(void)
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
        CALL_ACCUMULATED_FUNCTION(RegisterEffects);
-       CALL_ACCUMULATED_FUNCTION(RegisterVehicles);
 
        WaypointSprite_Load();
 
index b80d787..1c739ab 100644 (file)
@@ -57,10 +57,9 @@ weapons/projectile.qc // TODO
 ../common/viewloc.qc
 
 ../common/items/all.qc
-
 ../common/monsters/all.qc
-
-../common/weapons/all.qc // TODO
+../common/vehicles/all.qc
+../common/weapons/all.qc
 
 ../common/triggers/include.qc
 
@@ -68,8 +67,6 @@ weapons/projectile.qc // TODO
 ../csqcmodellib/cl_player.qc
 ../csqcmodellib/interpolate.qc
 
-../common/vehicles/all.qc
-
 ../server/mutators/mutator_multijump.qc
 
 ../warpzonelib/anglestransform.qc
index 2c45308..4923c1b 100644 (file)
@@ -14,7 +14,6 @@
 #undef IMPLEMENTATION
 
 // VEHICLE PLUGIN SYSTEM
-entity vehicle_info[VEH_MAXCOUNT];
 entity dummy_vehicle_info;
 
 void vehicles_common_initialize()
@@ -48,10 +47,9 @@ void vehicles_common_initialize()
 #endif // SVQC
 }
 
-void register_vehicle(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)
+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)
 {
-       entity e;
-       vehicle_info[id - 1] = e = spawn();
+       vehicle_info[id - 1] = e;
        e.classname = "vehicle_info";
        e.vehicleid = id;
        e.netname = shortname;
@@ -72,7 +70,6 @@ void register_vehicle(float id, float(float) func, float vehicleflags, vector mi
        vehicles_common_initialize();
        #endif
 }
-float v_null(float dummy) { return 0; }
 void register_vehicles_done()
 {
        dummy_vehicle_info = spawn();
index 03be212..dbb7b0e 100644 (file)
@@ -65,38 +65,30 @@ entity get_vehicleinfo(float id);
 //  Vehicle Registration
 // =====================
 
-int v_null(int dummy);
-void register_vehicle(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();
-
+void RegisterVehicles();
 const int VEH_MAXCOUNT = 24;
-#define VEH_FIRST 1
+entity vehicle_info[VEH_MAXCOUNT], vehicle_info_first, vehicle_info_last;
 int VEH_COUNT;
-int VEH_LAST;
-
-#define REGISTER_VEHICLE_2(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \
-       int id; \
-       int func(int); \
-       void RegisterVehicles_##id() \
-       { \
-               VEH_LAST = (id = VEH_FIRST + VEH_COUNT); \
-               ++VEH_COUNT; \
-               register_vehicle(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname); \
-       } \
-       ACCUMULATE_FUNCTION(RegisterVehicles, RegisterVehicles_##id)
-#ifdef MENUQC
-#define REGISTER_VEHICLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \
-       REGISTER_VEHICLE_2(VEH_##id,v_null,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname)
-#else
-#define REGISTER_VEHICLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \
-       REGISTER_VEHICLE_2(VEH_##id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname)
-#endif
+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))
+#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)
+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"
 
-#undef REGISTER_VEHICLE
 ACCUMULATE_FUNCTION(RegisterVehicles, register_vehicles_done);
 
-#include "all.inc"
-
 #endif
index 859a89e..7d338d3 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef VEHICLE_BUMBLEBEE
 #define VEHICLE_BUMBLEBEE
 #include "bumblebee.qh"
-REGISTER_VEHICLE(
+REGISTER_VEHICLE_SIMPLE(
 /* VEH_##id   */ BUMBLEBEE,
 /* function   */ v_bumblebee,
 /* spawnflags */ VHF_DMGSHAKE,
index 6c1f30c..3549150 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef VEHICLE_RACER
 #define VEHICLE_RACER
-REGISTER_VEHICLE(
+REGISTER_VEHICLE_SIMPLE(
 /* VEH_##id   */ RACER,
 /* function   */ v_racer,
 /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL,
@@ -859,9 +859,10 @@ bool v_racer(int req)
 
                        precache_model ("models/vhshield.md3");
                #endif
-
+               #ifndef MENUQC
                        precache_model ("models/vehicles/wakizashi.dpm");
                        precache_model ("models/vehicles/wakizashi_cockpit.dpm");
+               #endif
                        return true;
                }
        }
index 4624835..8eaa0c9 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef VEHICLE_RAPTOR
 #define VEHICLE_RAPTOR
 #include "raptor.qh"
-REGISTER_VEHICLE(
+REGISTER_VEHICLE_SIMPLE(
 /* VEH_##id   */ RAPTOR,
 /* function   */ v_raptor,
 /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL,
index 511f996..7c23205 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef VEHICLE_SPIDERBOT
 #define VEHICLE_SPIDERBOT
-REGISTER_VEHICLE(
+REGISTER_VEHICLE_SIMPLE(
 /* VEH_##id   */ SPIDERBOT,
 /* function   */ v_spiderbot,
 /* spawnflags */ VHF_DMGSHAKE,
diff --git a/qcsrc/common/vehicles/vehicle.qh b/qcsrc/common/vehicles/vehicle.qh
new file mode 100644 (file)
index 0000000..65b1397
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef VEHICLE_H
+#define VEHICLE_H
+
+int v_null(int) { return 0; }
+
+CLASS(Vehicle, Object)
+    ATTRIB(Vehicle, m_id, int, 0)
+ENDCLASS(Vehicle)
+
+#endif
index 64f1247..2bde451 100644 (file)
@@ -23,10 +23,9 @@ xonotic/util.qc
 ../common/util.qc
 
 ../common/items/all.qc
-
 ../common/monsters/all.qc
-
-../common/weapons/all.qc // TODO
+../common/vehicles/all.qc
+../common/weapons/all.qc
 
 ../warpzonelib/mathlib.qc
 
index 0a3462d..2df126d 100644 (file)
@@ -565,7 +565,6 @@ void spawnfunc___init_dedicated_server(void)
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterEffects);
-       CALL_ACCUMULATED_FUNCTION(RegisterVehicles);
 
        MapInfo_Enumerate();
        MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
@@ -614,7 +613,6 @@ void spawnfunc_worldspawn (void)
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterEffects);
-       CALL_ACCUMULATED_FUNCTION(RegisterVehicles);
 
        ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
 
index cda751f..e13a760 100644 (file)
@@ -87,7 +87,6 @@ weapons/weaponsystem.qc
 ../common/campaign_setup.qc
 ../common/effects.qc
 ../common/mapinfo.qc
-../common/monsters/all.qc
 ../common/monsters/spawn.qc
 ../common/monsters/sv_monsters.qc
 ../common/movetypes/include.qc
@@ -102,12 +101,13 @@ weapons/weaponsystem.qc
 ../common/triggers/include.qc
 ../common/urllib.qc
 ../common/util.qc
-../common/vehicles/all.qc
 
 ../common/items/all.qc
+../common/monsters/all.qc
+../common/vehicles/all.qc
+../common/weapons/all.qc // TODO
 
 ../common/weapons/config.qc
-../common/weapons/all.qc // TODO
 
 ../csqcmodellib/sv_model.qc