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