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