d1714c9c42e655d4c52cd1ef3da3b786cc174eb6
[divverent/nexuiz.git] / data / qcsrc / common / items.qc
1 // WEAPON PLUGIN SYSTEM
2 entity weapon_info[24];
3 entity dummy_weapon_info;
4
5 void register_weapon(float id, float(float) func, float ammotype, float i, float normalweapon, float canclimb, float weapontype, float pickupbasevalue, string modelname, string shortname, string wname)
6 {
7         entity e;
8         weapon_info[id - 1] = e = spawn();
9         e.classname = "weapon_info";
10         e.weapon = id;
11         e.weapons = power2of(id - WEP_FIRST);
12         e.netname = shortname;
13         e.message = wname;
14         e.items = ammotype;
15         e.weapon_func = func;
16         e.mdl = modelname;
17         e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
18         e.spawnflags = 0;
19         e.model2 = strzone(strcat("wpn-", e.mdl));
20         if(normalweapon > 0)
21                 e.spawnflags |= WEPSPAWNFLAG_NORMAL;
22         if(normalweapon < 0)
23                 e.spawnflags |= WEPSPAWNFLAG_HIDDEN;
24         if(canclimb)
25                 e.spawnflags |= WEPSPAWNFLAG_CANCLIMB;
26         e.impulse = i;
27         e.weapon_type = weapontype;
28         e.bot_pickupbasevalue = pickupbasevalue;
29 }
30 float w_null(float dummy)
31 {
32         return 0;
33 }
34 void register_weapons_done()
35 {
36         entity wi;
37
38         dummy_weapon_info = spawn();
39         dummy_weapon_info.classname = "weapon_info";
40         dummy_weapon_info.weapon = 0; // you can recognize dummies by this
41         dummy_weapon_info.weapons = 0; // you can recognize dummies by this too
42         dummy_weapon_info.netname = "@!#%'n Tuba";
43         dummy_weapon_info.items = 0;
44         dummy_weapon_info.weapon_func = w_null;
45         dummy_weapon_info.mdl = "";
46         dummy_weapon_info.model = "";
47         dummy_weapon_info.spawnflags = 0;
48         dummy_weapon_info.impulse = -1;
49         dummy_weapon_info.weapon_type = WEP_TYPE_OTHER;
50         dummy_weapon_info.bot_pickupbasevalue = 0;
51         dummy_weapon_info.model2 = "";
52
53         float i;
54         weaponpriority_hudselector_0 = "";
55         for(i = 24; i >= 1; --i)
56                 if(weapon_info[i-1])
57                         weaponpriority_hudselector_0 = strcat(weaponpriority_hudselector_0, " ", ftos(i));
58
59         float imp;
60         weaponpriority_hudselector_1 = "";
61         for(i = 1; i <= 24; ++i)
62         {
63                 wi = weapon_info[i-1];
64                 if(wi && wi.impulse == 0)
65                         weaponpriority_hudselector_1 = strcat(weaponpriority_hudselector_1, " ", ftos(i));
66         }
67         for(imp = 9; imp > 0; --imp)
68                 for(i = 1; i <= 24; ++i)
69                 {
70                         wi = weapon_info[i-1];
71                         if(wi && wi.impulse == imp)
72                                 weaponpriority_hudselector_1 = strcat(weaponpriority_hudselector_1, " ", ftos(i));
73                 }
74
75         weaponpriority_hudselector_0 = strzone(substring(weaponpriority_hudselector_0, 1, strlen(weaponpriority_hudselector_0) - 1));
76         weaponpriority_hudselector_1 = strzone(substring(weaponpriority_hudselector_1, 1, strlen(weaponpriority_hudselector_1) - 1));
77 }
78 entity get_weaponinfo(float id)
79 {
80         entity w;
81         if(id < WEP_FIRST || id > WEP_LAST)
82                 return dummy_weapon_info;
83         w = weapon_info[id - 1];
84         if(w)
85                 return w;
86         return dummy_weapon_info;
87 }
88 string W_FixWeaponOrder(string order, float complete)
89 {
90         return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
91 }