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, vector clr, string modelname, string shortname, string wname)
80 weapon_info[id - 1] = e = spawn();
81 e.classname = "weapon_info";
84 e.netname = shortname;
90 e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
91 e.spawnflags = weapontype;
92 e.model2 = strzone(strcat("wpn-", ftos(id)));
94 e.bot_pickupbasevalue = pickupbasevalue;
95 e.current_ammo = ammotype;
101 float w_null(float dummy)
105 void register_weapons_done()
107 dummy_weapon_info = spawn();
108 dummy_weapon_info.classname = "weapon_info";
109 dummy_weapon_info.weapon = 0; // you can recognize dummies by this
110 dummy_weapon_info.weapons = '0 0 0';
111 dummy_weapon_info.netname = "";
112 dummy_weapon_info.message = "AOL CD Thrower";
113 //dummy_weapon_info.items = 0;
114 dummy_weapon_info.weapon_func = w_null;
115 dummy_weapon_info.mdl = "";
116 dummy_weapon_info.model = "";
117 dummy_weapon_info.spawnflags = 0;
118 dummy_weapon_info.model2 = "";
119 dummy_weapon_info.impulse = -1;
120 dummy_weapon_info.bot_pickupbasevalue = 0;
121 dummy_weapon_info.current_ammo = ammo_none;
124 weaponorder_byid = "";
125 for(i = WEP_MAXCOUNT; i >= 1; --i)
127 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
128 weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
130 entity get_weaponinfo(float id)
133 if(id < WEP_FIRST || id > WEP_LAST)
134 return dummy_weapon_info;
135 w = weapon_info[id - 1];
138 return dummy_weapon_info;
140 string W_FixWeaponOrder(string order, float complete)
142 return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
144 string W_NameWeaponOrder_MapFunc(string s)
147 if(s == "0" || stof(s))
149 wi = get_weaponinfo(stof(s));
150 if(wi != dummy_weapon_info)
155 string W_NameWeaponOrder(string order)
157 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
159 string W_NumberWeaponOrder_MapFunc(string s)
162 if(s == "0" || stof(s))
164 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
165 if(s == get_weaponinfo(i).netname)
169 string W_NumberWeaponOrder(string order)
171 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
174 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
175 string W_FixWeaponOrder_BuildImpulseList_order;
176 void W_FixWeaponOrder_BuildImpulseList_swap(float i, float j, entity pass)
179 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
180 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
181 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
183 float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
187 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
188 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
189 d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
191 return -d; // high impulse first!
193 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
195 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
196 ; // low char index first!
198 string W_FixWeaponOrder_BuildImpulseList(string o)
201 W_FixWeaponOrder_BuildImpulseList_order = o;
202 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
203 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
204 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
206 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
207 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
208 W_FixWeaponOrder_BuildImpulseList_order = string_null;
209 return substring(o, 1, -1);
212 string W_FixWeaponOrder_AllowIncomplete(string order)
214 return W_FixWeaponOrder(order, 0);
217 string W_FixWeaponOrder_ForceComplete(string order)
220 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
221 return W_FixWeaponOrder(order, 1);
224 void W_RandomWeapons(entity e, float n)
229 remaining = e.weapons;
231 for(i = 0; i < n; ++i)
233 RandomSelection_Init();
234 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
235 if(remaining & WepSet_FromWeapon(j))
236 RandomSelection_Add(world, j, string_null, 1, 1);
237 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
238 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
243 string W_Name(float weaponid) // WEAPONTODO: make into a macro
245 return (get_weaponinfo(weaponid)).message;