home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq729 / weapons.qc < prev   
Encoding:
Text File  |  1996-07-27  |  25.4 KB  |  1,242 lines

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