home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / launchs / weapons.qc < prev   
Encoding:
Text File  |  1996-07-30  |  24.9 KB  |  1,240 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.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()    s_explode1    =    [0,        s_explode2] {};
  312. void()    s_explode2    =    [1,        s_explode3] {};
  313. void()    s_explode3    =    [2,        s_explode4] {};
  314. void()    s_explode4    =    [3,        s_explode5] {};
  315. void()    s_explode5    =    [4,        s_explode6] {};
  316. void()    s_explode6    =    [5,        SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330. local float    damg;
  331.  
  332.     if (other == self.owner)
  333.         return;        
  334.  
  335.     damg = 100 + random()*20;
  336.     T_Damage (other, self, self.owner, damg );
  337.     remove(self);
  338. /*    
  339.     
  340.     // don't explode on owner
  341.  
  342.     if (pointcontents(self.origin) == CONTENT_SKY)
  343.     {
  344.         remove(self);
  345.         return;
  346.     }
  347.     
  348.     
  349.     
  350.     if (other.health)
  351.     {
  352.         if (other.classname == "monster_shambler")
  353.             damg = damg * 0.5;    // mostly immune
  354.         
  355.     }
  356.  
  357.     // don't do radius damage to the other, because all the damage
  358.     // was done in the impact
  359.     //T_RadiusDamage (self, self.owner, 120, other);
  360.  
  361. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  362.     self.origin = self.origin - 8*normalize(self.velocity);
  363.  
  364.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  365.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  366.     WriteCoord (MSG_BROADCAST, self.origin_x);
  367.     WriteCoord (MSG_BROADCAST, self.origin_y);
  368.     WriteCoord (MSG_BROADCAST, self.origin_z);
  369.  
  370.     //BecomeExplosion ();
  371. */
  372. };
  373.  
  374.  
  375.  
  376. /*
  377. ================
  378. W_FireRocket
  379. ================
  380. */
  381. void() RichThink;
  382. void() W_FireRocket =
  383. {
  384.     local    entity missile, mpuff;
  385.     
  386.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  387.     
  388.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  389.  
  390.     self.punchangle_x = -2;
  391.  
  392.     missile = spawn ();
  393.     missile.owner = self;
  394.     missile.movetype = MOVETYPE_FLYMISSILE;
  395.     missile.solid = SOLID_BBOX;
  396.         
  397. // set missile speed    
  398.  
  399.     makevectors (self.v_angle);
  400.     missile.velocity = aim(self, 1000);
  401.     missile.velocity = missile.velocity * 1000;
  402.     missile.angles = vectoangles(missile.velocity);
  403.     
  404.     missile.touch = T_MissileTouch;
  405.     
  406. // set missile duration
  407.     missile.nextthink = time + 30;
  408.     missile.think = SUB_Remove;
  409.     missile.nextthink = time + 0.001;
  410.     missile.think = RichThink;    
  411.  
  412.     setmodel (missile, "progs/missile.mdl");
  413.     setsize (missile, '0 0 0', '0 0 0');        
  414.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  415. };
  416.  
  417. void() RichThink =
  418. {
  419.     self.owner.origin = self.origin;
  420.     self.nextthink = time + 0.001;
  421.     self.think = RichThink;
  422. };
  423.  
  424. /*
  425. ===============================================================================
  426.  
  427. LIGHTNING
  428.  
  429. ===============================================================================
  430. */
  431.  
  432. /*
  433. =================
  434. LightningDamage
  435. =================
  436. */
  437. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  438. {
  439.     local entity        e1, e2;
  440.     local vector        f;
  441.     
  442.     f = p2 - p1;
  443.     normalize (f);
  444.     f_x = 0 - f_y;
  445.     f_y = f_x;
  446.     f_z = 0;
  447.     f = f*16;
  448.  
  449.     e1 = e2 = world;
  450.  
  451.     traceline (p1, p2, FALSE, self);
  452.     if (trace_ent.takedamage)
  453.     {
  454.         particle (trace_endpos, '0 0 100', 225, damage*4);
  455.         T_Damage (trace_ent, from, from, damage);
  456.         if (self.classname == "player")
  457.         {
  458.             if (other.classname == "player")
  459.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  460.         }
  461.     }
  462.     e1 = trace_ent;
  463.  
  464.     traceline (p1 + f, p2 + f, FALSE, self);
  465.     if (trace_ent != e1 && trace_ent.takedamage)
  466.     {
  467.         particle (trace_endpos, '0 0 100', 225, damage*4);
  468.         T_Damage (trace_ent, from, from, damage);
  469.     }
  470.     e2 = trace_ent;
  471.  
  472.     traceline (p1 - f, p2 - f, FALSE, self);
  473.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  474.     {
  475.         particle (trace_endpos, '0 0 100', 225, damage*4);
  476.         T_Damage (trace_ent, from, from, damage);
  477.     }
  478. };
  479.  
  480.  
  481. void() W_FireLightning =
  482. {
  483.     local    vector        org;
  484.  
  485.     if (self.ammo_cells < 1)
  486.     {
  487.         self.weapon = W_BestWeapon ();
  488.         W_SetCurrentAmmo ();
  489.         return;
  490.     }
  491.  
  492. // explode if under water
  493.     if (self.waterlevel > 1)
  494.     {
  495.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  496.         self.ammo_cells = 0;
  497.         W_SetCurrentAmmo ();
  498.         return;
  499.     }
  500.  
  501.     if (self.t_width < time)
  502.     {
  503.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  504.         self.t_width = time + 0.6;
  505.     }
  506.     self.punchangle_x = -2;
  507.  
  508.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  509.  
  510.     org = self.origin + '0 0 16';
  511.     
  512.     traceline (org, org + v_forward*600, TRUE, self);
  513.  
  514.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  515.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  516.     WriteEntity (MSG_BROADCAST, self);
  517.     WriteCoord (MSG_BROADCAST, org_x);
  518.     WriteCoord (MSG_BROADCAST, org_y);
  519.     WriteCoord (MSG_BROADCAST, org_z);
  520.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  521.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  522.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  523.  
  524.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  525. };
  526.  
  527.  
  528. //=============================================================================
  529.  
  530.  
  531. void() GrenadeExplode =
  532. {
  533.     T_RadiusDamage (self, self.owner, 120, world);
  534.  
  535.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  536.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  537.     WriteCoord (MSG_BROADCAST, self.origin_x);
  538.     WriteCoord (MSG_BROADCAST, self.origin_y);
  539.     WriteCoord (MSG_BROADCAST, self.origin_z);
  540.  
  541.     BecomeExplosion ();
  542. };
  543.  
  544. void() GrenadeTouch =
  545. {
  546.     if (other == self.owner)
  547.         return;        // don't explode on owner
  548.     if (other.takedamage == DAMAGE_AIM)
  549.     {
  550.         GrenadeExplode();
  551.         return;
  552.     }
  553.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  554.     if (self.velocity == '0 0 0')
  555.         self.avelocity = '0 0 0';
  556. };
  557.  
  558. /*
  559. ================
  560. W_FireGrenade
  561. ================
  562. */
  563. void() W_FireGrenade =
  564. {
  565.     local    entity missile, mpuff;
  566.     
  567.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  568.     
  569.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  570.  
  571.     self.punchangle_x = -2;
  572.  
  573.     missile = spawn ();
  574.     missile.owner = self;
  575.     missile.movetype = MOVETYPE_BOUNCE;
  576.     missile.solid = SOLID_BBOX;
  577.     missile.classname = "grenade";
  578.         
  579. // set missile speed    
  580.  
  581.     makevectors (self.v_angle);
  582.  
  583.     if (self.v_angle_x)
  584.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  585.     else
  586.     {
  587.         missile.velocity = aim(self, 10000);
  588.         missile.velocity = missile.velocity * 600;
  589.         missile.velocity_z = 200;
  590.     }
  591.  
  592.     missile.avelocity = '300 300 300';
  593.  
  594.     missile.angles = vectoangles(missile.velocity);
  595.     
  596.     missile.touch = GrenadeTouch;
  597.     
  598. // set missile duration
  599.     missile.nextthink = time + 2.5;
  600.     missile.think = GrenadeExplode;
  601.  
  602.     setmodel (missile, "progs/grenade.mdl");
  603.     setsize (missile, '0 0 0', '0 0 0');        
  604.     setorigin (missile, self.origin);
  605. };
  606.  
  607.  
  608. //=============================================================================
  609.  
  610. void() spike_touch;
  611. void() superspike_touch;
  612.  
  613.  
  614. /*
  615. ===============
  616. launch_spike
  617.  
  618. Used for both the player and the ogre
  619. ===============
  620. */
  621. void(vector org, vector dir) launch_spike =
  622. {
  623.     newmis = spawn ();
  624.     newmis.owner = self;
  625.     newmis.movetype = MOVETYPE_FLYMISSILE;
  626.     newmis.solid = SOLID_BBOX;
  627.  
  628.     newmis.angles = vectoangles(dir);
  629.     
  630.     newmis.touch = spike_touch;
  631.     newmis.classname = "spike";
  632.     newmis.think = SUB_Remove;
  633.     newmis.nextthink = time + 6;
  634.     setmodel (newmis, "progs/spike.mdl");
  635.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  636.     setorigin (newmis, org);
  637.  
  638.     newmis.velocity = dir * 1000;
  639. };
  640.  
  641. void() W_FireSuperSpikes =
  642. {
  643.     local vector    dir;
  644.     local entity    old;
  645.     
  646.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  647.     self.attack_finished = time + 0.2;
  648.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  649.     dir = aim (self, 1000);
  650.     launch_spike (self.origin + '0 0 16', dir);
  651.     newmis.touch = superspike_touch;
  652.     setmodel (newmis, "progs/s_spike.mdl");
  653.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  654.     self.punchangle_x = -2;
  655. };
  656.  
  657. void(float ox) W_FireSpikes =
  658. {
  659.     local vector    dir;
  660.     local entity    old;
  661.     
  662.     makevectors (self.v_angle);
  663.     
  664.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  665.     {
  666.         W_FireSuperSpikes ();
  667.         return;
  668.     }
  669.  
  670.     if (self.ammo_nails < 1)
  671.     {
  672.         self.weapon = W_BestWeapon ();
  673.         W_SetCurrentAmmo ();
  674.         return;
  675.     }
  676.  
  677.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  678.     self.attack_finished = time + 0.2;
  679.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  680.     dir = aim (self, 1000);
  681.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  682.  
  683.     self.punchangle_x = -2;
  684. };
  685.  
  686.  
  687.  
  688. .float hit_z;
  689. void() spike_touch =
  690. {
  691. local float rand;
  692.     if (other == self.owner)
  693.         return;
  694.  
  695.     if (other.solid == SOLID_TRIGGER)
  696.         return;    // trigger field, do nothing
  697.  
  698.     if (pointcontents(self.origin) == CONTENT_SKY)
  699.     {
  700.         remove(self);
  701.         return;
  702.     }
  703.     
  704. // hit something that bleeds
  705.     if (other.takedamage)
  706.     {
  707.         spawn_touchblood (9);
  708.         T_Damage (other, self, self.owner, 9);
  709.     }
  710.     else
  711.     {
  712.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  713.         
  714.         if (self.classname == "wizspike")
  715.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  716.         else if (self.classname == "knightspike")
  717.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  718.         else
  719.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  720.         WriteCoord (MSG_BROADCAST, self.origin_x);
  721.         WriteCoord (MSG_BROADCAST, self.origin_y);
  722.         WriteCoord (MSG_BROADCAST, self.origin_z);
  723.     }
  724.  
  725.     remove(self);
  726.  
  727. };
  728.  
  729. void() superspike_touch =
  730. {
  731. local float rand;
  732.     if (other == self.owner)
  733.         return;
  734.  
  735.     if (other.solid == SOLID_TRIGGER)
  736.         return;    // trigger field, do nothing
  737.  
  738.     if (pointcontents(self.origin) == CONTENT_SKY)
  739.     {
  740.         remove(self);
  741.         return;
  742.     }
  743.     
  744. // hit something that bleeds
  745.     if (other.takedamage)
  746.     {
  747.         spawn_touchblood (18);
  748.         T_Damage (other, self, self.owner, 18);
  749.     }
  750.     else
  751.     {
  752.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  753.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  754.         WriteCoord (MSG_BROADCAST, self.origin_x);
  755.         WriteCoord (MSG_BROADCAST, self.origin_y);
  756.         WriteCoord (MSG_BROADCAST, self.origin_z);
  757.     }
  758.  
  759.     remove(self);
  760.  
  761. };
  762.  
  763.  
  764. /*
  765. ===============================================================================
  766.  
  767. PLAYER WEAPON USE
  768.  
  769. ===============================================================================
  770. */
  771.  
  772. void() W_SetCurrentAmmo =
  773. {
  774.     player_run ();        // get out of any weapon firing states
  775.  
  776.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  777.     
  778.     if (self.weapon == IT_AXE)
  779.     {
  780.         self.currentammo = 0;
  781.         self.weaponmodel = "progs/v_axe.mdl";
  782.         self.weaponframe = 0;
  783.     }
  784.     else if (self.weapon == IT_SHOTGUN)
  785.     {
  786.         self.currentammo = self.ammo_shells;
  787.         self.weaponmodel = "progs/v_shot.mdl";
  788.         self.weaponframe = 0;
  789.         self.items = self.items | IT_SHELLS;
  790.     }
  791.     else if (self.weapon == IT_SUPER_SHOTGUN)
  792.     {
  793.         self.currentammo = self.ammo_shells;
  794.         self.weaponmodel = "progs/v_shot2.mdl";
  795.         self.weaponframe = 0;
  796.         self.items = self.items | IT_SHELLS;
  797.     }
  798.     else if (self.weapon == IT_NAILGUN)
  799.     {
  800.         self.currentammo = self.ammo_nails;
  801.         self.weaponmodel = "progs/v_nail.mdl";
  802.         self.weaponframe = 0;
  803.         self.items = self.items | IT_NAILS;
  804.     }
  805.     else if (self.weapon == IT_SUPER_NAILGUN)
  806.     {
  807.         self.currentammo = self.ammo_nails;
  808.         self.weaponmodel = "progs/v_nail2.mdl";
  809.         self.weaponframe = 0;
  810.         self.items = self.items | IT_NAILS;
  811.     }
  812.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  813.     {
  814.         self.currentammo = self.ammo_rockets;
  815.         self.weaponmodel = "progs/v_rock.mdl";
  816.         self.weaponframe = 0;
  817.         self.items = self.items | IT_ROCKETS;
  818.     }
  819.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  820.     {
  821.         self.currentammo = self.ammo_rockets;
  822.         self.weaponmodel = "progs/v_rock2.mdl";
  823.         self.weaponframe = 0;
  824.         self.items = self.items | IT_ROCKETS;
  825.     }
  826.     else if (self.weapon == IT_LIGHTNING)
  827.     {
  828.         self.currentammo = self.ammo_cells;
  829.         self.weaponmodel = "progs/v_light.mdl";
  830.         self.weaponframe = 0;
  831.         self.items = self.items | IT_CELLS;
  832.     }
  833.     else
  834.     {
  835.         self.currentammo = 0;
  836.         self.weaponmodel = "";
  837.         self.weaponframe = 0;
  838.     }
  839. };
  840.  
  841. float() W_BestWeapon =
  842. {
  843.     local    float    it;
  844.     
  845.     it = self.items;
  846.  
  847.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  848.         return IT_LIGHTNING;
  849.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  850.         return IT_SUPER_NAILGUN;
  851.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  852.         return IT_SUPER_SHOTGUN;
  853.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  854.         return IT_NAILGUN;
  855.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  856.         return IT_SHOTGUN;
  857.         
  858. /*
  859.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  860.         return IT_ROCKET_LAUNCHER;
  861.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  862.         return IT_GRENADE_LAUNCHER;
  863.  
  864. */
  865.  
  866.     return IT_AXE;
  867. };
  868.  
  869. float() W_CheckNoAmmo =
  870. {
  871.     if (self.currentammo > 0)
  872.         return TRUE;
  873.  
  874.     if (self.weapon == IT_AXE)
  875.         return TRUE;
  876.     
  877.     self.weapon = W_BestWeapon ();
  878.  
  879.     W_SetCurrentAmmo ();
  880.     
  881. // drop the weapon down
  882.     return FALSE;
  883. };
  884.  
  885. /*
  886. ============
  887. W_Attack
  888.  
  889. An attack impulse can be triggered now
  890. ============
  891. */
  892. void()    player_axe1;
  893. void()    player_axeb1;
  894. void()    player_axec1;
  895. void()    player_axed1;
  896. void()    player_shot1;
  897. void()    player_nail1;
  898. void()    player_light1;
  899. void()    player_rocket1;
  900.  
  901. void() W_Attack =
  902. {
  903.     local    float    r;
  904.  
  905.     if (!W_CheckNoAmmo ())
  906.         return;
  907.  
  908.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  909.     self.show_hostile = time + 1;    // wake monsters up
  910.  
  911.     if (self.weapon == IT_AXE)
  912.     {
  913.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  914.         r = random();
  915.         if (r < 0.25)
  916.             player_axe1 ();
  917.         else if (r<0.5)
  918.             player_axeb1 ();
  919.         else if (r<0.75)
  920.             player_axec1 ();
  921.         else
  922.             player_axed1 ();
  923.         self.attack_finished = time + 0.5;
  924.     }
  925.     else if (self.weapon == IT_SHOTGUN)
  926.     {
  927.         player_shot1 ();
  928.         W_FireShotgun ();
  929.         self.attack_finished = time + 0.5;
  930.     }
  931.     else if (self.weapon == IT_SUPER_SHOTGUN)
  932.     {
  933.         player_shot1 ();
  934.         W_FireSuperShotgun ();
  935.         self.attack_finished = time + 0.7;
  936.     }
  937.     else if (self.weapon == IT_NAILGUN)
  938.     {
  939.         player_nail1 ();
  940.     }
  941.     else if (self.weapon == IT_SUPER_NAILGUN)
  942.     {
  943.         player_nail1 ();
  944.     }
  945.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  946.     {
  947.         player_rocket1();
  948.         W_FireGrenade();
  949.         self.attack_finished = time + 0.6;
  950.     }
  951.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  952.     {
  953.         player_rocket1();
  954.         W_FireRocket();
  955.         self.attack_finished = time + 0.8;
  956.     }
  957.     else if (self.weapon == IT_LIGHTNING)
  958.     {
  959.         player_light1();
  960.         self.attack_finished = time + 0.1;
  961.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  962.     }
  963. };
  964.  
  965. /*
  966. ============
  967. W_ChangeWeapon
  968.  
  969. ============
  970. */
  971. void() W_ChangeWeapon =
  972. {
  973.     local    float    it, am, fl;
  974.     
  975.     it = self.items;
  976.     am = 0;
  977.     
  978.     if (self.impulse == 1)
  979.     {
  980.         fl = IT_AXE;
  981.     }
  982.     else if (self.impulse == 2)
  983.     {
  984.         fl = IT_SHOTGUN;
  985.         if (self.ammo_shells < 1)
  986.             am = 1;
  987.     }
  988.     else if (self.impulse == 3)
  989.     {
  990.         fl = IT_SUPER_SHOTGUN;
  991.         if (self.ammo_shells < 2)
  992.             am = 1;
  993.     }        
  994.     else if (self.impulse == 4)
  995.     {
  996.         fl = IT_NAILGUN;
  997.         if (self.ammo_nails < 1)
  998.             am = 1;
  999.     }
  1000.     else if (self.impulse == 5)
  1001.     {
  1002.         fl = IT_SUPER_NAILGUN;
  1003.         if (self.ammo_nails < 2)
  1004.             am = 1;
  1005.     }
  1006.     else if (self.impulse == 6)
  1007.     {
  1008.         fl = IT_GRENADE_LAUNCHER;
  1009.         if (self.ammo_rockets < 1)
  1010.             am = 1;
  1011.     }
  1012.     else if (self.impulse == 7)
  1013.     {
  1014.         fl = IT_ROCKET_LAUNCHER;
  1015.         if (self.ammo_rockets < 1)
  1016.             am = 1;
  1017.     }
  1018.     else if (self.impulse == 8)
  1019.     {
  1020.         fl = IT_LIGHTNING;
  1021.         if (self.ammo_cells < 1)
  1022.             am = 1;
  1023.     }
  1024.  
  1025.     self.impulse = 0;
  1026.     
  1027.     if (!(self.items & fl))
  1028.     {    // don't have the weapon or the ammo
  1029.         sprint (self, "no weapon.\n");
  1030.         return;
  1031.     }
  1032.     
  1033.     if (am)
  1034.     {    // don't have the ammo
  1035.         sprint (self, "not enough ammo.\n");
  1036.         return;
  1037.     }
  1038.  
  1039. //
  1040. // set weapon, set ammo
  1041. //
  1042.     self.weapon = fl;        
  1043.     W_SetCurrentAmmo ();
  1044. };
  1045.  
  1046. /*
  1047. ============
  1048. CheatCommand
  1049. ============
  1050. */
  1051. void() CheatCommand =
  1052. {
  1053.     if (deathmatch || coop)
  1054.         return;
  1055.  
  1056.     self.ammo_rockets = 100;
  1057.     self.ammo_nails = 200;
  1058.     self.ammo_shells = 100;
  1059.     self.items = self.items | 
  1060.         IT_AXE |
  1061.         IT_SHOTGUN |
  1062.         IT_SUPER_SHOTGUN |
  1063.         IT_NAILGUN |
  1064.         IT_SUPER_NAILGUN |
  1065.         IT_GRENADE_LAUNCHER |
  1066.         IT_ROCKET_LAUNCHER |
  1067.         IT_KEY1 | IT_KEY2;
  1068.  
  1069.     self.ammo_cells = 200;
  1070.     self.items = self.items | IT_LIGHTNING;
  1071.  
  1072.     self.weapon = IT_ROCKET_LAUNCHER;
  1073.     self.impulse = 0;
  1074.     W_SetCurrentAmmo ();
  1075. };
  1076.  
  1077. /*
  1078. ============
  1079. CycleWeaponCommand
  1080.  
  1081. Go to the next weapon with ammo
  1082. ============
  1083. */
  1084. void() CycleWeaponCommand =
  1085. {
  1086.     local    float    it, am;
  1087.     
  1088.     it = self.items;
  1089.     self.impulse = 0;
  1090.     
  1091.     while (1)
  1092.     {
  1093.         am = 0;
  1094.  
  1095.         if (self.weapon == IT_LIGHTNING)
  1096.         {
  1097.             self.weapon = IT_AXE;
  1098.         }
  1099.         else if (self.weapon == IT_AXE)
  1100.         {
  1101.             self.weapon = IT_SHOTGUN;
  1102.             if (self.ammo_shells < 1)
  1103.                 am = 1;
  1104.         }
  1105.         else if (self.weapon == IT_SHOTGUN)
  1106.         {
  1107.             self.weapon = IT_SUPER_SHOTGUN;
  1108.             if (self.ammo_shells < 2)
  1109.                 am = 1;
  1110.         }        
  1111.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1112.         {
  1113.             self.weapon = IT_NAILGUN;
  1114.             if (self.ammo_nails < 1)
  1115.                 am = 1;
  1116.         }
  1117.         else if (self.weapon == IT_NAILGUN)
  1118.         {
  1119.             self.weapon = IT_SUPER_NAILGUN;
  1120.             if (self.ammo_nails < 2)
  1121.                 am = 1;
  1122.         }
  1123.         else if (self.weapon == IT_SUPER_NAILGUN)
  1124.         {
  1125.             self.weapon = IT_GRENADE_LAUNCHER;
  1126.             if (self.ammo_rockets < 1)
  1127.                 am = 1;
  1128.         }
  1129.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1130.         {
  1131.             self.weapon = IT_ROCKET_LAUNCHER;
  1132.             if (self.ammo_rockets < 1)
  1133.                 am = 1;
  1134.         }
  1135.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1136.         {
  1137.             self.weapon = IT_LIGHTNING;
  1138.             if (self.ammo_cells < 1)
  1139.                 am = 1;
  1140.         }
  1141.     
  1142.         if ( (self.items & self.weapon) && am == 0)
  1143.         {
  1144.             W_SetCurrentAmmo ();
  1145.             return;
  1146.         }
  1147.     }
  1148.  
  1149. };
  1150.  
  1151. /*
  1152. ============
  1153. ServerflagsCommand
  1154.  
  1155. Just for development
  1156. ============
  1157. */
  1158. void() ServerflagsCommand =
  1159. {
  1160.     serverflags = serverflags * 2 + 1;
  1161. };
  1162.  
  1163. void() QuadCheat =
  1164. {
  1165.     if (deathmatch || coop)
  1166.         return;
  1167.     self.super_time = 1;
  1168.     self.super_damage_finished = time + 30;
  1169.     self.items = self.items | IT_QUAD;
  1170.     dprint ("quad cheat\n");
  1171. };
  1172.  
  1173. /*
  1174. ============
  1175. ImpulseCommands
  1176.  
  1177. ============
  1178. */
  1179. void() ImpulseCommands =
  1180. {
  1181.     if (self.impulse >= 1 && self.impulse <= 8)
  1182.         W_ChangeWeapon ();
  1183.  
  1184.     if (self.impulse == 9)
  1185.         CheatCommand ();
  1186.     if (self.impulse == 10)
  1187.         CycleWeaponCommand ();
  1188.     if (self.impulse == 11)
  1189.         ServerflagsCommand ();
  1190.  
  1191.     if (self.impulse == 255)
  1192.         QuadCheat ();
  1193.         
  1194.     self.impulse = 0;
  1195. };
  1196.  
  1197. /*
  1198. ============
  1199. W_WeaponFrame
  1200.  
  1201. Called every frame so impulse events can be handled as well as possible
  1202. ============
  1203. */
  1204. void() W_WeaponFrame =
  1205. {
  1206.     if (time < self.attack_finished)
  1207.         return;
  1208.  
  1209.     ImpulseCommands ();
  1210.     
  1211. // check for attack
  1212.     if (self.button0)
  1213.     {
  1214.         SuperDamageSound ();
  1215.         W_Attack ();
  1216.     }
  1217. };
  1218.  
  1219. /*
  1220. ========
  1221. SuperDamageSound
  1222.  
  1223. Plays sound if needed
  1224. ========
  1225. */
  1226. void() SuperDamageSound =
  1227. {
  1228.     if (self.super_damage_finished > time)
  1229.     {
  1230.         if (self.super_sound < time)
  1231.         {
  1232.             self.super_sound = time + 1;
  1233.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1234.         }
  1235.     }
  1236.     return;
  1237. };
  1238.  
  1239.  
  1240.