home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq115 / src / weapons.qc < prev    next >
Encoding:
Text File  |  1996-09-02  |  23.8 KB  |  1,215 lines

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