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