home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / punish / weapons.qc < prev   
Encoding:
Text File  |  1996-08-12  |  39.2 KB  |  1,743 lines

  1. /*
  2. ==========================================================
  3. SplitMissile v1.01
  4. Tracer v1.0
  5. by Punisher
  6. email: punisher@trojan.neta.com
  7.  
  8. Auto Shotgun v1.0
  9. by Biafra with supervision from Punisher
  10.  
  11. Bouncing Fragmentation Grenade!    7/28/96 by Steve Bond
  12. Email: wedge@nuc.net    WWW: http://www.nuc.net/quake
  13. improved by Punisher
  14. ==========================================================
  15. */
  16. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  17. void () player_run;
  18. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  19. void(vector org, vector vel, float damage) SpawnBlood;
  20. void() SuperDamageSound;
  21.  
  22.  
  23. // called by worldspawn
  24. void() W_Precache =
  25. {
  26.         precache_model ("progs/laser.mdl");     //for tracer
  27.         precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  28.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  29.     precache_sound ("weapons/sgun1.wav");
  30.     precache_sound ("weapons/guncock.wav"); // player shotgun
  31.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  32.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  33.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  34.     precache_sound ("weapons/spike2.wav");  // super spikes
  35.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  36.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  37.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  38.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  39. };
  40.  
  41. float() crandom =
  42. {
  43.     return 2*(random() - 0.5);
  44. };
  45.  
  46. /*
  47. ================
  48. W_FireAxe
  49. ================
  50. */
  51. void() W_FireAxe =
  52. {
  53.     local   vector  source;
  54.     local   vector  org;
  55.  
  56.     source = self.origin + '0 0 16';
  57.     traceline (source, source + v_forward*64, FALSE, self);
  58.     if (trace_fraction == 1.0)
  59.         return;
  60.     
  61.     org = trace_endpos - v_forward*4;
  62.  
  63.     if (trace_ent.takedamage)
  64.     {
  65.         trace_ent.axhitme = 1;
  66.         SpawnBlood (org, '0 0 0', 20);
  67.         T_Damage (trace_ent, self, self, 20);
  68.     }
  69.     else
  70.     {       // hit wall
  71.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  72.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  73.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  74.         WriteCoord (MSG_BROADCAST, org_x);
  75.         WriteCoord (MSG_BROADCAST, org_y);
  76.         WriteCoord (MSG_BROADCAST, org_z);
  77.     }
  78. };
  79.  
  80.  
  81. //============================================================================
  82.  
  83.  
  84. vector() wall_velocity =
  85. {
  86.     local vector    vel;
  87.     
  88.     vel = normalize (self.velocity);
  89.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  90.     vel = vel + 2*trace_plane_normal;
  91.     vel = vel * 200;
  92.     
  93.     return vel;
  94. };
  95.  
  96.  
  97. /*
  98. ================
  99. SpawnMeatSpray
  100. ================
  101. */
  102. void(vector org, vector vel) SpawnMeatSpray =
  103. {
  104.     local   entity missile, mpuff;
  105.     local   vector  org;
  106.  
  107.     missile = spawn ();
  108.     missile.owner = self;
  109.     missile.movetype = MOVETYPE_BOUNCE;
  110.     missile.solid = SOLID_NOT;
  111.  
  112.     makevectors (self.angles);
  113.  
  114.     missile.velocity = vel;
  115.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  116.  
  117.     missile.avelocity = '3000 1000 2000';
  118.     
  119. // set missile duration
  120.     missile.nextthink = time + 1;
  121.     missile.think = SUB_Remove;
  122.  
  123.     setmodel (missile, "progs/zom_gib.mdl");
  124.     setsize (missile, '0 0 0', '0 0 0');            
  125.     setorigin (missile, org);
  126. };
  127.  
  128. /*
  129. ================
  130. SpawnBlood
  131. ================
  132. */
  133. void(vector org, vector vel, float damage) SpawnBlood =
  134. {
  135.     particle (org, vel*0.1, 73, damage*2);
  136. };
  137.  
  138. /*
  139. ================
  140. spawn_touchblood
  141. ================
  142. */
  143. void(float damage) spawn_touchblood =
  144. {
  145.     local vector    vel;
  146.  
  147.     vel = wall_velocity () * 0.2;
  148.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  149. };
  150.  
  151.  
  152. /*
  153. ================
  154. SpawnChunk
  155. ================
  156. */
  157. void(vector org, vector vel) SpawnChunk =
  158. {
  159.     particle (org, vel*0.02, 0, 10);
  160. };
  161.  
  162. /*
  163. ==============================================================================
  164.  
  165. MULTI-DAMAGE
  166.  
  167. Collects multiple small damages into a single damage
  168.  
  169. ==============================================================================
  170. */
  171.  
  172. entity  multi_ent;
  173. float   multi_damage;
  174.  
  175. void() ClearMultiDamage =
  176. {
  177.     multi_ent = world;
  178.     multi_damage = 0;
  179. };
  180.  
  181. void() ApplyMultiDamage =
  182. {
  183.     if (!multi_ent)
  184.         return;
  185.     T_Damage (multi_ent, self, self, multi_damage);
  186. };
  187.  
  188. void(entity hit, float damage) AddMultiDamage =
  189. {
  190.     if (!hit)
  191.         return;
  192.     
  193.     if (hit != multi_ent)
  194.     {
  195.         ApplyMultiDamage ();
  196.         multi_damage = damage;
  197.         multi_ent = hit;
  198.     }
  199.     else
  200.         multi_damage = multi_damage + damage;
  201. };
  202.  
  203. /*
  204. ==============================================================================
  205.  
  206. BULLETS
  207.  
  208. ==============================================================================
  209. */
  210.  
  211. /*
  212. ================
  213. TraceAttack
  214. ================
  215. */
  216. void(float damage, vector dir) TraceAttack =
  217. {
  218.     local   vector  vel, org;
  219.     
  220.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  221.     vel = vel + 2*trace_plane_normal;
  222.     vel = vel * 200;
  223.  
  224.     org = trace_endpos - dir*4;
  225.  
  226.     if (trace_ent.takedamage)
  227.     {
  228.         SpawnBlood (org, vel*0.2, damage);
  229.         AddMultiDamage (trace_ent, damage);
  230.     }
  231.     else
  232.     {
  233.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  234.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  235.         WriteCoord (MSG_BROADCAST, org_x);
  236.         WriteCoord (MSG_BROADCAST, org_y);
  237.         WriteCoord (MSG_BROADCAST, org_z);
  238.     }
  239. };
  240.  
  241. /*
  242. ================
  243. FireBullets
  244.  
  245. Used by shotgun, super shotgun, and enemy soldier firing
  246. Go to the trouble of combining multiple pellets into a single damage call.
  247. ================
  248. */
  249. void(float shotcount, vector dir, vector spread) FireBullets =
  250. {
  251.     local   vector direction;
  252.     local   vector  src;
  253.     
  254.     makevectors(self.v_angle);
  255.  
  256.     src = self.origin + v_forward*10;
  257.     src_z = self.absmin_z + self.size_z * 0.7;
  258.  
  259.     ClearMultiDamage ();
  260.     while (shotcount > 0)
  261.     {
  262.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  263.  
  264.         traceline (src, src + direction*2048, FALSE, self);
  265.         if (trace_fraction != 1.0)
  266.             TraceAttack (4, direction);
  267.  
  268.         shotcount = shotcount - 1;
  269.     }
  270.     ApplyMultiDamage ();
  271. };
  272.  
  273. /*
  274. ================
  275. W_FireShotgun
  276. ================
  277. */
  278. void() W_FireShotgun =
  279. {
  280.     local vector dir;
  281.  
  282.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  283.  
  284.     self.punchangle_x = -2;
  285.     
  286.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  287.     dir = aim (self, 100000);
  288.     FireBullets (6, dir, '0.04 0.04 0');
  289. };
  290.  
  291.  
  292. /*
  293. ================
  294. W_FireSuperShotgun
  295. ================
  296. */
  297. void() W_FireSuperShotgun =
  298. {
  299.     local vector dir;
  300.  
  301.     if (self.currentammo == 1)
  302.     {
  303.         W_FireShotgun ();
  304.         return;
  305.     }
  306.         
  307.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  308.  
  309.     self.punchangle_x = -4;
  310.     
  311.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  312.     dir = aim (self, 100000);
  313.     FireBullets (14, dir, '0.14 0.08 0');
  314. };
  315.  
  316.  
  317. /*
  318. ==============================================================================
  319.  
  320. ROCKETS
  321.  
  322. ==============================================================================
  323. */
  324.  
  325. void()  s_explode1      =       [0,             s_explode2] {};
  326. void()  s_explode2      =       [1,             s_explode3] {};
  327. void()  s_explode3      =       [2,             s_explode4] {};
  328. void()  s_explode4      =       [3,             s_explode5] {};
  329. void()  s_explode5      =       [4,             s_explode6] {};
  330. void()  s_explode6      =       [5,             SUB_Remove] {};
  331.  
  332. void() BecomeExplosion =
  333. {
  334.     self.movetype = MOVETYPE_NONE;
  335.     self.velocity = '0 0 0';
  336.     self.touch = SUB_Null;
  337.     setmodel (self, "progs/s_explod.spr");
  338.     self.solid = SOLID_NOT;
  339.     s_explode1 ();
  340. };
  341.  
  342. void() T_MissileTouch =
  343. {
  344.     local float     damg;
  345.  
  346.     if (other == self.owner)
  347.         return;         // don't explode on owner
  348.  
  349.     if (pointcontents(self.origin) == CONTENT_SKY)
  350.     {
  351.         remove(self);
  352.         return;
  353.     }
  354.  
  355.     damg = 100 + random()*20;
  356.     
  357.     if (other.health)
  358.     {
  359.         if (other.classname == "monster_shambler")
  360.             damg = damg * 0.5;      // mostly immune
  361.         T_Damage (other, self, self.owner, damg );
  362.     }
  363.  
  364.     // don't do radius damage to the other, because all the damage
  365.     // was done in the impact
  366.     T_RadiusDamage (self, self.owner, 120, other);
  367.  
  368. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  369.     self.origin = self.origin - 8*normalize(self.velocity);
  370.  
  371.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  372.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  373.     WriteCoord (MSG_BROADCAST, self.origin_x);
  374.     WriteCoord (MSG_BROADCAST, self.origin_y);
  375.     WriteCoord (MSG_BROADCAST, self.origin_z);
  376.  
  377.     BecomeExplosion ();
  378. };
  379.  
  380.  
  381.  
  382. /*
  383. ================
  384. W_FireRocket
  385. ================
  386. */
  387. void() W_FireRocket =
  388. {
  389.     local   entity missile, mpuff;
  390.     
  391.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  392.     
  393.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  394.  
  395.     self.punchangle_x = -2;
  396.  
  397.     missile = spawn ();
  398.     missile.owner = self;
  399.     missile.movetype = MOVETYPE_FLYMISSILE;
  400.     missile.solid = SOLID_BBOX;
  401.         
  402. // set missile speed    
  403.  
  404.     makevectors (self.v_angle);
  405.     missile.velocity = aim(self, 1000);
  406.     missile.velocity = missile.velocity * 1000;
  407.     missile.angles = vectoangles(missile.velocity);
  408.     
  409.     missile.touch = T_MissileTouch;
  410.     
  411. // set missile duration
  412.     missile.nextthink = time + 5;
  413.     missile.think = SUB_Remove;
  414.  
  415.     setmodel (missile, "progs/missile.mdl");
  416.     setsize (missile, '0 0 0', '0 0 0');            
  417.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  418. };
  419.  
  420. /*
  421. ===============================================================================
  422.  
  423. LIGHTNING
  424.  
  425. ===============================================================================
  426. */
  427.  
  428. /*
  429. =================
  430. LightningDamage
  431. =================
  432. */
  433. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  434. {
  435.     local entity            e1, e2;
  436.     local vector            f;
  437.     
  438.     f = p2 - p1;
  439.     normalize (f);
  440.     f_x = 0 - f_y;
  441.     f_y = f_x;
  442.     f_z = 0;
  443.     f = f*16;
  444.  
  445.     e1 = e2 = world;
  446.  
  447.     traceline (p1, p2, FALSE, self);
  448.     if (trace_ent.takedamage)
  449.     {
  450.         particle (trace_endpos, '0 0 100', 225, damage*4);
  451.         T_Damage (trace_ent, from, from, damage);
  452.         if (self.classname == "player")
  453.         {
  454.             if (other.classname == "player")
  455.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  456.         }
  457.     }
  458.     e1 = trace_ent;
  459.  
  460.     traceline (p1 + f, p2 + f, FALSE, self);
  461.     if (trace_ent != e1 && trace_ent.takedamage)
  462.     {
  463.         particle (trace_endpos, '0 0 100', 225, damage*4);
  464.         T_Damage (trace_ent, from, from, damage);
  465.     }
  466.     e2 = trace_ent;
  467.  
  468.     traceline (p1 - f, p2 - f, FALSE, self);
  469.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  470.     {
  471.         particle (trace_endpos, '0 0 100', 225, damage*4);
  472.         T_Damage (trace_ent, from, from, damage);
  473.     }
  474. };
  475.  
  476. void() W_FireLightning =
  477. {
  478.     local   vector          org;
  479.  
  480.     if (self.ammo_cells < 1)
  481.     {
  482.         self.weapon = W_BestWeapon ();
  483.         W_SetCurrentAmmo ();
  484.         return;
  485.     }
  486.  
  487. // explode if under water
  488.     if (self.waterlevel > 1)
  489.     {
  490.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  491.         self.ammo_cells = 0;
  492.         W_SetCurrentAmmo ();
  493.         return;
  494.     }
  495.  
  496.     if (self.t_width < time)
  497.     {
  498.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  499.         self.t_width = time + 0.6;
  500.     }
  501.     self.punchangle_x = -2;
  502.  
  503.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  504.  
  505.     org = self.origin + '0 0 16';
  506.     
  507.     traceline (org, org + v_forward*600, TRUE, self);
  508.  
  509.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  510.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  511.     WriteEntity (MSG_BROADCAST, self);
  512.     WriteCoord (MSG_BROADCAST, org_x);
  513.     WriteCoord (MSG_BROADCAST, org_y);
  514.     WriteCoord (MSG_BROADCAST, org_z);
  515.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  516.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  517.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  518.  
  519.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  520. };
  521.  
  522.  
  523. //=============================================================================
  524. void() GrenadeExplode =
  525. {
  526.     T_RadiusDamage (self, self.owner, 120, world);
  527.  
  528.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  529.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  530.     WriteCoord (MSG_BROADCAST, self.origin_x);
  531.     WriteCoord (MSG_BROADCAST, self.origin_y);
  532.     WriteCoord (MSG_BROADCAST, self.origin_z);
  533.  
  534.     BecomeExplosion ();
  535. };
  536.  
  537. void() GrenadeTouch =
  538. {
  539.     if (other == self.owner)
  540.         return;         // don't explode on owner
  541.     if (other.takedamage == DAMAGE_AIM)
  542.     {
  543.         GrenadeExplode();
  544.         return;
  545.     }
  546.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  547.     if (self.velocity == '0 0 0')
  548.         self.avelocity = '0 0 0';
  549. };
  550.  
  551. /*
  552. ================
  553. W_FireGrenade
  554. ================
  555. */
  556. void() W_FireGrenade =
  557. {
  558.     local   entity missile, mpuff;
  559.     
  560.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  561.     
  562.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  563.  
  564.     self.punchangle_x = -2;
  565.  
  566.     missile = spawn ();
  567.     missile.owner = self;
  568.     missile.movetype = MOVETYPE_BOUNCE;
  569.     missile.solid = SOLID_BBOX;
  570.     missile.classname = "grenade";
  571.         
  572. // set missile speed    
  573.  
  574.     makevectors (self.v_angle);
  575.  
  576.     if (self.v_angle_x)
  577.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  578.     else
  579.     {
  580.         missile.velocity = aim(self, 10000);
  581.         missile.velocity = missile.velocity * 600;
  582.         missile.velocity_z = 200;
  583.     }
  584.  
  585.     missile.avelocity = '300 300 300';
  586.  
  587.     missile.angles = vectoangles(missile.velocity);
  588.     
  589.     missile.touch = GrenadeTouch;
  590.     
  591. // set missile duration
  592.     missile.nextthink = time + 2.5;
  593.         missile.think = GrenadeExplode;
  594.     setmodel (missile, "progs/grenade.mdl");
  595.     setsize (missile, '0 0 0', '0 0 0');            
  596.     setorigin (missile, self.origin);
  597. };
  598. /*
  599. ================
  600. Tracer Rounds
  601. ================
  602. */
  603. void() Tracer_Touch =
  604. {
  605.     local vector org;
  606.     
  607.     if (other.solid == SOLID_TRIGGER)
  608.         {
  609.                 return;
  610.         }        
  611.         if (pointcontents(self.origin) == CONTENT_SKY)
  612.     {
  613.         remove(self);
  614.         return;
  615.     }
  616.     if (other.takedamage)
  617.     {
  618.                 spawn_touchblood (5);
  619.                 T_Damage (other, self, self.owner, 5);
  620.                 remove(self);
  621.                 return;
  622.     }
  623.         else
  624.         {
  625.                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  626.                 WriteByte (MSG_BROADCAST, TE_SPIKE);
  627.                 WriteCoord (MSG_BROADCAST, org_x);
  628.                 WriteCoord (MSG_BROADCAST, org_y);
  629.                 WriteCoord (MSG_BROADCAST, org_z);
  630.         }
  631.         self.velocity = '0 0 0';
  632.  
  633. };
  634.  
  635. void(vector org, vector vec) LaunchTracer =
  636. {
  637.     local    vector    vec;
  638.         
  639.     vec = normalize(vec);
  640.     
  641.     newmis = spawn();
  642.     newmis.owner = self;
  643.     newmis.movetype = MOVETYPE_FLY;
  644.     newmis.solid = SOLID_BBOX;
  645.     newmis.effects = EF_DIMLIGHT;
  646.  
  647.     setmodel (newmis, "progs/laser.mdl");
  648.     setsize (newmis, '0 0 0', '0 0 0');        
  649.  
  650.     setorigin (newmis, org);
  651.  
  652.     newmis.velocity = vec * 600;
  653.     newmis.angles = vectoangles(newmis.velocity);
  654.  
  655.         newmis.nextthink = time + 5;
  656.     newmis.think = SUB_Remove;
  657.         newmis.touch = Tracer_Touch;
  658. };
  659.  
  660. void(vector org, vector vec) tracer_fire =
  661. {
  662.     self.effects = self.effects | EF_MUZZLEFLASH;
  663.     makevectors (self.angles);
  664.     
  665.         LaunchTracer(org, vec);
  666. };
  667.  
  668. //=============================================================================
  669.  
  670. void() spike_touch;
  671. void() superspike_touch;
  672.  
  673.  
  674. /*
  675. ===============
  676. launch_spike
  677.  
  678. Used for both the player and the ogre
  679. ===============
  680. */
  681. void(vector org, vector dir) launch_spike =
  682. {
  683.     newmis = spawn ();
  684.     newmis.owner = self;
  685.     newmis.movetype = MOVETYPE_FLYMISSILE;
  686.     newmis.solid = SOLID_BBOX;
  687.  
  688.     newmis.angles = vectoangles(dir);
  689.     
  690.     newmis.touch = spike_touch;
  691.     newmis.classname = "spike";
  692.     newmis.think = SUB_Remove;
  693.         newmis.nextthink = time + 6;
  694.     setmodel (newmis, "progs/spike.mdl");
  695.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  696.     setorigin (newmis, org);
  697.  
  698.     newmis.velocity = dir * 1000;
  699. };
  700. void() W_FireAutoShot =
  701. {
  702.     local vector    dir;
  703.     local entity    old;
  704.     
  705.     self.attack_finished = time + 0.2;
  706.         sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);
  707.         dir = aim (self, 100000);
  708.         self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  709.         self.punchangle_x = -2;
  710.     FireBullets (6, dir, '0.04 0.04 0');
  711. };
  712.  
  713. void() W_FireSuperSpikes =
  714. {
  715.     local vector    dir;
  716.     local entity    old;
  717.     
  718.     self.attack_finished = time + 0.2;
  719.         sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  720.     dir = aim (self, 1000);
  721.         if (tracer == 0)
  722.         {
  723.                 tracer = 3;
  724.                 self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  725.                 tracer_fire (self.origin + '0 0 16', dir);
  726.                 self.punchangle_x = -2;
  727.                 return;
  728.         }
  729.         else
  730.         {
  731.                 tracer = tracer - 1;
  732.                 self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  733.                 launch_spike (self.origin + '0 0 16', dir);
  734.                 newmis.touch = superspike_touch;
  735.                 setmodel (newmis, "progs/s_spike.mdl");
  736.                 setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  737.                 self.punchangle_x = -2;
  738.                 return;
  739.         }
  740. };
  741.  
  742. void(float ox) W_FireSpikes =
  743. {
  744.     local vector    dir;
  745.     local entity    old;
  746.     
  747.     makevectors (self.v_angle);
  748.     
  749.         if (self.ammo_shells >= 2 && self.weapon == IT_SUPER_NAILGUN && ashot == 1)
  750.         {
  751.                 W_FireAutoShot ();
  752.                 return;
  753.         }
  754.  
  755.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  756.     {
  757.         W_FireSuperSpikes ();
  758.         return;
  759.     }
  760.  
  761.     if (self.ammo_nails < 1)
  762.     {
  763.         self.weapon = W_BestWeapon ();
  764.         W_SetCurrentAmmo ();
  765.         return;
  766.     }
  767.  
  768.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  769.     self.attack_finished = time + 0.2;
  770.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  771.     dir = aim (self, 1000);
  772.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  773.  
  774.     self.punchangle_x = -2;
  775. };
  776.  
  777.  
  778.  
  779. .float hit_z;
  780. void() spike_touch =
  781. {
  782. local float rand;
  783.     if (other == self.owner)
  784.         return;
  785.  
  786.     if (other.solid == SOLID_TRIGGER)
  787.         return; // trigger field, do nothing
  788.  
  789.     if (pointcontents(self.origin) == CONTENT_SKY)
  790.     {
  791.         remove(self);
  792.         return;
  793.     }
  794.     
  795. // hit something that bleeds
  796.     if (other.takedamage)
  797.     {
  798.         spawn_touchblood (9);
  799.         T_Damage (other, self, self.owner, 9);
  800.         remove(self);
  801.     }
  802.     else
  803.     {
  804.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  805.         
  806.         if (self.classname == "wizspike")
  807.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  808.         else if (self.classname == "knightspike")
  809.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  810.         else
  811.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  812.         WriteCoord (MSG_BROADCAST, self.origin_x);
  813.         WriteCoord (MSG_BROADCAST, self.origin_y);
  814.         WriteCoord (MSG_BROADCAST, self.origin_z);
  815.     }
  816.     self.velocity='0 0 0'; // make the nail stop!
  817.         remove(self);
  818.  
  819. };
  820.  
  821. void() superspike_touch =
  822. {
  823. local float rand;
  824.     if (other == self.owner)
  825.         return;
  826.  
  827.     if (other.solid == SOLID_TRIGGER)
  828.         return; // trigger field, do nothing
  829.  
  830.     if (pointcontents(self.origin) == CONTENT_SKY)
  831.     {
  832.         remove(self);
  833.         return;
  834.     }
  835.     
  836. // hit something that bleeds
  837.     if (other.takedamage)
  838.     {
  839.         spawn_touchblood (18);
  840.         T_Damage (other, self, self.owner, 18);
  841.     }
  842.     else
  843.     {
  844.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  845.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  846.         WriteCoord (MSG_BROADCAST, self.origin_x);
  847.         WriteCoord (MSG_BROADCAST, self.origin_y);
  848.         WriteCoord (MSG_BROADCAST, self.origin_z);
  849.     }
  850.  
  851.     remove(self);
  852.  
  853. };
  854.  
  855. /*========================================================================
  856. BOUNCING FRAGMENTATION GRENADE - Version .9
  857. 7/28/96 - Steve Bond  email:wedge@nuc.net
  858. http://www.nuc.net/quake
  859. moded by Punisher
  860. =======================================================================*/
  861.  
  862. void() shrapnel_touch =
  863. {
  864. local float rand;
  865.     if (other.solid == SOLID_TRIGGER)
  866.         return; // trigger field, do nothing
  867.  
  868.     if (pointcontents(self.origin) == CONTENT_SKY)
  869.     {
  870.         remove(self);
  871.         return;
  872.     }
  873.     
  874.     if (other.takedamage)
  875.     {
  876.         spawn_touchblood (33);
  877.         T_Damage (other, self, self.owner, 33);
  878.     }
  879.     else
  880.     {
  881.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  882.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  883.         WriteCoord (MSG_BROADCAST, self.origin_x);
  884.         WriteCoord (MSG_BROADCAST, self.origin_y);
  885.         WriteCoord (MSG_BROADCAST, self.origin_z);
  886.     }
  887.     remove(self);
  888. };
  889.  
  890. void (vector org, float spin) launch_shrapnel=
  891. {
  892.     local float xdir,ydir,zdir;
  893.     
  894.     xdir = 110 * random() - 55;
  895.     ydir = 110 * random() - 55;
  896.     zdir = 50 * random() - 25;
  897.  
  898.     newmis = spawn ();
  899.     newmis.owner = self;
  900.     newmis.movetype = MOVETYPE_BOUNCE;
  901.     self.touch = SUB_Null;
  902.     newmis.solid = SOLID_BBOX;
  903.  
  904.     newmis.touch = shrapnel_touch;
  905.     newmis.classname = "spike";
  906.     newmis.think = SUB_Remove;
  907.     
  908.     newmis.nextthink = time + 6;
  909.     
  910.     newmis.velocity_x = xdir * 5;
  911.     newmis.velocity_y = ydir * 5;
  912.     newmis.velocity_z = zdir * 4;
  913.  
  914.     if (spin == 0)
  915.     newmis.avelocity='250 300 400';
  916.     if (spin == 1)
  917.     newmis.avelocity='400 250 300';
  918.     if (spin == 2)
  919.     newmis.avelocity='300 400 250';
  920.     if (spin == 3)
  921.     newmis.avelocity='300 300 300';
  922.     if (spin == 4) 
  923.     newmis.avelocity='400 250 400';
  924.  
  925.     setmodel (newmis, "progs/s_spike.mdl");
  926.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  927.     setorigin (newmis, org);
  928. };
  929.  
  930. void()  BouncerExplode =
  931. {
  932.     T_RadiusDamage (self, self.owner, 120, world);
  933.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  934.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  935.     WriteCoord (MSG_BROADCAST, self.origin_x);
  936.     WriteCoord (MSG_BROADCAST, self.origin_y);
  937.     WriteCoord (MSG_BROADCAST, self.origin_z);
  938.  
  939.     self.solid=SOLID_NOT;
  940.     BecomeExplosion ();
  941.  
  942.     launch_shrapnel (self.origin + '0 0 -1',0);
  943.     launch_shrapnel (self.origin + '0 0 -1',1);
  944.     launch_shrapnel (self.origin + '0 0 -1',2);
  945.     launch_shrapnel (self.origin + '0 0 -1',3);
  946.     launch_shrapnel (self.origin + '0 0 -1',4);
  947.     launch_shrapnel (self.origin + '0 0 -1',0);
  948.     launch_shrapnel (self.origin + '0 0 -1',1);
  949.     launch_shrapnel (self.origin + '0 0 -1',2);
  950.     launch_shrapnel (self.origin + '0 0 -1',3);
  951.     launch_shrapnel (self.origin + '0 0 -1',4);
  952.     launch_shrapnel (self.origin + '0 0 -1',0);
  953.     launch_shrapnel (self.origin + '0 0 -1',1);
  954.     launch_shrapnel (self.origin + '0 0 -1',2);
  955.     launch_shrapnel (self.origin + '0 0 -1',3);
  956.     launch_shrapnel (self.origin + '0 0 -1',4);
  957.     launch_shrapnel (self.origin + '0 0 -1',0);
  958.     launch_shrapnel (self.origin + '0 0 -1',1);
  959.     launch_shrapnel (self.origin + '0 0 -1',2);
  960.     launch_shrapnel (self.origin + '0 0 -1',3);
  961.     launch_shrapnel (self.origin + '0 0 -1',4);
  962. };
  963.  
  964. void() BouncerPopUp=
  965. {
  966.     local entity missile, mpuff;
  967.  
  968.     self.movetype=MOVETYPE_NONE;
  969.     self.velocity='0 0 0';
  970.     setmodel (self, "progs/s_explod.spr");
  971.     s_explode1 ();
  972.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  973.     missile = spawn ();
  974.     missile.owner = self;
  975.     missile.movetype = MOVETYPE_BOUNCE;
  976.     missile.solid = SOLID_BBOX;
  977.     missile.classname = "grenade";
  978.     missile.velocity = '0 0 650';
  979.     missile.angles = vectoangles(missile.velocity);
  980.     missile.touch = BouncerExplode;
  981.     missile.nextthink = time + 1;
  982.     missile.think = BouncerExplode;
  983.  
  984.     setmodel (missile, "progs/missile.mdl");
  985.     setsize (missile, '0 0 0', '0 0 0');
  986.     setorigin (missile, self.origin);
  987. };
  988.  
  989.  
  990. void() BouncerTouch =
  991. {
  992.     if (other.takedamage)
  993.     {
  994.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);
  995.     return;
  996.     }
  997.  
  998.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);
  999.     if (self.velocity == '0 0 0')
  1000.         self.avelocity = '0 0 0';
  1001. };
  1002.  
  1003. void() W_LaunchBouncer =
  1004. {
  1005.     if (self.ammo_rockets < 3)
  1006.     {
  1007.     return;
  1008.     }
  1009.  
  1010.     local   entity missile, mpuff;
  1011.     
  1012.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 3;
  1013.     
  1014.     self.punchangle_x = -2;
  1015.  
  1016.     missile = spawn ();
  1017.     missile.owner = self;
  1018.     missile.movetype = MOVETYPE_BOUNCE;
  1019.     missile.solid = SOLID_BBOX;
  1020.     missile.classname = "grenade";
  1021.         
  1022.  
  1023.     makevectors (self.v_angle);
  1024.  
  1025.     if (self.v_angle_x)
  1026.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  1027.     else
  1028.     {
  1029.         missile.velocity = aim(self, 10000);
  1030.         missile.velocity = missile.velocity * 600;
  1031.         missile.velocity_z = 200;
  1032.     }
  1033.  
  1034.     missile.avelocity = '300 300 300';
  1035.  
  1036.     missile.angles = vectoangles(missile.velocity);
  1037.     
  1038.     missile.touch = BouncerTouch;
  1039.     
  1040.     missile.nextthink = time + 1.5;
  1041.     
  1042.     missile.think = BouncerPopUp;
  1043.  
  1044.     setmodel (missile, "progs/grenade.mdl");
  1045.     setsize (missile, '0 0 0', '0 0 0');            
  1046.     setorigin (missile, self.origin);
  1047. };
  1048. /*
  1049. ===============================================================================
  1050. End of Bouncing Fragmentation Grenade code.
  1051. ===============================================================================
  1052. */
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059. /*
  1060. ========================================================================
  1061. SplitMissile v1.0
  1062. by Punisher
  1063. =======================================================================
  1064. */
  1065.  
  1066. void() T_MissTouch =
  1067. {
  1068.     local float     damg;
  1069.  
  1070.     if (pointcontents(self.origin) == CONTENT_SKY)
  1071.     {
  1072.         remove(self);
  1073.         return;
  1074.     }
  1075.  
  1076.         damg = 20 + random() * 20;
  1077.     
  1078.     if (other.health)
  1079.     {
  1080.         if (other.classname == "monster_shambler")
  1081.             damg = damg * 0.5;      // mostly immune
  1082.         T_Damage (other, self, self.owner, damg );
  1083.     }
  1084.  
  1085.         T_RadiusDamage (self, self.owner, 60, other);
  1086.  
  1087.     self.origin = self.origin - 8*normalize(self.velocity);
  1088.  
  1089.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1090.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1091.     WriteCoord (MSG_BROADCAST, self.origin_x);
  1092.     WriteCoord (MSG_BROADCAST, self.origin_y);
  1093.     WriteCoord (MSG_BROADCAST, self.origin_z);
  1094.  
  1095.         BecomeExplosion ();
  1096. };
  1097.  
  1098. void (vector org) LaunchMis2=
  1099. {
  1100.         local float xdir,ydir,zdir;
  1101.  
  1102.         sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  1103.  
  1104.  
  1105.         xdir = 110 * random() - 55;
  1106.         ydir = 110 * random() - 55;
  1107.         zdir = 110 * random() - 55;
  1108.         newmis = spawn ();
  1109.         newmis.owner = self;
  1110.         newmis.movetype = MOVETYPE_FLYMISSILE;
  1111.         newmis.solid = SOLID_BBOX;
  1112.         newmis.touch = T_MissTouch;
  1113.         newmis.think = SUB_Remove;
  1114.         newmis.nextthink = time + 6;
  1115.         newmis.velocity_x = xdir * 6;
  1116.         newmis.velocity_y = ydir * 6;
  1117.         newmis.velocity_z = zdir * 6;
  1118.         newmis.angles = vectoangles(newmis.velocity);
  1119.  
  1120.         setmodel (newmis, "progs/missile.mdl");
  1121.         setsize (newmis, '0 0 0', '0 0 0');
  1122.     setorigin (newmis, org);
  1123. };
  1124.  
  1125. void()  SplitMissile =
  1126. {    
  1127.         T_RadiusDamage (self, self.owner, 20, world);
  1128.  
  1129.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1130.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1131.     WriteCoord (MSG_BROADCAST, self.origin_x);
  1132.     WriteCoord (MSG_BROADCAST, self.origin_y);
  1133.     WriteCoord (MSG_BROADCAST, self.origin_z);
  1134.  
  1135.     self.solid=SOLID_NOT;
  1136.         BecomeExplosion ();
  1137.  
  1138.         LaunchMis2 (self.origin);
  1139.         LaunchMis2 (self.origin);
  1140.         LaunchMis2 (self.origin);
  1141.         LaunchMis2 (self.origin);
  1142.         LaunchMis2 (self.origin);
  1143. };
  1144.  
  1145. void() W_LaunchSplitter =
  1146. {
  1147.         if (self.ammo_rockets >= 4)
  1148.         {
  1149.                 break;
  1150.         }
  1151.         local   entity missile, mpuff;
  1152.  
  1153.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 5;
  1154.     self.punchangle_x = -2;
  1155.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  1156.  
  1157.     missile = spawn ();
  1158.     missile.owner = self;
  1159.         missile.movetype = MOVETYPE_FLYMISSILE;
  1160.     missile.solid = SOLID_BBOX;
  1161.         missile.classname = "missile";
  1162.         makevectors (self.v_angle);
  1163.         missile.velocity = aim(self, 10000);
  1164.         missile.velocity = missile.velocity * 1000;
  1165.     missile.angles = vectoangles(missile.velocity);
  1166.         missile.touch = T_MissileTouch;
  1167.         missile.nextthink = time + 0.5;
  1168.         missile.think = SplitMissile;
  1169.         setmodel (missile, "progs/missile.mdl");
  1170.     setsize (missile, '0 0 0', '0 0 0');            
  1171.         setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  1172. };
  1173. /*
  1174. ===============================================================================
  1175. End of SplitMissile code.
  1176. ===============================================================================
  1177. */
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184. /*
  1185.  
  1186. PLAYER WEAPON USE
  1187.  
  1188. ===============================================================================
  1189. */
  1190.  
  1191. void() W_SetCurrentAmmo =
  1192. {
  1193.     player_run ();          // get out of any weapon firing states
  1194.  
  1195.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  1196.     
  1197.     if (self.weapon == IT_AXE)
  1198.     {
  1199.         self.currentammo = 0;
  1200.         self.weaponmodel = "progs/v_axe.mdl";
  1201.         self.weaponframe = 0;
  1202.     }
  1203.     else if (self.weapon == IT_SHOTGUN)
  1204.     {
  1205.         self.currentammo = self.ammo_shells;
  1206.         self.weaponmodel = "progs/v_shot.mdl";
  1207.         self.weaponframe = 0;
  1208.         self.items = self.items | IT_SHELLS;
  1209.     }
  1210.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1211.     {
  1212.         self.currentammo = self.ammo_shells;
  1213.         self.weaponmodel = "progs/v_shot2.mdl";
  1214.         self.weaponframe = 0;
  1215.         self.items = self.items | IT_SHELLS;
  1216.     }
  1217.     else if (self.weapon == IT_NAILGUN)
  1218.     {
  1219.         self.currentammo = self.ammo_nails;
  1220.         self.weaponmodel = "progs/v_nail.mdl";
  1221.         self.weaponframe = 0;
  1222.         self.items = self.items | IT_NAILS;
  1223.     }
  1224.         else if (self.weapon == IT_SUPER_NAILGUN && ashot == 0)
  1225.     {
  1226.         self.currentammo = self.ammo_nails;
  1227.         self.weaponmodel = "progs/v_nail2.mdl";
  1228.         self.weaponframe = 0;
  1229.         self.items = self.items | IT_NAILS;
  1230.     }
  1231.         else if (self.weapon == IT_SUPER_NAILGUN && ashot == 1)
  1232.         {
  1233.                 self.currentammo = self.ammo_shells;
  1234.                 self.weaponmodel = "progs/v_nail2.mdl";
  1235.                 self.weaponframe = 0;
  1236.                 self.items = self.items | IT_SHELLS;
  1237.         }
  1238.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1239.     {
  1240.         self.currentammo = self.ammo_rockets;
  1241.         self.weaponmodel = "progs/v_rock.mdl";
  1242.         self.weaponframe = 0;
  1243.         self.items = self.items | IT_ROCKETS;
  1244.     }
  1245.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1246.     {
  1247.         self.currentammo = self.ammo_rockets;
  1248.         self.weaponmodel = "progs/v_rock2.mdl";
  1249.         self.weaponframe = 0;
  1250.         self.items = self.items | IT_ROCKETS;
  1251.     }
  1252.     else if (self.weapon == IT_LIGHTNING)
  1253.     {
  1254.         self.currentammo = self.ammo_cells;
  1255.         self.weaponmodel = "progs/v_light.mdl";
  1256.         self.weaponframe = 0;
  1257.         self.items = self.items | IT_CELLS;
  1258.     }
  1259.     else
  1260.     {
  1261.         self.currentammo = 0;
  1262.         self.weaponmodel = "";
  1263.         self.weaponframe = 0;
  1264.     }
  1265. };
  1266.  
  1267. float() W_BestWeapon =
  1268. {
  1269.     local   float   it;
  1270.     
  1271.     it = self.items;
  1272.  
  1273.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  1274.         return IT_LIGHTNING;
  1275.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1276.         return IT_SUPER_NAILGUN;
  1277.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  1278.         return IT_SUPER_SHOTGUN;
  1279.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1280.         return IT_NAILGUN;
  1281.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1282.         return IT_SHOTGUN;      
  1283.         else if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  1284.         return IT_ROCKET_LAUNCHER;
  1285.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  1286.         return IT_GRENADE_LAUNCHER;
  1287.  
  1288.  
  1289.     return IT_AXE;
  1290. };
  1291.  
  1292. float() W_CheckNoAmmo =
  1293. {
  1294.     if (self.currentammo > 0)
  1295.         return TRUE;
  1296.  
  1297.     if (self.weapon == IT_AXE)
  1298.         return TRUE;
  1299.     
  1300.     self.weapon = W_BestWeapon ();
  1301.  
  1302.     W_SetCurrentAmmo ();
  1303.     
  1304. // drop the weapon down
  1305.     return FALSE;
  1306. };
  1307.  
  1308. /*
  1309. ============
  1310. W_Attack
  1311.  
  1312. An attack impulse can be triggered now
  1313. ============
  1314. */
  1315. void()  player_axe1;
  1316. void()  player_axeb1;
  1317. void()  player_axec1;
  1318. void()  player_axed1;
  1319. void()  player_shot1;
  1320. void()  player_nail1;
  1321. void()  player_light1;
  1322. void()  player_rocket1;
  1323. void()  player_rocket2;
  1324.  
  1325. void() W_Attack =
  1326. {
  1327.     local   float   r;
  1328.  
  1329.     if (!W_CheckNoAmmo ())
  1330.         return;
  1331.  
  1332.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  1333.     self.show_hostile = time + 1;   // wake monsters up
  1334.  
  1335.     if (self.weapon == IT_AXE)
  1336.     {
  1337.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1338.         r = random();
  1339.         if (r < 0.25)
  1340.             player_axe1 ();
  1341.         else if (r<0.5)
  1342.             player_axeb1 ();
  1343.         else if (r<0.75)
  1344.             player_axec1 ();
  1345.         else
  1346.             player_axed1 ();
  1347.         self.attack_finished = time + 0.5;
  1348.     }
  1349.     else if (self.weapon == IT_SHOTGUN)
  1350.     {
  1351.         player_shot1 ();
  1352.         W_FireShotgun ();
  1353.         self.attack_finished = time + 0.5;
  1354.     }
  1355.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1356.     {
  1357.         player_shot1 ();
  1358.         W_FireSuperShotgun ();
  1359.         self.attack_finished = time + 0.7;
  1360.     }
  1361.     else if (self.weapon == IT_NAILGUN)
  1362.     {
  1363.         player_nail1 ();
  1364.     }
  1365.     else if (self.weapon == IT_SUPER_NAILGUN)
  1366.     {
  1367.         player_nail1 ();
  1368.     }
  1369.         else if (self.weapon == IT_GRENADE_LAUNCHER && ngren == 0)
  1370.     {
  1371.         player_rocket1();
  1372.         W_FireGrenade();
  1373.         self.attack_finished = time + 0.6;
  1374.     }
  1375.         else if (self.weapon == IT_GRENADE_LAUNCHER && ngren == 1)
  1376.     {
  1377.         player_rocket1();
  1378.                 W_LaunchBouncer();
  1379.                 self.attack_finished = time + 0.9;
  1380.     }
  1381.  
  1382.         else if (self.weapon == IT_ROCKET_LAUNCHER && smis == 0)
  1383.     {
  1384.         player_rocket1();
  1385.         W_FireRocket();
  1386.         self.attack_finished = time + 0.8;
  1387.     }
  1388.         else if (self.weapon == IT_ROCKET_LAUNCHER && smis == 1)
  1389.     {
  1390.         player_rocket1();
  1391.                 W_LaunchSplitter();
  1392.                 self.attack_finished = time + 1.2;
  1393.     }
  1394.     else if (self.weapon == IT_LIGHTNING)
  1395.     {
  1396.         player_light1();
  1397.         self.attack_finished = time + 0.1;
  1398.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1399.     }
  1400. };
  1401.  
  1402. /*
  1403. ============
  1404. W_ChangeWeapon
  1405.  
  1406. ============
  1407. */
  1408. void() W_ChangeWeapon =
  1409. {
  1410.     local   float   it, am, fl;
  1411.     
  1412.     it = self.items;
  1413.     am = 0;
  1414.     
  1415.     if (self.impulse == 1)
  1416.     {
  1417.         fl = IT_AXE;
  1418.     }
  1419.     else if (self.impulse == 2)
  1420.     {
  1421.         fl = IT_SHOTGUN;
  1422.         if (self.ammo_shells < 1)
  1423.             am = 1;
  1424.     }
  1425.     else if (self.impulse == 3)
  1426.     {
  1427.         fl = IT_SUPER_SHOTGUN;
  1428.         if (self.ammo_shells < 2)
  1429.             am = 1;
  1430.     }               
  1431.     else if (self.impulse == 4)
  1432.     {
  1433.         fl = IT_NAILGUN;
  1434.         if (self.ammo_nails < 1)
  1435.             am = 1;
  1436.     }
  1437.         else if (self.impulse == 5 && ashot == 0)
  1438.     {
  1439.         fl = IT_SUPER_NAILGUN;
  1440.         if (self.ammo_nails < 2)
  1441.             am = 1;
  1442.     }
  1443.         else if (self.impulse == 5 && ashot == 1)
  1444.     {
  1445.         fl = IT_SUPER_NAILGUN;
  1446.                 if (self.ammo_shells < 2)
  1447.             am = 1;
  1448.     }
  1449.     else if (self.impulse == 6)
  1450.     {
  1451.         fl = IT_GRENADE_LAUNCHER;
  1452.         if (self.ammo_rockets < 1)
  1453.             am = 1;
  1454.     }
  1455.     else if (self.impulse == 7)
  1456.     {
  1457.         fl = IT_ROCKET_LAUNCHER;
  1458.         if (self.ammo_rockets < 1)
  1459.             am = 1;
  1460.     }
  1461.     else if (self.impulse == 8)
  1462.     {
  1463.         fl = IT_LIGHTNING;
  1464.         if (self.ammo_cells < 1)
  1465.             am = 1;
  1466.     }
  1467.     self.impulse = 0;
  1468.     
  1469.     if (!(self.items & fl))
  1470.     {       // don't have the weapon or the ammo
  1471.         sprint (self, "no weapon.\n");
  1472.         return;
  1473.     }
  1474.     
  1475.     if (am)
  1476.     {       // don't have the ammo
  1477.         sprint (self, "not enough ammo.\n");
  1478.         return;
  1479.     }
  1480.  
  1481. //
  1482. // set weapon, set ammo
  1483. //
  1484.     self.weapon = fl;               
  1485.     W_SetCurrentAmmo ();
  1486. };
  1487.  
  1488. /*
  1489. ============
  1490. CheatCommand
  1491. ============
  1492. */
  1493. void() CheatCommand =
  1494. {
  1495.     if (deathmatch || coop)
  1496.         return;
  1497.  
  1498.     self.ammo_rockets = 100;
  1499.     self.ammo_nails = 200;
  1500.     self.ammo_shells = 100;
  1501.     self.items = self.items | 
  1502.         IT_AXE |
  1503.         IT_SHOTGUN |
  1504.         IT_SUPER_SHOTGUN |
  1505.         IT_NAILGUN |
  1506.         IT_SUPER_NAILGUN |
  1507.         IT_GRENADE_LAUNCHER |
  1508.         IT_ROCKET_LAUNCHER |
  1509.                 IT_KEY1 | IT_KEY2;
  1510.                 
  1511.     self.ammo_cells = 200;
  1512.     self.items = self.items | IT_LIGHTNING;
  1513.  
  1514.         self.weapon = IT_ROCKET_LAUNCHER;
  1515.     self.impulse = 0;
  1516.     W_SetCurrentAmmo ();
  1517. };
  1518.  
  1519. /*
  1520. ============
  1521. CycleWeaponCommand
  1522.  
  1523. Go to the next weapon with ammo
  1524. ============
  1525. */
  1526. void() CycleWeaponCommand =
  1527. {
  1528.     local   float   it, am;
  1529.     
  1530.     it = self.items;
  1531.     self.impulse = 0;
  1532.     
  1533.     while (1)
  1534.     {
  1535.         am = 0;
  1536.  
  1537.         if (self.weapon == IT_LIGHTNING)
  1538.         {
  1539.             self.weapon = IT_AXE;
  1540.         }
  1541.         else if (self.weapon == IT_AXE)
  1542.         {
  1543.             self.weapon = IT_SHOTGUN;
  1544.             if (self.ammo_shells < 1)
  1545.                 am = 1;
  1546.         }
  1547.         else if (self.weapon == IT_SHOTGUN)
  1548.         {
  1549.             self.weapon = IT_SUPER_SHOTGUN;
  1550.             if (self.ammo_shells < 2)
  1551.                 am = 1;
  1552.         }               
  1553.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1554.         {
  1555.             self.weapon = IT_NAILGUN;
  1556.             if (self.ammo_nails < 1)
  1557.                 am = 1;
  1558.         }
  1559.         else if (self.weapon == IT_NAILGUN)
  1560.         {
  1561.             self.weapon = IT_SUPER_NAILGUN;
  1562.             if (self.ammo_nails < 2)
  1563.                 am = 1;
  1564.         }
  1565.         else if (self.weapon == IT_SUPER_NAILGUN)
  1566.         {
  1567.             self.weapon = IT_GRENADE_LAUNCHER;
  1568.             if (self.ammo_rockets < 1)
  1569.                 am = 1;
  1570.         }
  1571.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1572.         {
  1573.             self.weapon = IT_ROCKET_LAUNCHER;
  1574.             if (self.ammo_rockets < 1)
  1575.                 am = 1;
  1576.         }
  1577.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1578.         {
  1579.                         self.weapon = IT_LIGHTNING;
  1580.                         if (self.ammo_cells < 1)
  1581.                 am = 1;
  1582.         }
  1583.                 if ( (self.items & self.weapon) && am == 0)
  1584.         {
  1585.             W_SetCurrentAmmo ();
  1586.             return;
  1587.         }
  1588.     }
  1589.  
  1590. };
  1591. void() ChangeSplit =
  1592. {
  1593.         if (smis == 0)
  1594.         {
  1595.                 smis = 1;
  1596.                 sprint (self, "Split Missile Activated\n");
  1597.                 break;
  1598.         }
  1599.         else
  1600.         {
  1601.                 smis = 0;
  1602.                 sprint (self, "Split Missile Deactivated\n");
  1603.                 break;
  1604.         }
  1605. };
  1606. void() ChangeAuto =
  1607. {
  1608.         if (ashot == 0 && self.weapon == IT_SUPER_NAILGUN)
  1609.         {
  1610.                 ashot = 1;
  1611.                 self.currentammo = self.ammo_shells;
  1612.                 sprint (self, "Auto Shotgun Activated\n");
  1613.                 break;
  1614.         }
  1615.         else if (ashot == 1 && self.weapon == IT_SUPER_NAILGUN)
  1616.         {
  1617.                 ashot = 0;
  1618.                 self.currentammo = self.ammo_nails;
  1619.                 sprint (self, "Auto Shotgun Deactivated\n");
  1620.                 break;
  1621.         }
  1622.         else if (ashot == 0 && self.weapon != IT_SUPER_NAILGUN)
  1623.         {
  1624.                 ashot = 1;
  1625.                 sprint (self, "Auto Shotgun Activated\n");
  1626.                 break;
  1627.         }
  1628.         else if (ashot == 1 && self.weapon != IT_SUPER_NAILGUN)
  1629.         {
  1630.                 ashot = 0;
  1631.                 sprint (self, "Auto Shotgun Deactivated\n");
  1632.                 break;
  1633.         }
  1634. };
  1635. void() ChangeGren =
  1636. {
  1637.         if (ngren == 0)
  1638.         {
  1639.                 ngren = 1;
  1640.                 sprint (self, "Nail Grenade Activated\n");
  1641.                 break;
  1642.         }
  1643.         else
  1644.         {
  1645.                 ngren = 0;
  1646.                 sprint (self, "Nail Grenade Deactivated\n");
  1647.                 break;
  1648.         }
  1649. };
  1650.  
  1651. /*
  1652. ============
  1653. ServerflagsCommand
  1654.  
  1655. Just for development
  1656. ============
  1657. */
  1658. void() ServerflagsCommand =
  1659. {
  1660.     serverflags = serverflags * 2 + 1;
  1661. };
  1662.  
  1663. void() QuadCheat =
  1664. {
  1665.     if (deathmatch || coop)
  1666.         return;
  1667.     self.super_time = 1;
  1668.     self.super_damage_finished = time + 30;
  1669.     self.items = self.items | IT_QUAD;
  1670.     dprint ("quad cheat\n");
  1671. };
  1672.  
  1673. /*
  1674. ============
  1675. ImpulseCommands
  1676.  
  1677. ============
  1678. */
  1679. void() ImpulseCommands =
  1680. {
  1681.     if (self.impulse >= 1 && self.impulse <= 8)
  1682.         W_ChangeWeapon ();
  1683.     if (self.impulse == 9)
  1684.         CheatCommand ();
  1685.     if (self.impulse == 10)
  1686.         CycleWeaponCommand ();
  1687.     if (self.impulse == 11)
  1688.         ServerflagsCommand ();
  1689.         if (self.impulse == 12)
  1690.                 ChangeSplit ();
  1691.         if (self.impulse == 13)
  1692.                 ChangeAuto ();
  1693.         if (self.impulse == 14)
  1694.                 ChangeGren ();
  1695.     if (self.impulse == 255)
  1696.         QuadCheat ();
  1697.         
  1698.     self.impulse = 0;
  1699. };
  1700.  
  1701. /*
  1702. ============
  1703. W_WeaponFrame
  1704.  
  1705. Called every frame so impulse events can be handled as well as possible
  1706. ============
  1707. */
  1708. void() W_WeaponFrame =
  1709. {
  1710.     if (time < self.attack_finished)
  1711.         return;
  1712.  
  1713.     ImpulseCommands ();
  1714.     
  1715. // check for attack
  1716.     if (self.button0)
  1717.     {
  1718.         SuperDamageSound ();
  1719.         W_Attack ();
  1720.     }
  1721. };
  1722.  
  1723. /*
  1724. ========
  1725. SuperDamageSound
  1726.  
  1727. Plays sound if needed
  1728. ========
  1729. */
  1730. void() SuperDamageSound =
  1731. {
  1732.     if (self.super_damage_finished > time)
  1733.     {
  1734.         if (self.super_sound < time)
  1735.         {
  1736.             self.super_sound = time + 1;
  1737.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1738.         }
  1739.     }
  1740.     return;
  1741. };
  1742.  
  1743.