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