2 ===========================================================================
4 CLIENT WEAPONSYSTEM CODE
5 Bring back W_Weaponframe
7 ===========================================================================
10 void() CL_Weaponentity_Think =
12 self.nextthink = time;
13 if (self.owner.weaponentity != self)
20 // spawning weaponentity for client
21 void() CL_SpawnWeaponentity =
23 if (self.weaponentity)
28 self.weaponentity = spawn();
29 self.weaponentity.solid = SOLID_NOT;
30 self.weaponentity.owner = self;
31 self.weaponentity.weaponentity = self.weaponentity;
32 setmodel(self.weaponentity, "");
33 self.weaponentity.origin = '0 0 0';
34 self.weaponentity.angles = '0 0 0';
35 self.weaponentity.viewmodelforclient = self;
36 self.weaponentity.flags = 0;
37 self.weaponentity.think = CL_Weaponentity_Think;
38 self.weaponentity.nextthink = time;
41 // convertion from index (= impulse) to flag in .items
42 float(float index) weapon_translateindextoflag =
44 if (index == WEP_LASER)
46 else if (index == WEP_SHOTGUN)
48 else if (index == WEP_UZI)
50 else if (index == WEP_GRENADE_LAUNCHER)
51 return IT_GRENADE_LAUNCHER;
52 else if (index == WEP_ELECTRO)
54 else if (index == WEP_CRYLINK)
56 else if (index == WEP_NEX)
58 else if (index == WEP_HAGAR)
60 else if (index == WEP_ROCKET_LAUNCHER)
61 return IT_ROCKET_LAUNCHER;
65 float(entity cl, float wpn, float andammo) client_hasweapon =
70 weapon_hasammo = TRUE;
71 if (wpn < WEP_FIRST || wpn > WEP_LAST)
73 itemcode = weapon_translateindextoflag(wpn);
74 if (cl.items & itemcode)
80 weapon_action(wpn, WR_CHECKAMMO);
94 weapon_action(self.weapon, WR_CLEAR);
95 if (self.weapon != -1)
97 self.weaponentity.state = WS_CLEAR;
98 setmodel(self.weaponentity, "");
99 self.weaponentity.effects = 0;
104 self.weaponentity.state = WS_READY;
105 weapon_action(self.weapon, WR_IDLE);
108 // FIXME: add qw-style client-custom weaponrating (cl_weaponrating)?
109 float(entity e) w_getbestweapon
110 {// add new weapons here
111 if (client_hasweapon(e, WEP_ROCKET_LAUNCHER, TRUE))
112 return WEP_ROCKET_LAUNCHER;
113 else if (client_hasweapon(e, WEP_NEX, TRUE))
115 else if (client_hasweapon(e, WEP_HAGAR, TRUE))
117 else if (client_hasweapon(e, WEP_GRENADE_LAUNCHER, TRUE))
118 return WEP_GRENADE_LAUNCHER;
119 else if (client_hasweapon(e, WEP_ELECTRO, TRUE))
121 else if (client_hasweapon(e, WEP_CRYLINK, TRUE))
123 else if (client_hasweapon(e, WEP_UZI, TRUE))
125 else if (client_hasweapon(e, WEP_SHOTGUN, TRUE))
129 weapon_hasammo = TRUE;
134 // Setup weapon for client (after this raise frame will be launched)
135 void(float windex, string wmodel, float hudammo) weapon_setup =
137 local string wdir, weaponmdl;
139 self.items = self.items - (self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS));
140 self.items = self.items | hudammo;
142 self.weapon = windex;
146 weaponmdl = strzone(strcat("models/weapons/", wmodel));
147 setmodel(self.weaponentity, weaponmdl);
149 // VorteX: update visible weapon
150 // CL_ViswepUpdate();
154 float WEAPON_MAXRELX = 14; // if more, shot can be spawned after wall surface (in empty worldspace) or inside other entity if client stands close to it
155 void(float x, float y, float z) weapon_shotdir =
157 makevectors(self.v_angle);
158 self.shotorg = self.origin + self.view_ofs + v_forward*bound(0, x, WEAPON_MAXRELX) + v_right*(y + self.weaponentity.view_ofs_y) + v_up*z;
159 self.shotdir = aim(self, 1000);
162 // perform weapon to attack (weaponstate and attack_finished check is here)
163 void(float() checkfunc1, float() checkfunc2, void() firefunc, float atktime) weapon_prepareattack =
165 // Change to best weapon if failed
166 if (!(game & GAME_INSTAGIB) && !(game & GAME_ROCKET_ARENA))
171 self.switchweapon = w_getbestweapon(self);
175 // Don't do shot if previos attack not finished
176 if (!(game & GAME_INSANE))
177 if (time < self.attack_finished)
179 // Can't do shot if changing weapon
180 if (!(game & GAME_INSANE))
181 if (self.weaponentity.state != WS_READY)
184 self.attack_finished = time + atktime;
188 // perform weapon attack
189 void(float() checkfunc1, float() checkfunc2, void() firefunc) weapon_doattack
191 // Change to best weapon if failed
192 if (!(game & GAME_INSTAGIB) && !(game & GAME_ROCKET_ARENA))
197 self.switchweapon = w_getbestweapon(self);
201 self.weaponentity.state = WS_INUSE;
203 weapon_action(self.weapon, WR_UPDATECOUNTS); // update ammo now
206 void(entity ent, float recoil) weapon_recoil =
208 ent.punchangle = (randomvec() + '-1 0 0')*recoil;
209 ent.punchangle_z = 0; // don't want roll
210 if (recoil > 3) // push back if large recoil
211 ent.velocity = ent.velocity - normalize(ent.shotdir)*recoil*25;
214 void(float fr, float t, void() func) weapon_thinkf =
217 if (self.weaponentity != world)
218 self.weaponentity.frame = fr;
219 // VorteX: haste can be added here
220 self.weapon_nextthink = time + t;
221 self.weapon_think = func;
224 void(float spd, vector org) weapon_boblayer1 =
226 // VorteX: haste can be added here
227 self.weaponentity.pos1 =org;
228 self.weaponentity.lip = spd;