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)
117 e.items = e.items | wep;
122 weapon_action(self.weapon, WR_UPDATECOUNTS);
130 void W_SwitchWeapon (float wep)
133 var float noammo = FALSE;
139 nextwep = IT_SHOTGUN;
140 if (!self.ammo_shells)
146 if (!self.ammo_nails)
151 nextwep = IT_CRYLINK;
152 if (!self.ammo_cells)
157 nextwep = IT_ELECTRO;
158 if (!self.ammo_cells)
163 nextwep = IT_GRENADE_LAUNCHER;
164 if (!self.ammo_rockets)
170 if (!self.ammo_rockets)
176 if (!self.ammo_cells)
181 nextwep = IT_ROCKET_LAUNCHER;
182 if (!self.ammo_rockets)
187 if (!(self.items & nextwep))
189 sprint (self, "You don't own that weapon\n");
194 sprint (self, "You don't have any ammo for that weapon\n");
198 self.weapon = nextwep;
201 self.attack_finished = time + 0.2;
202 if (self.viewzoom != 1)
206 void W_NextWeapon (void)
214 if (self.weapon == IT_ROCKET_LAUNCHER)
215 self.weapon = IT_LASER;
216 else if (self.weapon == IT_LASER)
218 self.weapon = IT_SHOTGUN;
219 if (!self.ammo_shells)
222 else if (self.weapon == IT_SHOTGUN)
224 self.weapon = IT_UZI;
225 if (!self.ammo_nails)
228 else if (self.weapon == IT_UZI)
230 self.weapon = IT_CRYLINK;
231 if (!self.ammo_cells)
234 else if (self.weapon == IT_CRYLINK)
236 self.weapon = IT_ELECTRO;
237 if (!self.ammo_cells)
240 else if (self.weapon == IT_ELECTRO)
242 self.weapon = IT_GRENADE_LAUNCHER;
243 if (!self.ammo_cells)
246 else if (self.weapon == IT_GRENADE_LAUNCHER)
248 self.weapon = IT_HAGAR;
249 if (!self.ammo_rockets)
252 else if (self.weapon == IT_HAGAR)
254 self.weapon = IT_NEX;
255 if (!self.ammo_rockets)
258 else if (self.weapon == IT_NEX)
260 self.weapon = IT_ROCKET_LAUNCHER;
261 if (!self.ammo_cells)
265 if ((self.items & self.weapon) && !noammo)
274 void W_PreviousWeapon (void)
282 if (self.weapon == IT_SHOTGUN)
283 self.weapon = IT_LASER;
284 else if (self.weapon == IT_UZI)
286 self.weapon = IT_SHOTGUN;
287 if (!self.ammo_shells)
290 else if (self.weapon == IT_CRYLINK)
292 self.weapon = IT_UZI;
293 if (!self.ammo_nails)
296 else if (self.weapon == IT_ELECTRO)
298 self.weapon = IT_CRYLINK;
299 if (!self.ammo_cells)
302 else if (self.weapon == IT_GRENADE_LAUNCHER)
304 self.weapon = IT_ELECTRO;
305 if (!self.ammo_cells)
308 else if (self.weapon == IT_HAGAR)
310 self.weapon = IT_GRENADE_LAUNCHER;
311 if (!self.ammo_rockets)
314 else if (self.weapon == IT_NEX)
316 self.weapon = IT_HAGAR;
317 if (!self.ammo_rockets)
320 else if (self.weapon == IT_ROCKET_LAUNCHER)
322 self.weapon = IT_NEX;
323 if (!self.ammo_cells)
326 else if (self.weapon == IT_LASER)
328 self.weapon = IT_ROCKET_LAUNCHER;
329 if (!self.ammo_rockets)
333 if ((self.items & self.weapon) && !noammo)
342 float W_CheckAmmo (void)
344 if (game & (GAME_INSTAGIB | GAME_ROCKET_ARENA))
348 if (self.weapon == IT_LASER)
350 else if (self.currentammo)
353 self.weapon = W_GetBestWeapon (self);
360 void FireRailgunBullet (vector src, float bdamage, vector dir, float spread, float deathtype)
363 entity saveself, last;
365 org = self.origin + self.view_ofs;
374 traceline_hitcorpse (self, org, org + v_forward * 4096 + v_right * crandom () * spread + v_up * crandom () * spread, FALSE, self);
376 lastpos = trace_endpos;
377 if (trace_fraction != 1.0)
379 if (pointcontents(trace_endpos - dir*4) == CONTENT_SKY)
382 if (trace_ent.takedamage || trace_ent.classname == "case")
384 if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
385 te_blood (trace_endpos, dir * bdamage * 16, bdamage);
386 Damage (trace_ent, self, self, bdamage, deathtype, trace_endpos, dir * bdamage);
389 if (last.solid == SOLID_BSP)
395 void FireRailgunBullet (vector start, vector end, float bdamage, float deathtype)
397 local vector hitloc, dir, force;
399 //local entity explosion;
401 force = normalize(end - start) * (bdamage * 0.1);
403 // find how far the beam can go until it hits a wall
404 traceline (start, end, TRUE, self);
405 // go a little bit into the wall because we need to hit this wall later
406 end = trace_endpos + normalize(end - start);
409 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
410 WriteByte (MSG_BROADCAST, 76);
411 WriteCoord (MSG_BROADCAST, start_x);
412 WriteCoord (MSG_BROADCAST, start_y);
413 WriteCoord (MSG_BROADCAST, start_z);
414 WriteCoord (MSG_BROADCAST, end_x);
415 WriteCoord (MSG_BROADCAST, end_y);
416 WriteCoord (MSG_BROADCAST, end_z);
417 WriteCoord (MSG_BROADCAST, 0);
418 WriteCoord (MSG_BROADCAST, 0);
419 WriteCoord (MSG_BROADCAST, 0);
421 // flash and burn the wall
422 te_plasmaburn (trace_endpos);
424 // flame effect at impact
425 dir = trace_plane_normal * 100;
426 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
427 WriteByte (MSG_BROADCAST, TE_FLAMEJET);
428 WriteCoord (MSG_BROADCAST, trace_endpos_x);
429 WriteCoord (MSG_BROADCAST, trace_endpos_y);
430 WriteCoord (MSG_BROADCAST, trace_endpos_z);
431 WriteCoord (MSG_BROADCAST, dir_x);
432 WriteCoord (MSG_BROADCAST, dir_y);
433 WriteCoord (MSG_BROADCAST, dir_z);
434 WriteByte (MSG_BROADCAST, 255);
437 PointSound (trace_endpos, "weapons/neximpact.wav", 1, ATTN_NORM);
440 // trace multiple times until we hit a wall, each obstacle will be made
441 // non-solid so we can hit the next, while doing this we spawn effects and
442 // note down which entities were hit so we can damage them later
445 traceline_hitcorpse (self, start, end, FALSE, self);
447 // if it is world we can't hurt it so stop now
448 if (trace_ent == world || trace_fraction == 1)
451 // make the entity non-solid so we can hit the next one
452 trace_ent.railgunhit = TRUE;
453 trace_ent.railgunhitloc = trace_endpos;
454 trace_ent.railgunhitsolidbackup = trace_ent.solid;
456 // stop if this is a wall
457 if (trace_ent.solid == SOLID_BSP)
460 // make the entity non-solid
461 trace_ent.solid = SOLID_NOT;
464 // find all the entities the railgun hit and restore their solid state
465 ent = findfloat(world, railgunhit, TRUE);
468 // restore their solid type
469 ent.solid = ent.railgunhitsolidbackup;
470 ent = findfloat(ent, railgunhit, TRUE);
473 // spawn a temporary explosion entity for RadiusDamage calls
474 //explosion = spawn();
476 // find all the entities the railgun hit and hurt them
477 ent = findfloat(world, railgunhit, TRUE);
480 // get the details we need to call the damage function
481 hitloc = ent.railgunhitloc;
482 ent.railgunhitloc = '0 0 0';
483 ent.railgunhitsolidbackup = SOLID_NOT;
484 ent.railgunhit = FALSE;
487 if (ent.takedamage || ent.classname == "case")
488 Damage (ent, self, self, bdamage, deathtype, hitloc, force);
490 // create a small explosion to throw gibs around (if applicable)
491 //setorigin (explosion, hitloc);
492 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
494 // advance to the next entity
495 ent = findfloat(ent, railgunhit, TRUE);
498 // we're done with the explosion entity, remove it
503 void fireBullet (vector start, vector dir, float spread, float damage, float dtype)
508 // use traceline_hitcorpse to make sure it can hit gibs and corpses too
509 end = start + (dir + randomvec() * spread) * 1048576;
510 traceline_hitcorpse (self, start, end, FALSE, self);
512 // FIXME - causes excessive 'tinking'. Hopefully remove "tink1.wav" from the ricochets with csqc
513 if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
515 if (trace_ent.solid == SOLID_BSP)
517 pointcontents (self.origin);
518 te_gunshot (trace_endpos);
521 sound (self, CHAN_IMPACT, "weapons/ric1.wav", 1, ATTN_NORM);
523 sound (self, CHAN_IMPACT, "weapons/ric2.wav", 1, ATTN_NORM);
525 sound (self, CHAN_IMPACT, "weapons/ric3.wav", 1, ATTN_NORM);
527 else if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
528 sound (trace_ent, CHAN_IMPACT, "misc/enemyimpact.wav", 1, ATTN_NORM);
529 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * damage);
536 if (self.deadflag != DEAD_NO)
538 if (self.death_time < time)
547 makevectors (self.v_angle);
548 //if (self.weapon == IT_LASER)
549 // W_Laser_Attack ();
550 //if (self.weapon == IT_SHOTGUN)
551 //W_Shotgun_Attack ();
552 //else if (self.weapon == IT_UZI)
554 if (self.weapon == IT_CRYLINK)
556 else if (self.weapon == IT_ELECTRO)
558 W_Electro_Attack (self.electrocount);
559 self.electrocount = self.electrocount + 1;
560 if (self.electrocount == 3)
561 self.electrocount = 0;
563 else if (self.weapon == IT_GRENADE_LAUNCHER)
565 else if (self.weapon == IT_HAGAR)
567 else if (self.weapon == IT_NEX)
569 //else if (self.weapon == IT_ROCKET_LAUNCHER)
570 // W_Rocket_Attack ();
575 void W_SecondaryAttack (void)
577 if (self.deadflag != DEAD_NO)
579 if (self.death_time < time)
588 makevectors (self.v_angle);
589 //if (self.weapon == IT_LASER)
590 //W_Laser_Attack2 ();
591 //if (self.weapon == IT_SHOTGUN)
592 //W_Shotgun_Attack2 ();
593 //else if (self.weapon == IT_UZI)
595 else if (self.weapon == IT_CRYLINK)
596 W_Crylink_Attack2 ();
597 else if (self.weapon == IT_ELECTRO) {
598 W_Electro_Attack2 (self.electrocount);
599 self.electrocount = self.electrocount + 1;
600 if (self.electrocount == 3)
601 self.electrocount = 0;
603 else if (self.weapon == IT_GRENADE_LAUNCHER)
604 W_Grenade_Attack2 ();
605 else if (self.weapon == IT_HAGAR)
607 else if (self.weapon == IT_NEX)
609 //else if (self.weapon == IT_ROCKET_LAUNCHER)
610 //W_Rocket_Attack2 ();
615 void W_ThirdAttack (void)
617 if (self.deadflag != DEAD_NO)
619 if (self.death_time < time)
628 makevectors (self.v_angle);
629 //if (self.weapon == IT_LASER)
630 //W_Laser_Attack2 ();
631 //if (self.weapon == IT_SHOTGUN)
632 //W_Shotgun_Attack2 ();
633 //else if (self.weapon == IT_UZI)
635 else if (self.weapon == IT_CRYLINK)
636 W_Crylink_Attack2 ();
637 else if (self.weapon == IT_ELECTRO) {
638 W_Electro_Attack3 (self.electrocount);
639 self.electrocount = self.electrocount + 1;
640 if (self.electrocount == 3)
641 self.electrocount = 0;
643 else if (self.weapon == IT_GRENADE_LAUNCHER)
644 W_Grenade_Attack3 ();
645 else if (self.weapon == IT_HAGAR)
647 else if (self.weapon == IT_NEX)
649 //else if (self.weapon == IT_ROCKET_LAUNCHER)
650 //W_Rocket_Attack3 ();