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';
84 float pickupbasevalue,
92 weapon_info[id - 1] = e = spawn();
93 e.classname = "weapon_info";
97 e.ammo_field = ammotype;
99 e.spawnflags = weapontype;
100 e.bot_pickupbasevalue = pickupbasevalue;
103 e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
104 e.w_crosshair = strzone(car(crosshair));
105 string s = cdr(crosshair);
106 e.w_crosshair_size = ((s != "") ? stof(s) : 1); // so that we can scale the crosshair from code (for compat)
107 e.model2 = strzone(strcat("wpn-", ftos(id)));
115 float w_null(float dummy)
119 void register_weapons_done()
121 dummy_weapon_info = spawn();
122 dummy_weapon_info.classname = "weapon_info";
123 dummy_weapon_info.weapon = 0; // you can recognize dummies by this
124 dummy_weapon_info.weapons = '0 0 0';
125 dummy_weapon_info.netname = "";
126 dummy_weapon_info.message = "AOL CD Thrower";
127 dummy_weapon_info.weapon_func = w_null;
128 dummy_weapon_info.mdl = "";
129 dummy_weapon_info.model = "";
130 dummy_weapon_info.spawnflags = 0;
131 dummy_weapon_info.model2 = "";
132 dummy_weapon_info.impulse = -1;
133 dummy_weapon_info.bot_pickupbasevalue = 0;
134 dummy_weapon_info.ammo_field = ammo_none;
136 dummy_weapon_info.w_crosshair = "gfx/crosshair1";
137 dummy_weapon_info.w_crosshair_size = 1;
140 weaponorder_byid = "";
141 for(i = WEP_MAXCOUNT; i >= 1; --i)
143 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
144 weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
146 entity get_weaponinfo(float id)
149 if(id < WEP_FIRST || id > WEP_LAST)
150 return dummy_weapon_info;
151 w = weapon_info[id - 1];
154 return dummy_weapon_info;
156 string W_FixWeaponOrder(string order, float complete)
158 return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
160 string W_NameWeaponOrder_MapFunc(string s)
163 if(s == "0" || stof(s))
165 wi = get_weaponinfo(stof(s));
166 if(wi != dummy_weapon_info)
171 string W_NameWeaponOrder(string order)
173 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
175 string W_NumberWeaponOrder_MapFunc(string s)
178 if(s == "0" || stof(s))
180 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
181 if(s == get_weaponinfo(i).netname)
185 string W_NumberWeaponOrder(string order)
187 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
190 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
191 string W_FixWeaponOrder_BuildImpulseList_order;
192 void W_FixWeaponOrder_BuildImpulseList_swap(float i, float j, entity pass)
195 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
196 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
197 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
199 float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
203 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
204 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
205 d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
207 return -d; // high impulse first!
209 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
211 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
212 ; // low char index first!
214 string W_FixWeaponOrder_BuildImpulseList(string o)
217 W_FixWeaponOrder_BuildImpulseList_order = o;
218 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
219 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
220 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
222 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
223 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
224 W_FixWeaponOrder_BuildImpulseList_order = string_null;
225 return substring(o, 1, -1);
228 string W_FixWeaponOrder_AllowIncomplete(string order)
230 return W_FixWeaponOrder(order, 0);
233 string W_FixWeaponOrder_ForceComplete(string order)
236 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
237 return W_FixWeaponOrder(order, 1);
240 void W_RandomWeapons(entity e, float n)
245 remaining = e.weapons;
247 for(i = 0; i < n; ++i)
249 RandomSelection_Init();
250 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
251 if(remaining & WepSet_FromWeapon(j))
252 RandomSelection_Add(world, j, string_null, 1, 1);
253 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
254 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
260 .float GetAmmoFieldFromNum(float i)
264 case 0: return ammo_shells;
265 case 1: return ammo_nails;
266 case 2: return ammo_rockets;
267 case 3: return ammo_cells;
268 case 4: return ammo_fuel;
269 default: return ammo_none;
273 string GetAmmoPicture(.float ammotype)
277 case ammo_shells: return "ammo_shells";
278 case ammo_nails: return "ammo_nails";
279 case ammo_rockets: return "ammo_rockets";
280 case ammo_cells: return "ammo_cells";
281 case ammo_fuel: return "ammo_fuel";
282 default: return ""; // wtf, no ammo type?
286 float GetAmmoStat(.float ammotype)
290 case ammo_shells: return STAT_SHELLS;
291 case ammo_nails: return STAT_NAILS;
292 case ammo_rockets: return STAT_ROCKETS;
293 case ammo_cells: return STAT_CELLS;
294 case ammo_fuel: return STAT_FUEL;