2 ===========================================================================
4 CLIENT WEAPONSYSTEM CODE
5 Bring back W_Weaponframe
7 ===========================================================================
10 // VorteX: static frame globals
11 float WFRAME_FIRE1 = 0;
12 float WFRAME_FIRE2 = 1;
13 float WFRAME_IDLE = 2;
15 void(float fr, float t, void() func) weapon_thinkf;
20 // this function calculates w_shotorg and w_shotdir based on the weapon model
21 // offset, trueaim and antilag, and won't put w_shotorg inside a wall.
22 // make sure you call makevectors first (FIXME?)
23 void(entity ent, vector vecs, float antilag, float recoil, string snd) W_SetupShot =
25 local vector trueaimpoint;
27 traceline_hitcorpse(self, self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 8192, MOVE_NOMONSTERS, self);
28 trueaimpoint = trace_endpos;
30 // if aiming at a player and the original trace won't hit that player
31 // anymore, try aiming at the player's new position
33 if (self.cursor_trace_ent)
34 if (self.cursor_trace_ent.takedamage)
35 if (trace_ent != self.cursor_trace_ent)
36 if (cvar("g_antilag"))
37 trueaimpoint = self.cursor_trace_ent.origin;
40 // don't allow the shot to start inside a wall
41 local vector startorg;
42 local vector idealorg;
43 startorg = ent.origin + ent.view_ofs;// - '0 0 8';
44 idealorg = ent.origin + ent.view_ofs + v_forward * vecs_x + v_right * vecs_y + v_up * vecs_z;
45 traceline_hitcorpse (ent, startorg, idealorg, MOVE_NOMONSTERS, ent);
46 w_shotorg = trace_endpos;
48 // all positions in the code are now required to be inside the player box
49 w_shotorg = ent.origin + ent.view_ofs + v_forward * vecs_x + v_right * vecs_y + v_up * vecs_z;
51 w_shotdir = normalize(trueaimpoint - w_shotorg);
53 if (!cvar("g_norecoil"))
54 self.punchangle_x = recoil * -1;
57 sound (self, CHAN_WEAPON, snd, 1, ATTN_NORM);
59 if (self.items & IT_STRENGTH)
60 if (!cvar("g_minstagib"))
61 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
64 void LaserTarget_Think()
71 // list of weapons that will use the laser, and the options that enable it
72 if(self.owner.laser_on && self.owner.weapon == WEP_ROCKET_LAUNCHER && cvar("g_laserguided_missile"))
75 //if(self.owner.weapon == WEP_ELECTRO && cvar("g_laserguided_electro"))
80 // if a laser-enabled weapon isn't selected, delete any existing laser and quit
83 // rocket launcher isn't selected, so no laser target.
84 if(self.lasertarget != world)
86 remove(self.lasertarget);
87 self.lasertarget = world;
94 // we don't have a lasertarget entity, so spawn one
95 //bprint("create laser target\n");
96 e = self.lasertarget = spawn();
97 e.owner = self.owner; // Its owner is my owner
98 e.classname = "laser_target";
99 e.movetype = MOVETYPE_NOCLIP; // don't touch things
100 setmodel(e, "models/laser_dot.mdl"); // what it looks like
101 e.scale = 1.25; // make it larger
102 e.alpha = 0.25; // transparency
103 e.colormod = '255 0 0' * (1/255) * 8; // change colors
104 e.effects = EF_FULLBRIGHT;
105 // make it dynamically glow
106 // you should avoid over-using this, as it can slow down the player's computer.
107 e.glow_color = 251; // red color
111 e = self.lasertarget;
113 // move the laser dot to where the player is looking
115 makevectors(self.owner.v_angle); // set v_forward etc to the direction the player is looking
116 offset = '0 0 26' + v_right*3;
117 traceline(self.owner.origin + offset, self.owner.origin + offset + v_forward * 8192, FALSE, self); // trace forward until you hit something, like a player or wall
118 setorigin(e, trace_endpos + v_forward*8); // move me to where the traceline ended
119 if(trace_plane_normal != '0 0 0')
120 e.angles = vectoangles(trace_plane_normal);
122 e.angles = vectoangles(v_forward);
126 void() CL_Weaponentity_Think =
128 self.nextthink = time;
129 if (intermission_running)
130 self.frame = WFRAME_IDLE;
131 if (self.owner.weaponentity != self)
136 if (self.owner.deadflag != DEAD_NO)
141 if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
143 self.cnt = self.owner.weapon;
144 self.dmg = self.owner.modelindex;
145 self.deadflag = self.owner.deadflag;
146 if (self.owner.weaponname != "")
147 setmodel(self, strcat("models/weapons/w_", self.owner.weaponname, ".zym"));
151 self.effects = self.owner.effects;
153 if (self.flags & FL_FLY)
154 // owner is currently being teleported, so don't apply EF_NODRAW otherwise the viewmodel would "blink"
155 self.effects = self.effects - (self.effects & EF_NODRAW);
157 self.alpha = self.owner.alpha;
158 self.colormap = self.owner.colormap;
160 self.angles = '0 0 0';
163 if (self.state == WS_RAISE)
164 f = (self.owner.weapon_nextthink - time) / cvar("g_balance_weaponswitchdelay");
165 else if (self.state == WS_DROP)
166 f = 1 - (self.owner.weapon_nextthink - time) / cvar("g_balance_weaponswitchdelay");
167 else if (self.state == WS_CLEAR)
169 self.angles_x = -90 * f * f;
171 // create or update the lasertarget entity
175 void() CL_ExteriorWeaponentity_Think =
177 self.nextthink = time;
178 if (self.owner.exteriorweaponentity != self)
183 if (self.owner.deadflag != DEAD_NO)
188 if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
190 self.cnt = self.owner.weapon;
191 self.dmg = self.owner.modelindex;
192 self.deadflag = self.owner.deadflag;
193 if (self.owner.weaponname != "")
194 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3"));
197 setattachment(self, self.owner, "bip01 r hand");
198 // if that didn't find a tag, hide the exterior weapon model
202 self.effects = self.owner.effects;
203 self.colormap = self.owner.colormap;
206 // spawning weaponentity for client
207 void() CL_SpawnWeaponentity =
209 self.weaponentity = spawn();
210 self.weaponentity.solid = SOLID_NOT;
211 self.weaponentity.owner = self;
212 self.weaponentity.weaponentity = self.weaponentity;
213 setmodel(self.weaponentity, "");
214 self.weaponentity.origin = '0 0 0';
215 self.weaponentity.angles = '0 0 0';
216 self.weaponentity.viewmodelforclient = self;
217 self.weaponentity.flags = 0;
218 self.weaponentity.think = CL_Weaponentity_Think;
219 self.weaponentity.nextthink = time;
220 self.weaponentity.scale = 0.61;
222 self.exteriorweaponentity = spawn();
223 self.exteriorweaponentity.solid = SOLID_NOT;
224 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
225 self.exteriorweaponentity.owner = self;
226 self.exteriorweaponentity.origin = '0 0 0';
227 self.exteriorweaponentity.angles = '0 0 0';
228 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
229 self.exteriorweaponentity.nextthink = time;
232 // convertion from index (= impulse) to flag in .items
233 float(float index) weapon_translateindextoflag =
235 if (index == WEP_LASER)
237 else if (index == WEP_SHOTGUN)
239 else if (index == WEP_UZI)
241 else if (index == WEP_GRENADE_LAUNCHER)
242 return IT_GRENADE_LAUNCHER;
243 else if (index == WEP_ELECTRO)
245 else if (index == WEP_CRYLINK)
247 else if (index == WEP_NEX)
249 else if (index == WEP_HAGAR)
251 else if (index == WEP_ROCKET_LAUNCHER)
252 return IT_ROCKET_LAUNCHER;
253 else if (index == WEP_LASER)
259 float(entity cl, float wpn, float andammo, float complain) client_hasweapon =
261 local float itemcode, f;
262 local entity oldself;
264 if (wpn < WEP_FIRST || wpn > WEP_LAST)
267 sprint(self, "Invalid weapon\n");
270 itemcode = weapon_translateindextoflag(wpn);
271 if (cl.items & itemcode)
277 f = weapon_action(wpn, WR_CHECKAMMO1);
278 f = f + weapon_action(wpn, WR_CHECKAMMO2);
283 sprint(self, "You don't have any ammo for that weapon\n");
290 sprint(self, "You don't own that weapon\n");
297 if (self.weapon != -1)
299 if (self.weaponentity)
301 self.weaponentity.state = WS_CLEAR;
302 setmodel(self.weaponentity, "");
303 self.weaponentity.effects = 0;
309 if (self.weaponentity)
311 self.weaponentity.state = WS_READY;
312 weapon_thinkf(WFRAME_IDLE, 0.1, w_ready);
316 // FIXME: add qw-style client-custom weaponrating (cl_weaponrating)?
317 float(entity e) w_getbestweapon
318 {// add new weapons here
319 if (client_hasweapon(e, WEP_ROCKET_LAUNCHER, TRUE, FALSE))
320 return WEP_ROCKET_LAUNCHER;
321 else if (client_hasweapon(e, WEP_NEX, TRUE, FALSE))
323 else if (client_hasweapon(e, WEP_HAGAR, TRUE, FALSE))
325 else if (client_hasweapon(e, WEP_GRENADE_LAUNCHER, TRUE, FALSE))
326 return WEP_GRENADE_LAUNCHER;
327 else if (client_hasweapon(e, WEP_ELECTRO, TRUE, FALSE))
329 else if (client_hasweapon(e, WEP_CRYLINK, TRUE, FALSE))
331 else if (client_hasweapon(e, WEP_UZI, TRUE, FALSE))
333 else if (client_hasweapon(e, WEP_SHOTGUN, TRUE, FALSE))
335 else if (client_hasweapon(e, WEP_LASER, FALSE, FALSE))
341 // Setup weapon for client (after this raise frame will be launched)
342 void(float windex, string wname, float hudammo) weapon_setup =
344 self.items = self.items - (self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS));
345 self.items = self.items | hudammo;
347 // the two weapon entities will notice this has changed and update their models
348 self.weapon = windex;
349 self.weaponname = wname;
352 // perform weapon to attack (weaponstate and attack_finished check is here)
353 float(float secondary, float attacktime) weapon_prepareattack =
355 if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
357 self.switchweapon = w_getbestweapon(self);
358 if (self.switchweapon != self.weapon)
359 self.cnt = self.weapon;
362 // don't fire if previous attack is not finished
363 if (self.attack_finished > time)
365 // don't fire while changing weapon
366 if (self.weaponentity.state != WS_READY)
368 self.weaponentity.state = WS_INUSE;
369 self.attack_finished = max(time, self.attack_finished + attacktime);
373 void(float fr, float t, void() func) weapon_thinkf =
377 if (self.weaponentity != world)
378 self.weaponentity.frame = fr;
381 if(cvar("g_runematch"))
383 if(self.runes & RUNE_SPEED)
385 if(self.runes & CURSE_SLOW)
386 t = t * cvar("g_balance_rune_speed_combo_atkrate");
388 t = t * cvar("g_balance_rune_speed_atkrate");
390 else if(self.runes & CURSE_SLOW)
392 t = t * cvar("g_balance_curse_slow_atkrate");
396 // VorteX: haste can be added here
397 self.weapon_nextthink = max(time, self.weapon_nextthink_lastframe + t);
398 self.weapon_think = func;
401 void(float spd, vector org) weapon_boblayer1 =
403 // VorteX: haste can be added here