home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1997 June / CDW0697.iso / Quake / NIVELES / GRAP111.ZIP / WEAPONS.QC < prev    next >
Encoding:
Text File  |  1996-10-16  |  29.1 KB  |  1,367 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.  
  26. // Grapple:  Precache grapple sounds too!
  27.         precache_sound2 ("blob/land1.wav");     // chain go splorch!
  28.         precache_sound ("items/protect3.wav");  // Heheh... fix for cheats
  29.         precache_sound ("items/damage3.wav");   // This too
  30.         precache_sound ("weapons/chain1.wav");  // chain cranking out
  31.         precache_sound ("weapons/chain2.wav");  // chain cranking in
  32.         precache_sound ("weapons/chain3.wav");  // chain swaying in breeze
  33.         precache_sound ("weapons/gotcha.wav");  // a lame programmer trying
  34.                                                 //   to cop a 'tude
  35.         precache_sound ("weapons/thankyou.wav"); // Thank you for playing!
  36.                                                  //   See you in hell!
  37.         precache_sound ("weapons/bounce2.wav");  // chain release
  38.  
  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.     makevectors (self.v_angle);
  57.     source = self.origin + '0 0 16';
  58.     traceline (source, source + v_forward*64, FALSE, self);
  59.     if (trace_fraction == 1.0)
  60.         return;
  61.     
  62.     org = trace_endpos - v_forward*4;
  63.  
  64.     if (trace_ent.takedamage)
  65.     {
  66.         trace_ent.axhitme = 1;
  67.         SpawnBlood (org, '0 0 0', 20);
  68.         T_Damage (trace_ent, self, self, 20);
  69.     }
  70.     else
  71.     {    // hit wall
  72.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  73.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  74.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  75.         WriteCoord (MSG_BROADCAST, org_x);
  76.         WriteCoord (MSG_BROADCAST, org_y);
  77.         WriteCoord (MSG_BROADCAST, org_z);
  78.     }
  79. };
  80.  
  81.  
  82. //============================================================================
  83.  
  84.  
  85. vector() wall_velocity =
  86. {
  87.     local vector    vel;
  88.     
  89.     vel = normalize (self.velocity);
  90.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  91.     vel = vel + 2*trace_plane_normal;
  92.     vel = vel * 200;
  93.     
  94.     return vel;
  95. };
  96.  
  97.  
  98. /*
  99. ================
  100. SpawnMeatSpray
  101. ================
  102. */
  103. void(vector org, vector vel) SpawnMeatSpray =
  104. {
  105.     local    entity missile, mpuff;
  106.     local    vector    org;
  107.  
  108.     missile = spawn ();
  109.     missile.owner = self;
  110.     missile.movetype = MOVETYPE_BOUNCE;
  111.     missile.solid = SOLID_NOT;
  112.  
  113.     makevectors (self.angles);
  114.  
  115.     missile.velocity = vel;
  116.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  117.  
  118.     missile.avelocity = '3000 1000 2000';
  119.     
  120. // set missile duration
  121.     missile.nextthink = time + 1;
  122.     missile.think = SUB_Remove;
  123.  
  124.     setmodel (missile, "progs/zom_gib.mdl");
  125.     setsize (missile, '0 0 0', '0 0 0');        
  126.     setorigin (missile, org);
  127. };
  128.  
  129. /*
  130. ================
  131. SpawnBlood
  132. ================
  133. */
  134. void(vector org, vector vel, float damage) SpawnBlood =
  135. {
  136.     particle (org, vel*0.1, 73, damage*2);
  137. };
  138.  
  139. /*
  140. ================
  141. spawn_touchblood
  142. ================
  143. */
  144. void(float damage) spawn_touchblood =
  145. {
  146.     local vector    vel;
  147.  
  148.     vel = wall_velocity () * 0.2;
  149.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  150. };
  151.  
  152.  
  153. /*
  154. ================
  155. SpawnChunk
  156. ================
  157. */
  158. void(vector org, vector vel) SpawnChunk =
  159. {
  160.     particle (org, vel*0.02, 0, 10);
  161. };
  162.  
  163. /*
  164. ==============================================================================
  165.  
  166. MULTI-DAMAGE
  167.  
  168. Collects multiple small damages into a single damage
  169.  
  170. ==============================================================================
  171. */
  172.  
  173. entity    multi_ent;
  174. float    multi_damage;
  175.  
  176. void() ClearMultiDamage =
  177. {
  178.     multi_ent = world;
  179.     multi_damage = 0;
  180. };
  181.  
  182. void() ApplyMultiDamage =
  183. {
  184.     if (!multi_ent)
  185.         return;
  186.     T_Damage (multi_ent, self, self, multi_damage);
  187. };
  188.  
  189. void(entity hit, float damage) AddMultiDamage =
  190. {
  191.     if (!hit)
  192.         return;
  193.     
  194.     if (hit != multi_ent)
  195.     {
  196.         ApplyMultiDamage ();
  197.         multi_damage = damage;
  198.         multi_ent = hit;
  199.     }
  200.     else
  201.         multi_damage = multi_damage + damage;
  202. };
  203.  
  204. /*
  205. ==============================================================================
  206.  
  207. BULLETS
  208.  
  209. ==============================================================================
  210. */
  211.  
  212. /*
  213. ================
  214. TraceAttack
  215. ================
  216. */
  217. void(float damage, vector dir) TraceAttack =
  218. {
  219.     local    vector    vel, org;
  220.     
  221.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  222.     vel = vel + 2*trace_plane_normal;
  223.     vel = vel * 200;
  224.  
  225.     org = trace_endpos - dir*4;
  226.  
  227.     if (trace_ent.takedamage)
  228.     {
  229.         SpawnBlood (org, vel*0.2, damage);
  230.         AddMultiDamage (trace_ent, damage);
  231.     }
  232.     else
  233.     {
  234.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  235.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  236.         WriteCoord (MSG_BROADCAST, org_x);
  237.         WriteCoord (MSG_BROADCAST, org_y);
  238.         WriteCoord (MSG_BROADCAST, org_z);
  239.     }
  240. };
  241.  
  242. /*
  243. ================
  244. FireBullets
  245.  
  246. Used by shotgun, super shotgun, and enemy soldier firing
  247. Go to the trouble of combining multiple pellets into a single damage call.
  248. ================
  249. */
  250. void(float shotcount, vector dir, vector spread) FireBullets =
  251. {
  252.     local    vector direction;
  253.     local    vector    src;
  254.     
  255.     makevectors(self.v_angle);
  256.  
  257.     src = self.origin + v_forward*10;
  258.     src_z = self.absmin_z + self.size_z * 0.7;
  259.  
  260.     ClearMultiDamage ();
  261.     while (shotcount > 0)
  262.     {
  263.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  264.  
  265.         traceline (src, src + direction*2048, FALSE, self);
  266.         if (trace_fraction != 1.0)
  267.             TraceAttack (4, direction);
  268.  
  269.         shotcount = shotcount - 1;
  270.     }
  271.     ApplyMultiDamage ();
  272. };
  273.  
  274. /*
  275. ================
  276. W_FireShotgun
  277. ================
  278. */
  279. void() W_FireShotgun =
  280. {
  281.     local vector dir;
  282.  
  283.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  284.  
  285.     self.punchangle_x = -2;
  286.     
  287.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  288.     dir = aim (self, 100000);
  289.     FireBullets (6, dir, '0.04 0.04 0');
  290. };
  291.  
  292.  
  293. /*
  294. ================
  295. W_FireSuperShotgun
  296. ================
  297. */
  298. void() W_FireSuperShotgun =
  299. {
  300.     local vector dir;
  301.  
  302.     if (self.currentammo == 1)
  303.     {
  304.         W_FireShotgun ();
  305.         return;
  306.     }
  307.         
  308.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  309.  
  310.     self.punchangle_x = -4;
  311.     
  312.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  313.     dir = aim (self, 100000);
  314.     FireBullets (14, dir, '0.14 0.08 0');
  315. };
  316.  
  317.  
  318. /*
  319. ==============================================================================
  320.  
  321. ROCKETS
  322.  
  323. ==============================================================================
  324. */
  325.  
  326. void()    s_explode1    =    [0,        s_explode2] {};
  327. void()    s_explode2    =    [1,        s_explode3] {};
  328. void()    s_explode3    =    [2,        s_explode4] {};
  329. void()    s_explode4    =    [3,        s_explode5] {};
  330. void()    s_explode5    =    [4,        s_explode6] {};
  331. void()    s_explode6    =    [5,        SUB_Remove] {};
  332.  
  333. void() BecomeExplosion =
  334. {
  335.     self.movetype = MOVETYPE_NONE;
  336.     self.velocity = '0 0 0';
  337.     self.touch = SUB_Null;
  338.     setmodel (self, "progs/s_explod.spr");
  339.     self.solid = SOLID_NOT;
  340.     s_explode1 ();
  341. };
  342.  
  343. void() T_MissileTouch =
  344. {
  345.     local float    damg;
  346.  
  347.     if (other == self.owner)
  348.         return;        // don't explode on owner
  349.  
  350.     if (pointcontents(self.origin) == CONTENT_SKY)
  351.     {
  352.         remove(self);
  353.         return;
  354.     }
  355.  
  356.     damg = 100 + random()*20;
  357.     
  358.     if (other.health)
  359.     {
  360.         if (other.classname == "monster_shambler")
  361.             damg = damg * 0.5;    // mostly immune
  362.         T_Damage (other, self, self.owner, damg );
  363.     }
  364.  
  365.     // don't do radius damage to the other, because all the damage
  366.     // was done in the impact
  367.     T_RadiusDamage (self, self.owner, 120, other);
  368.  
  369. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  370.     self.origin = self.origin - 8*normalize(self.velocity);
  371.  
  372.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  373.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  374.     WriteCoord (MSG_BROADCAST, self.origin_x);
  375.     WriteCoord (MSG_BROADCAST, self.origin_y);
  376.     WriteCoord (MSG_BROADCAST, self.origin_z);
  377.  
  378.     BecomeExplosion ();
  379. };
  380.  
  381.  
  382.  
  383. /*
  384. ================
  385. W_FireRocket
  386. ================
  387. */
  388. void() W_FireRocket =
  389. {
  390.     local    entity missile, mpuff;
  391.     
  392.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  393.     
  394.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  395.  
  396.     self.punchangle_x = -2;
  397.  
  398.     missile = spawn ();
  399.     missile.owner = self;
  400.     missile.movetype = MOVETYPE_FLYMISSILE;
  401.     missile.solid = SOLID_BBOX;
  402.     missile.classname = "missile";
  403.         
  404. // set missile speed    
  405.  
  406.     makevectors (self.v_angle);
  407.     missile.velocity = aim(self, 1000);
  408.     missile.velocity = missile.velocity * 1000;
  409.     missile.angles = vectoangles(missile.velocity);
  410.     
  411.     missile.touch = T_MissileTouch;
  412.     
  413. // set missile duration
  414.     missile.nextthink = time + 5;
  415.     missile.think = SUB_Remove;
  416.  
  417.     setmodel (missile, "progs/missile.mdl");
  418.     setsize (missile, '0 0 0', '0 0 0');        
  419.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  420. };
  421.  
  422. /*
  423. ===============================================================================
  424.  
  425. LIGHTNING
  426.  
  427. ===============================================================================
  428. */
  429.  
  430. /*
  431. =================
  432. LightningDamage
  433. =================
  434. */
  435. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  436. {
  437.     local entity        e1, e2;
  438.     local vector        f;
  439.     
  440.     f = p2 - p1;
  441.     normalize (f);
  442.     f_x = 0 - f_y;
  443.     f_y = f_x;
  444.     f_z = 0;
  445.     f = f*16;
  446.  
  447.     e1 = e2 = world;
  448.  
  449.     traceline (p1, p2, FALSE, self);
  450.     if (trace_ent.takedamage)
  451.     {
  452.         particle (trace_endpos, '0 0 100', 225, damage*4);
  453.         T_Damage (trace_ent, from, from, damage);
  454.         if (self.classname == "player")
  455.         {
  456.             if (other.classname == "player")
  457.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  458.         }
  459.     }
  460.     e1 = trace_ent;
  461.  
  462.     traceline (p1 + f, p2 + f, FALSE, self);
  463.     if (trace_ent != e1 && trace_ent.takedamage)
  464.     {
  465.         particle (trace_endpos, '0 0 100', 225, damage*4);
  466.         T_Damage (trace_ent, from, from, damage);
  467.     }
  468.     e2 = trace_ent;
  469.  
  470.     traceline (p1 - f, p2 - f, FALSE, self);
  471.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  472.     {
  473.         particle (trace_endpos, '0 0 100', 225, damage*4);
  474.         T_Damage (trace_ent, from, from, damage);
  475.     }
  476. };
  477.  
  478.  
  479. void() W_FireLightning =
  480. {
  481.     local    vector        org;
  482.     local    float        cells;
  483.  
  484.     if (self.ammo_cells < 1)
  485.     {
  486.         self.weapon = W_BestWeapon ();
  487.         W_SetCurrentAmmo ();
  488.         return;
  489.     }
  490.  
  491. // explode if under water
  492.     if (self.waterlevel > 1)
  493.     {
  494.         cells = self.ammo_cells;
  495.         self.ammo_cells = 0;
  496.         W_SetCurrentAmmo ();
  497.         T_RadiusDamage (self, self, 35*cells, world);
  498.         return;
  499.     }
  500.  
  501.     if (self.t_width < time)
  502.     {
  503.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  504.         self.t_width = time + 0.6;
  505.     }
  506.     self.punchangle_x = -2;
  507.  
  508.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  509.  
  510.     org = self.origin + '0 0 16';
  511.     
  512.     traceline (org, org + v_forward*600, TRUE, self);
  513.  
  514.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  515.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  516.     WriteEntity (MSG_BROADCAST, self);
  517.     WriteCoord (MSG_BROADCAST, org_x);
  518.     WriteCoord (MSG_BROADCAST, org_y);
  519.     WriteCoord (MSG_BROADCAST, org_z);
  520.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  521.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  522.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  523.  
  524.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  525. };
  526.  
  527.  
  528. //=============================================================================
  529.  
  530.  
  531. void() GrenadeExplode =
  532. {
  533.     T_RadiusDamage (self, self.owner, 120, world);
  534.  
  535.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  536.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  537.     WriteCoord (MSG_BROADCAST, self.origin_x);
  538.     WriteCoord (MSG_BROADCAST, self.origin_y);
  539.     WriteCoord (MSG_BROADCAST, self.origin_z);
  540.  
  541.     BecomeExplosion ();
  542. };
  543.  
  544. void() GrenadeTouch =
  545. {
  546.     if (other == self.owner)
  547.         return;        // don't explode on owner
  548.     if (other.takedamage == DAMAGE_AIM)
  549.     {
  550.         GrenadeExplode();
  551.         return;
  552.     }
  553.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  554.     if (self.velocity == '0 0 0')
  555.         self.avelocity = '0 0 0';
  556. };
  557.  
  558. /*
  559. ================
  560. W_FireGrenade
  561. ================
  562. */
  563. void() W_FireGrenade =
  564. {
  565.     local    entity missile, mpuff;
  566.     
  567.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  568.     
  569.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  570.  
  571.     self.punchangle_x = -2;
  572.  
  573.     missile = spawn ();
  574.     missile.owner = self;
  575.     missile.movetype = MOVETYPE_BOUNCE;
  576.     missile.solid = SOLID_BBOX;
  577.     missile.classname = "grenade";
  578.         
  579. // set missile speed    
  580.  
  581.     makevectors (self.v_angle);
  582.  
  583.     if (self.v_angle_x)
  584.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  585.     else
  586.     {
  587.         missile.velocity = aim(self, 10000);
  588.         missile.velocity = missile.velocity * 600;
  589.         missile.velocity_z = 200;
  590.     }
  591.  
  592.     missile.avelocity = '300 300 300';
  593.  
  594.     missile.angles = vectoangles(missile.velocity);
  595.     
  596.     missile.touch = GrenadeTouch;
  597.     
  598. // set missile duration
  599.     missile.nextthink = time + 2.5;
  600.     missile.think = GrenadeExplode;
  601.  
  602.     setmodel (missile, "progs/grenade.mdl");
  603.     setsize (missile, '0 0 0', '0 0 0');        
  604.     setorigin (missile, self.origin);
  605. };
  606.  
  607.  
  608. //=============================================================================
  609.  
  610. void() spike_touch;
  611. void() superspike_touch;
  612.  
  613.  
  614. /*
  615. ===============
  616. launch_spike
  617.  
  618. Used for both the player and the ogre
  619. ===============
  620. */
  621. void(vector org, vector dir) launch_spike =
  622. {
  623.     newmis = spawn ();
  624.     newmis.owner = self;
  625.     newmis.movetype = MOVETYPE_FLYMISSILE;
  626.     newmis.solid = SOLID_BBOX;
  627.  
  628.     newmis.angles = vectoangles(dir);
  629.     
  630.     newmis.touch = spike_touch;
  631.     newmis.classname = "spike";
  632.     newmis.think = SUB_Remove;
  633.     newmis.nextthink = time + 6;
  634.     setmodel (newmis, "progs/spike.mdl");
  635.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  636.     setorigin (newmis, org);
  637.  
  638.     newmis.velocity = dir * 1000;
  639. };
  640.  
  641. void() W_FireSuperSpikes =
  642. {
  643.     local vector    dir;
  644.     local entity    old;
  645.     
  646.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  647.     self.attack_finished = time + 0.2;
  648.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  649.     dir = aim (self, 1000);
  650.     launch_spike (self.origin + '0 0 16', dir);
  651.     newmis.touch = superspike_touch;
  652.     setmodel (newmis, "progs/s_spike.mdl");
  653.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  654.     self.punchangle_x = -2;
  655. };
  656.  
  657. void(float ox) W_FireSpikes =
  658. {
  659.     local vector    dir;
  660.     local entity    old;
  661.     
  662.     makevectors (self.v_angle);
  663.     
  664.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  665.     {
  666.         W_FireSuperSpikes ();
  667.         return;
  668.     }
  669.  
  670.     if (self.ammo_nails < 1)
  671.     {
  672.         self.weapon = W_BestWeapon ();
  673.         W_SetCurrentAmmo ();
  674.         return;
  675.     }
  676.  
  677.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  678.     self.attack_finished = time + 0.2;
  679.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  680.     dir = aim (self, 1000);
  681.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  682.  
  683.     self.punchangle_x = -2;
  684. };
  685.  
  686.  
  687.  
  688. .float hit_z;
  689. void() spike_touch =
  690. {
  691. local float rand;
  692.     if (other == self.owner)
  693.         return;
  694.  
  695.     if (other.solid == SOLID_TRIGGER)
  696.         return;    // trigger field, do nothing
  697.  
  698.     if (pointcontents(self.origin) == CONTENT_SKY)
  699.     {
  700.         remove(self);
  701.         return;
  702.     }
  703.     
  704. // hit something that bleeds
  705.     if (other.takedamage)
  706.     {
  707.         spawn_touchblood (9);
  708.         T_Damage (other, self, self.owner, 9);
  709.     }
  710.     else
  711.     {
  712.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  713.         
  714.         if (self.classname == "wizspike")
  715.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  716.         else if (self.classname == "knightspike")
  717.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  718.         else
  719.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  720.         WriteCoord (MSG_BROADCAST, self.origin_x);
  721.         WriteCoord (MSG_BROADCAST, self.origin_y);
  722.         WriteCoord (MSG_BROADCAST, self.origin_z);
  723.     }
  724.  
  725.     remove(self);
  726.  
  727. };
  728.  
  729. void() superspike_touch =
  730. {
  731. local float rand;
  732.     if (other == self.owner)
  733.         return;
  734.  
  735.     if (other.solid == SOLID_TRIGGER)
  736.         return;    // trigger field, do nothing
  737.  
  738.     if (pointcontents(self.origin) == CONTENT_SKY)
  739.     {
  740.         remove(self);
  741.         return;
  742.     }
  743.     
  744. // hit something that bleeds
  745.     if (other.takedamage)
  746.     {
  747.         spawn_touchblood (18);
  748.         T_Damage (other, self, self.owner, 18);
  749.     }
  750.     else
  751.     {
  752.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  753.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  754.         WriteCoord (MSG_BROADCAST, self.origin_x);
  755.         WriteCoord (MSG_BROADCAST, self.origin_y);
  756.         WriteCoord (MSG_BROADCAST, self.origin_z);
  757.     }
  758.  
  759.     remove(self);
  760.  
  761. };
  762.  
  763.  
  764. /*
  765. ===============================================================================
  766.  
  767. PLAYER WEAPON USE
  768.  
  769. ===============================================================================
  770. */
  771.  
  772. void() W_SetCurrentAmmo =
  773. {
  774.     player_run ();        // get out of any weapon firing states
  775.  
  776.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  777.     
  778.     if (self.weapon == IT_AXE)
  779.     {
  780.         self.currentammo = 0;
  781.         self.weaponmodel = "progs/v_axe.mdl";
  782.         self.weaponframe = 0;
  783.     }
  784. // Grapple:  Gotta fit this thing in somewhere...
  785.         else if (self.weapon == IT_MORNINGSTAR)
  786.         {
  787.                 self.currentammo = 0;
  788.                 self.weaponmodel = "progs/v_star.mdl";
  789.                 self.weaponframe = 0;
  790.         }
  791. //===============================================
  792.     else if (self.weapon == IT_SHOTGUN)
  793.     {
  794.         self.currentammo = self.ammo_shells;
  795.         self.weaponmodel = "progs/v_shot.mdl";
  796.         self.weaponframe = 0;
  797.         self.items = self.items | IT_SHELLS;
  798.     }
  799.     else if (self.weapon == IT_SUPER_SHOTGUN)
  800.     {
  801.         self.currentammo = self.ammo_shells;
  802.         self.weaponmodel = "progs/v_shot2.mdl";
  803.         self.weaponframe = 0;
  804.         self.items = self.items | IT_SHELLS;
  805.     }
  806.     else if (self.weapon == IT_NAILGUN)
  807.     {
  808.         self.currentammo = self.ammo_nails;
  809.         self.weaponmodel = "progs/v_nail.mdl";
  810.         self.weaponframe = 0;
  811.         self.items = self.items | IT_NAILS;
  812.     }
  813.     else if (self.weapon == IT_SUPER_NAILGUN)
  814.     {
  815.         self.currentammo = self.ammo_nails;
  816.         self.weaponmodel = "progs/v_nail2.mdl";
  817.         self.weaponframe = 0;
  818.         self.items = self.items | IT_NAILS;
  819.     }
  820.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  821.     {
  822.         self.currentammo = self.ammo_rockets;
  823.         self.weaponmodel = "progs/v_rock.mdl";
  824.         self.weaponframe = 0;
  825.         self.items = self.items | IT_ROCKETS;
  826.     }
  827.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  828.     {
  829.         self.currentammo = self.ammo_rockets;
  830.         self.weaponmodel = "progs/v_rock2.mdl";
  831.         self.weaponframe = 0;
  832.         self.items = self.items | IT_ROCKETS;
  833.     }
  834.     else if (self.weapon == IT_LIGHTNING)
  835.     {
  836.         self.currentammo = self.ammo_cells;
  837.         self.weaponmodel = "progs/v_light.mdl";
  838.         self.weaponframe = 0;
  839.         self.items = self.items | IT_CELLS;
  840.     }
  841.     else
  842.     {
  843.         self.currentammo = 0;
  844.         self.weaponmodel = "";
  845.         self.weaponframe = 0;
  846.     }
  847. };
  848.  
  849. float() W_BestWeapon =
  850. {
  851.     local    float    it;
  852.     it = self.items;
  853.  
  854.     if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  855.             return IT_LIGHTNING;
  856.     if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  857.         return IT_SUPER_NAILGUN;
  858.     if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  859.         return IT_SUPER_SHOTGUN;
  860.     if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  861.         return IT_NAILGUN;
  862.     if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  863.         return IT_SHOTGUN;
  864.         return IT_AXE;
  865. };
  866.  
  867. float() W_CheckNoAmmo =
  868. {
  869.     if (self.currentammo > 0)
  870.         return TRUE;
  871.  
  872. // Grapple:  No ammo for grapple, either.
  873.         if (self.weapon == IT_AXE || self.weapon == IT_MORNINGSTAR)
  874.         return TRUE;
  875.     
  876.     self.weapon = W_BestWeapon ();
  877.  
  878.     W_SetCurrentAmmo ();
  879.     
  880. // drop the weapon down
  881.     return FALSE;
  882. };
  883.  
  884. /*
  885. ============
  886. W_Attack
  887.  
  888. An attack impulse can be triggered now
  889. ============
  890. */
  891. void()    player_axe1;
  892. void()    player_axeb1;
  893. void()    player_axec1;
  894. void()    player_axed1;
  895. void()    player_shot1;
  896. void()    player_nail1;
  897. void()    player_light1;
  898. void()    player_rocket1;
  899.  
  900. // Grapple:  Declare chain functions, too!
  901.  
  902. void()    player_chain1;
  903. void()  player_chain3;
  904.  
  905. void() W_Attack =
  906. {
  907.     local    float    r;
  908.  
  909.     if (!W_CheckNoAmmo ())
  910.         return;
  911.  
  912.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  913.     self.show_hostile = time + 1;    // wake monsters up
  914.  
  915.     if (self.weapon == IT_AXE)
  916.     {
  917.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  918.         r = random();
  919.         if (r < 0.25)
  920.             player_axe1 ();
  921.         else if (r<0.5)
  922.             player_axeb1 ();
  923.         else if (r<0.75)
  924.             player_axec1 ();
  925.         else
  926.             player_axed1 ();
  927.         self.attack_finished = time + 0.5;
  928.     }
  929.     else if (self.weapon == IT_SHOTGUN)
  930.     {
  931.         player_shot1 ();
  932.         W_FireShotgun ();
  933.         self.attack_finished = time + 0.5;
  934.     }
  935.     else if (self.weapon == IT_SUPER_SHOTGUN)
  936.     {
  937.         player_shot1 ();
  938.         W_FireSuperShotgun ();
  939.         self.attack_finished = time + 0.7;
  940.     }
  941.     else if (self.weapon == IT_NAILGUN)
  942.     {
  943.         player_nail1 ();
  944.     }
  945.     else if (self.weapon == IT_SUPER_NAILGUN)
  946.     {
  947.         player_nail1 ();
  948.     }
  949.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  950.     {
  951.         player_rocket1();
  952.         W_FireGrenade();
  953.         self.attack_finished = time + 0.6;
  954.     }
  955.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  956.     {
  957.         player_rocket1();
  958.         W_FireRocket();
  959.         self.attack_finished = time + 0.8;
  960.     }
  961.     else if (self.weapon == IT_LIGHTNING)
  962.     {
  963.         player_light1();
  964.         self.attack_finished = time + 0.1;
  965.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  966.     }
  967. // Grapple:  Handle grapple attack.
  968.         else if (self.weapon == IT_MORNINGSTAR)
  969.         {
  970.                 if (!self.hook_out)
  971.                 {
  972.                      player_chain1();
  973.                 }
  974.                 else {player_chain3();}
  975.                 self.attack_finished = time + 0.5;
  976.         }
  977. //===============================================
  978. };
  979.  
  980. /*
  981. ============
  982. W_ChangeWeapon
  983.  
  984. ============
  985. */
  986. void() W_ChangeWeapon =
  987. {
  988.     local    float    it, am, fl;
  989.     
  990.     it = self.items;
  991.     am = 0;
  992.     
  993.     if (self.impulse == 1)
  994.     {
  995. // Grapple:  Allow llamas who don't know how to bind impulses to use the grapple.
  996.         if (self.weapon == IT_AXE) fl = IT_MORNINGSTAR;
  997.                 else fl = IT_AXE;
  998. //===============================================
  999.     }
  1000.     else if (self.impulse == 2)
  1001.     {
  1002.         fl = IT_SHOTGUN;
  1003.         if (self.ammo_shells < 1)
  1004.             am = 1;
  1005.     }
  1006.     else if (self.impulse == 3)
  1007.     {
  1008.         fl = IT_SUPER_SHOTGUN;
  1009.         if (self.ammo_shells < 2)
  1010.             am = 1;
  1011.     }        
  1012.     else if (self.impulse == 4)
  1013.     {
  1014.         fl = IT_NAILGUN;
  1015.         if (self.ammo_nails < 1)
  1016.             am = 1;
  1017.     }
  1018.     else if (self.impulse == 5)
  1019.     {
  1020.         fl = IT_SUPER_NAILGUN;
  1021.         if (self.ammo_nails < 2)
  1022.             am = 1;
  1023.     }
  1024.     else if (self.impulse == 6)
  1025.     {
  1026.         fl = IT_GRENADE_LAUNCHER;
  1027.         if (self.ammo_rockets < 1)
  1028.             am = 1;
  1029.     }
  1030.     else if (self.impulse == 7)
  1031.     {
  1032.         fl = IT_ROCKET_LAUNCHER;
  1033.         if (self.ammo_rockets < 1)
  1034.             am = 1;
  1035.     }
  1036.     else if (self.impulse == 8)
  1037.     {
  1038.         fl = IT_LIGHTNING;
  1039.         if (self.ammo_cells < 1)
  1040.             am = 1;
  1041.     }
  1042. // Grapple:  ... And an impulse for the Quakers.
  1043.         else if (self.impulse == 21)
  1044.                 fl = IT_MORNINGSTAR;
  1045. //===============================================
  1046.  
  1047.     self.impulse = 0;
  1048.     
  1049.     if (!(self.items & fl))
  1050.     {    // don't have the weapon or the ammo
  1051.         sprint (self, "no weapon.\n");
  1052.         return;
  1053.     }
  1054.     
  1055.     if (am)
  1056.     {    // don't have the ammo
  1057.         sprint (self, "not enough ammo.\n");
  1058.         return;
  1059.     }
  1060.  
  1061. //
  1062. // set weapon, set ammo
  1063. //
  1064.     self.weapon = fl;        
  1065.     W_SetCurrentAmmo ();
  1066. };
  1067.  
  1068. /*
  1069. ============
  1070. CheatCommand
  1071. ============
  1072. */
  1073. void() CheatCommand =
  1074. {
  1075.     if (deathmatch || coop)
  1076.         return;
  1077.  
  1078.     self.ammo_rockets = 100;
  1079.     self.ammo_nails = 200;
  1080.     self.ammo_shells = 100;
  1081.     self.items = self.items | 
  1082.         IT_AXE |
  1083.         IT_SHOTGUN |
  1084.         IT_SUPER_SHOTGUN |
  1085.         IT_NAILGUN |
  1086.         IT_SUPER_NAILGUN |
  1087.         IT_GRENADE_LAUNCHER |
  1088.         IT_ROCKET_LAUNCHER |
  1089.         IT_KEY1 | IT_KEY2;
  1090.  
  1091.     self.ammo_cells = 200;
  1092.     self.items = self.items | IT_LIGHTNING;
  1093.  
  1094.     self.weapon = IT_ROCKET_LAUNCHER;
  1095.     self.impulse = 0;
  1096.     W_SetCurrentAmmo ();
  1097. };
  1098.  
  1099. /*
  1100. ============
  1101. CycleWeaponCommand
  1102.  
  1103. Go to the next weapon with ammo
  1104. ============
  1105. */
  1106. void() CycleWeaponCommand =
  1107. {
  1108.     local    float    it, am;
  1109.     
  1110.     it = self.items;
  1111.     self.impulse = 0;
  1112.     
  1113.     while (1)
  1114.     {
  1115.         am = 0;
  1116.  
  1117.         if (self.weapon == IT_LIGHTNING)
  1118.         {
  1119.             self.weapon = IT_AXE;
  1120.         }
  1121.         else if (self.weapon == IT_AXE)
  1122. // Grapple:  Install the grappling hook in the switch command.
  1123.                 {
  1124.                         self.weapon = IT_MORNINGSTAR;
  1125.                 }
  1126.                 else if (self.weapon == IT_MORNINGSTAR)
  1127. //===============================================
  1128.         {
  1129.             self.weapon = IT_SHOTGUN;
  1130.             if (self.ammo_shells < 1)
  1131.                 am = 1;
  1132.         }
  1133.         else if (self.weapon == IT_SHOTGUN)
  1134.         {
  1135.             self.weapon = IT_SUPER_SHOTGUN;
  1136.             if (self.ammo_shells < 2)
  1137.                 am = 1;
  1138.         }        
  1139.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1140.         {
  1141.             self.weapon = IT_NAILGUN;
  1142.             if (self.ammo_nails < 1)
  1143.                 am = 1;
  1144.         }
  1145.         else if (self.weapon == IT_NAILGUN)
  1146.         {
  1147.             self.weapon = IT_SUPER_NAILGUN;
  1148.             if (self.ammo_nails < 2)
  1149.                 am = 1;
  1150.         }
  1151.         else if (self.weapon == IT_SUPER_NAILGUN)
  1152.         {
  1153.             self.weapon = IT_GRENADE_LAUNCHER;
  1154.             if (self.ammo_rockets < 1)
  1155.                 am = 1;
  1156.         }
  1157.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1158.         {
  1159.             self.weapon = IT_ROCKET_LAUNCHER;
  1160.             if (self.ammo_rockets < 1)
  1161.                 am = 1;
  1162.         }
  1163.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1164.         {
  1165.             self.weapon = IT_LIGHTNING;
  1166.             if (self.ammo_cells < 1)
  1167.                 am = 1;
  1168.         }
  1169.     
  1170.         if ( (it & self.weapon) && am == 0)
  1171.         {
  1172.             W_SetCurrentAmmo ();
  1173.             return;
  1174.         }
  1175.     }
  1176.  
  1177. };
  1178.  
  1179. /*
  1180. ============
  1181. CycleWeaponReverseCommand
  1182.  
  1183. Go to the prev weapon with ammo
  1184. ============
  1185. */
  1186. void() CycleWeaponReverseCommand =
  1187. {
  1188.     local    float    it, am;
  1189.     
  1190.     it = self.items;
  1191.     self.impulse = 0;
  1192.  
  1193.     while (1)
  1194.     {
  1195.         am = 0;
  1196.  
  1197.         if (self.weapon == IT_LIGHTNING)
  1198.         {
  1199.             self.weapon = IT_ROCKET_LAUNCHER;
  1200.             if (self.ammo_rockets < 1)
  1201.                 am = 1;
  1202.         }
  1203.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1204.         {
  1205.             self.weapon = IT_GRENADE_LAUNCHER;
  1206.             if (self.ammo_rockets < 1)
  1207.                 am = 1;
  1208.         }
  1209.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1210.         {
  1211.             self.weapon = IT_SUPER_NAILGUN;
  1212.             if (self.ammo_nails < 2)
  1213.                 am = 1;
  1214.         }
  1215.         else if (self.weapon == IT_SUPER_NAILGUN)
  1216.         {
  1217.             self.weapon = IT_NAILGUN;
  1218.             if (self.ammo_nails < 1)
  1219.                 am = 1;
  1220.         }
  1221.         else if (self.weapon == IT_NAILGUN)
  1222.         {
  1223.             self.weapon = IT_SUPER_SHOTGUN;
  1224.             if (self.ammo_shells < 2)
  1225.                 am = 1;
  1226.         }        
  1227.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1228.         {
  1229.             self.weapon = IT_SHOTGUN;
  1230.             if (self.ammo_shells < 1)
  1231.                 am = 1;
  1232.         }
  1233.         else if (self.weapon == IT_SHOTGUN)
  1234. // Grapple:  Here, too.
  1235.                 {
  1236.                         self.weapon = IT_MORNINGSTAR;
  1237.                 }
  1238.                 else if (self.weapon == IT_MORNINGSTAR)
  1239. //===============================================
  1240.         {
  1241.             self.weapon = IT_AXE;
  1242.         }
  1243.         else if (self.weapon == IT_AXE)
  1244.         {
  1245.             self.weapon = IT_LIGHTNING;
  1246.             if (self.ammo_cells < 1)
  1247.                 am = 1;
  1248.         }
  1249.     
  1250.         if ( (it & self.weapon) && am == 0)
  1251.         {
  1252.             W_SetCurrentAmmo ();
  1253.             return;
  1254.         }
  1255.     }
  1256.  
  1257. };
  1258.  
  1259. /*
  1260. ============
  1261. ServerflagsCommand
  1262.  
  1263. Just for development
  1264. ============
  1265. */
  1266. void() ServerflagsCommand =
  1267. {
  1268.     serverflags = serverflags * 2 + 1;
  1269. };
  1270.  
  1271. void() QuadCheat =
  1272. {
  1273. // Grapple:  I loved this cheat so much, I just had to improve it.  <grin>
  1274.     if (deathmatch || coop)
  1275.         return;
  1276.     self.super_time = 1;
  1277.         self.super_damage_finished = time + 9999999;
  1278.         self.rad_time = 1;
  1279.         self.radsuit_finished = time + 9999999;
  1280.         self.invincible_time = 1;
  1281.         self.invincible_finished = time + 9999999;
  1282.         self.items = self.items | IT_QUAD | IT_SUIT | 
  1283.                 IT_INVULNERABILITY;
  1284.         dprint ("mega cheat\n");
  1285. //===============================================
  1286. };
  1287.  
  1288. /*
  1289. ============
  1290. ImpulseCommands
  1291.  
  1292. ============
  1293. */
  1294. void() ImpulseCommands =
  1295. {
  1296.     if (self.impulse >= 1 && self.impulse <= 8)
  1297.         W_ChangeWeapon ();
  1298.  
  1299.     if (self.impulse == 9)
  1300.         CheatCommand ();
  1301.     if (self.impulse == 10)
  1302.         CycleWeaponCommand ();
  1303.     if (self.impulse == 11)
  1304.         ServerflagsCommand ();
  1305.     if (self.impulse == 12)
  1306.         CycleWeaponReverseCommand ();
  1307. // Grapple:  Switch to the hook on impulse
  1308.         if (self.impulse == 21)
  1309.                 W_ChangeWeapon();
  1310.         if (self.impulse == 112)
  1311.         {
  1312.                 sprint (self,"Program by Tatter_D!\n");
  1313.                 sound (self, CHAN_AUTO, "weapons/thankyou.wav", 1,
  1314.                         ATTN_STATIC);
  1315.         }
  1316. //===============================================
  1317.  
  1318.     if (self.impulse == 255)
  1319.         QuadCheat ();
  1320.         
  1321.     self.impulse = 0;
  1322. };
  1323.  
  1324. /*
  1325. ============
  1326. W_WeaponFrame
  1327.  
  1328. Called every frame so impulse events can be handled as well as possible
  1329. ============
  1330. */
  1331. void() W_WeaponFrame =
  1332. {
  1333.         if (time < self.attack_finished)
  1334.         return;
  1335.  
  1336.     ImpulseCommands ();
  1337.     
  1338. // check for attack
  1339.     if (self.button0)
  1340.     {
  1341.         SuperDamageSound ();
  1342.         W_Attack ();
  1343.     }
  1344. };
  1345.  
  1346. /*
  1347. ========
  1348. SuperDamageSound
  1349.  
  1350. Plays sound if needed
  1351. ========
  1352. */
  1353. void() SuperDamageSound =
  1354. {
  1355.     if (self.super_damage_finished > time)
  1356.     {
  1357.         if (self.super_sound < time)
  1358.         {
  1359.             self.super_sound = time + 1;
  1360.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1361.         }
  1362.     }
  1363.     return;
  1364. };
  1365.  
  1366.  
  1367.