]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/vehicle.qh
Vehicles: prepare for upgrade
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle.qh
1 #ifndef VEHICLE_H
2 #define VEHICLE_H
3
4 // vehicle requests
5 const int VR_SETUP          = 1; // (BOTH) setup vehicle data
6 .bool(entity) vr_setup;
7 const int VR_THINK                      = 2; // (SERVER) logic to run every frame
8 .bool(entity) vr_think;
9 const int VR_DEATH          = 3; // (SERVER) called when vehicle dies
10 .bool(entity) vr_death;
11 const int VR_PRECACHE       = 4; // (BOTH) precaches models/sounds used by this vehicle
12 .bool(entity) vr_precache;
13 const int VR_ENTER          = 5; // (SERVER) called when a player enters this vehicle
14 .bool(entity) vr_enter;
15 const int VR_SPAWN          = 6; // (SERVER) called when the vehicle re-spawns
16 .bool(entity) vr_spawn;
17 const int VR_IMPACT         = 7; // (SERVER) called when a vehicle hits something
18 .bool(entity) vr_impact;
19 const int VR_HUD            = 8; // (CLIENT) logic to run every frame
20 .bool(entity) vr_hud;
21
22 // vehicle spawn flags (need them here for common registrations)
23 const int VHF_ISVEHICLE                 = 2; /// Indicates vehicle
24 const int VHF_HASSHIELD                 = 4; /// Vehicle has shileding
25 const int VHF_SHIELDREGEN               = 8; /// Vehicles shield regenerates
26 const int VHF_HEALTHREGEN               = 16; /// Vehicles health regenerates
27 const int VHF_ENERGYREGEN               = 32; /// Vehicles energy regenerates
28 const int VHF_DEATHEJECT                = 64; /// Vehicle ejects pilot upon fatal damage
29 const int VHF_MOVE_GROUND               = 128; /// Vehicle moves on gound
30 const int VHF_MOVE_HOVER                = 256; /// Vehicle hover close to gound
31 const int VHF_MOVE_FLY                  = 512; /// Vehicle is airborn
32 const int VHF_DMGSHAKE                  = 1024; /// Add random velocity each frame if health < 50%
33 const int VHF_DMGROLL                   = 2048; /// Add random angles each frame if health < 50%
34 const int VHF_DMGHEADROLL               = 4096; /// Add random head angles each frame if health < 50%
35 const int VHF_MULTISLOT                 = 8192; /// Vehicle has multiple player slots
36 const int VHF_PLAYERSLOT                = 16384; /// This ent is a player slot on a multi-person vehicle
37
38 // functions:
39 entity get_vehicleinfo(int id);
40
41 // fields:
42 .entity tur_head;
43
44 // other useful macros
45 #define _VEH_ACTION(veh, mrequest) veh.vehicle_func(veh, mrequest)
46 #define VEH_ACTION(veh, mrequest) _VEH_ACTION(get_vehicleinfo(veh), mrequest)
47 #define VEH_NAME(veh) (get_vehicleinfo(veh)).vehicle_name
48
49 bool v_null(entity, int) { return false; }
50 bool v_new(entity, int);
51
52 CLASS(Vehicle, Object)
53     ATTRIB(Vehicle, vehicleid, int, 0)
54     /** hud icon */
55     ATTRIB(Vehicle, m_icon, string, string_null)
56     /** short name */
57     ATTRIB(Vehicle, netname, string, "")
58     /** human readable name */
59     ATTRIB(Vehicle, vehicle_name, string, "Vehicle")
60     /**  */
61     ATTRIB(Vehicle, vehicle_func, bool(Vehicle, int), v_null)
62     /** full name of model */
63     ATTRIB(Vehicle, model, string, "")
64     /** currently a copy of the model */
65     ATTRIB(Vehicle, mdl, string, "")
66     /** full name of tur_head model */
67     ATTRIB(Vehicle, head_model, string, "")
68     /** cockpit model */
69     ATTRIB(Vehicle, hud_model, string, "")
70     /** tur_head model tag */
71     ATTRIB(Vehicle, tag_head, string, string_null)
72     /** hud model tag */
73     ATTRIB(Vehicle, tag_hud, string, string_null)
74     /** cockpit model tag */
75     ATTRIB(Vehicle, tag_view, string, string_null)
76     /** player physics mod */
77     ATTRIB(Vehicle, PlayerPhysplug, int(), func_null)
78     /**  */
79     ATTRIB(Vehicle, spawnflags, int, 0)
80     /** vehicle hitbox size */
81     ATTRIB(Vehicle, mins, vector, '-0 -0 -0')
82     /** vehicle hitbox size */
83     ATTRIB(Vehicle, maxs, vector, '0 0 0')
84 ENDCLASS(Vehicle)
85
86 bool v_new(Vehicle this, int req)
87 {
88     if (req == VR_SETUP) return this.vr_setup ? this.vr_setup(this) : false;
89     if (req == VR_THINK) return this.vr_think ? this.vr_think(this) : false;
90     if (req == VR_DEATH) return this.vr_death ? this.vr_death(this) : false;
91     if (req == VR_PRECACHE) return this.vr_precache ? this.vr_precache(this) : false;
92     if (req == VR_ENTER) return this.vr_enter ? this.vr_enter(this) : false;
93     if (req == VR_SPAWN) return this.vr_spawn ? this.vr_spawn(this) : false;
94     if (req == VR_IMPACT) return this.vr_impact ? this.vr_impact(this) : false;
95     if (req == VR_HUD) return this.vr_hud ? this.vr_hud(this) : false;
96     return false;
97 }
98
99 #endif