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,
93 weapon_info[id - 1] = e = spawn();
94 e.classname = "weapon_info";
98 e.ammo_field = ammotype;
100 e.spawnflags = weapontype;
101 e.bot_pickupbasevalue = pickupbasevalue;
103 e.wpmodel = strzone(strcat("wpn-", ftos(id)));
105 e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
106 e.w_simplemdl = strzone(simplemdl); // simpleitems weapon model/image
107 e.w_crosshair = strzone(car(crosshair));
108 string s = cdr(crosshair);
109 e.w_crosshair_size = ((s != "") ? stof(s) : 1); // so that we can scale the crosshair from code (for compat)
117 float w_null(float dummy)
121 void register_weapons_done()
123 dummy_weapon_info = spawn();
124 dummy_weapon_info.classname = "weapon_info";
125 dummy_weapon_info.weapon = 0; // you can recognize dummies by this
126 dummy_weapon_info.weapons = '0 0 0';
127 dummy_weapon_info.netname = "";
128 dummy_weapon_info.message = "AOL CD Thrower";
129 dummy_weapon_info.weapon_func = w_null;
130 dummy_weapon_info.wpmodel = "";
131 dummy_weapon_info.mdl = "";
132 dummy_weapon_info.model = "";
133 dummy_weapon_info.spawnflags = 0;
134 dummy_weapon_info.impulse = -1;
135 dummy_weapon_info.bot_pickupbasevalue = 0;
136 dummy_weapon_info.ammo_field = ammo_none;
138 dummy_weapon_info.w_crosshair = "gfx/crosshair1";
139 dummy_weapon_info.w_crosshair_size = 1;
142 weaponorder_byid = "";
143 for(i = WEP_MAXCOUNT; i >= 1; --i)
145 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
146 weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
148 entity get_weaponinfo(float id)
151 if(id < WEP_FIRST || id > WEP_LAST)
152 return dummy_weapon_info;
153 w = weapon_info[id - 1];
156 return dummy_weapon_info;
158 string W_FixWeaponOrder(string order, float complete)
160 return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
162 string W_NameWeaponOrder_MapFunc(string s)
165 if(s == "0" || stof(s))
167 wi = get_weaponinfo(stof(s));
168 if(wi != dummy_weapon_info)
173 string W_NameWeaponOrder(string order)
175 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
177 string W_NumberWeaponOrder_MapFunc(string s)
180 if(s == "0" || stof(s))
182 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
183 if(s == get_weaponinfo(i).netname)
187 string W_NumberWeaponOrder(string order)
189 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
192 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
193 string W_FixWeaponOrder_BuildImpulseList_order;
194 void W_FixWeaponOrder_BuildImpulseList_swap(float i, float j, entity pass)
197 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
198 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
199 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
201 float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
205 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
206 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
207 d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
209 return -d; // high impulse first!
211 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
213 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
214 ; // low char index first!
216 string W_FixWeaponOrder_BuildImpulseList(string o)
219 W_FixWeaponOrder_BuildImpulseList_order = o;
220 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
221 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
222 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
224 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
225 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
226 W_FixWeaponOrder_BuildImpulseList_order = string_null;
227 return substring(o, 1, -1);
230 string W_FixWeaponOrder_AllowIncomplete(string order)
232 return W_FixWeaponOrder(order, 0);
235 string W_FixWeaponOrder_ForceComplete(string order)
238 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
239 return W_FixWeaponOrder(order, 1);
242 void W_RandomWeapons(entity e, float n)
247 remaining = e.weapons;
249 for(i = 0; i < n; ++i)
251 RandomSelection_Init();
252 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
253 if(remaining & WepSet_FromWeapon(j))
254 RandomSelection_Add(world, j, string_null, 1, 1);
255 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
256 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
262 .float GetAmmoFieldFromNum(float i)
266 case 0: return ammo_shells;
267 case 1: return ammo_nails;
268 case 2: return ammo_rockets;
269 case 3: return ammo_cells;
270 case 4: return ammo_fuel;
271 default: return ammo_none;
275 string GetAmmoPicture(.float ammotype)
279 case ammo_shells: return "ammo_shells";
280 case ammo_nails: return "ammo_nails";
281 case ammo_rockets: return "ammo_rockets";
282 case ammo_cells: return "ammo_cells";
283 case ammo_fuel: return "ammo_fuel";
284 default: return ""; // wtf, no ammo type?
288 float GetAmmoStat(.float ammotype)
292 case ammo_shells: return STAT_SHELLS;
293 case ammo_nails: return STAT_NAILS;
294 case ammo_rockets: return STAT_ROCKETS;
295 case ammo_cells: return STAT_CELLS;
296 case ammo_fuel: return STAT_FUEL;