2 // increments sprite frame, loops when end is hit.. simple
5 void (vector vec) WriteVec =
7 WriteCoord (MSG_BROADCAST, vec_x);
8 WriteCoord (MSG_BROADCAST, vec_y);
9 WriteCoord (MSG_BROADCAST, vec_z);
11 void (vector org, vector dir, float counts) W_Smoke =
13 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
14 WriteByte (MSG_BROADCAST, TE_SMOKE);
17 WriteByte (MSG_BROADCAST, counts);
20 // increments sprite frame, loops when end is hit.. simple
21 void animate_sprite (float startframe, float frame_count)
23 if ((self.frame - startframe) >= (frame_count - 1 ))
24 self.frame = startframe;
26 self.frame = self.frame + 1;
29 void W_UpdateAmmo (void)
32 self.items = self.items - (self.items & (IT_NAILS | IT_SHELLS | IT_ROCKETS | IT_CELLS));
34 if (self.weapon == IT_LASER)
36 else if (self.weapon == IT_SHOTGUN)
38 self.currentammo = self.ammo_shells;
39 self.items = self.items | IT_SHELLS;
41 else if (self.weapon == IT_UZI)
43 self.currentammo = self.ammo_nails;
44 self.items = self.items | IT_NAILS;
46 else if (self.weapon == IT_GRENADE_LAUNCHER || self.weapon == IT_HAGAR || self.weapon == IT_ROCKET_LAUNCHER)
48 self.currentammo = self.ammo_rockets;
49 self.items = self.items | IT_ROCKETS;
51 else if (self.weapon == IT_ELECTRO || self.weapon == IT_NEX || self.weapon == IT_CRYLINK)
53 self.currentammo = self.ammo_cells;
54 self.items = self.items | IT_CELLS;
59 void W_UpdateWeapon (void)
62 if (self.weapon == IT_LASER)
63 self.weaponmodel = "models/weapons/w_laser.zym";
64 else if (self.weapon == IT_SHOTGUN)
65 self.weaponmodel = "models/weapons/w_shotgun.zym";
66 else if (self.weapon == IT_UZI)
67 self.weaponmodel = "models/weapons/w_uzi.zym";
68 else if (self.weapon == IT_GRENADE_LAUNCHER)
69 self.weaponmodel = "models/weapons/w_gl.zym";
70 else if (self.weapon == IT_ELECTRO)
71 self.weaponmodel = "models/weapons/w_electro.zym";
72 else if (self.weapon == IT_CRYLINK)
73 self.weaponmodel = "models/weapons/w_crylink.zym";
74 else if (self.weapon == IT_NEX)
75 self.weaponmodel = "models/weapons/w_nex.zym";
76 else if (self.weapon == IT_HAGAR)
77 self.weaponmodel = "models/weapons/w_hagar.zym";
78 else if (self.weapon == IT_ROCKET_LAUNCHER)
79 self.weaponmodel = "models/weapons/w_rl.zym";
81 objerror ("Illegal weapon - please register your guns please!");
85 float W_GetBestWeapon (entity e)
88 if ((e.items & IT_ROCKET_LAUNCHER) && e.ammo_rockets)
89 return IT_ROCKET_LAUNCHER;
90 else if ((e.items & IT_NEX) && e.ammo_cells)
92 else if ((e.items & IT_HAGAR) && e.ammo_rockets)
94 else if ((e.items & IT_GRENADE_LAUNCHER) && e.ammo_rockets)
95 return IT_GRENADE_LAUNCHER;
96 else if ((e.items & IT_ELECTRO) && e.ammo_cells)
98 else if ((e.items & IT_CRYLINK) && e.ammo_cells)
100 else if ((e.items & IT_UZI) && e.ammo_nails)
102 else if ((e.items & IT_SHOTGUN) && e.ammo_shells)
110 void W_GiveWeapon (entity e, float wep, string name)
117 e.items = e.items | wep;
122 weapon_action(self.weapon, WR_UPDATECOUNTS);
124 if (other.classname == "player")
126 sprint (other, "You got the ^2");
127 sprint (other, name);
128 sprint (other, "\n");
139 void W_SwitchWeapon (float wep)
142 var float noammo = FALSE;
148 nextwep = IT_SHOTGUN;
149 if (!self.ammo_shells)
155 if (!self.ammo_nails)
160 nextwep = IT_CRYLINK;
161 if (!self.ammo_cells)
166 nextwep = IT_ELECTRO;
167 if (!self.ammo_cells)
172 nextwep = IT_GRENADE_LAUNCHER;
173 if (!self.ammo_rockets)
179 if (!self.ammo_rockets)
185 if (!self.ammo_cells)
190 nextwep = IT_ROCKET_LAUNCHER;
191 if (!self.ammo_rockets)
196 if (!(self.items & nextwep))
198 sprint (self, "You don't own that weapon\n");
203 sprint (self, "You don't have any ammo for that weapon\n");
207 self.weapon = nextwep;
210 self.attack_finished = time + 0.2;
211 if (self.viewzoom != 1)
215 void W_NextWeapon (void)
223 if (self.weapon == IT_ROCKET_LAUNCHER)
224 self.weapon = IT_LASER;
225 else if (self.weapon == IT_LASER)
227 self.weapon = IT_SHOTGUN;
228 if (!self.ammo_shells)
231 else if (self.weapon == IT_SHOTGUN)
233 self.weapon = IT_UZI;
234 if (!self.ammo_nails)
237 else if (self.weapon == IT_UZI)
239 self.weapon = IT_CRYLINK;
240 if (!self.ammo_cells)
243 else if (self.weapon == IT_CRYLINK)
245 self.weapon = IT_ELECTRO;
246 if (!self.ammo_cells)
249 else if (self.weapon == IT_ELECTRO)
251 self.weapon = IT_GRENADE_LAUNCHER;
252 if (!self.ammo_cells)
255 else if (self.weapon == IT_GRENADE_LAUNCHER)
257 self.weapon = IT_HAGAR;
258 if (!self.ammo_rockets)
261 else if (self.weapon == IT_HAGAR)
263 self.weapon = IT_NEX;
264 if (!self.ammo_rockets)
267 else if (self.weapon == IT_NEX)
269 self.weapon = IT_ROCKET_LAUNCHER;
270 if (!self.ammo_cells)
274 if ((self.items & self.weapon) && !noammo)
283 void W_PreviousWeapon (void)
291 if (self.weapon == IT_SHOTGUN)
292 self.weapon = IT_LASER;
293 else if (self.weapon == IT_UZI)
295 self.weapon = IT_SHOTGUN;
296 if (!self.ammo_shells)
299 else if (self.weapon == IT_CRYLINK)
301 self.weapon = IT_UZI;
302 if (!self.ammo_nails)
305 else if (self.weapon == IT_ELECTRO)
307 self.weapon = IT_CRYLINK;
308 if (!self.ammo_cells)
311 else if (self.weapon == IT_GRENADE_LAUNCHER)
313 self.weapon = IT_ELECTRO;
314 if (!self.ammo_cells)
317 else if (self.weapon == IT_HAGAR)
319 self.weapon = IT_GRENADE_LAUNCHER;
320 if (!self.ammo_rockets)
323 else if (self.weapon == IT_NEX)
325 self.weapon = IT_HAGAR;
326 if (!self.ammo_rockets)
329 else if (self.weapon == IT_ROCKET_LAUNCHER)
331 self.weapon = IT_NEX;
332 if (!self.ammo_cells)
335 else if (self.weapon == IT_LASER)
337 self.weapon = IT_ROCKET_LAUNCHER;
338 if (!self.ammo_rockets)
342 if ((self.items & self.weapon) && !noammo)
351 float W_CheckAmmo (void)
353 if ((cvar("g_instagib") == 1) | (cvar("g_rocketarena") == 1))
357 if (self.weapon == IT_LASER)
359 else if (self.currentammo)
362 self.weapon = W_GetBestWeapon (self);
369 void FireRailgunBullet (vector src, float bdamage, vector dir, float spread, float deathtype)
372 entity saveself, last;
374 org = self.origin + self.view_ofs;
383 traceline_hitcorpse (self, org, org + v_forward * 4096 + v_right * crandom () * spread + v_up * crandom () * spread, FALSE, self);
385 lastpos = trace_endpos;
386 if (trace_fraction != 1.0)
388 if (pointcontents(trace_endpos - dir*4) == CONTENT_SKY)
391 if (trace_ent.takedamage || trace_ent.classname == "case")
393 if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
394 te_blood (trace_endpos, dir * bdamage * 16, bdamage);
395 Damage (trace_ent, self, self, bdamage, deathtype, trace_endpos, dir * bdamage);
398 if (last.solid == SOLID_BSP)
404 void FireRailgunBullet (vector start, vector end, float bdamage, float deathtype)
406 local vector hitloc, force;
408 //local entity explosion;
410 force = normalize(end - start) * 800; //(bdamage * 10);
412 // find how far the beam can go until it hits a wall
413 traceline (start, end, TRUE, self);
414 // go a little bit into the wall because we need to hit this wall later
415 end = trace_endpos + normalize(end - start);
417 // trace multiple times until we hit a wall, each obstacle will be made
418 // non-solid so we can hit the next, while doing this we spawn effects and
419 // note down which entities were hit so we can damage them later
422 traceline_hitcorpse (self, start, end, FALSE, self);
424 // if it is world we can't hurt it so stop now
425 if (trace_ent == world || trace_fraction == 1)
428 // make the entity non-solid so we can hit the next one
429 trace_ent.railgunhit = TRUE;
430 trace_ent.railgunhitloc = trace_endpos;
431 trace_ent.railgunhitsolidbackup = trace_ent.solid;
433 // stop if this is a wall
434 if (trace_ent.solid == SOLID_BSP)
437 // make the entity non-solid
438 trace_ent.solid = SOLID_NOT;
441 // find all the entities the railgun hit and restore their solid state
442 ent = findfloat(world, railgunhit, TRUE);
445 // restore their solid type
446 ent.solid = ent.railgunhitsolidbackup;
447 ent = findfloat(ent, railgunhit, TRUE);
450 // spawn a temporary explosion entity for RadiusDamage calls
451 //explosion = spawn();
453 // find all the entities the railgun hit and hurt them
454 ent = findfloat(world, railgunhit, TRUE);
457 // get the details we need to call the damage function
458 hitloc = ent.railgunhitloc;
459 ent.railgunhitloc = '0 0 0';
460 ent.railgunhitsolidbackup = SOLID_NOT;
461 ent.railgunhit = FALSE;
464 if (ent.takedamage || ent.classname == "case")
465 Damage (ent, self, self, bdamage, deathtype, hitloc, force);
467 // create a small explosion to throw gibs around (if applicable)
468 //setorigin (explosion, hitloc);
469 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
471 // advance to the next entity
472 ent = findfloat(ent, railgunhit, TRUE);
475 // we're done with the explosion entity, remove it
479 void fireBullet (vector start, vector dir, float spread, float damage, float dtype, float tracer)
485 // use traceline_hitcorpse to make sure it can hit gibs and corpses too
486 dir = dir + randomvec() * spread;
487 end = start + dir * 4096;
488 traceline_hitcorpse (self, start, end, FALSE, self);
494 e.movetype = MOVETYPE_FLY;
496 e.think = SUB_Remove;
497 e.nextthink = time + vlen(trace_endpos - start) / 6000;
498 e.velocity = dir * 6000;
499 e.angles = vectoangles(e.velocity);
500 setmodel (e, "models/tracer.mdl");
501 setsize (e, '0 0 0', '0 0 0');
502 setorigin (e, start);
503 e.effects = e.effects | EF_ADDITIVE | EF_FULLBRIGHT;
506 // FIXME - causes excessive 'tinking'. Hopefully remove "tink1.wav" from the ricochets with csqc
507 if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
509 if (trace_ent.solid == SOLID_BSP)
511 pointcontents (self.origin);
512 te_gunshot (trace_endpos);
515 PointSound (trace_endpos, "weapons/ric1.wav", 1, ATTN_NORM);
517 PointSound (trace_endpos, "weapons/ric2.wav", 1, ATTN_NORM);
519 PointSound (trace_endpos, "weapons/ric3.wav", 1, ATTN_NORM);
521 else if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
522 sound (self, CHAN_BODY, "misc/hit.wav", 1, ATTN_NORM);
523 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * damage * 5);
530 if (self.deadflag != DEAD_NO)
532 if (self.death_time < time)
541 makevectors (self.v_angle);
542 //if (self.weapon == IT_LASER)
543 // W_Laser_Attack ();
544 //if (self.weapon == IT_SHOTGUN)
545 //W_Shotgun_Attack ();
546 //else if (self.weapon == IT_UZI)
548 if (self.weapon == IT_CRYLINK)
550 else if (self.weapon == IT_ELECTRO)
552 W_Electro_Attack (self.electrocount);
553 self.electrocount = self.electrocount + 1;
554 if (self.electrocount == 3)
555 self.electrocount = 0;
557 else if (self.weapon == IT_GRENADE_LAUNCHER)
559 else if (self.weapon == IT_HAGAR)
561 else if (self.weapon == IT_NEX)
563 //else if (self.weapon == IT_ROCKET_LAUNCHER)
564 // W_Rocket_Attack ();
569 void W_SecondaryAttack (void)
571 if (self.deadflag != DEAD_NO)
573 if (self.death_time < time)
582 makevectors (self.v_angle);
583 //if (self.weapon == IT_LASER)
584 //W_Laser_Attack2 ();
585 //if (self.weapon == IT_SHOTGUN)
586 //W_Shotgun_Attack2 ();
587 //else if (self.weapon == IT_UZI)
589 else if (self.weapon == IT_CRYLINK)
590 W_Crylink_Attack2 ();
591 else if (self.weapon == IT_ELECTRO) {
592 W_Electro_Attack2 (self.electrocount);
593 self.electrocount = self.electrocount + 1;
594 if (self.electrocount == 3)
595 self.electrocount = 0;
597 else if (self.weapon == IT_GRENADE_LAUNCHER)
598 W_Grenade_Attack2 ();
599 else if (self.weapon == IT_HAGAR)
601 else if (self.weapon == IT_NEX)
603 //else if (self.weapon == IT_ROCKET_LAUNCHER)
604 //W_Rocket_Attack2 ();
609 void W_ThirdAttack (void)
611 if (self.deadflag != DEAD_NO)
613 if (self.death_time < time)
622 makevectors (self.v_angle);
623 //if (self.weapon == IT_LASER)
624 //W_Laser_Attack2 ();
625 //if (self.weapon == IT_SHOTGUN)
626 //W_Shotgun_Attack2 ();
627 //else if (self.weapon == IT_UZI)
629 else if (self.weapon == IT_CRYLINK)
630 W_Crylink_Attack2 ();
631 else if (self.weapon == IT_ELECTRO) {
632 W_Electro_Attack3 (self.electrocount);
633 self.electrocount = self.electrocount + 1;
634 if (self.electrocount == 3)
635 self.electrocount = 0;
637 else if (self.weapon == IT_GRENADE_LAUNCHER)
638 W_Grenade_Attack3 ();
639 else if (self.weapon == IT_HAGAR)
641 else if (self.weapon == IT_NEX)
643 //else if (self.weapon == IT_ROCKET_LAUNCHER)
644 //W_Rocket_Attack3 ();