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