From 807e413f50626007f11b5822a4c60512c22289fc Mon Sep 17 00:00:00 2001 From: TimePath Date: Mon, 28 Sep 2015 16:12:32 +1000 Subject: [PATCH] Vehicles: prepare for upgrade --- qcsrc/common/vehicles/all.inc | 8 +-- qcsrc/common/vehicles/all.qc | 20 +++--- qcsrc/common/vehicles/all.qh | 61 +++--------------- qcsrc/common/vehicles/vehicle.qh | 63 ++++++++++++++++++- .../vehicles/{unit => vehicle}/bumblebee.qc | 6 +- .../vehicles/{unit => vehicle}/bumblebee.qh | 0 .../vehicles/{unit => vehicle}/racer.qc | 4 +- .../vehicles/{unit => vehicle}/raptor.qc | 6 +- .../vehicles/{unit => vehicle}/raptor.qh | 0 .../vehicles/{unit => vehicle}/spiderbot.qc | 6 +- 10 files changed, 96 insertions(+), 78 deletions(-) rename qcsrc/common/vehicles/{unit => vehicle}/bumblebee.qc (99%) rename qcsrc/common/vehicles/{unit => vehicle}/bumblebee.qh (100%) rename qcsrc/common/vehicles/{unit => vehicle}/racer.qc (99%) rename qcsrc/common/vehicles/{unit => vehicle}/raptor.qc (99%) rename qcsrc/common/vehicles/{unit => vehicle}/raptor.qh (100%) rename qcsrc/common/vehicles/{unit => vehicle}/spiderbot.qc (99%) diff --git a/qcsrc/common/vehicles/all.inc b/qcsrc/common/vehicles/all.inc index eda4e00bb..e4c73a449 100644 --- a/qcsrc/common/vehicles/all.inc +++ b/qcsrc/common/vehicles/all.inc @@ -1,6 +1,6 @@ -#include "unit/spiderbot.qc" -#include "unit/raptor.qc" -#include "unit/racer.qc" +#include "vehicle/spiderbot.qc" +#include "vehicle/raptor.qc" +#include "vehicle/racer.qc" #ifndef VEHICLES_NO_UNSTABLE - #include "unit/bumblebee.qc" + #include "vehicle/bumblebee.qc" #endif diff --git a/qcsrc/common/vehicles/all.qc b/qcsrc/common/vehicles/all.qc index 6e26f1712..b071cf5a7 100644 --- a/qcsrc/common/vehicles/all.qc +++ b/qcsrc/common/vehicles/all.qc @@ -3,16 +3,6 @@ #include "all.qh" -#if defined(SVQC) - #include "sv_vehicles.qc" -#elif defined(CSQC) - #include "cl_vehicles.qc" -#endif - -#define IMPLEMENTATION -#include "all.inc" -#undef IMPLEMENTATION - #ifndef MENUQC STATIC_INIT(vehicles_common_initialize) { @@ -40,4 +30,14 @@ entity get_vehicleinfo(int id) return m ? m : VEH_Null; } +#if defined(SVQC) + #include "sv_vehicles.qc" +#elif defined(CSQC) + #include "cl_vehicles.qc" +#endif + +#define IMPLEMENTATION +#include "all.inc" +#undef IMPLEMENTATION + #endif diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index a18bfe13e..cf4a034eb 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -1,53 +1,7 @@ #ifndef VEHICLES_ALL_H #define VEHICLES_ALL_H -#if defined(SVQC) - #include "sv_vehicles.qh" -#elif defined(CSQC) - #include "cl_vehicles.qh" -#endif - - -// vehicle requests -const int VR_SETUP = 1; // (BOTH) setup vehicle data -const int VR_THINK = 2; // (SERVER) logic to run every frame -const int VR_DEATH = 3; // (SERVER) called when vehicle dies -const int VR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this vehicle -const int VR_ENTER = 5; // (SERVER) called when a player enters this vehicle -const int VR_SPAWN = 6; // (SERVER) called when the vehicle re-spawns -const int VR_IMPACT = 7; // (SERVER) called when a vehicle hits something -const int VR_HUD = 8; // (CLIENT) logic to run every frame - -// vehicle spawn flags (need them here for common registrations) -const int VHF_ISVEHICLE = 2; /// Indicates vehicle -const int VHF_HASSHIELD = 4; /// Vehicle has shileding -const int VHF_SHIELDREGEN = 8; /// Vehicles shield regenerates -const int VHF_HEALTHREGEN = 16; /// Vehicles health regenerates -const int VHF_ENERGYREGEN = 32; /// Vehicles energy regenerates -const int VHF_DEATHEJECT = 64; /// Vehicle ejects pilot upon fatal damage -const int VHF_MOVE_GROUND = 128; /// Vehicle moves on gound -const int VHF_MOVE_HOVER = 256; /// Vehicle hover close to gound -const int VHF_MOVE_FLY = 512; /// Vehicle is airborn -const int VHF_DMGSHAKE = 1024; /// Add random velocity each frame if health < 50% -const int VHF_DMGROLL = 2048; /// Add random angles each frame if health < 50% -const int VHF_DMGHEADROLL = 4096; /// Add random head angles each frame if health < 50% -const int VHF_MULTISLOT = 8192; /// Vehicle has multiple player slots -const int VHF_PLAYERSLOT = 16384; /// This ent is a player slot on a multi-person vehicle - -// functions: -entity get_vehicleinfo(float id); - -// fields: -.entity tur_head; - - -// other useful macros -#define VEH_ACTION(vehicletype,mrequest) (get_vehicleinfo(vehicletype)).vehicle_func(mrequest) -#define VEH_NAME(vehicletype) (get_vehicleinfo(vehicletype)).vehicle_name - -// ===================== -// Vehicle Registration -// ===================== +#include "vehicle.qh" void RegisterVehicles(); const int VEH_MAXCOUNT = 24; @@ -56,10 +10,9 @@ 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, VEH, vehicle_info, VEH_COUNT, id, vehicleid, NEW(class)) -#include "vehicle.qh" +#define REGISTER_VEHICLE(id, inst) REGISTER(RegisterVehicles, VEH, vehicle_info, VEH_COUNT, id, vehicleid, inst) #define REGISTER_VEHICLE_SIMPLE(id, vehicleflags, min_s, max_s, modelname, headmodelname, hudmodelname, headtag, hudtag, viewtag, shortname, vname) \ - REGISTER_VEHICLE(id, Vehicle) { \ + REGISTER_VEHICLE(id, NEW(Vehicle)) { \ this.netname = shortname; \ this.vehicle_name = vname; \ this.mdl = modelname; \ @@ -76,7 +29,13 @@ const int VEH_FIRST = 1; REGISTER_INIT(VEH, id) REGISTER_REGISTRY(RegisterVehicles) -REGISTER_VEHICLE(Null, Vehicle); +#if defined(SVQC) + #include "sv_vehicles.qh" +#elif defined(CSQC) + #include "cl_vehicles.qh" +#endif + +REGISTER_VEHICLE(Null, NEW(Vehicle)); #include "all.inc" diff --git a/qcsrc/common/vehicles/vehicle.qh b/qcsrc/common/vehicles/vehicle.qh index 7df34206f..8de51fd36 100644 --- a/qcsrc/common/vehicles/vehicle.qh +++ b/qcsrc/common/vehicles/vehicle.qh @@ -1,7 +1,53 @@ #ifndef VEHICLE_H #define VEHICLE_H -int v_null(int) { return 0; } +// vehicle requests +const int VR_SETUP = 1; // (BOTH) setup vehicle data +.bool(entity) vr_setup; +const int VR_THINK = 2; // (SERVER) logic to run every frame +.bool(entity) vr_think; +const int VR_DEATH = 3; // (SERVER) called when vehicle dies +.bool(entity) vr_death; +const int VR_PRECACHE = 4; // (BOTH) precaches models/sounds used by this vehicle +.bool(entity) vr_precache; +const int VR_ENTER = 5; // (SERVER) called when a player enters this vehicle +.bool(entity) vr_enter; +const int VR_SPAWN = 6; // (SERVER) called when the vehicle re-spawns +.bool(entity) vr_spawn; +const int VR_IMPACT = 7; // (SERVER) called when a vehicle hits something +.bool(entity) vr_impact; +const int VR_HUD = 8; // (CLIENT) logic to run every frame +.bool(entity) vr_hud; + +// vehicle spawn flags (need them here for common registrations) +const int VHF_ISVEHICLE = 2; /// Indicates vehicle +const int VHF_HASSHIELD = 4; /// Vehicle has shileding +const int VHF_SHIELDREGEN = 8; /// Vehicles shield regenerates +const int VHF_HEALTHREGEN = 16; /// Vehicles health regenerates +const int VHF_ENERGYREGEN = 32; /// Vehicles energy regenerates +const int VHF_DEATHEJECT = 64; /// Vehicle ejects pilot upon fatal damage +const int VHF_MOVE_GROUND = 128; /// Vehicle moves on gound +const int VHF_MOVE_HOVER = 256; /// Vehicle hover close to gound +const int VHF_MOVE_FLY = 512; /// Vehicle is airborn +const int VHF_DMGSHAKE = 1024; /// Add random velocity each frame if health < 50% +const int VHF_DMGROLL = 2048; /// Add random angles each frame if health < 50% +const int VHF_DMGHEADROLL = 4096; /// Add random head angles each frame if health < 50% +const int VHF_MULTISLOT = 8192; /// Vehicle has multiple player slots +const int VHF_PLAYERSLOT = 16384; /// This ent is a player slot on a multi-person vehicle + +// functions: +entity get_vehicleinfo(int id); + +// fields: +.entity tur_head; + +// other useful macros +#define _VEH_ACTION(veh, mrequest) veh.vehicle_func(veh, mrequest) +#define VEH_ACTION(veh, mrequest) _VEH_ACTION(get_vehicleinfo(veh), mrequest) +#define VEH_NAME(veh) (get_vehicleinfo(veh)).vehicle_name + +bool v_null(entity, int) { return false; } +bool v_new(entity, int); CLASS(Vehicle, Object) ATTRIB(Vehicle, vehicleid, int, 0) @@ -12,7 +58,7 @@ CLASS(Vehicle, Object) /** human readable name */ ATTRIB(Vehicle, vehicle_name, string, "Vehicle") /** */ - ATTRIB(Vehicle, vehicle_func, int(int), v_null) + ATTRIB(Vehicle, vehicle_func, bool(Vehicle, int), v_null) /** full name of model */ ATTRIB(Vehicle, model, string, "") /** currently a copy of the model */ @@ -37,4 +83,17 @@ CLASS(Vehicle, Object) ATTRIB(Vehicle, maxs, vector, '0 0 0') ENDCLASS(Vehicle) +bool v_new(Vehicle this, int req) +{ + if (req == VR_SETUP) return this.vr_setup ? this.vr_setup(this) : false; + if (req == VR_THINK) return this.vr_think ? this.vr_think(this) : false; + if (req == VR_DEATH) return this.vr_death ? this.vr_death(this) : false; + if (req == VR_PRECACHE) return this.vr_precache ? this.vr_precache(this) : false; + if (req == VR_ENTER) return this.vr_enter ? this.vr_enter(this) : false; + if (req == VR_SPAWN) return this.vr_spawn ? this.vr_spawn(this) : false; + if (req == VR_IMPACT) return this.vr_impact ? this.vr_impact(this) : false; + if (req == VR_HUD) return this.vr_hud ? this.vr_hud(this) : false; + return false; +} + #endif diff --git a/qcsrc/common/vehicles/unit/bumblebee.qc b/qcsrc/common/vehicles/vehicle/bumblebee.qc similarity index 99% rename from qcsrc/common/vehicles/unit/bumblebee.qc rename to qcsrc/common/vehicles/vehicle/bumblebee.qc index 6f8a2bf8f..490e165c3 100644 --- a/qcsrc/common/vehicles/unit/bumblebee.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee.qc @@ -2,7 +2,7 @@ #define VEHICLE_BUMBLEBEE #include "bumblebee.qh" #ifndef MENUQC -int v_bumblebee(int); +int v_bumblebee(entity, int); #endif REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ BUMBLEBEE, @@ -774,7 +774,7 @@ void spawnfunc_vehicle_bumblebee() if(!vehicle_initialize(VEH_BUMBLEBEE, false)) { remove(self); return; } } -float v_bumblebee(float req) +float v_bumblebee(Vehicle thisveh, float req) {SELFPARAM(); switch(req) { @@ -1094,7 +1094,7 @@ void bumble_raygun_read(bool bIsNew) } } -float v_bumblebee(float req) +float v_bumblebee(Vehicle thisveh, float req) { switch(req) { diff --git a/qcsrc/common/vehicles/unit/bumblebee.qh b/qcsrc/common/vehicles/vehicle/bumblebee.qh similarity index 100% rename from qcsrc/common/vehicles/unit/bumblebee.qh rename to qcsrc/common/vehicles/vehicle/bumblebee.qh diff --git a/qcsrc/common/vehicles/unit/racer.qc b/qcsrc/common/vehicles/vehicle/racer.qc similarity index 99% rename from qcsrc/common/vehicles/unit/racer.qc rename to qcsrc/common/vehicles/vehicle/racer.qc index 3c0db8854..0606e9d38 100644 --- a/qcsrc/common/vehicles/unit/racer.qc +++ b/qcsrc/common/vehicles/vehicle/racer.qc @@ -2,7 +2,7 @@ #define VEHICLE_RACER #ifndef MENUQC -int v_racer(int); +int v_racer(entity, int); #endif REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RACER, @@ -734,7 +734,7 @@ void racer_draw() #endif #endif -bool v_racer(int req) +bool v_racer(Vehicle thisveh, int req) {SELFPARAM(); switch(req) { diff --git a/qcsrc/common/vehicles/unit/raptor.qc b/qcsrc/common/vehicles/vehicle/raptor.qc similarity index 99% rename from qcsrc/common/vehicles/unit/raptor.qc rename to qcsrc/common/vehicles/vehicle/raptor.qc index 742ef7b9b..21fe402d4 100644 --- a/qcsrc/common/vehicles/unit/raptor.qc +++ b/qcsrc/common/vehicles/vehicle/raptor.qc @@ -2,7 +2,7 @@ #define VEHICLE_RAPTOR #include "raptor.qh" #ifndef MENUQC -int v_raptor(int); +int v_raptor(entity, int); #endif REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RAPTOR, @@ -795,7 +795,7 @@ void spawnfunc_vehicle_raptor() if(!vehicle_initialize(VEH_RAPTOR, false)) { remove(self); return; } } -float v_raptor(float req) +float v_raptor(Vehicle thisveh, float req) {SELFPARAM(); switch(req) { @@ -1023,7 +1023,7 @@ void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang) sfrag.drawmask = MASK_NORMAL; } -float v_raptor(float req) +float v_raptor(Vehicle thisveh, float req) { switch(req) { diff --git a/qcsrc/common/vehicles/unit/raptor.qh b/qcsrc/common/vehicles/vehicle/raptor.qh similarity index 100% rename from qcsrc/common/vehicles/unit/raptor.qh rename to qcsrc/common/vehicles/vehicle/raptor.qh diff --git a/qcsrc/common/vehicles/unit/spiderbot.qc b/qcsrc/common/vehicles/vehicle/spiderbot.qc similarity index 99% rename from qcsrc/common/vehicles/unit/spiderbot.qc rename to qcsrc/common/vehicles/vehicle/spiderbot.qc index f8efe528d..f01206f68 100644 --- a/qcsrc/common/vehicles/unit/spiderbot.qc +++ b/qcsrc/common/vehicles/vehicle/spiderbot.qc @@ -1,7 +1,7 @@ #ifndef VEHICLE_SPIDERBOT #define VEHICLE_SPIDERBOT #ifndef MENUQC -int v_spiderbot(int); +int v_spiderbot(entity, int); #endif REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ SPIDERBOT, @@ -817,7 +817,7 @@ void spawnfunc_vehicle_spiderbot() if(!vehicle_initialize(VEH_SPIDERBOT, false)) { remove(self); return; } } -float v_spiderbot(float req) +float v_spiderbot(Vehicle thisveh, float req) {SELFPARAM(); switch(req) { @@ -937,7 +937,7 @@ float v_spiderbot(float req) float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6; float autocvar_cl_vehicle_spiderbot_cross_size = 1; -float v_spiderbot(float req) +float v_spiderbot(Vehicle thisveh, float req) { switch(req) { -- 2.39.2