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