home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / kicking2 / weapons.qc < prev   
Encoding:
Text File  |  1996-07-29  |  27.7 KB  |  1,349 lines

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