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