home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / kick / weapons.qc < prev   
Encoding:
Text File  |  1991-08-20  |  25.0 KB  |  1,237 lines

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