home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qwiz12 / weapons.qc < prev    next >
Encoding:
Text File  |  1996-08-16  |  25.5 KB  |  1,262 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_model ("progs/w_spike.mdl");
  14.     precache_model2 ("progs/k_spike.mdl");
  15.         precache_model2 ("progs/end3.mdl");
  16.  
  17.         precache_sound2 ("hknight/slash1.wav");  // jump swoosh
  18.     precache_sound ("enforcer/enfstop.wav");    // magic missle hit
  19.         precache_sound2 ("shalrath/attack2.wav");  // cast magic sound
  20.  
  21.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  22.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  23.     precache_sound ("weapons/sgun1.wav");
  24.     precache_sound ("weapons/guncock.wav");    // player shotgun
  25.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  26.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  27.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  28.     precache_sound ("weapons/spike2.wav");    // super spikes
  29.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  30.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  31.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  32.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  33. };
  34.  
  35. float() crandom =
  36. {
  37.     return 2*(random() - 0.5);
  38. };
  39.  
  40. /*
  41. ================
  42. W_FireAxe
  43. ================
  44. */
  45. void() W_FireAxe =
  46. {
  47.     local    vector    source;
  48.     local    vector    org;
  49.  
  50.     source = self.origin + '0 0 16';
  51.     traceline (source, source + v_forward*64, FALSE, self);
  52.     if (trace_fraction == 1.0)
  53.                 return;
  54.     
  55.     org = trace_endpos - v_forward*4;
  56.  
  57.     if (trace_ent.takedamage)
  58.     {
  59.         trace_ent.axhitme = 1;
  60.         SpawnBlood (org, '0 0 0', 20);
  61.         T_Damage (trace_ent, self, self, 20);
  62.     }
  63.     else
  64.     {    // hit wall
  65.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  66.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  67.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  68.         WriteCoord (MSG_BROADCAST, org_x);
  69.         WriteCoord (MSG_BROADCAST, org_y);
  70.         WriteCoord (MSG_BROADCAST, org_z);
  71.     }
  72. };
  73.  
  74.  
  75. //============================================================================
  76.  
  77.  
  78. vector() wall_velocity =
  79. {
  80.     local vector    vel;
  81.     
  82.     vel = normalize (self.velocity);
  83.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  84.     vel = vel + 2*trace_plane_normal;
  85.     vel = vel * 200;
  86.     
  87.     return vel;
  88. };
  89.  
  90.  
  91. /*
  92. ================
  93. SpawnMeatSpray
  94. ================
  95. */
  96. void(vector org, vector vel) SpawnMeatSpray =
  97. {
  98.     local    entity missile, mpuff;
  99.     local    vector    org;
  100.  
  101.     missile = spawn ();
  102.     missile.owner = self;
  103.     missile.movetype = MOVETYPE_BOUNCE;
  104.     missile.solid = SOLID_NOT;
  105.  
  106.     makevectors (self.angles);
  107.  
  108.     missile.velocity = vel;
  109.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  110.  
  111.     missile.avelocity = '3000 1000 2000';
  112.     
  113. // set missile duration
  114.     missile.nextthink = time + 1;
  115.     missile.think = SUB_Remove;
  116.  
  117.     setmodel (missile, "progs/zom_gib.mdl");
  118.     setsize (missile, '0 0 0', '0 0 0');        
  119.     setorigin (missile, org);
  120. };
  121.  
  122. /*
  123. ================
  124. SpawnBlood
  125. ================
  126. */
  127. void(vector org, vector vel, float damage) SpawnBlood =
  128. {
  129.     particle (org, vel*0.1, 73, damage*2);
  130. };
  131.  
  132. /*
  133. ================
  134. spawn_touchblood
  135. ================
  136. */
  137. void(float damage) spawn_touchblood =
  138. {
  139.     local vector    vel;
  140.  
  141.     vel = wall_velocity () * 0.2;
  142.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  143. };
  144.  
  145.  
  146. /*
  147. ================
  148. SpawnChunk
  149. ================
  150. */
  151. void(vector org, vector vel) SpawnChunk =
  152. {
  153.     particle (org, vel*0.02, 0, 10);
  154. };
  155.  
  156. /*
  157. ==============================================================================
  158.  
  159. MULTI-DAMAGE
  160.  
  161. Collects multiple small damages into a single damage
  162.  
  163. ==============================================================================
  164. */
  165.  
  166. entity    multi_ent;
  167. float    multi_damage;
  168.  
  169. void() ClearMultiDamage =
  170. {
  171.     multi_ent = world;
  172.     multi_damage = 0;
  173. };
  174.  
  175. void() ApplyMultiDamage =
  176. {
  177.     if (!multi_ent)
  178.         return;
  179.     T_Damage (multi_ent, self, self, multi_damage);
  180. };
  181.  
  182. void(entity hit, float damage) AddMultiDamage =
  183. {
  184.     if (!hit)
  185.         return;
  186.     
  187.     if (hit != multi_ent)
  188.     {
  189.         ApplyMultiDamage ();
  190.         multi_damage = damage;
  191.         multi_ent = hit;
  192.     }
  193.     else
  194.         multi_damage = multi_damage + damage;
  195. };
  196.  
  197. /*
  198. ==============================================================================
  199.  
  200. BULLETS
  201.  
  202. ==============================================================================
  203. */
  204.  
  205. /*
  206. ================
  207. TraceAttack
  208. ================
  209. */
  210. void(float damage, vector dir) TraceAttack =
  211. {
  212.     local    vector    vel, org;
  213.     
  214.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  215.     vel = vel + 2*trace_plane_normal;
  216.     vel = vel * 200;
  217.  
  218.     org = trace_endpos - dir*4;
  219.  
  220.     if (trace_ent.takedamage)
  221.     {
  222.         SpawnBlood (org, vel*0.2, damage);
  223.         AddMultiDamage (trace_ent, damage);
  224.     }
  225.     else
  226.     {
  227.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  228.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  229.         WriteCoord (MSG_BROADCAST, org_x);
  230.         WriteCoord (MSG_BROADCAST, org_y);
  231.         WriteCoord (MSG_BROADCAST, org_z);
  232.     }
  233. };
  234.  
  235. /*
  236. ================
  237. FireBullets
  238.  
  239. Used by shotgun, super shotgun, and enemy soldier firing
  240. Go to the trouble of combining multiple pellets into a single damage call.
  241. ================
  242. */
  243. void(float shotcount, vector dir, vector spread) FireBullets =
  244. {
  245.     local    vector direction;
  246.     local    vector    src;
  247.     
  248.     makevectors(self.v_angle);
  249.  
  250.     src = self.origin + v_forward*10;
  251.     src_z = self.absmin_z + self.size_z * 0.7;
  252.  
  253.     ClearMultiDamage ();
  254.     while (shotcount > 0)
  255.     {
  256.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  257.  
  258.         traceline (src, src + direction*2048, FALSE, self);
  259.         if (trace_fraction != 1.0)
  260.             TraceAttack (4, direction);
  261.  
  262.         shotcount = shotcount - 1;
  263.     }
  264.     ApplyMultiDamage ();
  265. };
  266.  
  267. /*
  268. ================
  269. W_FireShotgun
  270. ================
  271. */
  272. void() W_FireShotgun =
  273. {
  274.     local vector dir;
  275.  
  276.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  277.  
  278.     self.punchangle_x = -2;
  279.     
  280.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  281.     dir = aim (self, 100000);
  282.     FireBullets (6, dir, '0.04 0.04 0');
  283. };
  284.  
  285.  
  286. /*
  287. ================
  288. W_FireSuperShotgun
  289. ================
  290. */
  291. void() W_FireSuperShotgun =
  292. {
  293.     local vector dir;
  294.  
  295.     if (self.currentammo == 1)
  296.     {
  297.         W_FireShotgun ();
  298.         return;
  299.     }
  300.         
  301.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  302.  
  303.     self.punchangle_x = -4;
  304.     
  305.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  306.     dir = aim (self, 100000);
  307.     FireBullets (14, dir, '0.14 0.08 0');
  308. };
  309.  
  310.  
  311. /*
  312. ==============================================================================
  313.  
  314. ROCKETS
  315.  
  316. ==============================================================================
  317. */
  318.  
  319. void()    s_explode1    =    [0,        s_explode2] {};
  320. void()    s_explode2    =    [1,        s_explode3] {};
  321. void()    s_explode3    =    [2,        s_explode4] {};
  322. void()    s_explode4    =    [3,        s_explode5] {};
  323. void()    s_explode5    =    [4,        s_explode6] {};
  324. void()    s_explode6    =    [5,        SUB_Remove] {};
  325.  
  326. void() BecomeExplosion =
  327. {
  328.     self.movetype = MOVETYPE_NONE;
  329.     self.velocity = '0 0 0';
  330.     self.touch = SUB_Null;
  331.     setmodel (self, "progs/s_explod.spr");
  332.     self.solid = SOLID_NOT;
  333.     s_explode1 ();
  334. };
  335.  
  336. void() T_MissileTouch =
  337. {
  338.     local float    damg;
  339.  
  340.     if (other == self.owner)
  341.         return;        // don't explode on owner
  342.  
  343.     if (pointcontents(self.origin) == CONTENT_SKY)
  344.     {
  345.         remove(self);
  346.         return;
  347.     }
  348.  
  349.     damg = 100 + random()*20;
  350.     
  351.     if (other.health)
  352.     {
  353.         if (other.classname == "monster_shambler")
  354.             damg = damg * 0.5;    // mostly immune
  355.         T_Damage (other, self, self.owner, damg );
  356.     }
  357.  
  358.     // don't do radius damage to the other, because all the damage
  359.     // was done in the impact
  360.     T_RadiusDamage (self, self.owner, 120, other);
  361.  
  362. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  363.     self.origin = self.origin - 8*normalize(self.velocity);
  364.  
  365.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  366.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  367.     WriteCoord (MSG_BROADCAST, self.origin_x);
  368.     WriteCoord (MSG_BROADCAST, self.origin_y);
  369.     WriteCoord (MSG_BROADCAST, self.origin_z);
  370.  
  371.     BecomeExplosion ();
  372. };
  373.  
  374.  
  375.  
  376. /*
  377. ================
  378. W_FireRocket
  379. ================
  380. */
  381. void() W_FireRocket =
  382. {
  383.     local    entity missile, mpuff;
  384.     
  385.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  386.     
  387.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  388.  
  389.     self.punchangle_x = -2;
  390.  
  391.     missile = spawn ();
  392.     missile.owner = self;
  393.     missile.movetype = MOVETYPE_FLYMISSILE;
  394.     missile.solid = SOLID_BBOX;
  395.         
  396. // set missile speed    
  397.  
  398.     makevectors (self.v_angle);
  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.  
  647. void(float ox) W_FireSpikes =
  648. {
  649.     local vector    dir;
  650.     local entity    old;
  651.     
  652.     makevectors (self.v_angle);
  653.     
  654.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  655.     {
  656.         W_FireSuperSpikes ();
  657.         return;
  658.     }
  659.  
  660.     if (self.ammo_nails < 1)
  661.     {
  662.         self.weapon = W_BestWeapon ();
  663.         W_SetCurrentAmmo ();
  664.         return;
  665.     }
  666.  
  667.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  668.     self.attack_finished = time + 0.2;
  669.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  670.     dir = aim (self, 1000);
  671.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  672.  
  673.     self.punchangle_x = -2;
  674. };
  675.  
  676.  
  677.  
  678. .float hit_z;
  679. void() spike_touch =
  680. {
  681. local float rand;
  682.     if (other == self.owner)
  683.         return;
  684.  
  685.     if (other.solid == SOLID_TRIGGER)
  686.         return;    // trigger field, do nothing
  687.  
  688.     if (pointcontents(self.origin) == CONTENT_SKY)
  689.     {
  690.         remove(self);
  691.         return;
  692.     }
  693.     
  694. // hit something that bleeds
  695.     if (other.takedamage)
  696.     {
  697.         spawn_touchblood (9);
  698.         T_Damage (other, self, self.owner, 9);
  699.     }
  700.     else
  701.     {
  702.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  703.         
  704.         if (self.classname == "wizspike")
  705.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  706.         else if (self.classname == "knightspike")
  707.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  708.         else
  709.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  710.         WriteCoord (MSG_BROADCAST, self.origin_x);
  711.         WriteCoord (MSG_BROADCAST, self.origin_y);
  712.         WriteCoord (MSG_BROADCAST, self.origin_z);
  713.     }
  714.  
  715.     remove(self);
  716.  
  717. };
  718.  
  719. void() superspike_touch =
  720. {
  721. local float rand;
  722.     if (other == self.owner)
  723.         return;
  724.  
  725.     if (other.solid == SOLID_TRIGGER)
  726.         return;    // trigger field, do nothing
  727.  
  728.     if (pointcontents(self.origin) == CONTENT_SKY)
  729.     {
  730.         remove(self);
  731.         return;
  732.     }
  733.     
  734. // hit something that bleeds
  735.     if (other.takedamage)
  736.     {
  737.         spawn_touchblood (18);
  738.         T_Damage (other, self, self.owner, 18);
  739.     }
  740.     else
  741.     {
  742.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  743.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  744.         WriteCoord (MSG_BROADCAST, self.origin_x);
  745.         WriteCoord (MSG_BROADCAST, self.origin_y);
  746.         WriteCoord (MSG_BROADCAST, self.origin_z);
  747.     }
  748.  
  749.     remove(self);
  750.  
  751. };
  752.  
  753.  
  754. /*
  755. ===============================================================================
  756.  
  757. PLAYER WEAPON USE
  758.  
  759. ===============================================================================
  760. */
  761.  
  762. void() W_SetCurrentAmmo =
  763. {
  764.     player_run ();        // get out of any weapon firing states
  765.  
  766.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  767.     
  768.     if (self.weapon == IT_AXE)
  769.     {
  770.         self.currentammo = 0;
  771.         self.weaponmodel = "progs/v_axe.mdl";
  772.         self.weaponframe = 0;
  773.     }
  774.     else if (self.weapon == IT_SHOTGUN)
  775.     {
  776.         self.currentammo = self.ammo_shells;
  777.         self.weaponmodel = "progs/v_shot.mdl";
  778.         self.weaponframe = 0;
  779.         self.items = self.items | IT_SHELLS;
  780.     }
  781.     else if (self.weapon == IT_SUPER_SHOTGUN)
  782.     {
  783.         self.currentammo = self.ammo_shells;
  784.         self.weaponmodel = "progs/v_shot2.mdl";
  785.         self.weaponframe = 0;
  786.         self.items = self.items | IT_SHELLS;
  787.     }
  788.     else if (self.weapon == IT_NAILGUN)
  789.     {
  790.         self.currentammo = self.ammo_nails;
  791.         self.weaponmodel = "progs/v_nail.mdl";
  792.         self.weaponframe = 0;
  793.         self.items = self.items | IT_NAILS;
  794.     }
  795.     else if (self.weapon == IT_SUPER_NAILGUN)
  796.     {
  797.         self.currentammo = self.ammo_nails;
  798.         self.weaponmodel = "progs/v_nail2.mdl";
  799.         self.weaponframe = 0;
  800.         self.items = self.items | IT_NAILS;
  801.     }
  802.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  803.     {
  804.         self.currentammo = self.ammo_rockets;
  805.         self.weaponmodel = "progs/v_rock.mdl";
  806.         self.weaponframe = 0;
  807.         self.items = self.items | IT_ROCKETS;
  808.     }
  809.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  810.     {
  811.         self.currentammo = self.ammo_rockets;
  812.         self.weaponmodel = "progs/v_rock2.mdl";
  813.         self.weaponframe = 0;
  814.         self.items = self.items | IT_ROCKETS;
  815.     }
  816.     else if (self.weapon == IT_LIGHTNING)
  817.     {
  818.         self.currentammo = self.ammo_cells;
  819.         self.weaponmodel = "progs/v_light.mdl";
  820.         self.weaponframe = 0;
  821.         self.items = self.items | IT_CELLS;
  822.     }
  823.     else
  824.     {
  825.         self.currentammo = 0;
  826.         self.weaponmodel = "";
  827.         self.weaponframe = 0;
  828.     }
  829. };
  830.  
  831. float() W_BestWeapon =
  832. {
  833.     local    float    it;
  834.     
  835.     it = self.items;
  836.  
  837.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  838.         return IT_LIGHTNING;
  839.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  840.         return IT_SUPER_NAILGUN;
  841.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  842.         return IT_SUPER_SHOTGUN;
  843.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  844.         return IT_NAILGUN;
  845.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  846.         return IT_SHOTGUN;
  847.         
  848. /*
  849.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  850.         return IT_ROCKET_LAUNCHER;
  851.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  852.         return IT_GRENADE_LAUNCHER;
  853.  
  854. */
  855.  
  856.     return IT_AXE;
  857. };
  858.  
  859. float() W_CheckNoAmmo =
  860. {
  861.     if (self.currentammo > 0)
  862.         return TRUE;
  863.  
  864.     if (self.weapon == IT_AXE)
  865.         return TRUE;
  866.     
  867.     self.weapon = W_BestWeapon ();
  868.  
  869.     W_SetCurrentAmmo ();
  870.     
  871. // drop the weapon down
  872.     return FALSE;
  873. };
  874.  
  875. /*
  876. ============
  877. W_Attack
  878.  
  879. An attack impulse can be triggered now
  880. ============
  881. */
  882. void()    player_axe1;
  883. void()    player_axeb1;
  884. void()    player_axec1;
  885. void()    player_axed1;
  886. void()    player_shot1;
  887. void()    player_nail1;
  888. void()    player_light1;
  889. void()    player_rocket1;
  890.  
  891. void() W_Attack =
  892. {
  893.     local    float    r;
  894.  
  895.     if (!W_CheckNoAmmo ())
  896.         return;
  897.  
  898.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  899.     self.show_hostile = time + 1;    // wake monsters up
  900.  
  901.     if (self.weapon == IT_AXE)
  902.     {
  903.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  904.         r = random();
  905.         if (r < 0.25)
  906.             player_axe1 ();
  907.         else if (r<0.5)
  908.             player_axeb1 ();
  909.         else if (r<0.75)
  910.             player_axec1 ();
  911.         else
  912.             player_axed1 ();
  913.         self.attack_finished = time + 0.5;
  914.     }
  915.     else if (self.weapon == IT_SHOTGUN)
  916.     {
  917.         player_shot1 ();
  918.         W_FireShotgun ();
  919.         self.attack_finished = time + 0.5;
  920.     }
  921.     else if (self.weapon == IT_SUPER_SHOTGUN)
  922.     {
  923.         player_shot1 ();
  924.         W_FireSuperShotgun ();
  925.         self.attack_finished = time + 0.7;
  926.     }
  927.     else if (self.weapon == IT_NAILGUN)
  928.     {
  929.         player_nail1 ();
  930.     }
  931.     else if (self.weapon == IT_SUPER_NAILGUN)
  932.     {
  933.         player_nail1 ();
  934.     }
  935.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  936.     {
  937.         player_rocket1();
  938.         W_FireGrenade();
  939.         self.attack_finished = time + 0.6;
  940.     }
  941.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  942.     {
  943.         player_rocket1();
  944.         W_FireRocket();
  945.         self.attack_finished = time + 0.8;
  946.     }
  947.     else if (self.weapon == IT_LIGHTNING)
  948.     {
  949.         player_light1();
  950.         self.attack_finished = time + 0.1;
  951.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  952.     }
  953. };
  954.  
  955. /*
  956. ============
  957. W_ChangeWeapon
  958.  
  959. ============
  960. */
  961. void() W_ChangeWeapon =
  962. {
  963.     local    float    it, am, fl;
  964.     
  965.     it = self.items;
  966.     am = 0;
  967.     
  968.     if (self.impulse == 1)
  969.     {
  970.         fl = IT_AXE;
  971.     }
  972.     else if (self.impulse == 2)
  973.     {
  974.         fl = IT_SHOTGUN;
  975.         if (self.ammo_shells < 1)
  976.             am = 1;
  977.     }
  978.     else if (self.impulse == 3)
  979.     {
  980.         fl = IT_SUPER_SHOTGUN;
  981.         if (self.ammo_shells < 2)
  982.             am = 1;
  983.     }        
  984.     else if (self.impulse == 4)
  985.     {
  986.         fl = IT_NAILGUN;
  987.         if (self.ammo_nails < 1)
  988.             am = 1;
  989.     }
  990.     else if (self.impulse == 5)
  991.     {
  992.         fl = IT_SUPER_NAILGUN;
  993.         if (self.ammo_nails < 2)
  994.             am = 1;
  995.     }
  996.     else if (self.impulse == 6)
  997.     {
  998.         fl = IT_GRENADE_LAUNCHER;
  999.         if (self.ammo_rockets < 1)
  1000.             am = 1;
  1001.     }
  1002.     else if (self.impulse == 7)
  1003.     {
  1004.         fl = IT_ROCKET_LAUNCHER;
  1005.         if (self.ammo_rockets < 1)
  1006.             am = 1;
  1007.     }
  1008.     else if (self.impulse == 8)
  1009.     {
  1010.         fl = IT_LIGHTNING;
  1011.         if (self.ammo_cells < 1)
  1012.             am = 1;
  1013.     }
  1014.  
  1015.     self.impulse = 0;
  1016.     
  1017.     if (!(self.items & fl))
  1018.     {    // don't have the weapon or the ammo
  1019.         sprint (self, "no weapon.\n");
  1020.         return;
  1021.     }
  1022.     
  1023.     if (am)
  1024.     {    // don't have the ammo
  1025.         sprint (self, "not enough ammo.\n");
  1026.         return;
  1027.     }
  1028.  
  1029. //
  1030. // set weapon, set ammo
  1031. //
  1032.     self.weapon = fl;        
  1033.     W_SetCurrentAmmo ();
  1034. };
  1035.  
  1036. /*
  1037. ============
  1038. CheatCommand
  1039. ============
  1040. */
  1041. void() CheatCommand =
  1042. {
  1043.     if (deathmatch || coop)
  1044.         return;
  1045.  
  1046.     self.ammo_rockets = 100;
  1047.     self.ammo_nails = 200;
  1048.     self.ammo_shells = 100;
  1049.     self.items = self.items | 
  1050.         IT_AXE |
  1051.         IT_SHOTGUN |
  1052.         IT_SUPER_SHOTGUN |
  1053.         IT_NAILGUN |
  1054.         IT_SUPER_NAILGUN |
  1055.         IT_GRENADE_LAUNCHER |
  1056.         IT_ROCKET_LAUNCHER |
  1057.         IT_KEY1 | IT_KEY2;
  1058.  
  1059.     self.ammo_cells = 200;
  1060.     self.items = self.items | IT_LIGHTNING;
  1061.  
  1062.     self.weapon = IT_ROCKET_LAUNCHER;
  1063.     self.impulse = 0;
  1064.     W_SetCurrentAmmo ();
  1065. };
  1066.  
  1067. /*
  1068. ============
  1069. CycleWeaponCommand
  1070.  
  1071. Go to the next weapon with ammo
  1072. ============
  1073. */
  1074. void() CycleWeaponCommand =
  1075. {
  1076.     local    float    it, am;
  1077.     
  1078.     it = self.items;
  1079.     self.impulse = 0;
  1080.     
  1081.     while (1)
  1082.     {
  1083.         am = 0;
  1084.  
  1085.         if (self.weapon == IT_LIGHTNING)
  1086.         {
  1087.             self.weapon = IT_AXE;
  1088.         }
  1089.         else if (self.weapon == IT_AXE)
  1090.         {
  1091.             self.weapon = IT_SHOTGUN;
  1092.             if (self.ammo_shells < 1)
  1093.                 am = 1;
  1094.         }
  1095.         else if (self.weapon == IT_SHOTGUN)
  1096.         {
  1097.             self.weapon = IT_SUPER_SHOTGUN;
  1098.             if (self.ammo_shells < 2)
  1099.                 am = 1;
  1100.         }        
  1101.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1102.         {
  1103.             self.weapon = IT_NAILGUN;
  1104.             if (self.ammo_nails < 1)
  1105.                 am = 1;
  1106.         }
  1107.         else if (self.weapon == IT_NAILGUN)
  1108.         {
  1109.             self.weapon = IT_SUPER_NAILGUN;
  1110.             if (self.ammo_nails < 2)
  1111.                 am = 1;
  1112.         }
  1113.         else if (self.weapon == IT_SUPER_NAILGUN)
  1114.         {
  1115.             self.weapon = IT_GRENADE_LAUNCHER;
  1116.             if (self.ammo_rockets < 1)
  1117.                 am = 1;
  1118.         }
  1119.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1120.         {
  1121.             self.weapon = IT_ROCKET_LAUNCHER;
  1122.             if (self.ammo_rockets < 1)
  1123.                 am = 1;
  1124.         }
  1125.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1126.         {
  1127.             self.weapon = IT_LIGHTNING;
  1128.             if (self.ammo_cells < 1)
  1129.                 am = 1;
  1130.         }
  1131.     
  1132.         if ( (self.items & self.weapon) && am == 0)
  1133.         {
  1134.             W_SetCurrentAmmo ();
  1135.             return;
  1136.         }
  1137.     }
  1138.  
  1139. };
  1140.  
  1141. /*
  1142. ============
  1143. ServerflagsCommand
  1144.  
  1145. Just for development
  1146. ============
  1147. */
  1148. void() ServerflagsCommand =
  1149. {
  1150.     serverflags = serverflags * 2 + 1;
  1151. };
  1152.  
  1153. void() QuadCheat =
  1154. {
  1155.     if (deathmatch || coop)
  1156.         return;
  1157.     self.super_time = 1;
  1158.     self.super_damage_finished = time + 30;
  1159.     self.items = self.items | IT_QUAD;
  1160.     dprint ("quad cheat\n");
  1161. };
  1162.  
  1163. /*
  1164. ============
  1165. ImpulseCommands
  1166.  
  1167. ============
  1168. */
  1169.  
  1170. void()    JumpC;
  1171. void()    WizmarkC;
  1172. void()    LightC;
  1173. void()    ShockingC;
  1174. void()    BurningC;
  1175. void()    ColorsC;
  1176. void()    ArmorC;
  1177. void()    PforceC;
  1178. void()    MagicmC;
  1179.  
  1180. void() ImpulseCommands =
  1181. {
  1182.  
  1183. if (self.impulse == 110)
  1184.     JumpC();
  1185. if (self.impulse == 111)
  1186.     WizmarkC();
  1187. if (self.impulse == 112)
  1188.     LightC();
  1189. if (self.impulse == 113)
  1190.     ShockingC();
  1191. if (self.impulse == 114)
  1192.     BurningC();
  1193. if (self.impulse == 115)
  1194.     ColorsC();
  1195. if (self.impulse == 116)
  1196.     ArmorC();
  1197. if (self.impulse == 117)
  1198.     PforceC();
  1199. if (self.impulse == 118)
  1200.     MagicmC();
  1201.  
  1202.  
  1203.     if (self.impulse >= 1 && self.impulse <= 8)
  1204.         W_ChangeWeapon ();
  1205.  
  1206.     if (self.impulse == 9)
  1207.         CheatCommand ();
  1208.     if (self.impulse == 10)
  1209.         CycleWeaponCommand ();
  1210.     if (self.impulse == 11)
  1211.         ServerflagsCommand ();
  1212.  
  1213.     if (self.impulse == 255)
  1214.         QuadCheat ();
  1215.         
  1216.     self.impulse = 0;
  1217. };
  1218.  
  1219. /*
  1220. ============
  1221. W_WeaponFrame
  1222.  
  1223. Called every frame so impulse events can be handled as well as possible
  1224. ============
  1225. */
  1226. void() W_WeaponFrame =
  1227. {
  1228.     if (time < self.attack_finished)
  1229.         return;
  1230.  
  1231.     ImpulseCommands ();
  1232.     
  1233. // check for attack
  1234.     if (self.button0)
  1235.     {
  1236.         SuperDamageSound ();
  1237.         W_Attack ();
  1238.     }
  1239. };
  1240.  
  1241. /*
  1242. ========
  1243. SuperDamageSound
  1244.  
  1245. Plays sound if needed
  1246. ========
  1247. */
  1248. void() SuperDamageSound =
  1249. {
  1250.     if (self.super_damage_finished > time)
  1251.     {
  1252.         if (self.super_sound < time)
  1253.         {
  1254.             self.super_sound = time + 1;
  1255.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1256.         }
  1257.     }
  1258.     return;
  1259. };
  1260.  
  1261.  
  1262.