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