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