2 #include "calculations.qc"
6 // WEAPON PLUGIN SYSTEM
7 entity weapon_info[WEP_MAXCOUNT];
8 entity dummy_weapon_info;
11 # error Kein Weltraum links auf dem Gerät
14 WepSet WepSet_FromWeapon(float a) {
22 return '0 0 1' * power2of(a);
25 return '0 1 0' * power2of(a);
28 return '1 0 0' * power2of(a);
33 addstat(STAT_WEAPONS, AS_INT, weapons_x);
35 addstat(STAT_WEAPONS2, AS_INT, weapons_y);
37 addstat(STAT_WEAPONS3, AS_INT, weapons_z);
41 void WriteWepSet(float dst, WepSet w)
45 #elif WEP_MAXCOUNT > 24
48 WriteInt24_t(dst, w_x);
53 WepSet WepSet_GetFromStat()
56 w_x = getstati(STAT_WEAPONS);
58 w_y = getstati(STAT_WEAPONS2);
60 w_z = getstati(STAT_WEAPONS3);
69 #elif WEP_MAXCOUNT > 24
72 return ReadInt24_t() * '1 0 0';
77 void register_weapon(float id, WepSet bit, float(float) func, .float ammotype, float i, float weapontype, float pickupbasevalue, string modelname, string shortname, string wname)
80 weapon_info[id - 1] = e = spawn();
81 e.classname = "weapon_info";
84 e.netname = shortname;
89 e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
90 e.spawnflags = weapontype;
91 e.model2 = strzone(strcat("wpn-", e.mdl));
93 e.bot_pickupbasevalue = pickupbasevalue;
94 e.current_ammo = ammotype;
100 float w_null(float dummy)
104 void register_weapons_done()
106 dummy_weapon_info = spawn();
107 dummy_weapon_info.classname = "weapon_info";
108 dummy_weapon_info.weapon = 0; // you can recognize dummies by this
109 dummy_weapon_info.weapons = '0 0 0';
110 dummy_weapon_info.netname = "";
111 dummy_weapon_info.message = "AOL CD Thrower";
112 //dummy_weapon_info.items = 0;
113 dummy_weapon_info.weapon_func = w_null;
114 dummy_weapon_info.mdl = "";
115 dummy_weapon_info.model = "";
116 dummy_weapon_info.spawnflags = 0;
117 dummy_weapon_info.model2 = "";
118 dummy_weapon_info.impulse = -1;
119 dummy_weapon_info.bot_pickupbasevalue = 0;
120 dummy_weapon_info.current_ammo = ammo_none;
123 weaponorder_byid = "";
124 for(i = WEP_MAXCOUNT; i >= 1; --i)
126 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
127 weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
129 entity get_weaponinfo(float id)
132 if(id < WEP_FIRST || id > WEP_LAST)
133 return dummy_weapon_info;
134 w = weapon_info[id - 1];
137 return dummy_weapon_info;
139 string W_FixWeaponOrder(string order, float complete)
141 return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
143 string W_NameWeaponOrder_MapFunc(string s)
146 if(s == "0" || stof(s))
148 wi = get_weaponinfo(stof(s));
149 if(wi != dummy_weapon_info)
154 string W_NameWeaponOrder(string order)
156 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
158 string W_NumberWeaponOrder_MapFunc(string s)
161 if(s == "0" || stof(s))
163 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
164 if(s == get_weaponinfo(i).netname)
168 string W_NumberWeaponOrder(string order)
170 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
173 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
174 string W_FixWeaponOrder_BuildImpulseList_order;
175 void W_FixWeaponOrder_BuildImpulseList_swap(float i, float j, entity pass)
178 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
179 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
180 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
182 float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
186 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
187 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
188 d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
190 return -d; // high impulse first!
192 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
194 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
195 ; // low char index first!
197 string W_FixWeaponOrder_BuildImpulseList(string o)
200 W_FixWeaponOrder_BuildImpulseList_order = o;
201 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
202 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
203 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
205 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
206 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
207 W_FixWeaponOrder_BuildImpulseList_order = string_null;
208 return substring(o, 1, -1);
211 string W_FixWeaponOrder_AllowIncomplete(string order)
213 return W_FixWeaponOrder(order, 0);
216 string W_FixWeaponOrder_ForceComplete(string order)
219 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
220 return W_FixWeaponOrder(order, 1);
223 void W_RandomWeapons(entity e, float n)
228 remaining = e.weapons;
230 for(i = 0; i < n; ++i)
232 RandomSelection_Init();
233 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
234 if(remaining & WepSet_FromWeapon(j))
235 RandomSelection_Add(world, j, string_null, 1, 1);
236 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
237 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
242 string W_Name(float weaponid) // WEAPONTODO: make into a macro
244 return (get_weaponinfo(weaponid)).message;