Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicles.qc
1 #include "unit/all.qh"
2
3 #include "vehicles_include.qc"
4
5 // VEHICLE PLUGIN SYSTEM
6 entity vehicle_info[VEH_MAXCOUNT];
7 entity dummy_vehicle_info;
8
9 void vehicles_common_initialize()
10 {
11 #ifdef CSQC
12         precache_model("models/vehicles/bomblet.md3");
13         precache_model("models/vehicles/clusterbomb.md3");
14         precache_model("models/vehicles/clusterbomb_fragment.md3");
15         precache_model("models/vehicles/rocket01.md3");
16         precache_model("models/vehicles/rocket02.md3");
17
18         precache_sound ("vehicles/alarm.wav");
19         precache_sound ("vehicles/alarm_shield.wav");
20 #endif // CSQC
21 #ifdef SVQC
22         precache_sound("onslaught/ons_hit2.wav");
23         precache_sound("onslaught/electricity_explode.wav");
24
25         addstat(STAT_HUD, AS_INT, hud);
26         addstat(STAT_VEHICLESTAT_HEALTH,  AS_INT, vehicle_health);
27         addstat(STAT_VEHICLESTAT_SHIELD,  AS_INT, vehicle_shield);
28         addstat(STAT_VEHICLESTAT_ENERGY,  AS_INT, vehicle_energy);
29
30         addstat(STAT_VEHICLESTAT_W2MODE, AS_INT, vehicle_weapon2mode);
31
32         addstat(STAT_VEHICLESTAT_AMMO1,   AS_INT, vehicle_ammo1);
33         addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
34
35         addstat(STAT_VEHICLESTAT_AMMO2,   AS_INT, vehicle_ammo2);
36         addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
37 #endif // SVQC
38 }
39
40 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)
41 {
42         entity e;
43         vehicle_info[id - 1] = e = spawn();
44         e.classname = "vehicle_info";
45         e.vehicleid = id;
46         e.netname = shortname;
47         e.vehicle_name = vname;
48         e.vehicle_func = func;
49         e.mdl = modelname;
50         e.spawnflags = vehicleflags;
51         e.mins = min_s;
52         e.maxs = max_s;
53         e.model = modelname;
54         e.head_model = headmodelname;
55         e.hud_model = hudmodelname;
56         e.tag_head = headtag;
57         e.tag_hud = hudtag;
58         e.tag_view = viewtag;
59         
60         #ifndef MENUQC
61         vehicles_common_initialize();
62         #endif
63 }
64 float v_null(float dummy) { return 0; }
65 void register_vehicles_done()
66 {
67         dummy_vehicle_info = spawn();
68         dummy_vehicle_info.classname = "vehicle_info";
69         dummy_vehicle_info.vehicleid = 0; // you can recognize dummies by this
70         dummy_vehicle_info.netname = "";
71         dummy_vehicle_info.vehicle_name = "Vehicle";
72         dummy_vehicle_info.vehicle_func = v_null;
73         dummy_vehicle_info.mdl = "";
74         dummy_vehicle_info.mins = '-0 -0 -0';
75         dummy_vehicle_info.maxs = '0 0 0';
76         dummy_vehicle_info.model = "";
77         dummy_vehicle_info.head_model = "";
78         dummy_vehicle_info.hud_model = "";
79 }
80 entity get_vehicleinfo(float id)
81 {
82         entity m;
83         if(id < VEH_FIRST || id > VEH_LAST)
84                 return dummy_vehicle_info;
85         m = vehicle_info[id - 1];
86         if(m)
87                 return m;
88         return dummy_vehicle_info;
89 }