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) * 800; //(bdamage * 10);
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);
425 // flame effect at impact
426 dir = trace_plane_normal * 100;
427 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
428 WriteByte (MSG_BROADCAST, TE_FLAMEJET);
429 WriteCoord (MSG_BROADCAST, trace_endpos_x);
430 WriteCoord (MSG_BROADCAST, trace_endpos_y);
431 WriteCoord (MSG_BROADCAST, trace_endpos_z);
432 WriteCoord (MSG_BROADCAST, dir_x);
433 WriteCoord (MSG_BROADCAST, dir_y);
434 WriteCoord (MSG_BROADCAST, dir_z);
435 WriteByte (MSG_BROADCAST, 255);
438 PointSound (trace_endpos, "weapons/neximpact.wav", 1, ATTN_NORM);
441 // trace multiple times until we hit a wall, each obstacle will be made
442 // non-solid so we can hit the next, while doing this we spawn effects and
443 // note down which entities were hit so we can damage them later
446 traceline_hitcorpse (self, start, end, FALSE, self);
448 // if it is world we can't hurt it so stop now
449 if (trace_ent == world || trace_fraction == 1)
452 // make the entity non-solid so we can hit the next one
453 trace_ent.railgunhit = TRUE;
454 trace_ent.railgunhitloc = trace_endpos;
455 trace_ent.railgunhitsolidbackup = trace_ent.solid;
457 // stop if this is a wall
458 if (trace_ent.solid == SOLID_BSP)
461 // make the entity non-solid
462 trace_ent.solid = SOLID_NOT;
465 // find all the entities the railgun hit and restore their solid state
466 ent = findfloat(world, railgunhit, TRUE);
469 // restore their solid type
470 ent.solid = ent.railgunhitsolidbackup;
471 ent = findfloat(ent, railgunhit, TRUE);
474 // spawn a temporary explosion entity for RadiusDamage calls
475 //explosion = spawn();
477 // find all the entities the railgun hit and hurt them
478 ent = findfloat(world, railgunhit, TRUE);
481 // get the details we need to call the damage function
482 hitloc = ent.railgunhitloc;
483 ent.railgunhitloc = '0 0 0';
484 ent.railgunhitsolidbackup = SOLID_NOT;
485 ent.railgunhit = FALSE;
488 if (ent.takedamage || ent.classname == "case")
489 Damage (ent, self, self, bdamage, deathtype, hitloc, force);
491 // create a small explosion to throw gibs around (if applicable)
492 //setorigin (explosion, hitloc);
493 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
495 // advance to the next entity
496 ent = findfloat(ent, railgunhit, TRUE);
499 // we're done with the explosion entity, remove it
504 void fireBullet (vector start, vector dir, float spread, float damage, float dtype)
509 // use traceline_hitcorpse to make sure it can hit gibs and corpses too
510 end = start + (dir + randomvec() * spread) * 1048576;
511 traceline_hitcorpse (self, start, end, FALSE, self);
513 // FIXME - causes excessive 'tinking'. Hopefully remove "tink1.wav" from the ricochets with csqc
514 if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
516 if (trace_ent.solid == SOLID_BSP)
518 pointcontents (self.origin);
519 te_gunshot (trace_endpos);
522 sound (self, CHAN_IMPACT, "weapons/ric1.wav", 1, ATTN_NORM);
524 sound (self, CHAN_IMPACT, "weapons/ric2.wav", 1, ATTN_NORM);
526 sound (self, CHAN_IMPACT, "weapons/ric3.wav", 1, ATTN_NORM);
528 else if (trace_ent.classname == "player" || trace_ent.classname == "corpse" || trace_ent.classname == "gib")
529 sound (trace_ent, CHAN_IMPACT, "misc/enemyimpact.wav", 1, ATTN_NORM);
530 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * damage * 5);
537 if (self.deadflag != DEAD_NO)
539 if (self.death_time < time)
548 makevectors (self.v_angle);
549 //if (self.weapon == IT_LASER)
550 // W_Laser_Attack ();
551 //if (self.weapon == IT_SHOTGUN)
552 //W_Shotgun_Attack ();
553 //else if (self.weapon == IT_UZI)
555 if (self.weapon == IT_CRYLINK)
557 else if (self.weapon == IT_ELECTRO)
559 W_Electro_Attack (self.electrocount);
560 self.electrocount = self.electrocount + 1;
561 if (self.electrocount == 3)
562 self.electrocount = 0;
564 else if (self.weapon == IT_GRENADE_LAUNCHER)
566 else if (self.weapon == IT_HAGAR)
568 else if (self.weapon == IT_NEX)
570 //else if (self.weapon == IT_ROCKET_LAUNCHER)
571 // W_Rocket_Attack ();
576 void W_SecondaryAttack (void)
578 if (self.deadflag != DEAD_NO)
580 if (self.death_time < time)
589 makevectors (self.v_angle);
590 //if (self.weapon == IT_LASER)
591 //W_Laser_Attack2 ();
592 //if (self.weapon == IT_SHOTGUN)
593 //W_Shotgun_Attack2 ();
594 //else if (self.weapon == IT_UZI)
596 else if (self.weapon == IT_CRYLINK)
597 W_Crylink_Attack2 ();
598 else if (self.weapon == IT_ELECTRO) {
599 W_Electro_Attack2 (self.electrocount);
600 self.electrocount = self.electrocount + 1;
601 if (self.electrocount == 3)
602 self.electrocount = 0;
604 else if (self.weapon == IT_GRENADE_LAUNCHER)
605 W_Grenade_Attack2 ();
606 else if (self.weapon == IT_HAGAR)
608 else if (self.weapon == IT_NEX)
610 //else if (self.weapon == IT_ROCKET_LAUNCHER)
611 //W_Rocket_Attack2 ();
616 void W_ThirdAttack (void)
618 if (self.deadflag != DEAD_NO)
620 if (self.death_time < time)
629 makevectors (self.v_angle);
630 //if (self.weapon == IT_LASER)
631 //W_Laser_Attack2 ();
632 //if (self.weapon == IT_SHOTGUN)
633 //W_Shotgun_Attack2 ();
634 //else if (self.weapon == IT_UZI)
636 else if (self.weapon == IT_CRYLINK)
637 W_Crylink_Attack2 ();
638 else if (self.weapon == IT_ELECTRO) {
639 W_Electro_Attack3 (self.electrocount);
640 self.electrocount = self.electrocount + 1;
641 if (self.electrocount == 3)
642 self.electrocount = 0;
644 else if (self.weapon == IT_GRENADE_LAUNCHER)
645 W_Grenade_Attack3 ();
646 else if (self.weapon == IT_HAGAR)
648 else if (self.weapon == IT_NEX)
650 //else if (self.weapon == IT_ROCKET_LAUNCHER)
651 //W_Rocket_Attack3 ();